Blender V2.61 - r43446
|
#include <MEM_SmartPtr.h>
Public Member Functions | |
MEM_SmartPtr (const MEM_SmartPtr &rhs) | |
MEM_SmartPtr (T *val) | |
MEM_SmartPtr () | |
operator T * () const | |
T & | Ref () const |
MEM_SmartPtr & | operator= (const MEM_SmartPtr &rhs) |
T * | operator-> () const |
T * | Release () const |
void | Delete () |
~MEM_SmartPtr () |
This class defines a smart pointer similar to that defined in the Standard Template Library but without the painful get() semantics to access the internal c style pointer.
It is often useful to explicitly declare ownership of memory allocated on the heap within class or function scope. This class helps you to encapsulate this ownership within a value type. When an instance of this class goes out of scope it makes sure that any memory associated with it's internal pointer is deleted. It can help to inform users of an aggregate class that it owns instances of it's members and these instances should not be shared. This is not reliably enforceable in C++ but this class attempts to make the 1-1 relationship clear.
class foo { ...constructors accessors etc. int x[1000]; }
class bar { public : static bar * New( ) { MEM_SmartPtr<foo> afoo = new foo(); MEM_SmartPtr<bar> that = new bar();
if (foo == NULL || that == NULL) return NULL;
that->m_foo = afoo.Release(); return that.Release(); }
~bar() { // smart ptr takes care of deletion } private : MEM_SmartPtr<foo> m_foo; }
You may also safely construct vectors of MEM_SmartPtrs and have the vector own stuff you put into it.
e.g. { std::vector<MEM_SmartPtr<foo> > foo_vector; foo_vector.push_back( new foo()); foo_vector.push_back( new foo());
foo_vector[0]->bla(); } // foo_vector out of scope => heap memory freed for both foos
Definition at line 111 of file MEM_SmartPtr.h.
MEM_SmartPtr< T >::MEM_SmartPtr | ( | const MEM_SmartPtr< T > & | rhs | ) | [inline] |
Construction from reference - this class always assumes ownership from the rhs.
Definition at line 120 of file MEM_SmartPtr.h.
MEM_SmartPtr< T >::MEM_SmartPtr | ( | T * | val | ) | [inline] |
Construction from ptr - this class always assumes that it now owns the memory associated with the ptr.
Definition at line 132 of file MEM_SmartPtr.h.
MEM_SmartPtr< T >::MEM_SmartPtr | ( | ) | [inline] |
Defalut constructor
Definition at line 143 of file MEM_SmartPtr.h.
MEM_SmartPtr< T >::~MEM_SmartPtr | ( | ) | [inline] |
Destructor - deletes object if it exists
Definition at line 229 of file MEM_SmartPtr.h.
void MEM_SmartPtr< T >::Delete | ( | ) | [inline] |
Force destruction of the internal object.
Definition at line 219 of file MEM_SmartPtr.h.
MEM_SmartPtr< T >::operator T * | ( | ) | const [inline] |
Type conversion from this class to the type of a pointer to the template parameter. This means you can pass an instance of this class to a function expecting a ptr of type T.
Definition at line 156 of file MEM_SmartPtr.h.
T* MEM_SmartPtr< T >::operator-> | ( | ) | const [inline] |
Overload the operator -> so that it's possible to access all the normal methods of the internal ptr.
Definition at line 197 of file MEM_SmartPtr.h.
MEM_SmartPtr& MEM_SmartPtr< T >::operator= | ( | const MEM_SmartPtr< T > & | rhs | ) | [inline] |
Assignment operator - ownership is transfered from rhs to lhs. There is an intenional side-effect of function of transferring ownership from the const parameter rhs. This is to insure the 1-1 relationship. The object associated with this instance is deleted if it is not the same as that contained in the rhs.
Definition at line 181 of file MEM_SmartPtr.h.
T& MEM_SmartPtr< T >::Ref | ( | ) | const [inline] |
Return a reference to the internal ptr class. Use with care when you now that the internal ptr is not NULL!
Definition at line 167 of file MEM_SmartPtr.h.
Referenced by LOD_FaceNormalEditor::BuildNormals(), LOD_ExternNormalEditor::BuildNormals(), LOD_DecimationClass::Decimator(), LOD_ManMesh2::EdgeSet(), LOD_DecimationClass::FaceEditor(), LOD_ManMesh2::FaceSet(), LOD_DecimationClass::Mesh(), LOD_DecimationClass::New(), LOD_FaceNormalEditor::Normals(), LOD_ExternNormalEditor::Normals(), LOD_ExternNormalEditor::Remove(), LOD_FaceNormalEditor::Remove(), LOD_FaceNormalEditor::RemoveVertexNormals(), LOD_ExternNormalEditor::Update(), LOD_FaceNormalEditor::Update(), LOD_FaceNormalEditor::UpdateVertexNormals(), LOD_FaceNormalEditor::VertexNormals(), and LOD_ManMesh2::VertexSet().
T* MEM_SmartPtr< T >::Release | ( | void | ) | const [inline] |
Caller takes ownership of the object - the object will not be deleted when the ptr goes out of scope.
Definition at line 207 of file MEM_SmartPtr.h.
Referenced by LOD_LoadMesh(), MEM_SmartPtr< GlutMouseManager >::MEM_SmartPtr(), MyGlutMouseHandler::New(), MyGlutKeyHandler::New(), LOD_QuadricEditor::New(), LOD_QSDecimator::New(), LOD_MeshBounds::New(), LOD_ManMesh2::New(), LOD_FaceNormalEditor::New(), LOD_ExternNormalEditor::New(), LOD_DecimationClass::New(), and MEM_SmartPtr< GlutMouseManager >::operator=().