Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / MEDMEM / MEDMEM_GenDriver.cxx
1 // Copyright (C) 2007-2012  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
23 #include "MEDMEM_GenDriver.hxx"
24 #include "MEDMEM_STRING.hxx"
25 #include "MEDMEM_Exception.hxx"
26
27 using namespace std;
28 using namespace MEDMEM;
29 using namespace MED_EN;
30
31 GENDRIVER::GENDRIVER(driverTypes driverType):
32   _id(MED_INVALID),
33   _fileName(""),
34   _accessMode( (med_mode_acces) MED_INVALID ),
35   _status(MED_INVALID),
36   _driverType(driverType) {}
37
38 GENDRIVER::GENDRIVER(const string & fileName,
39                      med_mode_acces accessMode/*=(med_mode_acces) MED_INVALID*/,
40                      driverTypes driverType)
41   : _id(MED_INVALID),
42     _fileName(fileName),
43     _accessMode(accessMode),
44     _status(MED_CLOSED),
45     _driverType(driverType) 
46 {
47 }
48
49 GENDRIVER::GENDRIVER(const GENDRIVER & genDriver):
50   //_id(MED_INVALID), 
51   _id(genDriver._id),
52   _fileName(genDriver._fileName),
53   _accessMode(genDriver._accessMode),
54   _status(genDriver._status),
55   _driverType(genDriver._driverType) 
56 {}
57
58 GENDRIVER::~GENDRIVER() {}
59
60
61 GENDRIVER & MEDMEM::GENDRIVER::operator=(const GENDRIVER &  genDriver) 
62 {
63   const char* LOC = " GENDRIVER & GENDRIVER::operator=(const GENDRIVER &  genDriver)  : ";
64   BEGIN_OF_MED(LOC);
65   _fileName    = genDriver._fileName;
66   _accessMode  = genDriver._accessMode;
67   _status      = genDriver._status;
68   _id          = genDriver._id;
69   _driverType  = genDriver._driverType;
70   return *this;
71 }
72
73 void GENDRIVER::writeFrom      ( void ) const {}
74 void GENDRIVER::readFileStruct ( void ) {}
75
76 void   GENDRIVER::setMeshName   (const string & ) {}
77 string GENDRIVER::getMeshName()  const { return ""; }
78 void   GENDRIVER::setFieldName  (const string & ) {}
79 string GENDRIVER::getFieldName() const { return ""; }
80
81 void GENDRIVER::openAppend ( void ) {}
82 void GENDRIVER::writeAppend ( void ) const {}
83
84 void GENDRIVER::setId ( int id )
85 {
86   const char* LOC = "void GENDRIVER::setId ( int id ) : ";
87   BEGIN_OF_MED(LOC);
88
89   if ( id >= 0 ) _id=id; else _id = MED_INVALID ;
90
91   END_OF_MED(LOC);
92 }
93
94 int GENDRIVER::getId ( void) const
95 {
96   const char* LOC = "int GENDRIVER::getId ( void) const ";
97   BEGIN_OF_MED(LOC);
98
99   return _id ;
100 }
101
102 string GENDRIVER::getFileName() const {
103
104   const char* LOC = "string GENDRIVER::getFileName() const : ";
105   BEGIN_OF_MED(LOC);
106   
107   return _fileName;
108 }
109     
110
111 void GENDRIVER::setFileName(const string & fileName)
112 {
113   const char * LOC = "void GENDRIVER::setFileName(const string & fileName) : ";
114   BEGIN_OF_MED(LOC);
115
116   if ( _status == MED_OPENED )
117     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" File |" << _fileName 
118                                  << "| is still openned, close it before openning : | " << fileName << "|"));
119   else
120     _fileName = fileName; 
121
122   END_OF_MED(LOC);
123 }
124
125 med_mode_acces GENDRIVER::getAccessMode() const
126 {
127   const char* LOC = "med_mode_acces GENDRIVER::getAccessMode() const : ";
128   BEGIN_OF_MED(LOC);
129
130   return _accessMode;
131 }
132
133 void GENDRIVER::setAccessMode(med_mode_acces mode)
134 {
135   _accessMode = mode;
136 }
137
138 ostream & MEDMEM::operator<<(ostream &os,const GENDRIVER & drv)
139 {
140   switch (drv._accessMode)
141     {
142     case RDONLY : 
143       os<<"C'est un IO de READ"<<endl;
144       break;
145     case RDWR :
146       os<<"C'est un IO d'READ/WRITE"<<endl;
147       break;
148     case WRONLY :
149       os<<"C'est un IO d'WRITE"<<endl;
150       break;
151     }
152   switch (drv._status)
153     {
154     case MED_OPENED :
155       os<<"L'IO_Mesh_MED est open"<<endl;
156       break;
157     case MED_CLOSED :
158       os<<"L'IO_Mesh_MED est fermé"<<endl;
159       break;
160     case MED_INVALID :
161       os<<"L'IO_Mesh_MED est non-valide"<<endl;
162       break;
163     }
164   return os;
165 }
166
167 // Test if this driver has been created from  MED driver
168 bool MEDMEM::GENDRIVER::operator ==(const GENDRIVER &genDriver) const {
169   
170
171   MESSAGE_MED("bool GENDRIVER::operator ==(const GENDRIVER &genDriver) const : ");
172
173   return /*( _id == genDriver._id )  &&*/
174     ( _driverType == genDriver._driverType ) &&
175     (_accessMode == genDriver._accessMode);
176   
177 }
178
179 // Take missing data from other driver.
180 // Is for object->read( genDriver ) if object was not passed to genDriver,
181 // then object asks driverFactory to create a driver initialized by object
182 // and fills the new driver up using merge( genDriver )
183
184 void GENDRIVER::merge ( const GENDRIVER &genDriver )
185 {
186   if ( _id == MED_INVALID )
187     _id = genDriver._id;
188   if ( _fileName.empty() )
189     _fileName = genDriver._fileName;
190   if ( _accessMode == MED_INVALID )
191     _accessMode = genDriver._accessMode;
192
193   if ( getMeshName().empty() )
194     setMeshName( genDriver.getMeshName() );
195   if ( getFieldName().empty() )
196     setFieldName( genDriver.getFieldName() );
197 }