From 69c406fac8e0d9cbf4bdc979b3a3687202c893fb Mon Sep 17 00:00:00 2001 From: nadir Date: Tue, 8 Feb 2005 16:47:01 +0000 Subject: [PATCH] update due to bugs PAL8113 and another I do not remember the number ;) . --- src/MEDMEM/MEDMEM_DriverFactory.cxx | 132 ++++++++++++++++++++++++--- src/MEDMEM/MEDMEM_DriverFactory.hxx | 58 ++++++++++-- src/MEDMEM/MEDMEM_Field.cxx | 3 +- src/MEDMEM/MEDMEM_Field.hxx | 47 ++++++---- src/MEDMEM/MEDMEM_Med.cxx | 10 +- src/MEDMEM/MEDMEM_Med.hxx | 4 +- src/MEDMEM/MEDMEM_MedFieldDriver.hxx | 4 +- src/MEDMEM/MEDMEM_Mesh.cxx | 11 ++- src/MEDMEM/MEDMEM_Mesh.hxx | 3 +- src/MEDMEM_SWIG/libMEDMEM_Swig.i | 15 +-- 10 files changed, 227 insertions(+), 60 deletions(-) diff --git a/src/MEDMEM/MEDMEM_DriverFactory.cxx b/src/MEDMEM/MEDMEM_DriverFactory.cxx index 80b7f80f0..f6e8037e9 100644 --- a/src/MEDMEM/MEDMEM_DriverFactory.cxx +++ b/src/MEDMEM/MEDMEM_DriverFactory.cxx @@ -17,31 +17,99 @@ //#include "utilities.h" using namespace MEDMEM; +using namespace MED_EN; -GENDRIVER *DRIVERFACTORY::buildDriverForMesh(driverTypes driverType, const std::string & fileName, MESH *mesh,const string & driverName) +GENDRIVER *DRIVERFACTORY::buildDriverForMesh(driverTypes driverType, + const std::string & fileName, + MESH *mesh, + const string & driverName, + med_mode_acces access) { GENDRIVER *ret; switch(driverType) { case MED_DRIVER : { - MED_MESH_RDWR_DRIVER *retmed=new MED_MESH_RDWR_DRIVER(fileName,mesh); - retmed->setMeshName(driverName); - return retmed; + switch(access) + { + case MED_LECT : { + MED_MESH_RDONLY_DRIVER *retmed=new MED_MESH_RDONLY_DRIVER(fileName, + mesh); + retmed->setMeshName(driverName); + return retmed; + } + case MED_ECRI : { + MED_MESH_WRONLY_DRIVER *retmed=new MED_MESH_WRONLY_DRIVER(fileName, + mesh); + retmed->setMeshName(driverName); + return retmed; + } + case MED_REMP : { + MED_MESH_RDWR_DRIVER *retmed=new MED_MESH_RDWR_DRIVER(fileName,mesh); + retmed->setMeshName(driverName); + return retmed; + } + default: + throw MED_EXCEPTION ("access type has not been properly specified to the method"); + } + break; } case GIBI_DRIVER : { - ret=new GIBI_MESH_RDWR_DRIVER(fileName,mesh); - return ret; + switch(access) + { + case MED_LECT : { + ret=new GIBI_MESH_RDONLY_DRIVER(fileName,mesh); + return ret; + } + case MED_ECRI : { + throw MED_EXCEPTION ("access mode other than MED_LECT has been specified with the GIBI_DRIVER type which is not allowed because GIBI_DRIVER is only a read access driver"); + } + case MED_REMP : { + throw MED_EXCEPTION ("access mode other than MED_LECT has been specified with the GIBI_DRIVER type which is not allowed because GIBI_DRIVER is only a read access driver"); + } + default: + throw MED_EXCEPTION ("access type has not been properly specified to the method"); + } + break; } case PORFLOW_DRIVER : { - ret=new PORFLOW_MESH_RDWR_DRIVER(fileName,mesh); - return ret; + switch(access) + { + case MED_LECT : { + ret=new PORFLOW_MESH_RDONLY_DRIVER(fileName,mesh); + return ret; + } + case MED_ECRI : { + throw MED_EXCEPTION ("access mode other than MED_LECT has been specified with the PORFLOW_DRIVER type which is not allowed because PORFLOW_DRIVER is only a read access driver"); + } + case MED_REMP : { + throw MED_EXCEPTION ("access mode other than MED_LECT has been specified with the PORFLOW_DRIVER type which is not allowed because PORFLOW_DRIVER is only a read access driver"); + } + default: + throw MED_EXCEPTION ("access type has not been properly specified to the method"); + } + break; } case VTK_DRIVER : { - ret=new VTK_MESH_DRIVER(fileName,mesh); - return ret; + switch(access) + { + case MED_LECT : { + throw MED_EXCEPTION ("access mode other than MED_ECRI or MED_REMPT has been specified with the VTK_DRIVER type which is not allowed because VTK_DRIVER is only a write access driver"); + } + case MED_ECRI : { + ret=new VTK_MESH_DRIVER(fileName,mesh); + return ret; + } + case MED_REMP : { + ret=new VTK_MESH_DRIVER(fileName,mesh); + return ret; + } + default: + throw MED_EXCEPTION ("access type has not been properly specified to the method"); + } + break; } case NO_DRIVER : { @@ -52,19 +120,53 @@ GENDRIVER *DRIVERFACTORY::buildDriverForMesh(driverTypes driverType, const std:: } } -GENDRIVER *DRIVERFACTORY::buildDriverForMed(driverTypes driverType, const std::string & fileName, MED *med) +GENDRIVER *DRIVERFACTORY::buildDriverForMed(driverTypes driverType, + const std::string & fileName, + MED *med, med_mode_acces access) { GENDRIVER *ret; + switch(driverType) { case MED_DRIVER : { - ret=new MED_MED_RDWR_DRIVER(fileName,med); - break ; + switch(access) + { + case MED_LECT : { + ret=new MED_MED_RDONLY_DRIVER(fileName,med); + break ; + } + case MED_ECRI : { + ret=new MED_MED_WRONLY_DRIVER(fileName,med); + break ; + } + case MED_REMP : { + ret=new MED_MED_RDONLY_DRIVER(fileName,med); + break ; + } + default: + throw MED_EXCEPTION ("access type has not been properly specified to the method"); + } + break; } case VTK_DRIVER : { - ret=new VTK_MED_DRIVER(fileName,med); - break ; + switch(access) + { + case MED_LECT : { + throw MED_EXCEPTION ("access mode other than MED_ECRI or MED_REMPT has been specified with the VTK_DRIVER type which is not allowed because VTK_DRIVER is only a write access driver"); + } + case MED_ECRI : { + ret=new VTK_MED_DRIVER(fileName,med); + break ; + } + case MED_REMP : { + ret=new VTK_MED_DRIVER(fileName,med); + break ; + } + default: + throw MED_EXCEPTION ("access type has not been properly specified to the method"); + } + break; } case GIBI_DRIVER : { diff --git a/src/MEDMEM/MEDMEM_DriverFactory.hxx b/src/MEDMEM/MEDMEM_DriverFactory.hxx index 4ca108492..b3ad300a6 100644 --- a/src/MEDMEM/MEDMEM_DriverFactory.hxx +++ b/src/MEDMEM/MEDMEM_DriverFactory.hxx @@ -13,26 +13,70 @@ namespace MEDMEM { class MED; namespace DRIVERFACTORY { - GENDRIVER *buildDriverForMesh(driverTypes driverType, const std::string & fileName, MESH *mesh,const string & driverName); + GENDRIVER *buildDriverForMesh(driverTypes driverType, + const std::string & fileName, + MESH *mesh,const string & driverName, + MED_EN::med_mode_acces access); template - GENDRIVER *buildDriverForField(driverTypes driverType, const std::string & fileName, FIELD *field); - GENDRIVER *buildDriverForMed(driverTypes driverType, const std::string & fileName, MED *med); + GENDRIVER *buildDriverForField(driverTypes driverType, + const std::string & fileName, + FIELD *fielde, + MED_EN::med_mode_acces access); + GENDRIVER *buildDriverForMed(driverTypes driverType, + const std::string & fileName, + MED *mede, + MED_EN::med_mode_acces access); } template -GENDRIVER *DRIVERFACTORY::buildDriverForField(driverTypes driverType, const std::string & fileName, FIELD *field) +GENDRIVER *DRIVERFACTORY::buildDriverForField(driverTypes driverType, + const std::string & fileName, + FIELD *field, + MED_EN::med_mode_acces access) { GENDRIVER *ret; switch(driverType) { case MED_DRIVER : { - ret=new MED_FIELD_RDWR_DRIVER(fileName,field); + switch(access) + { + case MED_EN::MED_LECT : { + ret=new MED_FIELD_RDONLY_DRIVER(fileName,field); + break; + } + case MED_EN::MED_ECRI : { + ret=new MED_FIELD_WRONLY_DRIVER(fileName,field); + break; + } + case MED_EN::MED_REMP : { + ret=new MED_FIELD_RDWR_DRIVER(fileName,field); + break; + } + default: + throw MED_EXCEPTION ("access type has not been properly specified to the method"); + } break; } case VTK_DRIVER : { - ret=new VTK_FIELD_DRIVER(fileName,field); - break ; + switch(access) + { + case MED_EN::MED_LECT : { + throw MED_EXCEPTION ("access mode other than MED_ECRI and MED_REMP has been specified with the VTK_DRIVER type which is not allowed because VTK_DRIVER is only a write access driver"); + break; + } + case MED_EN::MED_ECRI : { + ret=new VTK_FIELD_DRIVER(fileName,field); + break; + } + case MED_EN::MED_REMP : { + ret=new VTK_FIELD_DRIVER(fileName,field); + break ; + } + default: + throw MED_EXCEPTION ("access type has not been properly specified to the method"); + } + break; } case GIBI_DRIVER : { diff --git a/src/MEDMEM/MEDMEM_Field.cxx b/src/MEDMEM/MEDMEM_Field.cxx index 9ad9c436e..cfaef1e86 100644 --- a/src/MEDMEM/MEDMEM_Field.cxx +++ b/src/MEDMEM/MEDMEM_Field.cxx @@ -265,7 +265,8 @@ void FIELD_::rmDriver (int index) }; int FIELD_::addDriver (driverTypes driverType, const string & fileName, - const string & driverFieldName) + const string & driverFieldName, + med_mode_acces access) { MESSAGE("int FIELD_::addDriver(driverTypes driverType, const string & fileName, const string & driverFieldName) : adding the driver " << driverType << " fileName = " << fileName.c_str() << " driverFieldName = " << driverFieldName.c_str()); return 0; diff --git a/src/MEDMEM/MEDMEM_Field.hxx b/src/MEDMEM/MEDMEM_Field.hxx index 0f1f6903c..cde465b13 100644 --- a/src/MEDMEM/MEDMEM_Field.hxx +++ b/src/MEDMEM/MEDMEM_Field.hxx @@ -164,7 +164,9 @@ public: virtual void rmDriver(int index); virtual int addDriver(driverTypes driverType, const string & fileName="Default File Name.med", - const string & driverFieldName="Default Field Nam") ; + const string & driverFieldName="Default Field Nam", + MED_EN::med_mode_acces access=MED_EN::MED_REMP) ; + virtual int addDriver( GENDRIVER & driver); virtual void read (const GENDRIVER &); virtual void read(int index=0); @@ -600,7 +602,9 @@ public: void rmDriver(int index=0); int addDriver(driverTypes driverType, const string & fileName="Default File Name.med", - const string & driverFieldName="Default Field Name") ; + const string & driverFieldName="Default Field Name", + MED_EN::med_mode_acces access=MED_EN::MED_REMP) ; + int addDriver(GENDRIVER & driver); void allocValue(const int NumberOfComponents); @@ -1642,15 +1646,17 @@ template FIELD::FIELD(const SUPPORT * Support, _time = 0.0; _orderNumber = orderNumber; - switch(driverType) - { - case MED_DRIVER : - { - MED_FIELD_RDONLY_DRIVER myDriver(fileName,this); - myDriver.setFieldName(fieldDriverName); - current = addDriver(myDriver); - break; - } + current = addDriver(driverType,fileName,fieldDriverName,MED_LECT); + +// switch(driverType) +// { +// case MED_DRIVER : +// { +// MED_FIELD_RDONLY_DRIVER myDriver(fileName,this); +// myDriver.setFieldName(fieldDriverName); +// current = addDriver(myDriver); +// break; +// } // current = addDriver(driverType,fileName,fieldDriverName); // switch(_drivers[current]->getAccessMode() ) { // case MED_WRONLY : { @@ -1660,12 +1666,12 @@ template FIELD::FIELD(const SUPPORT * Support, // default : { // } // } - default : - { - throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Driver type unknown : can't create driver!")); - break; - } - } +// default : +// { +// throw MEDEXCEPTION(LOCALIZED(STRING(LOC)<<"Driver type unknown : can't create driver!")); +// break; +// } +// } _drivers[current]->open(); _drivers[current]->read(); @@ -1781,9 +1787,10 @@ template void FIELD::deallocValue() template int FIELD::addDriver(driverTypes driverType, const string & fileName/*="Default File Name.med"*/, - const string & driverName/*="Default Field Name"*/) + const string & driverName/*="Default Field Name"*/, + MED_EN::med_mode_acces access) { - const char * LOC = "FIELD::addDriver(driverTypes driverType, const string & fileName=\"Default File Name.med\",const string & driverName=\"Default Field Name\") : "; + const char * LOC = "FIELD::addDriver(driverTypes driverType, const string & fileName=\"Default File Name.med\",const string & driverName=\"Default Field Name\,MED_EN::med_mode_acces access) : "; GENDRIVER * driver; @@ -1791,7 +1798,7 @@ template int FIELD::addDriver(driverTypes driverType, SCRUTE(driverType); - driver = DRIVERFACTORY::buildDriverForField(driverType,fileName,this); + driver = DRIVERFACTORY::buildDriverForField(driverType,fileName,this,access); _drivers.push_back(driver); diff --git a/src/MEDMEM/MEDMEM_Med.cxx b/src/MEDMEM/MEDMEM_Med.cxx index 1ae52600e..2041f3cc4 100644 --- a/src/MEDMEM/MEDMEM_Med.cxx +++ b/src/MEDMEM/MEDMEM_Med.cxx @@ -32,7 +32,7 @@ MED::MED(driverTypes driverType, const string & fileName) MESSAGE(LOC << "driverType = " << driverType); - int current = addDriver(driverType,fileName); + int current = addDriver(driverType,fileName,MED_LECT); _drivers[current]->open(); _drivers[current]->readFileStruct(); @@ -149,7 +149,9 @@ MED::~MED() Create the specified driver and return its index reference to path to read or write methods. */ -int MED::addDriver(driverTypes driverType, const string & fileName="Default File Name.med") { +int MED::addDriver(driverTypes driverType, + const string & fileName="Default File Name.med", + MED_EN::med_mode_acces access) { const char * LOC = "MED::addDriver(driverTypes driverType, const string & fileName=\"Default File Name.med\") : "; @@ -158,8 +160,10 @@ int MED::addDriver(driverTypes driverType, const string & fileName="Default File MESSAGE(LOC << " the file name is " << fileName); SCRUTE(driverType); + SCRUTE(access); - GENDRIVER *driver = DRIVERFACTORY::buildDriverForMed(driverType,fileName,this); + GENDRIVER *driver = DRIVERFACTORY::buildDriverForMed(driverType,fileName, + this,access); _drivers.push_back(driver); diff --git a/src/MEDMEM/MEDMEM_Med.hxx b/src/MEDMEM/MEDMEM_Med.hxx index cd83deba7..910f9f0d2 100644 --- a/src/MEDMEM/MEDMEM_Med.hxx +++ b/src/MEDMEM/MEDMEM_Med.hxx @@ -80,7 +80,9 @@ public: void addField ( FIELD_ * const ptrField ) throw (MED_EXCEPTION) ; void addMesh ( MESH * const ptrMesh ) throw (MED_EXCEPTION) ; - int addDriver (driverTypes driverType, const string & fileName); + int addDriver (driverTypes driverType, + const string & fileName, + MED_EN::med_mode_acces access=MED_EN::MED_REMP); int addDriver (GENDRIVER & driver); void rmDriver (int index=0) throw (MEDEXCEPTION) ; diff --git a/src/MEDMEM/MEDMEM_MedFieldDriver.hxx b/src/MEDMEM/MEDMEM_MedFieldDriver.hxx index 6bf171c13..71d9fd1aa 100644 --- a/src/MEDMEM/MEDMEM_MedFieldDriver.hxx +++ b/src/MEDMEM/MEDMEM_MedFieldDriver.hxx @@ -167,7 +167,7 @@ public : Constructor. */ MED_FIELD_RDONLY_DRIVER(const string & fileName, FIELD * ptrField): - MED_FIELD_DRIVER(fileName,ptrField,MED_RDONLY) { + MED_FIELD_DRIVER(fileName,ptrField,MED_EN::MED_RDONLY) { BEGIN_OF("MED_FIELD_RDONLY_DRIVER::MED_FIELD_RDONLY_DRIVER(const string & fileName, const FIELD * ptrField)"); END_OF("MED_FIELD_RDONLY_DRIVER::MED_FIELD_RDONLY_DRIVER(const string & fileName, const FIELD * ptrField)"); } @@ -220,7 +220,7 @@ public : Constructor. */ MED_FIELD_WRONLY_DRIVER(const string & fileName, FIELD * ptrField): - MED_FIELD_DRIVER(fileName,ptrField,MED_WRONLY) + MED_FIELD_DRIVER(fileName,ptrField,MED_EN::MED_WRONLY) { BEGIN_OF("MED_FIELD_WRONLY_DRIVER::MED_FIELD_WRONLY_DRIVER(const string & fileName, const FIELD * ptrField)"); END_OF("MED_FIELD_WRONLY_DRIVER::MED_FIELD_WRONLY_DRIVER(const string & fileName, const FIELD * ptrField)"); diff --git a/src/MEDMEM/MEDMEM_Mesh.cxx b/src/MEDMEM/MEDMEM_Mesh.cxx index 03e283202..9a3a4485c 100644 --- a/src/MEDMEM/MEDMEM_Mesh.cxx +++ b/src/MEDMEM/MEDMEM_Mesh.cxx @@ -36,9 +36,11 @@ using namespace MED_EN; /*! Add a %MESH driver of type %driverTypes (MED_DRIVER, ....) associated with file fileName. The meshname used in the file is driverName. addDriver returns an integer handler. */ int MESH::addDriver(driverTypes driverType, - const string & fileName/*="Default File Name.med"*/,const string & driverName/*="Default Mesh Name"*/) { + const string & fileName/*="Default File Name.med"*/, + const string & driverName/*="Default Mesh Name"*/, + med_mode_acces access) { - const char * LOC = "MESH::addDriver(driverTypes driverType, const string & fileName=\"Default File Name.med\",const string & driverName=\"Default Mesh Name\") : "; + const char * LOC = "MESH::addDriver(driverTypes driverType, const string & fileName=\"Default File Name.med\",const string & driverName=\"Default Mesh Name\",MED_EN::med_mode_acces access) : "; GENDRIVER * driver; @@ -46,7 +48,8 @@ int MESH::addDriver(driverTypes driverType, SCRUTE(driverType); - driver = DRIVERFACTORY::buildDriverForMesh(driverType,fileName,this,driverName) ; + driver = DRIVERFACTORY::buildDriverForMesh(driverType,fileName,this, + driverName,access) ; _drivers.push_back(driver); @@ -296,7 +299,7 @@ MESH::MESH(driverTypes driverType, const string & fileName/*=""*/, const string BEGIN_OF(LOC); init(); - GENDRIVER *myDriver=DRIVERFACTORY::buildDriverForMesh(driverType,fileName,this,driverName); + GENDRIVER *myDriver=DRIVERFACTORY::buildDriverForMesh(driverType,fileName,this,driverName,MED_LECT); current = addDriver(*myDriver); delete myDriver; _drivers[current]->open(); diff --git a/src/MEDMEM/MEDMEM_Mesh.hxx b/src/MEDMEM/MEDMEM_Mesh.hxx index 590b4d26f..ebe7bdc96 100644 --- a/src/MEDMEM/MEDMEM_Mesh.hxx +++ b/src/MEDMEM/MEDMEM_Mesh.hxx @@ -124,7 +124,8 @@ public : int addDriver(driverTypes driverType, const string & fileName ="Default File Name.med", - const string & driverName="Default Mesh Name"); + const string & driverName="Default Mesh Name", + MED_EN::med_mode_acces access=MED_EN::MED_REMP); int addDriver(GENDRIVER & driver); void rmDriver(int index=0); diff --git a/src/MEDMEM_SWIG/libMEDMEM_Swig.i b/src/MEDMEM_SWIG/libMEDMEM_Swig.i index b1adf35f8..f366cf9a1 100644 --- a/src/MEDMEM_SWIG/libMEDMEM_Swig.i +++ b/src/MEDMEM_SWIG/libMEDMEM_Swig.i @@ -633,10 +633,11 @@ public: %extend { int addDriver(driverTypes driverType, char * fileName="Default File Name.med", - char * driverName="Default Field Name") + char * driverName="Default Field Name", + med_mode_acces access=MED_REMP) { return self->addDriver(driverType,string(fileName), - string(driverName)); + string(driverName),access); } } @@ -1101,10 +1102,11 @@ public : int addDriver(driverTypes driverType, char * fileName="Default File Name.med", - char * driverName="Default Mesh Name") + char * driverName="Default Mesh Name", + med_mode_acces access=MED_REMP) { return self->addDriver(driverType,string(fileName), - string(driverName)); + string(driverName),access); } void write(int index=0, char * driverName="") @@ -1581,9 +1583,10 @@ class MED } int addDriver(driverTypes driverType, - char * fileName="Default File Name.med") + char * fileName="Default File Name.med", + med_mode_acces access=MED_REMP) { - return self->addDriver(driverType,string(fileName)); + return self->addDriver(driverType,string(fileName),access); } %newobject getMeshName(int ); -- 2.39.2