Back to index

salome-med  6.5.0
MEDMEM_GenDriver.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "MEDMEM_GenDriver.hxx"
00024 #include "MEDMEM_STRING.hxx"
00025 #include "MEDMEM_Exception.hxx"
00026 
00027 using namespace std;
00028 using namespace MEDMEM;
00029 using namespace MED_EN;
00030 
00031 GENDRIVER::GENDRIVER(driverTypes driverType):
00032   _id(MED_INVALID),
00033   _fileName(""),
00034   _accessMode( (med_mode_acces) MED_INVALID ),
00035   _status(MED_INVALID),
00036   _driverType(driverType) {}
00037 
00038 GENDRIVER::GENDRIVER(const string & fileName,
00039                      med_mode_acces accessMode/*=(med_mode_acces) MED_INVALID*/,
00040                      driverTypes driverType)
00041   : _id(MED_INVALID),
00042     _fileName(fileName),
00043     _accessMode(accessMode),
00044     _status(MED_CLOSED),
00045     _driverType(driverType) 
00046 {
00047 }
00048 
00049 GENDRIVER::GENDRIVER(const GENDRIVER & genDriver):
00050   //_id(MED_INVALID), 
00051   _id(genDriver._id),
00052   _fileName(genDriver._fileName),
00053   _accessMode(genDriver._accessMode),
00054   _status(genDriver._status),
00055   _driverType(genDriver._driverType) 
00056 {}
00057 
00058 GENDRIVER::~GENDRIVER() {}
00059 
00060 
00061 GENDRIVER & MEDMEM::GENDRIVER::operator=(const GENDRIVER &  genDriver) 
00062 {
00063   const char* LOC = " GENDRIVER & GENDRIVER::operator=(const GENDRIVER &  genDriver)  : ";
00064   BEGIN_OF_MED(LOC);
00065   _fileName    = genDriver._fileName;
00066   _accessMode  = genDriver._accessMode;
00067   _status      = genDriver._status;
00068   _id          = genDriver._id;
00069   _driverType  = genDriver._driverType;
00070   return *this;
00071 }
00072 
00073 void GENDRIVER::writeFrom      ( void ) const {}
00074 void GENDRIVER::readFileStruct ( void ) {}
00075 
00076 void   GENDRIVER::setMeshName   (const string & ) {}
00077 string GENDRIVER::getMeshName()  const { return ""; }
00078 void   GENDRIVER::setFieldName  (const string & ) {}
00079 string GENDRIVER::getFieldName() const { return ""; }
00080 
00081 void GENDRIVER::openAppend ( void ) {}
00082 void GENDRIVER::writeAppend ( void ) const {}
00083 
00084 void GENDRIVER::setId ( int id )
00085 {
00086   const char* LOC = "void GENDRIVER::setId ( int id ) : ";
00087   BEGIN_OF_MED(LOC);
00088 
00089   if ( id >= 0 ) _id=id; else _id = MED_INVALID ;
00090 
00091   END_OF_MED(LOC);
00092 }
00093 
00094 int GENDRIVER::getId ( void) const
00095 {
00096   const char* LOC = "int GENDRIVER::getId ( void) const ";
00097   BEGIN_OF_MED(LOC);
00098 
00099   return _id ;
00100 }
00101 
00102 string GENDRIVER::getFileName() const {
00103 
00104   const char* LOC = "string GENDRIVER::getFileName() const : ";
00105   BEGIN_OF_MED(LOC);
00106   
00107   return _fileName;
00108 }
00109     
00110 
00111 void GENDRIVER::setFileName(const string & fileName)
00112 {
00113   const char * LOC = "void GENDRIVER::setFileName(const string & fileName) : ";
00114   BEGIN_OF_MED(LOC);
00115 
00116   if ( _status == MED_OPENED )
00117     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" File |" << _fileName 
00118                                  << "| is still openned, close it before openning : | " << fileName << "|"));
00119   else
00120     _fileName = fileName; 
00121 
00122   END_OF_MED(LOC);
00123 }
00124 
00125 med_mode_acces GENDRIVER::getAccessMode() const
00126 {
00127   const char* LOC = "med_mode_acces GENDRIVER::getAccessMode() const : ";
00128   BEGIN_OF_MED(LOC);
00129 
00130   return _accessMode;
00131 }
00132 
00133 void GENDRIVER::setAccessMode(med_mode_acces mode)
00134 {
00135   _accessMode = mode;
00136 }
00137 
00138 ostream & MEDMEM::operator<<(ostream &os,const GENDRIVER & drv)
00139 {
00140   switch (drv._accessMode)
00141     {
00142     case RDONLY : 
00143       os<<"C'est un IO de READ"<<endl;
00144       break;
00145     case RDWR :
00146       os<<"C'est un IO d'READ/WRITE"<<endl;
00147       break;
00148     case WRONLY :
00149       os<<"C'est un IO d'WRITE"<<endl;
00150       break;
00151     }
00152   switch (drv._status)
00153     {
00154     case MED_OPENED :
00155       os<<"L'IO_Mesh_MED est open"<<endl;
00156       break;
00157     case MED_CLOSED :
00158       os<<"L'IO_Mesh_MED est fermé"<<endl;
00159       break;
00160     case MED_INVALID :
00161       os<<"L'IO_Mesh_MED est non-valide"<<endl;
00162       break;
00163     }
00164   return os;
00165 }
00166 
00167 // Test if this driver has been created from  MED driver
00168 bool MEDMEM::GENDRIVER::operator ==(const GENDRIVER &genDriver) const {
00169   
00170 
00171   MESSAGE_MED("bool GENDRIVER::operator ==(const GENDRIVER &genDriver) const : ");
00172 
00173   return /*( _id == genDriver._id )  &&*/
00174     ( _driverType == genDriver._driverType ) &&
00175     (_accessMode == genDriver._accessMode);
00176   
00177 }
00178 
00179 // Take missing data from other driver.
00180 // Is for object->read( genDriver ) if object was not passed to genDriver,
00181 // then object asks driverFactory to create a driver initialized by object
00182 // and fills the new driver up using merge( genDriver )
00183 
00184 void GENDRIVER::merge ( const GENDRIVER &genDriver )
00185 {
00186   if ( _id == MED_INVALID )
00187     _id = genDriver._id;
00188   if ( _fileName.empty() )
00189     _fileName = genDriver._fileName;
00190   if ( _accessMode == MED_INVALID )
00191     _accessMode = genDriver._accessMode;
00192 
00193   if ( getMeshName().empty() )
00194     setMeshName( genDriver.getMeshName() );
00195   if ( getFieldName().empty() )
00196     setFieldName( genDriver.getFieldName() );
00197 }