Teamcenter C++ API Reference  2312
Public Member Functions | Protected Attributes | Private Member Functions | List of all members
Teamcenter::scoped_smptr< T, F > Class Template Reference

Template class that stores a pointer pointing to memory allocated using some SM (Storage Management module from NX) allocation API. It ensures that memory is freed automatically when the instance of this class goes out of scope. More...

#include <ScopedSmPtr.hxx>

Public Member Functions

T * get () const
 
T *& getReference ()
 
const T * getString () const
 
bool operator! () const
 
bool operator!= (const T *t) const
 
T ** operator& ()
 
T & operator* () const
 
T * operator-> () const
 
scoped_smptroperator= (T *ptr)
 
bool operator== (const T *t) const
 
const T & operator[] (std::size_t inx) const
 
T & operator[] (std::size_t inx)
 
const T & operator[] (int inx) const
 
T & operator[] (int inx)
 
const T & operator[] (unsigned int inx) const
 
T & operator[] (unsigned int inx)
 
const T & operator[] (short inx) const
 
T & operator[] (short inx)
 
const T & operator[] (long inx) const
 
T & operator[] (long inx)
 
T * release ()
 
 scoped_smptr (T *b=0)
 
virtual ~scoped_smptr ()
 

Protected Attributes

T * bucket
 

Private Member Functions

scoped_smptroperator= (const scoped_smptr &)
 
 scoped_smptr (const scoped_smptr &)
 

Detailed Description

template<class T, class F = scoped_smptr_my_deallocator< T >>
class Teamcenter::scoped_smptr< T, F >

Template class that stores a pointer pointing to memory allocated using some SM (Storage Management module from NX) allocation API. It ensures that memory is freed automatically when the instance of this class goes out of scope.

Things to be aware of when using scoped_smptr

Allocation scheme: scoped_smptr requires that memory be allocated via SM (Storage Management module from NX) API (e.g. MEM_alloc, etc.).
2) scoped_smptr cannot be used for a class which uses SM memory via 'operator new' override.
Though the memory may be freed OK, the destructor wont be called and may lead to issues.

Example

// example.
// allocate some SM memory
void allocateSomeSmMemory( int** ptr )
{
*ptr = (int*) MEM_alloc( 10 * sizeof( int ) );
}
void fooAcceptsIntPtr( const int* ptr )
{
[...]
}
void incorrectUsage()
{
int* ptr0 = 0;
// scoped_smptr internally stores the value of supplied pointer and uses it for cleanup when it goes out of scope.
// As the value of 'ptr0' is 0, the value stored internally by 'smptr' is 0.
scoped_smptr< int > smptr( ptr0 );
allocateSomeSmMemory( &ptr0 ); // 'smptr' is not aware about this allocation. This leads to a memory leak!
}
// scoped_ptr can be used just like a normal pointer.
// It is best to avoid using two named variables (one for the normal pointer and other scoped_smptr) and
// use the scoped_smptr just like normal pointer.
void recommendedUsage()
{
scoped_smptr< int > smptr;
allocatedDummy( &smptr );
// use like a normal pointer.
smptr[0] = 1;
// pass around like a normal pointer.
fooAcceptsIntPtr( smptr );
}

Definition at line 89 of file ScopedSmPtr.hxx.

Constructor & Destructor Documentation

template<class T, class F = scoped_smptr_my_deallocator< T >>
Teamcenter::scoped_smptr< T, F >::scoped_smptr ( T *  b = 0)
inlineexplicit

Constructor. Note that no conversion will be allowed: the pointer needs to be of the specified type (T).

Definition at line 96 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
virtual Teamcenter::scoped_smptr< T, F >::~scoped_smptr ( )
inlinevirtual

Default destructor. It also deletes the object to which it points.

Definition at line 101 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
Teamcenter::scoped_smptr< T, F >::scoped_smptr ( const scoped_smptr< T, F > &  )
private

Prevention of usage of the copy constructor.

Member Function Documentation

template<class T, class F = scoped_smptr_my_deallocator< T >>
T* Teamcenter::scoped_smptr< T, F >::get ( ) const
inline

Returns the pointed memory.

Definition at line 194 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
T*& Teamcenter::scoped_smptr< T, F >::getReference ( )
inline

Returns the reference of pointed memory.

Definition at line 189 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
const T* Teamcenter::scoped_smptr< T, F >::getString ( ) const
inline

Safe getter of the string of elements of type T.

It returns the memory pointed by this object, or a pointer to a default constructed element if the object does not point to any memory.
This is particularly useful if the object manages memory of a C-string, because it can be used for a NULL-safe assignment to a std::string.

Definition at line 184 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
bool Teamcenter::scoped_smptr< T, F >::operator! ( ) const
inline

Unary NOT operator

Definition at line 208 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
bool Teamcenter::scoped_smptr< T, F >::operator!= ( const T *  t) const
inline

Operator !=

Definition at line 205 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
T** Teamcenter::scoped_smptr< T, F >::operator& ( )
inline

Operator &

Definition at line 114 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
T& Teamcenter::scoped_smptr< T, F >::operator* ( ) const
inline

Operator *

Definition at line 119 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
T* Teamcenter::scoped_smptr< T, F >::operator-> ( ) const
inline

Operator ->

Definition at line 124 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
scoped_smptr& Teamcenter::scoped_smptr< T, F >::operator= ( T *  ptr)
inline

Operator =
If the scoped pointer was already assigned, the current assignment is removed (memory is freed) and replaced with the requested pointed.

Definition at line 109 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
scoped_smptr& Teamcenter::scoped_smptr< T, F >::operator= ( const scoped_smptr< T, F > &  )
private

Prevention of usage of the operator =

template<class T, class F = scoped_smptr_my_deallocator< T >>
bool Teamcenter::scoped_smptr< T, F >::operator== ( const T *  t) const
inline

Operator ==

Definition at line 202 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
const T& Teamcenter::scoped_smptr< T, F >::operator[] ( std::size_t  inx) const
inline

Operator []

Definition at line 129 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
T& Teamcenter::scoped_smptr< T, F >::operator[] ( std::size_t  inx)
inline

Operator []

Definition at line 134 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
const T& Teamcenter::scoped_smptr< T, F >::operator[] ( int  inx) const
inline

Operator []

Definition at line 139 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
T& Teamcenter::scoped_smptr< T, F >::operator[] ( int  inx)
inline

Operator []

Definition at line 144 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
const T& Teamcenter::scoped_smptr< T, F >::operator[] ( unsigned int  inx) const
inline

Operator []

Definition at line 149 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
T& Teamcenter::scoped_smptr< T, F >::operator[] ( unsigned int  inx)
inline

Operator []

Definition at line 154 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
const T& Teamcenter::scoped_smptr< T, F >::operator[] ( short  inx) const
inline

Operator []

Definition at line 159 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
T& Teamcenter::scoped_smptr< T, F >::operator[] ( short  inx)
inline

Operator []

Definition at line 164 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
const T& Teamcenter::scoped_smptr< T, F >::operator[] ( long  inx) const
inline

Operator []

Definition at line 169 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
T& Teamcenter::scoped_smptr< T, F >::operator[] ( long  inx)
inline

Operator []

Definition at line 174 of file ScopedSmPtr.hxx.

template<class T, class F = scoped_smptr_my_deallocator< T >>
T* Teamcenter::scoped_smptr< T, F >::release ( )
inline

Returns the memory that has been managed by the smart pointer, and ends its management of this memory.

Definition at line 199 of file ScopedSmPtr.hxx.

Member Data Documentation

template<class T, class F = scoped_smptr_my_deallocator< T >>
T* Teamcenter::scoped_smptr< T, F >::bucket
protected

The managed pointer.

Definition at line 217 of file ScopedSmPtr.hxx.


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