1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
20 #ifndef DRIVERFACTORY_HXX
21 #define DRIVERFACTORY_HXX
23 #include "MEDMEM_MedVersion.hxx"
24 #include "MEDMEM_GenDriver.hxx"
25 #include "MEDMEM_define.hxx"
27 #include "MEDMEM_FieldForward.hxx"
37 namespace DRIVERFACTORY {
40 definition of static variable across the Med Memory of a Med File version
41 for the writing of Med File set to V22
44 extern MED_EN::medFileVersion globalMedFileVersionForWriting;
46 MED_EN::medFileVersion getMedFileVersionForWriting();
48 void setMedFileVersionForWriting(MED_EN::medFileVersion version);
50 driverTypes deduceDriverTypeFromFileName(const std::string & fileName);
52 GENDRIVER * buildDriverForMesh(driverTypes driverType,
53 const std::string & fileName,
54 MESH *mesh,const string & driverName,
55 MED_EN::med_mode_acces access);
57 template<class T, class INTERLACING_TAG>
58 GENDRIVER * buildDriverForField(driverTypes driverType,
59 const std::string & fileName,
60 FIELD<T,INTERLACING_TAG> *fielde,
61 MED_EN::med_mode_acces access);
62 GENDRIVER * buildDriverForMed(driverTypes driverType,
63 const std::string & fileName,
65 MED_EN::med_mode_acces access);
66 GENDRIVER * buildMedDriverFromFile(const string & fileName,
68 MED_EN::med_mode_acces access);
69 GENDRIVER * buildMeshDriverFromFile(const string & fileName,
71 MED_EN::med_mode_acces access);
72 template<class T, class INTERLACING_TAG>
73 GENDRIVER * buildFieldDriverFromFile(const string & fileName,
74 FIELD<T,INTERLACING_TAG> * ptrField,
75 MED_EN::med_mode_acces access);
76 GENDRIVER * buildConcreteMedDriverForMesh(const std::string & fileName,
78 const string & driverName,
79 MED_EN::med_mode_acces access,
80 MED_EN::medFileVersion version);
81 template<class T, class INTERLACING_TAG>
82 GENDRIVER * buildConcreteMedDriverForField(const std::string & fileName,
83 FIELD<T,INTERLACING_TAG> *fielde,
84 MED_EN::med_mode_acces access,
85 MED_EN::medFileVersion version);
89 #include "MEDMEM_VtkFieldDriver.hxx"
90 #include "MEDMEM_MedFieldDriver.hxx"
91 #include "MEDMEM_MedFieldDriver21.hxx"
92 #include "MEDMEM_MedFieldDriver22.hxx"
93 #include "MEDMEM_AsciiFieldDriver.hxx"
96 template<class T, class INTERLACING_TAG>
97 GENDRIVER * DRIVERFACTORY::buildDriverForField(driverTypes driverType,
98 const std::string & fileName,
99 FIELD<T,INTERLACING_TAG> *field,
100 MED_EN::med_mode_acces access)
108 case MED_EN::MED_LECT : {
109 ret = new MED_FIELD_RDONLY_DRIVER<T>(fileName,field);
112 case MED_EN::MED_ECRI : {
113 ret= new MED_FIELD_WRONLY_DRIVER<T>(fileName,field);
116 case MED_EN::MED_REMP : {
117 ret = new MED_FIELD_RDWR_DRIVER<T>(fileName,field);
121 throw MED_EXCEPTION ("access type has not been properly specified to the method");
129 case MED_EN::MED_LECT : {
130 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");
133 case MED_EN::MED_ECRI : {
134 ret=new VTK_FIELD_DRIVER<T>(fileName,field);
137 case MED_EN::MED_REMP : {
138 ret=new VTK_FIELD_DRIVER<T>(fileName,field);
142 throw MED_EXCEPTION ("access type has not been properly specified to the method");
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 case PORFLOW_DRIVER : {
153 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");
157 case ASCII_DRIVER : {
160 case MED_EN::MED_ECRI : {
161 ret=new ASCII_FIELD_DRIVER<T>(fileName,field);
165 throw MED_EXCEPTION ("driver ASCII_DRIVER on FIELD only in write mod");
171 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");
175 MED_EXCEPTION ("driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD");
180 template<class T, class INTERLACING_TAG>
181 GENDRIVER * DRIVERFACTORY::buildFieldDriverFromFile(const string & fileName,
182 FIELD<T,INTERLACING_TAG> * ptrField,
183 MED_EN::med_mode_acces access)
185 MED_EN::medFileVersion version;
189 version = getMedFileVersion(fileName);
191 catch (MEDEXCEPTION & ex)
193 version = DRIVERFACTORY::globalMedFileVersionForWriting;
196 MESSAGE("buildFieldDriverFromFile version of the file " << version);
202 case MED_EN::MED_LECT : {
203 if (version == MED_EN::V21)
204 driver = new MED_FIELD_RDONLY_DRIVER21<T>(fileName,ptrField);
205 else if (version == MED_EN::V22)
206 driver = new MED_FIELD_RDONLY_DRIVER22<T>(fileName,ptrField);
209 case MED_EN::MED_ECRI : {
210 if (version == MED_EN::V21)
211 driver = new MED_FIELD_WRONLY_DRIVER21<T>(fileName,ptrField);
212 else if (version == MED_EN::V22)
213 driver = new MED_FIELD_WRONLY_DRIVER22<T>(fileName,ptrField);
216 case MED_EN::MED_REMP : {
217 if (version == MED_EN::V21)
218 driver = new MED_FIELD_RDWR_DRIVER21<T>(fileName,ptrField);
219 else if (version == MED_EN::V22)
220 driver = new MED_FIELD_RDWR_DRIVER22<T>(fileName,ptrField);
224 throw MED_EXCEPTION ("access type has not been properly specified to the method");
228 template<class T, class INTERLACING_TAG>
229 GENDRIVER * DRIVERFACTORY::buildConcreteMedDriverForField(const std::string & fileName,
230 FIELD<T,INTERLACING_TAG> *ptrField,
231 MED_EN::med_mode_acces access,
232 MED_EN::medFileVersion version)
235 MESSAGE("buildConcreteMedDriverForField version of the file " << version);
241 case MED_EN::MED_LECT : {
242 if (version == MED_EN::V21)
243 driver = new MED_FIELD_RDONLY_DRIVER21<T>(fileName,ptrField);
244 else if (version == MED_EN::V22)
245 driver = new MED_FIELD_RDONLY_DRIVER22<T>(fileName,ptrField);
248 case MED_EN::MED_ECRI : {
249 if (version == MED_EN::V21)
250 driver = new MED_FIELD_WRONLY_DRIVER21<T>(fileName,ptrField);
251 else if (version == MED_EN::V22)
252 driver = new MED_FIELD_WRONLY_DRIVER22<T>(fileName,ptrField);
255 case MED_EN::MED_REMP : {
256 if (version == MED_EN::V21)
257 driver = new MED_FIELD_RDWR_DRIVER21<T>(fileName,ptrField);
258 else if (version == MED_EN::V22)
259 driver = new MED_FIELD_RDWR_DRIVER22<T>(fileName,ptrField);
263 throw MED_EXCEPTION ("access type has not been properly specified to the method");