Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_GenDriver.hxx
1 //  Copyright (C) 2007-2008  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 #ifndef GENDRIVER_HXX
23 #define GENDRIVER_HXX
24
25 #include <MEDMEM.hxx>
26
27 #include <string>
28
29 #include "MEDMEM_define.hxx"
30 #include "MEDMEM_Utilities.hxx"
31
32 /* Generic Read/Write Driver Class for Meshes & Fields */
33
34 using namespace std;
35
36 /*!
37
38   Virtual class GENDRIVER use by all driver.
39
40 */
41 namespace MEDMEM {
42
43   /* Modify the following line to add a new driver type (step 1) */
44   typedef enum { MED_DRIVER = 0, GIBI_DRIVER = 1, PORFLOW_DRIVER = 2,
45                  ENSIGHT_DRIVER = 250, VTK_DRIVER = 254, ASCII_DRIVER = 3,
46                  NO_DRIVER = 255 } driverTypes;
47
48   class GENDRIVER;
49   MEDMEM_EXPORT ostream & operator<<(ostream &os,const GENDRIVER &genDriver);
50
51   class MEDMEM_EXPORT GENDRIVER {
52
53 protected :
54
55   int            _id;         // MED_INVALID : if the driver hasn't been created by a MedMedDriver
56                               // the MedMedDriver index of the driver vector in the MED object where it has been created
57   /*File related part*/
58   string         _fileName;   // The name of the file currently in use.
59   MED_EN::med_mode_acces _accessMode; // The file access mode set by the adequate construtor.
60   int            _status;     // The file status {MED_INVALID, MED_OPENED, MED_CLOSED } 
61   driverTypes    _driverType; //  A FAIRE LE POSITIONNER DS TOUTES LES SS CLASSES !!
62
63
64 public:
65   /*!
66     Constructor.
67   */
68   GENDRIVER(driverTypes driverType);
69   /*!
70     Constructor.
71   */
72   GENDRIVER(const string & fileName, MED_EN::med_mode_acces accessMode,
73             driverTypes driverType);
74   /*!
75     Copy constructor.
76   */
77   GENDRIVER(const GENDRIVER & genDriver);
78
79   /*!
80     Destructor.
81   */
82   virtual ~GENDRIVER();
83
84   /*!
85     Operator = : duplicate the given genDriver.
86   */
87   GENDRIVER & operator=(const GENDRIVER & genDriver);
88
89   /*!
90     Operator << : put GENDRIVER object information to the given stream
91   */
92   friend ostream & operator<<(ostream &os,const GENDRIVER &genDriver);
93
94   bool operator ==(const GENDRIVER &genDriver) const;
95   /*!
96     Open file.
97   */
98   virtual void open ( void ) = 0;
99   /*!
100     Open file with the append option. This method is used especially
101     on ASCII drivers (e.g. VTK_DRIVER).
102   */
103   virtual void openAppend ( void );
104   /*!
105     Close file.
106   */
107   virtual void close( void ) = 0;
108   /*!
109     Write object in opened file.
110   */
111   virtual void write( void ) const = 0;
112   /*!
113     Write object in opened file. This method is used especially
114     on ASCII drivers (e.g. VTK_DRIVER).
115   */
116   virtual void writeAppend( void ) const;
117   /*!
118     Read object in opened file.
119   */
120   virtual void read ( void ) = 0;
121   
122   // needed to duplicate arrays 
123   virtual GENDRIVER * copy ( void ) const = 0 ;
124
125   // Take missing data from other driver.
126   // Is for object->read( genDriver ) if object was not passed to genDriver
127   // (i.e. genDriver has been created through constructor without parameters),
128   // then object asks driverFactory to create a driver initialized by object
129   // and fills the new driver up using merge( genDriver ).
130   // Needed for drivers possessing own data
131   virtual void merge ( const GENDRIVER &genDriver );
132
133   // MED  related part
134   virtual void writeFrom      ( void ) const;
135   virtual void readFileStruct ( void );
136   // MESH related Part
137   virtual void setMeshName    ( const string & meshName);
138   virtual string getMeshName() const;
139   // FIELD related Part
140   virtual void setFieldName   ( const string & fieldName);
141   virtual string getFieldName() const;
142
143   void   setId       ( int id = MED_INVALID );
144   int    getId       ( void ) const ;
145   string getFileName () const;
146   virtual void setFileName ( const string & fileName);
147   virtual MED_EN::med_mode_acces getAccessMode() const;
148   driverTypes getDriverType() const { return _driverType; }
149 };
150 }
151
152
153 #endif /* GENDRIVER_HXX */