MULTIBODY SIMULATION SOFTWARE - API documentation

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


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. Suggested way of using it: ChSharedPtr<MyClass> pointerA(new MyClass);

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. Warnings! - check on MyClassB being really inherited from MyClassB is done in runtime (debug version only!) via assert() and dynamic cast, so MyClassA & MyClassB must be polimorphic.

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>
ChSharedPtr& chrono::ChSharedPtr< T >::operator= ( const ChSharedPtr< T > &  r  ) 

Assignment form for an already-constructed smart-pointer.

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

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

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>
bool chrono::ChSharedPtr< T >::IsUnique (  )  const throw ()

Tells if this is shared by no one else.

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.


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