1 #ifndef DRIVERFACTORY_HXX
2 #define DRIVERFACTORY_HXX
4 #include "MEDMEM_MedVersion.hxx"
5 #include "MEDMEM_GenDriver.hxx"
6 #include "MEDMEM_define.hxx"
13 template<class T> class FIELD;
17 namespace DRIVERFACTORY {
20 definition of static variable across the Med Memory of a Med File version
21 for the writing of Med File set to V22
24 extern MED_EN::medFileVersion globalMedFileVersionForWriting;
26 MED_EN::medFileVersion getMedFileVersionForWriting();
28 void setMedFileVersionForWriting(MED_EN::medFileVersion version);
30 GENDRIVER * buildDriverForMesh(driverTypes driverType,
31 const std::string & fileName,
32 MESH *mesh,const string & driverName,
33 MED_EN::med_mode_acces access);
35 GENDRIVER * buildDriverForField(driverTypes driverType,
36 const std::string & fileName,
38 MED_EN::med_mode_acces access);
39 GENDRIVER * buildDriverForMed(driverTypes driverType,
40 const std::string & fileName,
42 MED_EN::med_mode_acces access);
43 GENDRIVER * buildMedDriverFromFile(const string & fileName,
45 MED_EN::med_mode_acces access);
46 GENDRIVER * buildMeshDriverFromFile(const string & fileName,
48 MED_EN::med_mode_acces access);
50 GENDRIVER * buildFieldDriverFromFile(const string & fileName,
52 MED_EN::med_mode_acces access);
53 GENDRIVER * buildConcreteMedDriverForMesh(const std::string & fileName,
55 const string & driverName,
56 MED_EN::med_mode_acces access,
57 MED_EN::medFileVersion version);
59 GENDRIVER * buildConcreteMedDriverForField(const std::string & fileName,
61 MED_EN::med_mode_acces access,
62 MED_EN::medFileVersion version);
66 #include "MEDMEM_VtkFieldDriver.hxx"
67 #include "MEDMEM_MedFieldDriver.hxx"
68 #include "MEDMEM_MedFieldDriver21.hxx"
69 #include "MEDMEM_MedFieldDriver22.hxx"
70 #include "MEDMEM_AsciiFieldDriver.hxx"
74 GENDRIVER * DRIVERFACTORY::buildDriverForField(driverTypes driverType,
75 const std::string & fileName,
77 MED_EN::med_mode_acces access)
85 case MED_EN::MED_LECT : {
86 ret = new MED_FIELD_RDONLY_DRIVER<T>(fileName,field);
89 case MED_EN::MED_ECRI : {
90 ret= new MED_FIELD_WRONLY_DRIVER<T>(fileName,field);
93 case MED_EN::MED_REMP : {
94 ret = new MED_FIELD_RDWR_DRIVER<T>(fileName,field);
98 throw MED_EXCEPTION ("access type has not been properly specified to the method");
106 case MED_EN::MED_LECT : {
107 throw MED_EXCEPTION ("access mode other than MED_ECRI and MED_REMP has been specified with the VTK_DRIVER type which is not allowed because VTK_DRIVER is only a write access driver");
110 case MED_EN::MED_ECRI : {
111 ret=new VTK_FIELD_DRIVER<T>(fileName,field);
114 case MED_EN::MED_REMP : {
115 ret=new VTK_FIELD_DRIVER<T>(fileName,field);
119 throw MED_EXCEPTION ("access type has not been properly specified to the method");
125 throw MED_EXCEPTION ("driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD");
129 case PORFLOW_DRIVER : {
130 throw MED_EXCEPTION ("driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD");
134 case ASCII_DRIVER : {
137 case MED_EN::MED_ECRI : {
138 ret=new ASCII_FIELD_DRIVER<T>(fileName,field);
142 throw MED_EXCEPTION ("driver ASCII_DRIVER on FIELD only in write mod");
148 throw MED_EXCEPTION ("driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD");
152 MED_EXCEPTION ("driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD");
158 GENDRIVER * DRIVERFACTORY::buildFieldDriverFromFile(const string & fileName,
160 MED_EN::med_mode_acces access)
162 MED_EN::medFileVersion version;
166 version = getMedFileVersion(fileName);
168 catch (MEDEXCEPTION & ex)
170 version = DRIVERFACTORY::globalMedFileVersionForWriting;
173 MESSAGE("buildFieldDriverFromFile version of the file " << version);
179 case MED_EN::MED_LECT : {
180 if (version == MED_EN::V21)
181 driver = new MED_FIELD_RDONLY_DRIVER21<T>(fileName,ptrField);
182 else if (version == MED_EN::V22)
183 driver = new MED_FIELD_RDONLY_DRIVER22<T>(fileName,ptrField);
186 case MED_EN::MED_ECRI : {
187 if (version == MED_EN::V21)
188 driver = new MED_FIELD_WRONLY_DRIVER21<T>(fileName,ptrField);
189 else if (version == MED_EN::V22)
190 driver = new MED_FIELD_WRONLY_DRIVER22<T>(fileName,ptrField);
193 case MED_EN::MED_REMP : {
194 if (version == MED_EN::V21)
195 driver = new MED_FIELD_RDWR_DRIVER21<T>(fileName,ptrField);
196 else if (version == MED_EN::V22)
197 driver = new MED_FIELD_RDWR_DRIVER22<T>(fileName,ptrField);
201 throw MED_EXCEPTION ("access type has not been properly specified to the method");
206 GENDRIVER * DRIVERFACTORY::buildConcreteMedDriverForField(const std::string & fileName,
208 MED_EN::med_mode_acces access,
209 MED_EN::medFileVersion version)
212 MESSAGE("buildConcreteMedDriverForField version of the file " << version);
218 case MED_EN::MED_LECT : {
219 if (version == MED_EN::V21)
220 driver = new MED_FIELD_RDONLY_DRIVER21<T>(fileName,ptrField);
221 else if (version == MED_EN::V22)
222 driver = new MED_FIELD_RDONLY_DRIVER22<T>(fileName,ptrField);
225 case MED_EN::MED_ECRI : {
226 if (version == MED_EN::V21)
227 driver = new MED_FIELD_WRONLY_DRIVER21<T>(fileName,ptrField);
228 else if (version == MED_EN::V22)
229 driver = new MED_FIELD_WRONLY_DRIVER22<T>(fileName,ptrField);
232 case MED_EN::MED_REMP : {
233 if (version == MED_EN::V21)
234 driver = new MED_FIELD_RDWR_DRIVER21<T>(fileName,ptrField);
235 else if (version == MED_EN::V22)
236 driver = new MED_FIELD_RDWR_DRIVER22<T>(fileName,ptrField);
240 throw MED_EXCEPTION ("access type has not been properly specified to the method");