Salome HOME
DCQ:prepare 2.0.0
[modules/med.git] / src / MEDMEM / MEDMEM_PointerOf.hxx
index a5f0bdce3eb329856020f8d7171a148fc23f7f47..be3201043b2a4ffd0c656516744a4e4b54dedf64 100644 (file)
 #include "MEDMEM_Exception.hxx"
 
 /*!
-  The template class PointerOf embedding a standard pointer (_pointer) is in
-  charge of managing the pointed memory.\n
-
-  the object PointerOf is the memory owner if a size is given at object
-  construction. In these cases, memory will be desallocated at object
-  destruction. In all other cases, the desallocator will only nullify pointers.
+       The template class PointerOf embedding a standard pointer (_pointer) is in charge of
+       managing the pointed memory.\n
+       
+        the object PointerOf is the memory owner if a size is given at object construction.
+        In these cases, memory will be desallocated at object destruction. In all other cases,
+       the desallocator will only nullify pointers.
 */
 namespace MEDMEM {
 
 template <typename T> class PointerOf
 {
 protected :
-  /*!
-    pointer to the pointed memory
-  */
-
-  T* _pointer ;
-
-  /*!
-    boolean setted to true if memory has to be desallocated
-  */
-
-  bool _done ;
+                       /*! pointer to the pointed memory */
+       T* _pointer ;
+                       /*! boolean setted to true if memory has to be desallocated */
+       bool _done ;
 
 public :
-  PointerOf() ;
-  ~PointerOf() ;
-  PointerOf( const int &size ) ;
-  PointerOf( const T *pointer ) ;
-  PointerOf( const int &size, const T *pointer ) ;
-  PointerOf( const PointerOf<T> & pointerOf ) ;
-  PointerOf( const int &size, const PointerOf<T> & pointerOf ) ;
-  operator T*() ;
-  operator const T*() const ;
-  void set( const int &size ) ;
-  void set( const T *pointer ) ;
-  void set( const int &size, const T *pointer ) ;
-  PointerOf<T>& operator=( const PointerOf<T> &pointer ) ;
+       PointerOf() ;
+       ~PointerOf() ;
+       PointerOf( const int &size ) ;
+       PointerOf( const T *pointer ) ;
+       PointerOf( const int &size, const T *pointer ) ;
+       PointerOf( const PointerOf<T> & pointerOf ) ;
+       PointerOf( const int &size, const PointerOf<T> & pointerOf ) ;
+       operator T*() ;
+       operator const T*() const ;
+       void set( const int &size ) ;
+       void set( const T *pointer ) ;
+       void set( const int &size, const T *pointer ) ;
+       PointerOf<T>& operator=( const PointerOf<T> &pointer ) ;
 } ;
 } ;
 
-/*
-  Implementation
-*/
+// ------------------------------------------------------------ //
+//                                                             //
+//                     Implementation                          //
+//                                                             //
+// ------------------------------------------------------------ //
 
 using namespace MEDMEM;
 
-/*!
-  Creates a null T* pointer and sets the boolean (for desallocation) to false.
-*/
-
+/*! Creates a null T* pointer and sets the boolean (for desallocation) to false. */
 template <typename T> PointerOf<T>::PointerOf() : _pointer(0), _done(false)
 {
-  BEGIN_OF("PointerOf<T>::PointerOf() empty constructor");
-  END_OF("PointerOf<T>::PointerOf() empty constructor");
 }
 
-/* !
-   Creates a standard T* pointer to the pointed memory. \n
-   The boolean for desallocation is setted to false. \n
-   Be aware : \n
-   - The "old" PointerOf always has propriety of the pointed memory. \n
-   - If the "old" PointerOf is detroyed, the "new" PointerOf points
-   a desallocated memory zone.
-*/
-
+/*! Creates a standard T* pointer to the pointed memory. \n
+    The boolean for desallocation is setted to false. \n
+    Be aware : \n
+    - The "old" PointerOf always has propriety of the pointed memory. \n
+    - If the "old" PointerOf is detroyed, the "new" PointerOf points
+      a desallocated memory zone. */
 template <typename T> PointerOf<T>::PointerOf(const PointerOf<T> & pointerOf) :
   _pointer((T*)(const T* const)pointerOf), _done(false)
 {
-  BEGIN_OF("PointerOf<T>::PointerOf(const PointerOf<T> & pointerOf)");
-  MESSAGE("Warning ! No Propriety Transfer");
-  END_OF  ("PointerOf<T>::PointerOf(const PointerOf<T> & pointerOf)");
+       BEGIN_OF("PointerOf<T>::PointerOf(const PointerOf<T> & pointerOf)");
+       MESSAGE("Warning ! No Propriety Transfer");
+       END_OF  ("PointerOf<T>::PointerOf(const PointerOf<T> & pointerOf)");
 }
 
 /*! 
   Duplicate array of size size pointed in pointerOf.
 */
-
 template <typename T> PointerOf<T>::PointerOf( const int &size, const PointerOf<T> & pointerOf) : 
   _pointer((size,(T*)pointerOf))
 {
 }
 
-/*!
-  If size <= 0, creates a null "T*" pointer\n
-  Else allocates memory and sets desallocation boolean to true./n
-  Memory will be desallocated  when erasing this PointerOf
-*/
-
+/*! If size <= 0, creates a null "T*" pointer\n
+    Else allocates memory and sets desallocation boolean to true./n
+    Memory will be desallocated  when erasing this PointerOf*/
 template <typename T> PointerOf<T>::PointerOf( const int &size )
 {
-  if (size <= 0)
-    {
-      _pointer=(T*)NULL;
-      _done=false;
-    }
-  else
-    {
-      _pointer = new T[ size ] ;
-      _done=true;
-    }
+        if (size <= 0)
+        {
+                _pointer=(T*)NULL;
+               _done=false;
+        }
+        else
+        {
+                _pointer = new T[ size ] ;
+               _done=true;
+        }
 }
 
 /*! Creates a standard pointer to the memory zone pointed by T*. /n
-  T* owner is in charged of memory desallocation. /n
-  Memory will not be released when erasing this PointerOf
-*/
-
+   T* owner is in charged of memory desallocation. /n
+   Memory will not be released when erasing this PointerOf*/
 template <typename T> PointerOf<T>::PointerOf( const T* pointer ) : _pointer( (T*)pointer ), _done(false)
 {
 }
 
-/*!
-  If size <= 0, return an exception\n
-  Else duplicate array and sets desallocation boolean to true./n
-  Memory will be desallocated  when erasing this PointerOf
-*/
-
+/*! If size <= 0, return an exception\n
+    Else duplicate array and sets desallocation boolean to true./n
+    Memory will be desallocated  when erasing this PointerOf*/
 template <typename T> PointerOf<T>::PointerOf( const int &size, const T* pointer)
 {
   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;
 }
 
-/*!
-  The destuctor desallocates memory if necessary (that is if the attribute
-  _done equals true).\n
-  The attribute _pointer is nullified
-*/
-
+/*! The destuctor desallocates memory if necessary (that is if the attribute _done equals true).\n
+    The attribute _pointer is nullified */
 template <typename T> PointerOf<T>::~PointerOf()
 {
-  if ( _pointer )
-    {
-      if( _done )
-       {
-         MESSAGE("PointerOf<T>::~PointerOf() --> deleting _pointer") ;
-         delete [] _pointer ;
-         _done = false ;
-       }
-      else
+       if ( _pointer )
        {
-         MESSAGE("_pointer is only nullified") ;
+               if( _done )
+               {
+                       MESSAGE("PointerOf<T>::~PointerOf() --> deleting _pointer") ;
+                       delete [] _pointer ;
+                       _done = false ;
+               }
+               else
+               {
+                       MESSAGE("_pointer is only nullified") ;
+               }
+               _pointer = 0 ;
        }
-      _pointer = 0 ;
-    }
 }
 
-/*!
-  Creates a standard pointer (T*) to the pointed memory. \n
-  The boolean for desallocation is setted to false. \n
-  Be aware : \n
-  - The "right" PointerOf always has propriety of the pointed memory. \n
-  - If the "right" PointerOf is detroyed, the "left" PointerOf points
-  a desallocated memory zone.
-  - it works the same way as PointerOf(const PointerOf<T> & pointerOf)
-*/
-
+/*! Creates a standard pointer (T*) to the pointed memory. \n
+    The boolean for desallocation is setted to false. \n
+    Be aware : \n
+    - The "right" PointerOf always has propriety of the pointed memory. \n
+    - If the "right" PointerOf is detroyed, the "left" PointerOf points
+      a desallocated memory zone.
+    - it works the same way as PointerOf(const PointerOf<T> & pointerOf) */
 template <typename T> PointerOf<T>& PointerOf<T>::operator=( const PointerOf<T> &pointer )
 {
-  BEGIN_OF("PointerOf<T>::operator=( const PointerOf<T> &pointer )") ;
-  if ( &pointer != this )
-    {
-      this->set( pointer._pointer ) ;
-    }
-  END_OF("PointerOf<T>::operator=( const PointerOf<T> &pointer )") ;
-  return *this ;
+       BEGIN_OF("PointerOf<T>::operator=( const PointerOf<T> &pointer )") ;
+       if ( &pointer != this )
+       {
+               this->set( pointer._pointer ) ;
+       }
+       END_OF("PointerOf<T>::operator=( const PointerOf<T> &pointer )") ;
+       return *this ;
 }
 
-/*!
-  Returns _pointer.
-*/
-
+/*! Returns _pointer.*/
 template <typename T> PointerOf<T>::operator T*()
 {
-  return _pointer ;
+       return _pointer ;
 }
 
-/*!
-  Returns _pointer.
-*/
 
+/*! Returns _pointer.*/
 template <typename T> PointerOf<T>::operator const T*() const
 {
-  return _pointer ;
+       return _pointer ;
 }
 
-/*!
-  If necessary, released memory holded by PointerOf/n.
-  Else allocates memory and sets desallocation boolean to true./n
-  Can be used in order to "nullify" an existing PointerOf/n
-  Memory will be desallocated  when erasing this PointerOf
-*/
 
+/*! If necessary, released memory holded by PointerOf/n.
+    Else allocates memory and sets desallocation boolean to true./n
+    Can be used in order to "nullify" an existing PointerOf/n
+    Memory will be desallocated  when erasing this PointerOf*/
 template <typename T> void PointerOf<T>::set( const int &size )
 {
-  if ( _pointer && _done )
-    {
-      delete [] _pointer ;
-      _pointer=0 ;
-    }
-  if (size <= 0)
-    {
-      _pointer=(T*)NULL;
-    }
-  else
-    {
-      _pointer = new T[ size ] ;
-    }
-  _done = true ;
+       if ( _pointer && _done )
+       {
+               delete [] _pointer ;
+               _pointer=0 ;
+       }
+       if (size <= 0)
+       {
+               _pointer=(T*)NULL;
+       }
+       else
+       {
+               _pointer = new T[ size ] ;
+       }
+       _done = true ;
+       return ;
 }
 
 /*! If necessary, released memory holded by PointerOf/n.
     Then, sets _pointer to the memory zone pointed by T*. /n
     T* owner is in charged of memory desallocation. /n
     memory will not be released when erasing this PointerOf*/
-
 template <typename T> void PointerOf<T>::set( const T *pointer )
 {
-  MESSAGE( "BEGIN PointerOf<T>::set( const T *pointer )" ) ;
-  SCRUTE(pointer) ;
-  SCRUTE(_done) ;
-  if ( _pointer && _done )
-    {
-      MESSAGE("PointerOf<T>::set --> deleting _pointer") ;
-      delete [] _pointer ;
-      _pointer=0 ;
-      _done=false ;
-    }
-  _pointer=(T*)pointer ;
-  _done=false ;
-  MESSAGE( "END PointerOf<T>::set( const T *pointer )" ) ;
+       MESSAGE( "BEGIN PointerOf<T>::set( const T *pointer )" ) ;
+       SCRUTE(pointer) ;
+       SCRUTE(_done) ;
+       if ( _pointer && _done )
+       {
+               MESSAGE("PointerOf<T>::set --> deleting _pointer") ;
+               delete [] _pointer ;
+               _pointer=0 ;
+               _done=false ;
+       }
+       _pointer=(T*)pointer ;
+       _done=false ;
+       MESSAGE( "END PointerOf<T>::set( const T *pointer )" ) ;
+       return ;
 }
 
-/*!
-  If necessary, released memory holded by PointerOf/n.
-  If size <= 0, return an exception\n.
-  Else allocates memory and sets desallocation boolean to true./n
-  Can be used in order to "nullify" an existing PointerOf/n
-  Memory will be desallocated  when erasing this PointerOf
-*/
-
+/*! If necessary, released memory holded by PointerOf/n.
+    If size <= 0, return an exception\n.
+    Else allocates memory and sets desallocation boolean to true./n
+    Can be used in order to "nullify" an existing PointerOf/n
+    Memory will be desallocated  when erasing this PointerOf*/
 template <typename T> void PointerOf<T>::set( const int &size, const T *pointer)
 {
   if ( _pointer && _done )
@@ -265,6 +227,8 @@ template <typename T> void PointerOf<T>::set( const int &size, const T *pointer)
   _pointer = new T[ size ] ;
   memcpy(_pointer,pointer,size*sizeof(T));
   _done=true;
+
+  return ;
 }
 
 # endif                /* # if ! defined( __PointerOf_HXX__ ) */