Salome HOME
DCQ:prepare 2.0.0
[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 using namespace MEDMEM;
6
7 GENDRIVER::GENDRIVER(): _id(MED_INVALID),
8                         _fileName(""),
9                         _accessMode( (med_mode_acces) MED_INVALID ),
10                         _status(MED_INVALID),
11                         _driverType(NO_DRIVER) {}
12
13 GENDRIVER::GENDRIVER(const string & fileName,
14                      med_mode_acces accessMode=(med_mode_acces) MED_INVALID): _id(MED_INVALID),
15                                                                               _fileName(fileName),
16                                                                               _accessMode(accessMode),
17                                                                               _status(MED_CLOSED),
18                                                                               _driverType(NO_DRIVER) {}
19
20 GENDRIVER::GENDRIVER(const GENDRIVER & genDriver):
21   //_id(MED_INVALID), 
22   _id(genDriver._id),
23   _fileName(genDriver._fileName),
24   _accessMode(genDriver._accessMode),
25   _status(genDriver._status),
26   _driverType(genDriver._driverType) 
27 {}
28
29 GENDRIVER::~GENDRIVER() {}
30
31
32 GENDRIVER & MEDMEM::GENDRIVER::operator=(const GENDRIVER &  genDriver) 
33 {
34   const char * LOC = " GENDRIVER & GENDRIVER::operator=(const GENDRIVER &  genDriver)  : ";
35   
36   BEGIN_OF(LOC);
37   _fileName    = genDriver._fileName;
38   _accessMode  = genDriver._accessMode;
39   _status      = genDriver._status;
40   _id          = genDriver._id;
41   return *this;
42
43   END_OF(LOC);
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   END_OF(LOC);
73 };
74
75 string GENDRIVER::getFileName() const {
76
77   const char * LOC = "string GENDRIVER::getFileName() const : ";
78   BEGIN_OF(LOC);
79   
80   return _fileName;
81
82   END_OF(LOC);
83 }
84     
85
86 void GENDRIVER::setFileName(const string & fileName)  {
87
88   const char * LOC = "void GENDRIVER::setFileName(const string & fileName) : ";
89   BEGIN_OF(LOC);
90
91   if ( _status == MED_OPENED )
92     throw MEDEXCEPTION(LOCALIZED(STRING(LOC) <<" File |" << _fileName 
93                                  << "| is still openned, close it before openning : | " << fileName << "|"));
94   else
95     _fileName = fileName; 
96
97   END_OF(LOC);
98 }
99        
100
101
102 med_mode_acces GENDRIVER::getAccessMode() const {
103
104   const char * LOC = "med_mode_acces GENDRIVER::getAccessMode() const : ";
105
106   BEGIN_OF(LOC);
107
108   return _accessMode;
109
110   END_OF(LOC);
111 }
112
113 ostream & MEDMEM::operator<<(ostream &os,const GENDRIVER & drv)
114 {
115   switch (drv._accessMode)
116     {
117     case MED_RDONLY : 
118       os<<"C'est un IO de READ"<<endl;
119       break;
120     case MED_RDWR :
121       os<<"C'est un IO d'READ/WRITE"<<endl;
122       break;
123     case MED_REMP :
124       os <<"C'est un IO de remplacement"<<endl;
125       break;
126     }
127   switch (drv._status)
128     {
129     case MED_OPENED :
130       os<<"L'IO_Mesh_MED est open"<<endl;
131       break;
132     case MED_CLOSED :
133       os<<"L'IO_Mesh_MED est fermé"<<endl;
134       break;
135     case MED_INVALID :
136       os<<"L'IO_Mesh_MED est non-valide"<<endl;
137       break;
138     }
139   return os;
140 }
141
142 // Test if this driver has been created from  MED driver
143 bool MEDMEM::GENDRIVER::operator ==(const GENDRIVER &genDriver) const {
144   
145   const char * LOC = "bool GENDRIVER::operator ==(const GENDRIVER &genDriver) const : ";
146
147   MESSAGE(LOC);
148
149   return ( _id == genDriver._id )  &&
150     ( _driverType == genDriver._driverType );
151   
152 };
153