Inheritance diagram for code::InitSmartPtr< X >:

The only difference is that on a default initialization, the InitSmartPtr does a new and thus, always creates a valid object.
Thus, many of the data accessors will be faster than SmartPtr when compiled without NDEBUG, simply because safety-assertions are not done.
Public Member Functions | |
| InitSmartPtr (X *p) | |
| Initialization with a valid pointer (non-zero) is the same. | |
| InitSmartPtr () | |
| Default initialization creates a new object. | |
| InitSmartPtr (const SmartPtr< X > &orig) | |
| Construction from a valid (non-zero) smart pointer is allowed. | |
| bool | is_ptr_valid () const |
| InitSmartPointers are always valid. | |
| bool | operator< (const InitSmartPtr< X > &other) const |
| To enable easy mapping of SmartPtrs of ordered objects to STL containers, the < operator is overloaded to compare the objects being pointed to. | |
| bool | is_stored_before (const InitSmartPtr< X > &other) const |
| In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances. | |
| X & | operator * () const |
| Use like a regular pointer; Unlike SmartPtr, doesn't assert, since all InitSmartPointers are always valid. | |
| X * | operator-> () const |
| Use like a regular pointer; Unlike SmartPtr, doesn't assert, since all InitSmartPointers are always valid. | |
| InitSmartPtr (X *p, int *n) | |
| Copy constructor out of the internal data of an already existing ptr. | |
| bool | is_unique () const |
| Is the pointed-to-object unique? | |
| int | copies () const |
| Returns number of references to this SmartPtr. | |
| SmartPtr< const X > | const_ptr () const |
| Will return a reference-counted pointer to const X, so that functions that promise not to change the object can ask for, and receive, SmartPtr<const X>. | |
| bool | operator< (const SmartPtr< X > &other) const |
| To enable easy mapping of SmartPtrs of ordered objects to STL containers, the < operator is overloaded to compare the objects being pointed to. | |
| bool | operator== (const SmartPtr< X > &other) const |
| To enable easy mapping of SmartPtrs of ordered objects to STL containers, the == operator is overloaded to compare the objects being pointed to. | |
| bool | is_stored_before (const SmartPtr< X > &other) const |
| In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances. | |
| template<class D> | |
| SmartPtr< D > | recast () |
| Recast this SmartPtr to the desired type. | |
| template<class D> | |
| SmartPtr< const D > | recast () const |
Public Attributes | |
| X * | ptr |
| Internal pointer storage. | |
| int * | numCopies |
| Internal number of copies storage. | |
| code::InitSmartPtr< X >::InitSmartPtr | ( | X * | p | ) | [inline] |
Initialization with a valid pointer (non-zero) is the same.
| code::InitSmartPtr< X >::InitSmartPtr | ( | ) | [inline] |
Default initialization creates a new object.
A default constructor is necessary.
| code::InitSmartPtr< X >::InitSmartPtr | ( | const SmartPtr< X > & | orig | ) | [inline] |
Construction from a valid (non-zero) smart pointer is allowed.
| code::InitSmartPtr< X >::InitSmartPtr | ( | X * | p, | |
| int * | n | |||
| ) | [inline] |
Copy constructor out of the internal data of an already existing ptr.
| SmartPtr<const X> code::SmartPtr< X >::const_ptr | ( | ) | const [inline, inherited] |
Will return a reference-counted pointer to const X, so that functions that promise not to change the object can ask for, and receive, SmartPtr<const X>.
| int code::SmartPtr< X >::copies | ( | ) | const [inline, inherited] |
Returns number of references to this SmartPtr.
| bool code::InitSmartPtr< X >::is_ptr_valid | ( | ) | const [inline] |
| bool code::SmartPtr< X >::is_stored_before | ( | const SmartPtr< X > & | other | ) | const [inline, inherited] |
In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances.
In that case, pointers need to be compared using is_stored_before()
When the objects themselves are ordered, you should be using the < operator.
| bool code::InitSmartPtr< X >::is_stored_before | ( | const InitSmartPtr< X > & | other | ) | const [inline] |
In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances.
In that case, pointers need to be compared using is_stored_before()
When the objects themselves are ordered, you should be using the < operator.
| bool code::SmartPtr< X >::is_unique | ( | ) | const [inline, inherited] |
Is the pointed-to-object unique?
You can use this function to determine whether there is anybody else holding references to this object.
| X& code::InitSmartPtr< X >::operator * | ( | ) | const [inline] |
Use like a regular pointer; Unlike SmartPtr, doesn't assert, since all InitSmartPointers are always valid.
Reimplemented from code::SmartPtr< X >.
Reimplemented in code::InitDerivedSmartPtr< BaseType, DerivedType >.
| X* code::InitSmartPtr< X >::operator-> | ( | ) | const [inline] |
Use like a regular pointer; Unlike SmartPtr, doesn't assert, since all InitSmartPointers are always valid.
Reimplemented from code::SmartPtr< X >.
Reimplemented in code::InitDerivedSmartPtr< BaseType, DerivedType >.
| bool code::SmartPtr< X >::operator< | ( | const SmartPtr< X > & | other | ) | const [inline, inherited] |
To enable easy mapping of SmartPtrs of ordered objects to STL containers, the < operator is overloaded to compare the objects being pointed to.
Hence, for this to be usable, the class X should have a < operator defined.
The behavior of the < and == operators is as follows:
In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances. In that case, pointers need to be compared. Use is_stored_before()
| bool code::InitSmartPtr< X >::operator< | ( | const InitSmartPtr< X > & | other | ) | const [inline] |
To enable easy mapping of SmartPtrs of ordered objects to STL containers, the < operator is overloaded to compare the objects being pointed to.
Hence, for this to be usable, the class X should have a < operator defined.
In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances. In that case, pointers need to be compared. Use is_stored_before()
| bool code::SmartPtr< X >::operator== | ( | const SmartPtr< X > & | other | ) | const [inline, inherited] |
To enable easy mapping of SmartPtrs of ordered objects to STL containers, the == operator is overloaded to compare the objects being pointed to.
Hence, for this to be usable, the class X should have a == operator defined.
The behavior of the < and == operators is as follows:
In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances. In that case, pointers need to be compared. Use is_stored_before()
| SmartPtr<const D> code::SmartPtr< X >::recast | ( | ) | const [inline, inherited] |
Recast this SmartPtr to the desired type.
An empty SmartPtr is returned if type conversion fails.
class A { ... }; class B: public A { ... }; class C: public B { ... }; class Unrelated { ... };
SmartPtr b = new C (); SmartPtr a = b.recast<A>(); // upcast SmartPtr<C> c = b.recast<C>(); // downcast assert (a.copies() == 3);
SmartPtr<Unrelated> u = b.recast<Unrelated>(); assert (!u.is_ptr_valid()); assert (a.copies() == 3);
int* code::SmartPtr< X >::numCopies [inherited] |
Internal number of copies storage.
DerivedSmartPtr has access.
X* code::SmartPtr< X >::ptr [inherited] |
Internal pointer storage.
DerivedSmartPtr has access.
1.4.7