]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_GenDriver.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_GenDriver.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "MEDMEM_GenDriver.hxx"
23 #include "MEDMEM_STRING.hxx"
24 #include "MEDMEM_Exception.hxx"
25
26 using namespace std;
27 using namespace MEDMEM;
28 using namespace MED_EN;
29
30 GENDRIVER::GENDRIVER(driverTypes driverType):
31   _id(MED_INVALID),
32   _fileName(""),
33   _accessMode( (med_mode_acces) MED_INVALID ),
34   _status(MED_INVALID),
35   _driverType(driverType) {}
36
37 GENDRIVER::GENDRIVER(const string & fileName,
38                      med_mode_acces accessMode/*=(med_mode_acces) MED_INVALID*/,
39                      driverTypes driverType)
40   : _id(MED_INVALID),
41     _fileName(fileName),
42     _accessMode(accessMode),
43     _status(MED_CLOSED),
44     _driverType(driverType) 
45 {
46 }
47
48 GENDRIVER::GENDRIVER(const GENDRIVER & genDriver):
49   //_id(MED_INVALID), 
50   _id(genDriver._id),
51   _fileName(genDriver._fileName),
52   _accessMode(genDriver._accessMode),
53   _status(genDriver._status),
54   _driverType(genDriver._driverType) 
55 {}
56
57 GENDRIVER::~GENDRIVER() {}
58
59
60 GENDRIVER & MEDMEM::GENDRIVER::operator=(const GENDRIVER &  genDriver) 
61 {
62   const char* LOC = " GENDRIVER & GENDRIVER::operator=(const GENDRIVER &  genDriver)  : ";
63   BEGIN_OF_MED(LOC);
64   _fileName    = genDriver._fileName;
65   _accessMode  = genDriver._accessMode;
66   _status      = genDriver._status;
67   _id          = genDriver._id;
68   _driverType  = genDriver._driverType;
69   return *this;
70 }
71
72 void GENDRIVER::writeFrom      ( void ) const {}
73 void GENDRIVER::readFileStruct ( void ) {}
74
75 void   GENDRIVER::setMeshName   (const string & ) {}
76 string GENDRIVER::getMeshName()  const { return ""; }
77 void   GENDRIVER::setFieldName  (const string & ) {}
78 string GENDRIVER::getFieldName() const { return ""; }
79
80 void GENDRIVER::openAppend ( void ) {}
81 void GENDRIVER::writeAppend ( void ) const {}
82
83 void GENDRIVER::setId ( int id )
84 {
85   const char* LOC = "void GENDRIVER::setId ( int id ) : ";
86   BEGIN_OF_MED(LOC);
87
88   if ( id >= 0 ) _id=id; else _id = MED_INVALID ;
89
90   END_OF_MED(LOC);
91 }
92
93 int GENDRIVER::getId ( void) const
94 {
95   const char* LOC = "int GENDRIVER::getId ( void) const ";
96   BEGIN_OF_MED(LOC);
97
98   return _id ;
99 }
100
101 string GENDRIVER::getFileName() const {
102
103   const char* LOC = "string GENDRIVER::getFileName() const : ";
104   BEGIN_OF_MED(LOC);
105   
106   return _fileName;
107 }
108     
109
110 void GENDRIVER::setFileName(const string & fileName)
111 {
112   const char * LOC = "void GENDRIVER::setFileName(const string & fileName) : ";
113   BEGIN_OF_MED(LOC);
114
115   if ( _status == MED_OPENED )
116     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" File |" << _fileName 
117                                  << "| is still openned, close it before openning : | " << fileName << "|"));
118   else
119     _fileName = fileName; 
120
121   END_OF_MED(LOC);
122 }
123        
124
125
126 med_mode_acces GENDRIVER::getAccessMode() const
127 {
128   const char* LOC = "med_mode_acces GENDRIVER::getAccessMode() const : ";
129   BEGIN_OF_MED(LOC);
130
131   return _accessMode;
132 }
133
134 ostream & MEDMEM::operator<<(ostream &os,const GENDRIVER & drv)
135 {
136   switch (drv._accessMode)
137     {
138     case RDONLY : 
139       os<<"C'est un IO de READ"<<endl;
140       break;
141     case RDWR :
142       os<<"C'est un IO d'READ/WRITE"<<endl;
143       break;
144       //case MED_REMP :
145       //os <<"C'est un IO de remplacement"<<endl;
146       //break;
147     }
148   switch (drv._status)
149     {
150     case MED_OPENED :
151       os<<"L'IO_Mesh_MED est open"<<endl;
152       break;
153     case MED_CLOSED :
154       os<<"L'IO_Mesh_MED est fermé"<<endl;
155       break;
156     case MED_INVALID :
157       os<<"L'IO_Mesh_MED est non-valide"<<endl;
158       break;
159     }
160   return os;
161 }
162
163 // Test if this driver has been created from  MED driver
164 bool MEDMEM::GENDRIVER::operator ==(const GENDRIVER &genDriver) const {
165   
166
167   MESSAGE_MED("bool GENDRIVER::operator ==(const GENDRIVER &genDriver) const : ");
168
169   return /*( _id == genDriver._id )  &&*/
170     ( _driverType == genDriver._driverType ) &&
171     (_accessMode == genDriver._accessMode);
172   
173 }
174
175 // Take missing data from other driver.
176 // Is for object->read( genDriver ) if object was not passed to genDriver,
177 // then object asks driverFactory to create a driver initialized by object
178 // and fills the new driver up using merge( genDriver )
179
180 void GENDRIVER::merge ( const GENDRIVER &genDriver )
181 {
182   if ( _id == MED_INVALID )
183     _id = genDriver._id;
184   if ( _fileName.empty() )
185     _fileName = genDriver._fileName;
186   if ( _accessMode == MED_INVALID )
187     _accessMode = genDriver._accessMode;
188
189   if ( getMeshName().empty() )
190     setMeshName( genDriver.getMeshName() );
191   if ( getFieldName().empty() )
192     setFieldName( genDriver.getFieldName() );
193 }