Back to index

salome-med  6.5.0
MEDMEM_DriverFactory.ixx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #ifndef DRIVERFACTORY_IXX
00024 #define DRIVERFACTORY_IXX
00025 
00026 #include "MEDMEM_VtkFieldDriver.hxx"
00027 #include "MEDMEM_MedFieldDriver.hxx"
00028 #include "MEDMEM_AsciiFieldDriver.hxx"
00029 #include "MEDMEM_EnsightFieldDriver.hxx"
00030 
00031 namespace MEDMEM {
00032   template<class T, class INTERLACING_TAG>
00033   GENDRIVER * DRIVERFACTORY::buildDriverForField(driverTypes driverType,
00034                                                  const std::string & fileName,
00035                                                  FIELD<T,INTERLACING_TAG> *field,
00036                                                  MED_EN::med_mode_acces access)
00037   {
00038     GENDRIVER *ret;
00039     switch(driverType)
00040       {
00041       case MED_DRIVER : {
00042         switch(access)
00043           {
00044           case MED_EN::RDONLY : {
00045             ret = new MED_FIELD_RDONLY_DRIVER<T>(fileName,field);
00046             break;
00047           }
00048           case MED_EN::WRONLY : {
00049             ret= new MED_FIELD_WRONLY_DRIVER<T>(fileName,field);
00050             break;
00051           }
00052           case MED_EN::RDWR : {
00053             ret = new MED_FIELD_RDWR_DRIVER<T>(fileName,field);
00054             break;
00055           }
00056           default:
00057             throw MED_EXCEPTION ("access type has not been properly specified to the method");
00058           }
00059         break;
00060       }
00061 
00062       case ENSIGHT_DRIVER : {
00063         switch(access)
00064           {
00065           case MED_EN::RDONLY : {
00066             ret = new ENSIGHT_FIELD_RDONLY_DRIVER(fileName,field);
00067             break;
00068           }
00069           case MED_EN::WRONLY : {
00070             ret=new ENSIGHT_FIELD_WRONLY_DRIVER(fileName,field);
00071             break;
00072           }
00073           case MED_EN::RDWR : {
00074             throw MED_EXCEPTION ("not yet implemented");
00075             break ;
00076           }
00077           default:
00078             throw MED_EXCEPTION ("access type has not been properly specified to the method");
00079           }
00080         break;
00081       }
00082 
00083       case VTK_DRIVER : {
00084         switch(access)
00085           {
00086           case MED_EN::RDONLY : {
00087             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");
00088             break;
00089           }
00090           case MED_EN::WRONLY : {
00091             ret=new VTK_FIELD_DRIVER<T>(fileName,field);
00092             break;
00093           }
00094           case MED_EN::RDWR : {
00095             ret=new VTK_FIELD_DRIVER<T>(fileName,field);
00096             break ;
00097           }
00098           default:
00099             throw MED_EXCEPTION ("access type has not been properly specified to the method");
00100           }
00101         break;
00102       }
00103 
00104       case GIBI_DRIVER : {
00105         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");
00106         break;
00107       }
00108 
00109       case PORFLOW_DRIVER : {
00110         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");
00111         break;
00112       }
00113 
00114       case ASCII_DRIVER : {
00115         switch(access)
00116           {
00117           case MED_EN::WRONLY : {
00118             ret=new ASCII_FIELD_DRIVER<T>(fileName,field);
00119             break;
00120           }
00121           default:
00122             throw MED_EXCEPTION ("driver ASCII_DRIVER on FIELD only in write mod");
00123           }
00124         break;
00125       }
00126 
00127       case NO_DRIVER : {
00128         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");
00129         break;
00130       }
00131       default:
00132         MED_EXCEPTION ("driverType other than MED_DRIVER and VTK_DRIVER has been specified to the method which is not allowed for the object FIELD");
00133       }
00134     return ret;
00135   }
00136 
00137   template<class T, class INTERLACING_TAG>
00138   GENDRIVER * DRIVERFACTORY::buildFieldDriverFromFile(const string & fileName,
00139                                                       FIELD<T,INTERLACING_TAG> * ptrField,
00140                                                       MED_EN::med_mode_acces access)
00141   {
00142     MED_EN::medFileVersion version = MED_EN::V22;
00143 
00144     try
00145       {
00146         version = getMedFileVersion(fileName);
00147       }
00148     catch (MEDEXCEPTION & )
00149       {
00150       }
00151 
00152     MESSAGE_MED("buildFieldDriverFromFile version of the file " << version);
00153 
00154     GENDRIVER * driver=0;
00155 
00156     switch(access)
00157       {
00158       case MED_EN::RDONLY : {
00159         if (version == MED_EN::V21)
00160           throw MED_EXCEPTION ("med-2.1 files are no more supported");
00161         else if (version == MED_EN::V22)
00162           driver = new MED_FIELD_RDONLY_DRIVER<T>(fileName,ptrField);
00163         return driver;
00164       }
00165       case MED_EN::WRONLY : {
00166         if (version == MED_EN::V21)
00167           throw MED_EXCEPTION ("med-2.1 files are no more supported");
00168         else if (version == MED_EN::V22)
00169           driver = new MED_FIELD_WRONLY_DRIVER<T>(fileName,ptrField);
00170         return driver;
00171       }
00172       case MED_EN::RDWR : {
00173         if (version == MED_EN::V21)
00174           throw MED_EXCEPTION ("med-2.1 files are no more supported");
00175         else if (version == MED_EN::V22)
00176           driver = new MED_FIELD_RDWR_DRIVER<T>(fileName,ptrField);
00177         return driver;
00178       }
00179       default:
00180         throw MED_EXCEPTION ("access type has not been properly specified to the method");
00181       }
00182     return driver;
00183   }
00184 
00185   template<class T, class INTERLACING_TAG>
00186   GENDRIVER * DRIVERFACTORY::buildConcreteMedDriverForField(const std::string & fileName,
00187                                                             FIELD<T,INTERLACING_TAG> *ptrField,
00188                                                             MED_EN::med_mode_acces access,
00189                                                             MED_EN::medFileVersion version)
00190   {
00191 
00192     MESSAGE_MED("buildConcreteMedDriverForField version of the file " << version);
00193 
00194     if (version == MED_EN::V21)
00195       throw MED_EXCEPTION ("med-2.1 files are no more supported");
00196 
00197     GENDRIVER * driver=0;
00198 
00199     switch(access)
00200       {
00201       case MED_EN::RDONLY : {
00202         driver = new MED_FIELD_RDONLY_DRIVER<T>(fileName,ptrField);
00203         return driver;
00204       }
00205       case MED_EN::WRONLY : {
00206         driver = new MED_FIELD_WRONLY_DRIVER<T>(fileName,ptrField);
00207         return driver;
00208       }
00209       case MED_EN::RDWR : {
00210         driver = new MED_FIELD_RDWR_DRIVER<T>(fileName,ptrField);
00211         return driver;
00212       }
00213       default:
00214         throw MED_EXCEPTION ("access type has not been properly specified to the method");
00215       }
00216     return driver;
00217   }
00218 }
00219 #endif