| MULTIBODY SIMULATION SOFTWARE - API documentation |
#include <CHsmartpointers.h>
Public Types | |
| typedef T | element_type |
Public Member Functions | |
| ChSharedPtr (T *p=0) | |
| ChSharedPtr (const ChSharedPtr &r) throw () | |
| template<class T_other > | |
| ChSharedPtr (const ChSharedPtr< T_other > &r) throw () | |
| ~ChSharedPtr () | |
| operator bool () const | |
| ChSharedPtr & | operator= (const ChSharedPtr &r) |
| T & | operator* () throw () |
| const T & | operator* () const throw () |
| T * | operator-> () throw () |
| const T * | operator-> (void) const throw () |
| bool | IsUnique () const throw () |
| T * | get_ptr () const throw () |
| T * | get () const throw () |
| bool | IsNull () const throw () |
| void | SetNull () |
| template<class T_other > | |
| bool | IsType () |
Smart pointer to be used with generic objects to be shared among multiple pointers, without the risk of deleting the pointed instance too early, hence avoids dangling pointers. When compared to the ChSharedPtr, this is a faster version but requires that you use it only for data which is instanced from the ChShared class. It should be initialized in the following two main ways: ChSmartPtr<MyClass> foo_pointer(new MyClass); or ChSmartPtr<MyClass> foo_pointer(another_smart_pointer); Doing so, you will _never_ need to call 'delete', because the reference count mechanism will automatically delete the instance when no smart pointers reference it. This kind of pointer does not perform copy of pointed data when copied.
| chrono::ChSharedPtr< T >::ChSharedPtr | ( | T * | p = 0 | ) | [explicit] |
Constructor for initializing with dynamically allocated data, with new() Mandatory way of using it: ChSharedPtr<MyClass> pointerA(new MyClass); Thank to automatic reference counting, you never have to call delete()!
| chrono::ChSharedPtr< T >::ChSharedPtr | ( | const ChSharedPtr< T > & | r | ) | throw () |
Copy constructor for the case ChSharedPtr<MyClassA> pointerA(pointerB);
| chrono::ChSharedPtr< T >::ChSharedPtr | ( | const ChSharedPtr< T_other > & | r | ) | throw () |
Copy constructor and converter for the case ChSharedPtr<MyClassA> pointerA(pointerB); when pointerB comes from a class MyClassB which is inherited from MyClassA or viceversa. If casting is not possible, the created shared pointer is invalidated (IsNull() = true). Warnings! - upcast (MyClassA is parent of MyClassB) exactness and..
MyClassA & MyClassB MUST have virtual destructors, if you want to use casting!
| chrono::ChSharedPtr< T >::~ChSharedPtr | ( | ) |
Destructor decrements the reference count and automatically delete only when the last reference is destroyed
| T* chrono::ChSharedPtr< T >::get_ptr | ( | ) | const throw () |
Returns the raw pointer to pointed instance. Note: If a correct programming style is used, you should never need to use this.
| bool chrono::ChSharedPtr< T >::IsNull | ( | ) | const throw () |
Occasionally, the shared pointer can be invalidated (unbound from object), for instance if you create it with null default ChSharedPtr<MyClass> pointerA; instead of typical ChSharedPtr<MyClass> pointerA(new MyClass);
Tells if the referenced object is inherited from a specific class and can be cast with copy constructor, for example if (ptrA.IsType<classB>() ) { ChSharedPtr<classB> ptrB (ptrA); }
| chrono::ChSharedPtr< T >::operator bool | ( | ) | const |
Bool type casting, true if the pointer is still bound to an object, or false if unbound and invalidated (ex. after unsuccesfull casting). Example: if(mysharedptr) {...}
| T* chrono::ChSharedPtr< T >::operator-> | ( | ) | throw () |
Used for member access to the contained object, e.g. pointer->Print() calls T::Print()
| void chrono::ChSharedPtr< T >::SetNull | ( | ) |
Unbind the shared pointer from referenced shared object, and automatically delete in case of last reference. It should be used sparingly, because this unbinding already happens automatically when the shared pointer dies. Use this only to 'force' premature unbinding.
CHRONO::ENGINE