From 0437838b3499071528a9a051e6097c6ffe3b13ce Mon Sep 17 00:00:00 2001 From: nadir Date: Wed, 28 Apr 2004 14:26:10 +0000 Subject: [PATCH] correct small problem from the version in the MedFileV2_2 branch. --- src/MEDMEM/MEDMEM_MedMeshDriver.cxx | 5 +- src/MEDMEM/MEDMEM_PointerOf.hxx | 294 +++++++++++++++------------ src/MEDMEM_SWIG/med_test_grid.py | 4 +- src/MEDMEM_SWIG/testMedMemGeneral.py | 12 +- 4 files changed, 174 insertions(+), 141 deletions(-) diff --git a/src/MEDMEM/MEDMEM_MedMeshDriver.cxx b/src/MEDMEM/MEDMEM_MedMeshDriver.cxx index 71a351db2..5ab0ffca7 100644 --- a/src/MEDMEM/MEDMEM_MedMeshDriver.cxx +++ b/src/MEDMEM/MEDMEM_MedMeshDriver.cxx @@ -372,10 +372,7 @@ void MED_MESH_RDONLY_DRIVER::getGRID() if (gridType == MED_EN::MED_GRILLE_CARTESIENNE) rep = MED_FR::MED_CART; else if (gridType == MED_EN::MED_GRILLE_POLAIRE) - { - if (SpaceDimension == 2) rep = MED_FR::MED_CYL; - else if (SpaceDimension == 3) rep = MED_FR::MED_SPHER; - } + rep = MED_FR::MED_CYL; } else throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" bad grid type : " << gridType)); diff --git a/src/MEDMEM/MEDMEM_PointerOf.hxx b/src/MEDMEM/MEDMEM_PointerOf.hxx index be3201043..a5f0bdce3 100644 --- a/src/MEDMEM/MEDMEM_PointerOf.hxx +++ b/src/MEDMEM/MEDMEM_PointerOf.hxx @@ -6,214 +6,252 @@ #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 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 & pointerOf ) ; - PointerOf( const int &size, const PointerOf & 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& operator=( const PointerOf &pointer ) ; + PointerOf() ; + ~PointerOf() ; + PointerOf( const int &size ) ; + PointerOf( const T *pointer ) ; + PointerOf( const int &size, const T *pointer ) ; + PointerOf( const PointerOf & pointerOf ) ; + PointerOf( const int &size, const PointerOf & 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& operator=( const PointerOf &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 PointerOf::PointerOf() : _pointer(0), _done(false) { + BEGIN_OF("PointerOf::PointerOf() empty constructor"); + END_OF("PointerOf::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 PointerOf::PointerOf(const PointerOf & pointerOf) : _pointer((T*)(const T* const)pointerOf), _done(false) { - BEGIN_OF("PointerOf::PointerOf(const PointerOf & pointerOf)"); - MESSAGE("Warning ! No Propriety Transfer"); - END_OF ("PointerOf::PointerOf(const PointerOf & pointerOf)"); + BEGIN_OF("PointerOf::PointerOf(const PointerOf & pointerOf)"); + MESSAGE("Warning ! No Propriety Transfer"); + END_OF ("PointerOf::PointerOf(const PointerOf & pointerOf)"); } /*! Duplicate array of size size pointed in pointerOf. */ + template PointerOf::PointerOf( const int &size, const PointerOf & 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 PointerOf::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 PointerOf::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 PointerOf::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 PointerOf::~PointerOf() { - if ( _pointer ) + if ( _pointer ) + { + if( _done ) + { + MESSAGE("PointerOf::~PointerOf() --> deleting _pointer") ; + delete [] _pointer ; + _done = false ; + } + else { - if( _done ) - { - MESSAGE("PointerOf::~PointerOf() --> deleting _pointer") ; - delete [] _pointer ; - _done = false ; - } - else - { - MESSAGE("_pointer is only nullified") ; - } - _pointer = 0 ; + MESSAGE("_pointer is only nullified") ; } + _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 & 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 & pointerOf) +*/ + template PointerOf& PointerOf::operator=( const PointerOf &pointer ) { - BEGIN_OF("PointerOf::operator=( const PointerOf &pointer )") ; - if ( &pointer != this ) - { - this->set( pointer._pointer ) ; - } - END_OF("PointerOf::operator=( const PointerOf &pointer )") ; - return *this ; + BEGIN_OF("PointerOf::operator=( const PointerOf &pointer )") ; + if ( &pointer != this ) + { + this->set( pointer._pointer ) ; + } + END_OF("PointerOf::operator=( const PointerOf &pointer )") ; + return *this ; } -/*! Returns _pointer.*/ +/*! + Returns _pointer. +*/ + template PointerOf::operator T*() { - return _pointer ; + return _pointer ; } +/*! + Returns _pointer. +*/ -/*! Returns _pointer.*/ template PointerOf::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 void PointerOf::set( const int &size ) { - if ( _pointer && _done ) - { - delete [] _pointer ; - _pointer=0 ; - } - if (size <= 0) - { - _pointer=(T*)NULL; - } - else - { - _pointer = new T[ size ] ; - } - _done = true ; - return ; + if ( _pointer && _done ) + { + delete [] _pointer ; + _pointer=0 ; + } + if (size <= 0) + { + _pointer=(T*)NULL; + } + else + { + _pointer = new T[ size ] ; + } + _done = true ; } /*! 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 void PointerOf::set( const T *pointer ) { - MESSAGE( "BEGIN PointerOf::set( const T *pointer )" ) ; - SCRUTE(pointer) ; - SCRUTE(_done) ; - if ( _pointer && _done ) - { - MESSAGE("PointerOf::set --> deleting _pointer") ; - delete [] _pointer ; - _pointer=0 ; - _done=false ; - } - _pointer=(T*)pointer ; - _done=false ; - MESSAGE( "END PointerOf::set( const T *pointer )" ) ; - return ; + MESSAGE( "BEGIN PointerOf::set( const T *pointer )" ) ; + SCRUTE(pointer) ; + SCRUTE(_done) ; + if ( _pointer && _done ) + { + MESSAGE("PointerOf::set --> deleting _pointer") ; + delete [] _pointer ; + _pointer=0 ; + _done=false ; + } + _pointer=(T*)pointer ; + _done=false ; + MESSAGE( "END PointerOf::set( const T *pointer )" ) ; } -/*! 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 void PointerOf::set( const int &size, const T *pointer) { if ( _pointer && _done ) @@ -227,8 +265,6 @@ template void PointerOf::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__ ) */ diff --git a/src/MEDMEM_SWIG/med_test_grid.py b/src/MEDMEM_SWIG/med_test_grid.py index 437d72dad..53c29d804 100755 --- a/src/MEDMEM_SWIG/med_test_grid.py +++ b/src/MEDMEM_SWIG/med_test_grid.py @@ -61,7 +61,7 @@ if K != 0: grid_type = grid.getGridType() print "grid_type =", grid_type -if grid_type != MED_CARTESIAN: +if grid_type != MED_GRILLE_CARTESIENNE: raise RuntimeError, "Wrong grid type" spaceDim = grid.getSpaceDimension() @@ -256,7 +256,7 @@ if K != 0: grid_type = grid.getGridType() print "grid_type =", grid_type -if grid_type != MED_BODY_FITTED: +if grid_type != MED_GRILLE_STANDARD: raise RuntimeError, "Wrong grid type" spaceDim = grid.getSpaceDimension() diff --git a/src/MEDMEM_SWIG/testMedMemGeneral.py b/src/MEDMEM_SWIG/testMedMemGeneral.py index e5db5c693..9d64fec29 100755 --- a/src/MEDMEM_SWIG/testMedMemGeneral.py +++ b/src/MEDMEM_SWIG/testMedMemGeneral.py @@ -237,8 +237,8 @@ for i in range(nbOfFiles): meshDriver.close() print "The mesh stored in the file ",file," is perhaps a GRID." try: - print "... of MED_CARTESIAN type ?" - type = MED_CARTESIAN + print "... of MED_GRILLE_CARTESIENNE type ?" + type = MED_GRILLE_CARTESIENNE mesh = GRID() mesh.setGridType(type) if (extensionFile == "med"): @@ -258,9 +258,9 @@ for i in range(nbOfFiles): except: meshDriver.close() try: - print "... of MED_POLAR type ?" + print "... of MED_GRILLE_POLAIRE type ?" mesh = GRID() - type = MED_POLAR + type = MED_GRILLE_POLAIRE mesh.setGridType(type) if (extensionFile == "med"): meshDriver = MED_MESH_RDONLY_DRIVER(file,mesh) @@ -275,9 +275,9 @@ for i in range(nbOfFiles): meshDriver.read() except: meshDriver.close() - print "... of MED_BODY_FITTED type ?" + print "... of MED_GRILLE_STANDARD type ?" mesh = GRID() - type = MED_BODY_FITTED + type = MED_GRILLE_STANDARD mesh.setGridType(type) if (extensionFile == "med"): meshDriver = MED_MESH_RDONLY_DRIVER(file,mesh) -- 2.39.2