Salome HOME
update from the MedMemory V1.0.1
[modules/med.git] / src / MEDMEM / MEDMEM_GenDriver.cxx
1 using namespace std;
2 #include "MEDMEM_GenDriver.hxx"
3 #include "MEDMEM_STRING.hxx"
4 #include "MEDMEM_Exception.hxx"
5
6 GENDRIVER::GENDRIVER(): _id(MED_INVALID),
7                         _fileName(""),
8                         _accessMode( (med_mode_acces) MED_INVALID ),
9                         _status(MED_INVALID),
10                         _driverType(NO_DRIVER) {}
11
12 GENDRIVER::GENDRIVER(const string & fileName,
13                      med_mode_acces accessMode=(med_mode_acces) MED_INVALID): _id(MED_INVALID),
14                                                                               _fileName(fileName),
15                                                                               _accessMode(accessMode),
16                                                                               _status(MED_CLOSED),
17                                                                               _driverType(NO_DRIVER) {}
18
19 GENDRIVER::GENDRIVER(const GENDRIVER & genDriver):
20   //_id(MED_INVALID), 
21   _id(genDriver._id),
22   _fileName(genDriver._fileName),
23   _accessMode(genDriver._accessMode),
24   _status(genDriver._status),
25   _driverType(genDriver._driverType) 
26 {}
27
28 GENDRIVER::~GENDRIVER() {}
29
30
31 GENDRIVER & GENDRIVER::operator=(const GENDRIVER &  genDriver) {
32   const char * LOC = " GENDRIVER & GENDRIVER::operator=(const GENDRIVER &  genDriver)  : ";
33   
34   BEGIN_OF(LOC);
35
36   _fileName    = genDriver._fileName;
37   _accessMode  = genDriver._accessMode;
38   _status      = genDriver._status;
39   _id          = genDriver._id;
40   return *this;
41
42   END_OF(LOC);
43 }
44
45 void GENDRIVER::writeFrom      ( void ) {};
46 void GENDRIVER::readFileStruct ( void ) {};
47
48 void GENDRIVER::setMeshName    (const string & ) {};
49 void GENDRIVER::setFieldName   (const string & ) {};
50
51 void GENDRIVER::openAppend ( void ) {};
52 void GENDRIVER::writeAppend ( void ) const {};
53
54 void GENDRIVER::setId ( int id ) {
55   const char * LOC = "void GENDRIVER::setId ( int id ) : ";
56
57   BEGIN_OF(LOC);
58
59   if ( id >= 0 ) _id=id; else _id = MED_INVALID ;
60
61   END_OF(LOC);
62 };
63
64 int GENDRIVER::getId ( void) const {
65   const char * LOC = "int GENDRIVER::getId ( void) const ";
66
67   BEGIN_OF(LOC);
68
69   return _id ;
70
71   END_OF(LOC);
72 };
73
74 string GENDRIVER::getFileName() const {
75
76   const char * LOC = "string GENDRIVER::getFileName() const : ";
77   BEGIN_OF(LOC);
78   
79   return _fileName;
80
81   END_OF(LOC);
82 }
83     
84
85 void GENDRIVER::setFileName(const string & fileName)  {
86
87   const char * LOC = "void GENDRIVER::setFileName(const string & fileName) : ";
88   BEGIN_OF(LOC);
89
90   if ( _status == MED_OPENED )
91     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" File |" << _fileName 
92                                  << "| is still openned, close it before openning : | " << fileName << "|"));
93   else
94     _fileName = fileName; 
95
96   END_OF(LOC);
97 }
98        
99
100
101 med_mode_acces GENDRIVER::getAccessMode() const {
102
103   const char * LOC = "med_mode_acces GENDRIVER::getAccessMode() const : ";
104
105   BEGIN_OF(LOC);
106
107   return _accessMode;
108
109   END_OF(LOC);
110 }
111
112 ostream & operator<<(ostream &os,const GENDRIVER & drv)
113 {
114   switch (drv._accessMode)
115     {
116     case MED_RDONLY : 
117       os<<"C'est un IO de READ"<<endl;
118       break;
119     case MED_RDWR :
120       os<<"C'est un IO d'READ/WRITE"<<endl;
121       break;
122     case MED_REMP :
123       os <<"C'est un IO de remplacement"<<endl;
124       break;
125     }
126   switch (drv._status)
127     {
128     case MED_OPENED :
129       os<<"L'IO_Mesh_MED est open"<<endl;
130       break;
131     case MED_CLOSED :
132       os<<"L'IO_Mesh_MED est fermé"<<endl;
133       break;
134     case MED_INVALID :
135       os<<"L'IO_Mesh_MED est non-valide"<<endl;
136       break;
137     }
138   return os;
139 }
140
141 // Test if this driver has been created from  MED driver
142 bool GENDRIVER::operator ==(const GENDRIVER &genDriver) const {
143   
144   const char * LOC = "bool GENDRIVER::operator ==(const GENDRIVER &genDriver) const : ";
145
146   MESSAGE(LOC);
147
148   return ( _id == genDriver._id )  &&
149     ( _driverType == genDriver._driverType );
150   
151 };
152