Inheritance diagram for code::DerivedSmartPtr< BaseType, DerivedType >:
All the functions are overloaded to return the derived type.
Public Member Functions | |
DerivedSmartPtr () | |
Default constructor, creates an invalid pointer; Do not dereference objects created using the default constructor. | |
DerivedSmartPtr (DerivedType *p) | |
Think of a DerivedSmartPtr as holding a pointer to DerivedType, i.e. | |
DerivedSmartPtr (SmartPtr< DerivedType > orig) | |
Think of a DerivedSmartPtr as holding a pointer to DerivedType, i.e. | |
DerivedSmartPtr (SmartPtr< BaseType > orig) | |
Think of a DerivedSmartPtr as holding a pointer to DerivedType, i.e. | |
SmartPtr< DerivedType > | getDerivedType () |
To obtain a derived object pointer. | |
bool | operator< (const DerivedSmartPtr< BaseType, DerivedType > &other) const |
To enable easy mapping of SmartPtrs to STL containers, we overload the < operator. | |
DerivedType & | operator * () const |
Like a regular pointer; Asserts to make sure the pointer is not NULL. | |
DerivedType * | operator-> () const |
Like a regular pointer; Asserts to make sure the pointer is not NULL. | |
bool | is_unique () const |
Is the pointed-to-object unique? | |
int | copies () const |
Returns number of references to this SmartPtr. | |
bool | is_ptr_valid () const |
Is the pointer that we are holding valid? | |
SmartPtr< const BaseType > | 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< BaseType > &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< BaseType > &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< BaseType > &other) const |
In some cases, it makes no sense for the objects themselves to be ordered; yet, you might want simply unique instances. | |
SmartPtr< D > | recast () |
Recast this SmartPtr to the desired type. | |
SmartPtr< const D > | recast () const |
Public Attributes | |
BaseType * | ptr |
Internal pointer storage. | |
int * | numCopies |
Internal number of copies storage. |
code::DerivedSmartPtr< BaseType, DerivedType >::DerivedSmartPtr | ( | ) | [inline] |
Default constructor, creates an invalid pointer; Do not dereference objects created using the default constructor.
code::DerivedSmartPtr< BaseType, DerivedType >::DerivedSmartPtr | ( | DerivedType * | p | ) | [inline] |
Think of a DerivedSmartPtr as holding a pointer to DerivedType, i.e.
as a SmartPtr< DerivedType >
A DerivedType* is a BaseType* also.
It is implemented as a subclass of BaseType to make virtual overloading possible.
code::DerivedSmartPtr< BaseType, DerivedType >::DerivedSmartPtr | ( | SmartPtr< DerivedType > | orig | ) | [inline] |
Think of a DerivedSmartPtr as holding a pointer to DerivedType, i.e.
as a SmartPtr< DerivedType >
A DerivedType* is a BaseType* also.
It is implemented as a subclass of BaseType to make virtual overloading possible.
code::DerivedSmartPtr< BaseType, DerivedType >::DerivedSmartPtr | ( | SmartPtr< BaseType > | orig | ) | [inline] |
Think of a DerivedSmartPtr as holding a pointer to DerivedType, i.e.
as a SmartPtr< DerivedType >
The dynamic downcast to DerivedType is done on access.
SmartPtr<const BaseType > code::SmartPtr< BaseType >::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< BaseType >::copies | ( | ) | const [inline, inherited] |
Returns number of references to this SmartPtr.
SmartPtr< DerivedType > code::DerivedSmartPtr< BaseType, DerivedType >::getDerivedType | ( | ) | [inline] |
To obtain a derived object pointer.
This is faster than keeping around the DerivedSmartPtr object.
bool code::SmartPtr< BaseType >::is_ptr_valid | ( | ) | const [inline, inherited] |
Is the pointer that we are holding valid?
Note that this is a test only on whether the pointer is valid. There is no test of whether the object is valid; Usually objects that require initialization, etc. will have a isValid() member function. To prevent typographical errors, the name of this function is different. Just because the pointer is valid doesn't mean that the object is valid.
Use this function to check the return value from a function that promises to return a SmartPtr to something. The SmartPtr will hold an invalid pointer on error.
Reimplemented in code::InitSmartPtr< BaseType >.
bool code::SmartPtr< BaseType >::is_stored_before | ( | const SmartPtr< BaseType > & | 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::SmartPtr< BaseType >::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.
DerivedType& code::DerivedSmartPtr< BaseType, DerivedType >::operator * | ( | ) | const [inline] |
Like a regular pointer; Asserts to make sure the pointer is not NULL.
Reimplemented from code::SmartPtr< BaseType >.
DerivedType* code::DerivedSmartPtr< BaseType, DerivedType >::operator-> | ( | ) | const [inline] |
Like a regular pointer; Asserts to make sure the pointer is not NULL.
Reimplemented from code::SmartPtr< BaseType >.
bool code::SmartPtr< BaseType >::operator< | ( | const SmartPtr< BaseType > & | 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::DerivedSmartPtr< BaseType, DerivedType >::operator< | ( | const DerivedSmartPtr< BaseType, DerivedType > & | other | ) | const [inline] |
To enable easy mapping of SmartPtrs to STL containers, we overload the < operator.
The meaning of < is to compare the objects being pointed to. Hence, for this to be usable, the class X should have a < operator defined.
bool code::SmartPtr< BaseType >::operator== | ( | const SmartPtr< BaseType > & | 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< BaseType >::recast | ( | ) | const [inline, inherited] |
SmartPtr<D> code::SmartPtr< BaseType >::recast | ( | ) | [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< BaseType >::numCopies [inherited] |
Internal number of copies storage.
DerivedSmartPtr has access.
BaseType * code::SmartPtr< BaseType >::ptr [inherited] |
Internal pointer storage.
DerivedSmartPtr has access.