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