MULTIBODY SIMULATION SOFTWARE - API documentation
Public Types | Public Member Functions
chrono::ChSharedPtr< T > Class Template Reference

#include <CHsmartpointers.h>

List of all members.

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
ChSharedPtroperator= (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 ()

Detailed Description

template<class T>
class chrono::ChSharedPtr< T >

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.


Constructor & Destructor Documentation

template<class T>
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()!

template<class T>
chrono::ChSharedPtr< T >::ChSharedPtr ( const ChSharedPtr< T > &  r) throw ()

Copy constructor for the case ChSharedPtr<MyClassA> pointerA(pointerB);

template<class T>
template<class T_other >
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..

  • downcast (MyClassA is child of MyClassB) exactness is done in runtime with dynamic_cast; MyClassA & MyClassB must be polimorphic.

MyClassA & MyClassB MUST have virtual destructors, if you want to use casting!

template<class T>
chrono::ChSharedPtr< T >::~ChSharedPtr ( )

Destructor decrements the reference count and automatically delete only when the last reference is destroyed


Member Function Documentation

template<class T>
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.

template<class T>
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);

template<class T>
template<class T_other >
bool chrono::ChSharedPtr< T >::IsType ( )

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); }

template<class T>
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) {...}

template<class T>
T* chrono::ChSharedPtr< T >::operator-> ( ) throw ()

Used for member access to the contained object, e.g. pointer->Print() calls T::Print()

template<class T>
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
C++ library for multibody simulation, (C) Alessandro Tasora
This API documentation has been generated on Tue Jul 10 2012 by Doxygen