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