Back to index

salome-med  6.5.0
Public Member Functions | Protected Attributes
MEDMEM::PointerOf< T > Class Template Reference

#include <MEDMEM_PointerOf.hxx>

Inheritance diagram for MEDMEM::PointerOf< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 PointerOf ()
 Creates a null T* pointer and sets the boolean (for desallocation) to false.
 ~PointerOf ()
 The destuctor desallocates memory if necessary (that is if the attribute _done equals true).
 PointerOf (const int &size)
 Duplicate array of size size pointed in pointerOf.
 PointerOf (const T *pointer)
 Creates a standard pointer to the memory zone pointed by T*.
 PointerOf (const int &size, const T *pointer)
 If size < 0, return an exception
Else duplicate array and sets desallocation boolean to true.
 PointerOf (const PointerOf< T > &pointerOf)
 Creates a standard T* pointer to the pointed memory.
 operator T * ()
 PointerOf( const int &size, const PointerOf<T> & pointerOf ) ;.
 operator const T * () const
 Returns _pointer.
void set (const int &size)
 If necessary, released memory holded by PointerOf
.
void set (const T *pointer)
 If necessary, released memory holded by PointerOf
.
void set (const int &size, const T *pointer)
 If necessary, released memory holded by PointerOf
.
void setShallowAndOwnership (const T *pointer)
PointerOf< T > & operator= (const PointerOf< T > &pointer)
 Creates a standard pointer (T*) to the pointed memory.

Protected Attributes

T * _pointer
 pointer to the pointed memory
bool _done
 boolean setted to true if memory has to be desallocated

Detailed Description

template<typename T>
class MEDMEM::PointerOf< T >

Definition at line 41 of file MEDMEM_PointerOf.hxx.


Constructor & Destructor Documentation

template<typename T >
MEDMEM::PointerOf< T >::PointerOf ( )

Creates a null T* pointer and sets the boolean (for desallocation) to false.

Definition at line 73 of file MEDMEM_PointerOf.hxx.

                                              : _pointer(0), _done(false)
{
}
template<typename T >
MEDMEM::PointerOf< T >::~PointerOf ( )

The destuctor desallocates memory if necessary (that is if the attribute _done equals true).


The attribute _pointer is nullified

Definition at line 139 of file MEDMEM_PointerOf.hxx.

{
        if ( _pointer )
        {
                if( _done )
                {
                        MESSAGE_MED("PointerOf<T>::~PointerOf() --> deleting _pointer") ;
                        delete [] _pointer ;
                        _done = false ;
                }
                else
                {
                        MESSAGE_MED("_pointer is only nullified") ;
                }
                _pointer = 0 ;
        }
}
template<typename T >
MEDMEM::PointerOf< T >::PointerOf ( const int &  size)

Duplicate array of size size pointed in pointerOf.

If size < 0, creates a null "T*" pointer
Else allocates memory and sets desallocation boolean to true.
Memory will be desallocated when erasing this PointerOf

Definition at line 103 of file MEDMEM_PointerOf.hxx.

{
        if (size < 0)
        {
                _pointer=(T*)NULL;
                _done=false;
        }
        else
        {
                _pointer = new T[ size ] ;
                _done=true;
        }
}
template<typename T>
MEDMEM::PointerOf< T >::PointerOf ( const T *  pointer)

Creates a standard pointer to the memory zone pointed by T*.


T* owner is in charged of memory desallocation.
Memory will not be released when erasing this PointerOf

Definition at line 120 of file MEDMEM_PointerOf.hxx.

                                                                : _pointer( (T*)pointer ), _done(false)
{
}
template<typename T>
MEDMEM::PointerOf< T >::PointerOf ( const int &  size,
const T *  pointer 
)

If size < 0, return an exception
Else duplicate array and sets desallocation boolean to true.


Memory will be desallocated when erasing this PointerOf

Definition at line 127 of file MEDMEM_PointerOf.hxx.

{
  if (size < 0)
    throw MEDEXCEPTION("PointerOf( const int,const T*) : array size < 0");

  _pointer = new T[ size ] ;
  memcpy(_pointer,pointer,size*sizeof(T));
  _done=true;
}
template<typename T>
MEDMEM::PointerOf< T >::PointerOf ( const PointerOf< T > &  pointerOf)

Creates a standard T* pointer to the pointed memory.


The boolean for desallocation is setted to false.
Be aware :

  • The "old" PointerOf always has propriety of the pointed memory.
  • If the "old" PointerOf is detroyed, the "new" PointerOf points a desallocated memory zone.

Definition at line 83 of file MEDMEM_PointerOf.hxx.

                                                                            :
  _pointer((T*)(const T* const)pointerOf), _done(false)
{
  const char* LOC = "PointerOf<T>::PointerOf(const PointerOf<T> & pointerOf)";
  BEGIN_OF_MED(LOC);
        MESSAGE_MED("Warning ! No Propriety Transfer");
  END_OF_MED(LOC);
}

Member Function Documentation

template<typename T >
MEDMEM::PointerOf< T >::operator const T * ( ) const

Returns _pointer.

Definition at line 184 of file MEDMEM_PointerOf.hxx.

{
        return _pointer ;
}
template<typename T >
MEDMEM::PointerOf< T >::operator T * ( )

PointerOf( const int &size, const PointerOf<T> & pointerOf ) ;.

Returns _pointer.

Definition at line 177 of file MEDMEM_PointerOf.hxx.

{
        return _pointer ;
}
template<typename T>
PointerOf< T > & MEDMEM::PointerOf< T >::operator= ( const PointerOf< T > &  pointer)

Creates a standard pointer (T*) to the pointed memory.


The boolean for desallocation is setted to false.
Be aware :

Definition at line 164 of file MEDMEM_PointerOf.hxx.

{
  const char* LOC = "PointerOf<T>::operator=( const PointerOf<T> &pointer )";
  BEGIN_OF_MED(LOC);
        if ( &pointer != this )
        {
                this->set( pointer._pointer ) ;
        }
  END_OF_MED(LOC);
        return *this ;
}
template<typename T >
void MEDMEM::PointerOf< T >::set ( const int &  size)

If necessary, released memory holded by PointerOf
.

Else allocates memory and sets desallocation boolean to true.
Can be used in order to "nullify" an existing PointerOf
Memory will be desallocated when erasing this PointerOf

Definition at line 193 of file MEDMEM_PointerOf.hxx.

{
        if ( _pointer && _done )
        {
                delete [] _pointer ;
                _pointer=0 ;
        }
        // if (size < 0) TODO: analyse why it does not work
        if (size <= 0)
        {
                _pointer=(T*)NULL;
        }
        else
        {
                _pointer = new T[ size ] ;
        }
        _done = true ;
        return ;
}

Here is the caller graph for this function:

template<typename T>
void MEDMEM::PointerOf< T >::set ( const T *  pointer)

If necessary, released memory holded by PointerOf
.

Then, sets _pointer to the memory zone pointed by T*.
T* owner is in charged of memory desallocation.
memory will not be released when erasing this PointerOf

Definition at line 217 of file MEDMEM_PointerOf.hxx.

{
        MESSAGE_MED( "BEGIN PointerOf<T>::set( const T *pointer )" ) ;
        SCRUTE_MED(pointer) ;
        SCRUTE_MED(_done) ;
        if ( _pointer && _done )
        {
                MESSAGE_MED("PointerOf<T>::set --> deleting _pointer") ;
                delete [] _pointer ;
                _pointer=0 ;
                _done=false ;
        }
        _pointer=(T*)pointer ;
        _done=false ;
        MESSAGE_MED( "END PointerOf<T>::set( const T *pointer )" ) ;
        return ;
}
template<typename T>
void MEDMEM::PointerOf< T >::set ( const int &  size,
const T *  pointer 
)

If necessary, released memory holded by PointerOf
.

If size < 0, return an exception
. Else allocates memory and sets desallocation boolean to true.
Can be used in order to "nullify" an existing PointerOf
Memory will be desallocated when erasing this PointerOf

Definition at line 240 of file MEDMEM_PointerOf.hxx.

{
  if ( _pointer && _done )
    {
      delete [] _pointer ;
      _pointer = NULL ;
    }
  if (size < 0)
    throw MEDEXCEPTION("PointerOf( const int,const T*) : array size < 0");

  _pointer = new T[ size ] ;
  memcpy(_pointer,pointer,size*sizeof(T));
  _done=true;

  return ;
}
template<typename T>
void MEDMEM::PointerOf< T >::setShallowAndOwnership ( const T *  pointer)

Definition at line 257 of file MEDMEM_PointerOf.hxx.

{
  if ( _pointer && _done )
    delete [] _pointer;
  _pointer=(T*)pointer;
  _done=true;
}

Here is the caller graph for this function:


Member Data Documentation

template<typename T>
bool MEDMEM::PointerOf< T >::_done [protected]

boolean setted to true if memory has to be desallocated

Definition at line 47 of file MEDMEM_PointerOf.hxx.

template<typename T>
T* MEDMEM::PointerOf< T >::_pointer [protected]

pointer to the pointed memory

Definition at line 45 of file MEDMEM_PointerOf.hxx.


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