Smart pointer for any class inheriting SoRefCounter. More...
#include <Inventor/misc/SoRef.h>
Public Member Functions | |
SoRef () | |
Default constructor. | |
SoRef (const SoRef< T > &that) | |
Copy constructor. | |
SoRef (T *pIn) | |
Construct from C++ pointer. | |
template<typename Y > | |
SoRef (const SoRef< Y > &that) | |
Construct from another SoRef. | |
T * | releaseNoDelete () |
Release reference and return the object stored. | |
SoRef< T > & | operator= (const SoRef< T > &that) |
Assign another SoRef . | |
template<typename Y > | |
SoRef< T > & | operator= (const SoRef< Y > &that) |
Assign to another SoRef if the types are assignable (from derived to base classes). | |
SoRef< T > & | operator= (T *ptr) |
Assign ordinary C pointer. | |
T & | operator* () const |
Dereference pointer. | |
T * | operator-> () const |
Cast to C pointer. | |
T * | ptr () const |
Cast to C pointer. | |
Public Member Functions inherited from SoAutoRef | |
SoAutoRef () | |
Default constructor. | |
SoAutoRef (const SoAutoRef &that) | |
Copy constructor. | |
SoAutoRef (SoRefCounter *pIn) | |
Construct from C++ pointer. | |
~SoAutoRef () | |
Destructor. | |
SoAutoRef & | operator= (const SoAutoRef &that) |
Assign another SoAutoRef . | |
SoAutoRef & | operator= (SoRefCounter *ptr) |
Assign ordinary C pointer. | |
bool | operator== (const SoAutoRef &other) const |
bool | operator!= (const SoAutoRef &other) const |
bool | operator< (const SoAutoRef &other) const |
bool | operator<= (const SoAutoRef &other) const |
bool | operator> (const SoAutoRef &other) const |
bool | operator>= (const SoAutoRef &other) const |
bool | operator== (const SoRefCounter *ptr) const |
bool | operator!= (const SoRefCounter *ptr) const |
bool | operator< (const SoRefCounter *ptr) const |
bool | operator<= (const SoRefCounter *ptr) const |
bool | operator> (const SoRefCounter *ptr) const |
bool | operator>= (const SoRefCounter *ptr) const |
operator bool () const | |
Conversion to boolean. | |
bool | operator! () const |
NOT operator. | |
SoRefCounter & | operator* () const |
Dereference pointer. | |
SoRefCounter * | operator-> () const |
Cast to C pointer. | |
SoRefCounter * | ptr () const |
Cast to C pointer. | |
Smart pointer for any class inheriting SoRefCounter.
This class implements a smart pointer for any reference counted class (class that inherits SoRefCounter). This includes nodes, engines, paths, buffer objects and others. We strongly recommend using SoRef to manage the life span of these objects (instead of the old style ref() and unref() methods).
The reference count of the managed object is automatically incremented when the SoRef is created and then decremented when the SoRef is destroyed, for example by going out of scope, or when 'null' is assigned to the SoRef object. If this decrement changes the managed object's reference count to zero, the managed object is destroyed.
For example SoRef allows a reference counted object to be safely cleaned up when it goes out of scope in a local block, as shown in the example below.
You can also explicitly cleanup a reference counted object like this:
Generally, in a function, you should not use SoRef on a reference counted object that will be returned by the function. In this case the calling code would receive a pointer to an invalid object after the SoRef goes out of scope and unref's the object.
Note that implicit casting to a pointer is not supported. So when a method expects a pointer, for example addChild(), you must use the explicit ptr() method. For example:
|
inline |
|
inline |
|
inline |
|
inline |