CFx SDK Documentation  2023 SP0
Public Member Functions | Protected Member Functions | List of all members
OdSmartPtr< T > Class Template Reference

#include <SmartPtr.h>

Inheritance diagram for OdSmartPtr< T >:
OdBaseObjectPtr OdApcObjectPoolHelper< TObject, TInitFn >

Public Member Functions

 OdSmartPtr ()
 
 OdSmartPtr (const T *pObject, OdRxObjMod)
 
 OdSmartPtr (const T *pObject)
 
 OdSmartPtr (const OdRxObject *pObject)
 
 OdSmartPtr (OdRxObject *pObject, OdRxObjMod)
 
 OdSmartPtr (const OdSmartPtr &pObject)
 
 OdSmartPtr (const OdRxObjectPtr &pObject)
 
 OdSmartPtr (const OdBaseObjectPtr &pObject)
 
void attach (const T *pObject)
 
void attach (OdRxObject *pObject)
 
 ~OdSmartPtr ()
 
void release ()
 
T * detach ()
 
OdSmartPtroperator= (const OdSmartPtr &pObject)
 
OdSmartPtroperator= (const OdBaseObjectPtr &pObject)
 
OdSmartPtroperator= (const T *pObject)
 
const T * get () const
 
T * get ()
 
T * operator-> ()
 
const T * operator-> () const
 
 operator T* ()
 
 operator const T * () const
 
bool operator== (const void *pObject) const
 
bool operator== (const OdSmartPtr &pObject) const
 
bool operator!= (const void *pObject) const
 
bool operator!= (const OdSmartPtr &pObject) const
 
- Public Member Functions inherited from OdBaseObjectPtr
OdRxObjectget () const
 
bool isNull () const
 

Protected Member Functions

void internalAddRef ()
 
void assign (const T *pObject)
 
void internalQueryX (const OdRxObject *pObject)
 
void assign (const OdRxObject *pObject)
 
bool operator! () const
 
 operator bool () const
 
 operator bool ()
 
- Protected Member Functions inherited from OdBaseObjectPtr
 OdBaseObjectPtr ()
 
 OdBaseObjectPtr (const OdRxObject *pSource)
 

Additional Inherited Members

- Protected Attributes inherited from OdBaseObjectPtr
OdRxObjectm_pObject
 

Detailed Description

template<class T>
class OdSmartPtr< T >

<group Other_Classes>

This template class provides the typified implementation of smart pointers for instances of classes derived from the OdRxObject class.

Remarks
SmartPointers relieve the programmer of having to determine when objects are no longer needed, or having to delete them them at that time.

Each object referenced by a SmartPointer (henceforth 'referenced object') maintains a reference count; i.e., how many SmartPointers are referencing it. When the reference count reaches zero, the referenced object is deleted.

See also
TD_Db
<link smart_pointers_example_refexchange.html, Example of Assigning Smart Pointers>

<link smart_pointers_example_typified.html, Example of a Typified Smart Pointer>

See also
<link smart_pointers_overview.html, Overview of Smart Pointer Classes>

The OdRxObjectPtr class

Definition at line 57 of file SmartPtr.h.

Constructor & Destructor Documentation

◆ OdSmartPtr() [1/8]

template<class T >
OdSmartPtr< T >::OdSmartPtr ( )
inline

Constructors for the typified smart pointer.

Parameters
pObject[in] Pointer to the object to be assigned to the new SmartPointer object.
Remarks
If pObject is specified, the smart pointer is set to the address of the specified object. If pObject is not specified, the smart pointer is set to a NULL.
If OdRxObjMod or const OdBaseObjectPtr& are specified, the reference counter of the specified object is not incremented.

Definition at line 153 of file SmartPtr.h.

◆ OdSmartPtr() [2/8]

template<class T >
OdSmartPtr< T >::OdSmartPtr ( const T *  pObject,
OdRxObjMod   
)
inline

Definition at line 158 of file SmartPtr.h.

◆ OdSmartPtr() [3/8]

template<class T >
OdSmartPtr< T >::OdSmartPtr ( const T *  pObject)
inline

Definition at line 163 of file SmartPtr.h.

◆ OdSmartPtr() [4/8]

template<class T >
OdSmartPtr< T >::OdSmartPtr ( const OdRxObject pObject)
inline

Definition at line 169 of file SmartPtr.h.

◆ OdSmartPtr() [5/8]

template<class T >
OdSmartPtr< T >::OdSmartPtr ( OdRxObject pObject,
OdRxObjMod   
)
inline

Definition at line 175 of file SmartPtr.h.

◆ OdSmartPtr() [6/8]

template<class T >
OdSmartPtr< T >::OdSmartPtr ( const OdSmartPtr< T > &  pObject)
inline

Definition at line 183 of file SmartPtr.h.

◆ OdSmartPtr() [7/8]

template<class T >
OdSmartPtr< T >::OdSmartPtr ( const OdRxObjectPtr pObject)
inline

Definition at line 189 of file SmartPtr.h.

◆ OdSmartPtr() [8/8]

template<class T >
OdSmartPtr< T >::OdSmartPtr ( const OdBaseObjectPtr pObject)
inline

Definition at line 195 of file SmartPtr.h.

◆ ~OdSmartPtr()

template<class T >
OdSmartPtr< T >::~OdSmartPtr ( )
inline

Destructor for the typified smart pointer.

Remarks
Decrements the reference counter of the referenced object. When the reference count reaches zero, the referenced object is deleted.

Definition at line 249 of file SmartPtr.h.

Member Function Documentation

◆ assign() [1/2]

template<class T >
void OdSmartPtr< T >::assign ( const OdRxObject pObject)
inlineprotected

Definition at line 110 of file SmartPtr.h.

◆ assign() [2/2]

template<class T >
void OdSmartPtr< T >::assign ( const T *  pObject)
inlineprotected

Assigns the pointer of specified object to the smart pointer.

Remarks
The reference counter of the specified object is incremented.

If this SmartPointer is currently referencing another object, that object is released prior to the assignment.

Parameters
pObject[in] Pointer to the specified object to be assigned.

Definition at line 80 of file SmartPtr.h.

◆ attach() [1/2]

template<class T >
void OdSmartPtr< T >::attach ( const T *  pObject)
inline

Assigns the pointer of the specifed object to the smart pointer without incrementing its reference counter.

Parameters
pObject[in] Pointer to the specifed object to be assigned.
Remarks
The reference counter of the specified object is not incremented.

If the smart pointer is currently referencing to another object, that object is released prior to the assignment.

See also
<link smart_pointers_example_typified.html, Example of a Typified Smart Pointer>

Definition at line 215 of file SmartPtr.h.

◆ attach() [2/2]

template<class T >
void OdSmartPtr< T >::attach ( OdRxObject pObject)
inline

Assigns the pointer of the specifed object to the smart pointer without incrementing its reference counter.

Parameters
pObject[in] Pointer to the specifed object to be assigned.
Remarks
The reference counter of the specified object is not incremented.

If the smart pointer is currently referencing to another object, that object is released prior to the assignment.

See also
<link smart_pointers_example_typified.html, Example of a Typified Smart Pointer>

Definition at line 235 of file SmartPtr.h.

◆ detach()

template<class T >
T* OdSmartPtr< T >::detach ( )
inline

Releases the smart pointer reference to the referenced object without decrementing of the reference counter.

Returns
Returns the raw pointer to the referenced object. The reference counter is not modified for the referenced object. Smart pointer is set to a NULL.
See also
<link smart_pointers_example_typified.html, Example of a Typified Smart Pointer>

Definition at line 283 of file SmartPtr.h.

◆ get() [1/2]

template<class T >
T* OdSmartPtr< T >::get ( )
inline

Returns the raw pointer to the referenced object.

Remarks
The smart pointer maintains its reference to the referenced object. The reference counter of the referenced object is not changed.
See also
<link smart_pointers_example_typified.html, Example of a Typified Smart Pointer>

Definition at line 341 of file SmartPtr.h.

◆ get() [2/2]

template<class T >
const T* OdSmartPtr< T >::get ( ) const
inline

Returns the raw pointer to the referenced object.

Remarks
The smart pointer maintains its reference to the referenced object. The reference counter of the referenced object is not changed.
See also
<link smart_pointers_example_typified.html, Example of a Typified Smart Pointer>

Definition at line 326 of file SmartPtr.h.

◆ internalAddRef()

template<class T >
void OdSmartPtr< T >::internalAddRef ( )
inlineprotected

Increments the reference counter of the referenced object.

Definition at line 63 of file SmartPtr.h.

◆ internalQueryX()

template<class T >
void OdSmartPtr< T >::internalQueryX ( const OdRxObject pObject)
inlineprotected

Performs a "safe" assignment of the specified object to this SmartPointer object.

Parameters
pObject[in] Pointer to the object to be assigned.

Throws: eNotThatKindOfClass if not successful.

Definition at line 98 of file SmartPtr.h.

◆ operator bool() [1/2]

template<class T >
OdSmartPtr< T >::operator bool ( )
inlineprotected

Declared private to prevent use.

Remarks
Use of SmartPtr<T> as a bool expression produces ambiguous calls with some compilers. Use isNull() instead.

Definition at line 138 of file SmartPtr.h.

◆ operator bool() [2/2]

template<class T >
OdSmartPtr< T >::operator bool ( ) const
inlineprotected

Declared private to prevent use.

Remarks
Use of SmartPtr<T> as a bool expression produces ambiguous calls with some compilers. Use isNull() instead.

Definition at line 131 of file SmartPtr.h.

◆ operator const T *()

template<class T >
OdSmartPtr< T >::operator const T * ( ) const
inline

Definition at line 394 of file SmartPtr.h.

◆ operator T*()

template<class T >
OdSmartPtr< T >::operator T* ( )
inline

Returns the raw pointer the referenced object.

Remarks
This SmartPointer maintains its reference to the referenced object.

The reference counter of the referenced object is not changed.

Definition at line 389 of file SmartPtr.h.

◆ operator!()

template<class T >
bool OdSmartPtr< T >::operator! ( ) const
inlineprotected

Declared private to prevent use.

Remarks
Use of SmartPtr<T> as a bool expression produces ambiguous calls with some compilers. Use isNull() instead.

Definition at line 124 of file SmartPtr.h.

◆ operator!=() [1/2]

template<class T >
bool OdSmartPtr< T >::operator!= ( const OdSmartPtr< T > &  pObject) const
inline

Definition at line 416 of file SmartPtr.h.

◆ operator!=() [2/2]

template<class T >
bool OdSmartPtr< T >::operator!= ( const void pObject) const
inline

Definition at line 411 of file SmartPtr.h.

◆ operator->() [1/2]

template<class T >
T* OdSmartPtr< T >::operator-> ( )
inline

Returns the raw pointer to the referenced object.

Remarks
The reference counter of the referenced object is not changed.

Definition at line 352 of file SmartPtr.h.

◆ operator->() [2/2]

template<class T >
const T* OdSmartPtr< T >::operator-> ( ) const
inline

Returns the raw pointer to the referenced object.

Remarks
The reference counter of the referenced object is not changed.

Definition at line 362 of file SmartPtr.h.

◆ operator=() [1/3]

template<class T >
OdSmartPtr& OdSmartPtr< T >::operator= ( const OdBaseObjectPtr pObject)
inline

Definition at line 304 of file SmartPtr.h.

◆ operator=() [2/3]

template<class T >
OdSmartPtr& OdSmartPtr< T >::operator= ( const OdSmartPtr< T > &  pObject)
inline
Remarks
The assignment operator increments the reference counter of the referenced object and saves its address in the smart pointer. If the smart pointer is currently referencing to another object, that assignment operator releases the referenced object prior to the assignment.
See also
<link smart_pointers_example_typified.html, Example of a Typified Smart Pointer>

Definition at line 298 of file SmartPtr.h.

◆ operator=() [3/3]

template<class T >
OdSmartPtr& OdSmartPtr< T >::operator= ( const T *  pObject)
inline

Definition at line 310 of file SmartPtr.h.

◆ operator==() [1/2]

template<class T >
bool OdSmartPtr< T >::operator== ( const OdSmartPtr< T > &  pObject) const
inline

Definition at line 406 of file SmartPtr.h.

◆ operator==() [2/2]

template<class T >
bool OdSmartPtr< T >::operator== ( const void pObject) const
inline

Definition at line 401 of file SmartPtr.h.

◆ release()

template<class T >
void OdSmartPtr< T >::release ( )
inline

Releases the smart pointer reference to the referenced object.

Remarks
Decrements the reference counter of the referenced object. When the reference count reaches zero, the referenced object is deleted. Smart pointer is set to a NULL.
See also
<link smart_pointers_example_typified.html, Example of a Typified Smart Pointer>

Definition at line 264 of file SmartPtr.h.


The documentation for this class was generated from the following files: