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 GENDRIVER * buildDriverForMesh(driverTypes driverType,
51 const std::string & fileName,
52 MESH *mesh,const string & driverName,
53 MED_EN::med_mode_acces access);
55 template<class T, class INTERLACING_TAG>
56 GENDRIVER * buildDriverForField(driverTypes driverType,
57 const std::string & fileName,
58 FIELD<T,INTERLACING_TAG> *fielde,
59 MED_EN::med_mode_acces access);
60 GENDRIVER * buildDriverForMed(driverTypes driverType,
61 const std::string & fileName,
63 MED_EN::med_mode_acces access);
64 GENDRIVER * buildMedDriverFromFile(const string & fileName,
66 MED_EN::med_mode_acces access);
67 GENDRIVER * buildMeshDriverFromFile(const string & fileName,
69 MED_EN::med_mode_acces access);
70 template<class T, class INTERLACING_TAG>
71 GENDRIVER * buildFieldDriverFromFile(const string & fileName,
72 FIELD<T,INTERLACING_TAG> * ptrField,
73 MED_EN::med_mode_acces access);
74 GENDRIVER * buildConcreteMedDriverForMesh(const std::string & fileName,
76 const string & driverName,
77 MED_EN::med_mode_acces access,
78 MED_EN::medFileVersion version);
79 template<class T, class INTERLACING_TAG>
80 GENDRIVER * buildConcreteMedDriverForField(const std::string & fileName,
81 FIELD<T,INTERLACING_TAG> *fielde,
82 MED_EN::med_mode_acces access,
83 MED_EN::medFileVersion version);
87 #include "MEDMEM_VtkFieldDriver.hxx"
88 #include "MEDMEM_MedFieldDriver.hxx"
89 #include "MEDMEM_MedFieldDriver21.hxx"
90 #include "MEDMEM_MedFieldDriver22.hxx"
91 #include "MEDMEM_AsciiFieldDriver.hxx"
94 template<class T, class INTERLACING_TAG>
95 GENDRIVER * DRIVERFACTORY::buildDriverForField(driverTypes driverType,
96 const std::string & fileName,
97 FIELD<T,INTERLACING_TAG> *field,
98 MED_EN::med_mode_acces access)
106 case MED_EN::MED_LECT : {
107 ret = new MED_FIELD_RDONLY_DRIVER<T>(fileName,field);
110 case MED_EN::MED_ECRI : {
111 ret= new MED_FIELD_WRONLY_DRIVER<T>(fileName,field);
114 case MED_EN::MED_REMP : {
115 ret = new MED_FIELD_RDWR_DRIVER<T>(fileName,field);
119 throw MED_EXCEPTION ("access type has not been properly specified to the method");
127 case MED_EN::MED_LECT : {
128 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");
131 case MED_EN::MED_ECRI : {
132 ret=new VTK_FIELD_DRIVER<T>(fileName,field);
135 case MED_EN::MED_REMP : {
136 ret=new VTK_FIELD_DRIVER<T>(fileName,field);
140 throw MED_EXCEPTION ("access type has not been properly specified to the method");
146 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");
150 case PORFLOW_DRIVER : {
151 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");
155 case ASCII_DRIVER : {
158 case MED_EN::MED_ECRI : {
159 ret=new ASCII_FIELD_DRIVER<T>(fileName,field);
163 throw MED_EXCEPTION ("driver ASCII_DRIVER on FIELD only in write mod");
169 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");
173 MED_EXCEPTION ("driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD");
178 template<class T, class INTERLACING_TAG>
179 GENDRIVER * DRIVERFACTORY::buildFieldDriverFromFile(const string & fileName,
180 FIELD<T,INTERLACING_TAG> * ptrField,
181 MED_EN::med_mode_acces access)
183 MED_EN::medFileVersion version;
187 version = getMedFileVersion(fileName);
189 catch (MEDEXCEPTION & ex)
191 version = DRIVERFACTORY::globalMedFileVersionForWriting;
194 MESSAGE("buildFieldDriverFromFile version of the file " << version);
200 case MED_EN::MED_LECT : {
201 if (version == MED_EN::V21)
202 driver = new MED_FIELD_RDONLY_DRIVER21<T>(fileName,ptrField);
203 else if (version == MED_EN::V22)
204 driver = new MED_FIELD_RDONLY_DRIVER22<T>(fileName,ptrField);
207 case MED_EN::MED_ECRI : {
208 if (version == MED_EN::V21)
209 driver = new MED_FIELD_WRONLY_DRIVER21<T>(fileName,ptrField);
210 else if (version == MED_EN::V22)
211 driver = new MED_FIELD_WRONLY_DRIVER22<T>(fileName,ptrField);
214 case MED_EN::MED_REMP : {
215 if (version == MED_EN::V21)
216 driver = new MED_FIELD_RDWR_DRIVER21<T>(fileName,ptrField);
217 else if (version == MED_EN::V22)
218 driver = new MED_FIELD_RDWR_DRIVER22<T>(fileName,ptrField);
222 throw MED_EXCEPTION ("access type has not been properly specified to the method");
226 template<class T, class INTERLACING_TAG>
227 GENDRIVER * DRIVERFACTORY::buildConcreteMedDriverForField(const std::string & fileName,
228 FIELD<T,INTERLACING_TAG> *ptrField,
229 MED_EN::med_mode_acces access,
230 MED_EN::medFileVersion version)
233 MESSAGE("buildConcreteMedDriverForField version of the file " << version);
239 case MED_EN::MED_LECT : {
240 if (version == MED_EN::V21)
241 driver = new MED_FIELD_RDONLY_DRIVER21<T>(fileName,ptrField);
242 else if (version == MED_EN::V22)
243 driver = new MED_FIELD_RDONLY_DRIVER22<T>(fileName,ptrField);
246 case MED_EN::MED_ECRI : {
247 if (version == MED_EN::V21)
248 driver = new MED_FIELD_WRONLY_DRIVER21<T>(fileName,ptrField);
249 else if (version == MED_EN::V22)
250 driver = new MED_FIELD_WRONLY_DRIVER22<T>(fileName,ptrField);
253 case MED_EN::MED_REMP : {
254 if (version == MED_EN::V21)
255 driver = new MED_FIELD_RDWR_DRIVER21<T>(fileName,ptrField);
256 else if (version == MED_EN::V22)
257 driver = new MED_FIELD_RDWR_DRIVER22<T>(fileName,ptrField);
261 throw MED_EXCEPTION ("access type has not been properly specified to the method");