MULTIBODY SIMULATION SOFTWARE - API documentation

chrono::ChSmartPtr< T > Class Template Reference

#include <CHsmartpointers.h>

List of all members.

Public Types

typedef T element_type

Public Member Functions

 ChSmartPtr (T *p=0)
 ChSmartPtr (const ChSmartPtr &r) throw ()
template<class T_other>
 ChSmartPtr (const ChSmartPtr< T_other > &r) throw ()
 ~ChSmartPtr ()
ChSmartPtroperator= (const ChSmartPtr &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 ()


Detailed Description

template<class T>
class chrono::ChSmartPtr< 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. It does not need that instances are inherited from ChShared because it uses an auxiliary reference counter which is allocated on heap). 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::ChSmartPtr< T >::ChSmartPtr ( T *  p = 0  )  [explicit]

Constructor for initializing with dynamically allocated data. Suggested way of using it: ChSmartPtr<MyClass> pointerA(new MyClass);

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

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

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

Copy constructor and converter for the case ChSmartPtr<MyClassA> pointerA(pointerB); when pointerB comes from a class MyClassB which is inherited from MyClassA. Warnings! - no check on MyClassB being really inherited from MyClassB,

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

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


Member Function Documentation

template<class T>
ChSmartPtr& chrono::ChSmartPtr< T >::operator= ( const ChSmartPtr< T > &  r  ) 

Assignment form for an already-constructed smart-pointer.

template<class T>
T& chrono::ChSmartPtr< T >::operator * (  )  throw ()

Dereference the smart pointer to get the object, as in the form *p1.

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

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

template<class T>
bool chrono::ChSmartPtr< T >::IsUnique (  )  const throw ()

Tells if this is shared by no one else.

template<class T>
T* chrono::ChSmartPtr< 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.


CHRONO::ENGINE
C++ library for multibody simulation, (C) Alessandro Tasora
This API documentation has been generated on 17 Jul 2009 by Doxygen