Salome HOME
Fix problem of make distcheck
[modules/med.git] / src / MEDMEM / MEDMEM_DriverFactory.ixx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef DRIVERFACTORY_IXX
24 #define DRIVERFACTORY_IXX
25
26 #include "MEDMEM_VtkFieldDriver.hxx"
27 #include "MEDMEM_MedFieldDriver.hxx"
28 #include "MEDMEM_AsciiFieldDriver.hxx"
29 #include "MEDMEM_EnsightFieldDriver.hxx"
30
31 namespace MEDMEM {
32   template<class T, class INTERLACING_TAG>
33   GENDRIVER * DRIVERFACTORY::buildDriverForField(driverTypes driverType,
34                                                  const std::string & fileName,
35                                                  FIELD<T,INTERLACING_TAG> *field,
36                                                  MED_EN::med_mode_acces access)
37   {
38     GENDRIVER *ret;
39     switch(driverType)
40       {
41       case MED_DRIVER : {
42         switch(access)
43           {
44           case MED_EN::RDONLY : {
45             ret = new MED_FIELD_RDONLY_DRIVER<T>(fileName,field);
46             break;
47           }
48           case MED_EN::WRONLY : {
49             ret= new MED_FIELD_WRONLY_DRIVER<T>(fileName,field);
50             break;
51           }
52           case MED_EN::RDWR : {
53             ret = new MED_FIELD_RDWR_DRIVER<T>(fileName,field);
54             break;
55           }
56           default:
57             throw MED_EXCEPTION ("access type has not been properly specified to the method");
58           }
59         break;
60       }
61
62       case ENSIGHT_DRIVER : {
63         switch(access)
64           {
65           case MED_EN::RDONLY : {
66             ret = new ENSIGHT_FIELD_RDONLY_DRIVER(fileName,field);
67             break;
68           }
69           case MED_EN::WRONLY : {
70             ret=new ENSIGHT_FIELD_WRONLY_DRIVER(fileName,field);
71             break;
72           }
73           case MED_EN::RDWR : {
74             throw MED_EXCEPTION ("not yet implemented");
75             break ;
76           }
77           default:
78             throw MED_EXCEPTION ("access type has not been properly specified to the method");
79           }
80         break;
81       }
82
83       case VTK_DRIVER : {
84         switch(access)
85           {
86           case MED_EN::RDONLY : {
87             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");
88             break;
89           }
90           case MED_EN::WRONLY : {
91             ret=new VTK_FIELD_DRIVER<T>(fileName,field);
92             break;
93           }
94           case MED_EN::RDWR : {
95             ret=new VTK_FIELD_DRIVER<T>(fileName,field);
96             break ;
97           }
98           default:
99             throw MED_EXCEPTION ("access type has not been properly specified to the method");
100           }
101         break;
102       }
103
104       case GIBI_DRIVER : {
105         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");
106         break;
107       }
108
109       case PORFLOW_DRIVER : {
110         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");
111         break;
112       }
113
114       case ASCII_DRIVER : {
115         switch(access)
116           {
117           case MED_EN::WRONLY : {
118             ret=new ASCII_FIELD_DRIVER<T>(fileName,field);
119             break;
120           }
121           default:
122             throw MED_EXCEPTION ("driver ASCII_DRIVER on FIELD only in write mod");
123           }
124         break;
125       }
126
127       case NO_DRIVER : {
128         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         break;
130       }
131       default:
132         MED_EXCEPTION ("driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD");
133       }
134     return ret;
135   }
136
137   template<class T, class INTERLACING_TAG>
138   GENDRIVER * DRIVERFACTORY::buildFieldDriverFromFile(const string & fileName,
139                                                       FIELD<T,INTERLACING_TAG> * ptrField,
140                                                       MED_EN::med_mode_acces access)
141   {
142     MED_EN::medFileVersion version = MED_EN::V22;
143
144     try
145       {
146         version = getMedFileVersion(fileName);
147       }
148     catch (MEDEXCEPTION & )
149       {
150       }
151
152     MESSAGE_MED("buildFieldDriverFromFile version of the file " << version);
153
154     GENDRIVER * driver=0;
155
156     switch(access)
157       {
158       case MED_EN::RDONLY : {
159         if (version == MED_EN::V21)
160           throw MED_EXCEPTION ("med-2.1 files are no more supported");
161         else if (version == MED_EN::V22)
162           driver = new MED_FIELD_RDONLY_DRIVER<T>(fileName,ptrField);
163         return driver;
164       }
165       case MED_EN::WRONLY : {
166         if (version == MED_EN::V21)
167           throw MED_EXCEPTION ("med-2.1 files are no more supported");
168         else if (version == MED_EN::V22)
169           driver = new MED_FIELD_WRONLY_DRIVER<T>(fileName,ptrField);
170         return driver;
171       }
172       case MED_EN::RDWR : {
173         if (version == MED_EN::V21)
174           throw MED_EXCEPTION ("med-2.1 files are no more supported");
175         else if (version == MED_EN::V22)
176           driver = new MED_FIELD_RDWR_DRIVER<T>(fileName,ptrField);
177         return driver;
178       }
179       default:
180         throw MED_EXCEPTION ("access type has not been properly specified to the method");
181       }
182     return driver;
183   }
184
185   template<class T, class INTERLACING_TAG>
186   GENDRIVER * DRIVERFACTORY::buildConcreteMedDriverForField(const std::string & fileName,
187                                                             FIELD<T,INTERLACING_TAG> *ptrField,
188                                                             MED_EN::med_mode_acces access,
189                                                             MED_EN::medFileVersion version)
190   {
191
192     MESSAGE_MED("buildConcreteMedDriverForField version of the file " << version);
193
194     if (version == MED_EN::V21)
195       throw MED_EXCEPTION ("med-2.1 files are no more supported");
196
197     GENDRIVER * driver=0;
198
199     switch(access)
200       {
201       case MED_EN::RDONLY : {
202         driver = new MED_FIELD_RDONLY_DRIVER<T>(fileName,ptrField);
203         return driver;
204       }
205       case MED_EN::WRONLY : {
206         driver = new MED_FIELD_WRONLY_DRIVER<T>(fileName,ptrField);
207         return driver;
208       }
209       case MED_EN::RDWR : {
210         driver = new MED_FIELD_RDWR_DRIVER<T>(fileName,ptrField);
211         return driver;
212       }
213       default:
214         throw MED_EXCEPTION ("access type has not been properly specified to the method");
215       }
216     return driver;
217   }
218 }
219 #endif