]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_GenDriver.cxx
Salome HOME
NRI : Merge from V1_2.
[modules/med.git] / src / MEDMEM / MEDMEM_GenDriver.cxx
1 //  MED MEDMEM : MED files in memory
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : MEDMEM_GenDriver.cxx
25 //  Module : MED
26
27 using namespace std;
28 #include "MEDMEM_GenDriver.hxx"
29 #include "MEDMEM_STRING.hxx"
30 #include "MEDMEM_Exception.hxx"
31
32 GENDRIVER::GENDRIVER(): _id(MED_INVALID),
33                         _fileName(""),
34                         _accessMode( (med_mode_acces) MED_INVALID ),
35                         _status(MED_INVALID),
36                         _driverType(NO_DRIVER) {}
37
38 GENDRIVER::GENDRIVER(const string & fileName,
39                      med_mode_acces accessMode=(med_mode_acces) MED_INVALID): _id(MED_INVALID),
40                                                                               _fileName(fileName),
41                                                                               _accessMode(accessMode),
42                                                                               _status(MED_CLOSED),
43                                                                               _driverType(NO_DRIVER) {}
44
45 GENDRIVER::GENDRIVER(const GENDRIVER & genDriver):
46   //_id(MED_INVALID), 
47   _id(genDriver._id),
48   _fileName(genDriver._fileName),
49   _accessMode(genDriver._accessMode),
50   _status(genDriver._status),
51   _driverType(genDriver._driverType) 
52 {}
53
54 GENDRIVER::~GENDRIVER() {}
55
56
57 GENDRIVER & GENDRIVER::operator=(const GENDRIVER &  genDriver) {
58   const char * LOC = " GENDRIVER & GENDRIVER::operator=(const GENDRIVER &  genDriver)  : ";
59   
60   BEGIN_OF(LOC);
61
62   _fileName    = genDriver._fileName;
63   _accessMode  = genDriver._accessMode;
64   _status      = genDriver._status;
65   _id          = genDriver._id;
66   return *this;
67
68   END_OF(LOC);
69 }
70
71 void GENDRIVER::writeFrom      ( void ) {};
72 void GENDRIVER::readFileStruct ( void ) {};
73
74 void GENDRIVER::setMeshName    (const string & meshName) {};
75 void GENDRIVER::setFieldName   (const string & fieldName) {};
76
77 void GENDRIVER::setId ( int id ) {
78   const char * LOC = "void GENDRIVER::setId ( int id ) : ";
79
80   BEGIN_OF(LOC);
81
82   if ( id >= 0 ) _id=id; else _id = MED_INVALID ;
83
84   END_OF(LOC);
85 };
86
87 int GENDRIVER::getId ( void) const {
88   const char * LOC = "int GENDRIVER::getId ( void) const ";
89
90   BEGIN_OF(LOC);
91
92   return _id ;
93
94   END_OF(LOC);
95 };
96
97 string GENDRIVER::getFileName() const {
98
99   const char * LOC = "string GENDRIVER::getFileName() const : ";
100   BEGIN_OF(LOC);
101   
102   return _fileName;
103
104   END_OF(LOC);
105 }
106     
107
108 void GENDRIVER::setFileName(const string & fileName)  {
109
110   const char * LOC = "void GENDRIVER::setFileName(const string & fileName) : ";
111   BEGIN_OF(LOC);
112
113   if ( _status == MED_OPENED )
114     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" File |" << _fileName 
115                                  << "| is still openned, close it before openning : | " << fileName << "|"));
116   else
117     _fileName = fileName; 
118
119   END_OF(LOC);
120 }
121        
122
123
124 med_mode_acces GENDRIVER::getAccessMode() const {
125
126   const char * LOC = "med_mode_acces GENDRIVER::getAccessMode() const : ";
127
128   BEGIN_OF(LOC);
129
130   return _accessMode;
131
132   END_OF(LOC);
133 }
134
135 ostream & operator<<(ostream &os,const GENDRIVER & drv)
136 {
137   switch (drv._accessMode)
138     {
139     case MED_RDONLY : 
140       os<<"C'est un IO de READ"<<endl;
141       break;
142     case MED_RDWR :
143       os<<"C'est un IO d'READ/WRITE"<<endl;
144       break;
145     }
146   switch (drv._status)
147     {
148     case MED_OPENED :
149       os<<"L'IO_Mesh_MED est open"<<endl;
150       break;
151     case MED_CLOSED :
152       os<<"L'IO_Mesh_MED est fermé"<<endl;
153       break;
154     case MED_INVALID :
155       os<<"L'IO_Mesh_MED est non-valide"<<endl;
156       break;
157     }
158   return os;
159 }
160
161 // Test if this driver has been created from  MED driver
162 bool GENDRIVER::operator ==(const GENDRIVER &genDriver) const {
163   
164   const char * LOC = "bool GENDRIVER::operator ==(const GENDRIVER &genDriver) const : ";
165
166   MESSAGE(LOC);
167
168   return ( _id == genDriver._id )  &&
169     ( _driverType == genDriver._driverType );
170   
171 };