Salome HOME
update from the MedMemory V1.0.1
[modules/med.git] / src / MEDMEM / MEDMEM_Med.hxx
1 # ifndef MED_HXX
2 # define MED_HXX
3
4 // STL
5 # include <string>
6 # include <map>
7 # include <vector>
8 # include <deque>
9
10 // LOCAL
11 # include "MEDMEM_define.hxx"
12
13 // Add your own driver header (step 2)
14 # include "MEDMEM_MedMedDriver.hxx"
15 # include "MEDMEM_VtkMedDriver.hxx"
16
17 # include "MEDMEM_Exception.hxx"
18 //using namespace MED_EN;
19
20
21 class MESH;
22 class FIELD_;
23 class SUPPORT ;
24
25 typedef string MESH_NAME_;
26 typedef string FIELD_NAME_;
27 typedef struct { int dt; int it; } DT_IT_;
28 struct LT_DT_IT_
29 {
30   bool operator() (const DT_IT_ &p1, const DT_IT_ &p2) const
31   {
32     if ( bool test = p1.dt == p2.dt)
33       return p1.it < p2.it ;
34     else
35       return  p1.dt < p2.dt ;
36   }
37 };
38 typedef map<DT_IT_, FIELD_*, LT_DT_IT_ > MAP_DT_IT_; 
39
40 // - IN THE FIRST CASE THE USER WANTS TO DISCOVER MESHES & FIELD_S 
41 //   CONTAINNED WITHIN A FILE <fileName> OF TYPE GIVEN BY THE  <driverType> PARAMETER
42 // - IN THE SECOND CASE THE USER BEGINS HIS WORK WITH A MESH OR A FIELD, 
43 //   ?? GET A MED POINTER THEN CAN ADD MESHes OR FIELDs ??
44 //
45
46 /*!
47
48   This class is use to group together some MESH, SUPPORT and FIELD
49   objects.
50
51 */
52
53 class MED
54 {
55   // Add your personnal driver line (step 2)
56   friend class MED_MED_RDONLY_DRIVER;
57   friend class MED_MED_WRONLY_DRIVER;
58   friend class MED_MED_RDWR_DRIVER;
59
60 private:
61
62   map<MESH_NAME_,MESH*>        _meshes;     // We can't have two MESHes with the same meshName.  
63                                             // The string key is a meshName.
64
65   map<FIELD_NAME_,MAP_DT_IT_>  _fields;     // We can't have two FIELD_s with the same fieldName. 
66  
67   map<FIELD_ *, MESH_NAME_>    _meshName;   // Get the meshName associated with a FIELD_ * 
68                                             // in order to get the MESH* from _meshes 
69
70   // POURQUOI MED_FR::med_entite_maillage ? devrait être MED_EN !
71   map < MESH_NAME_, map <MED_FR::med_entite_maillage,SUPPORT * > > _support ;
72   // For each MESH, we list support for each entity on all elements.
73
74   vector<GENDRIVER *>  _drivers;          // Storage of the MED_MED drivers currently in use
75
76 public:
77
78   MED();
79   MED (driverTypes driverType, const string & fileName); // Analyse the file <fileName> by calling readFileStruct
80   ~MED();
81   
82   // INUTILE : void addMesh  (const string & meshName  ); // Read the mesh <meshName> found in the file <_fileName>. <_fileName> must be set.
83   // INUTILE : void addField (const string & fieldName ); // Pensez au cas ou on ajoute un Field/Mesh avec un driver déjà existant.
84   
85   void addField ( FIELD_  * const ptrField  ) throw (MED_EXCEPTION) ;
86   void addMesh  ( MESH    * const ptrMesh   ) throw (MED_EXCEPTION) ;
87
88   // ------  Drivers Management Part
89 protected:
90
91   class INSTANCE {
92   public:
93     virtual GENDRIVER * run(const string & fileName, MED * const ptrMed) const = 0 ;
94   } ;
95   
96   template <class T> class INSTANCE_DE : public INSTANCE {
97   public :
98     GENDRIVER * run(const string & fileName,  MED * const ptrMed) const 
99     { 
100       MESSAGE("GENDRIVER * run") ;
101       return new T(fileName,ptrMed) ; 
102     }
103   } ;
104   
105   // Add your new driver instance here (step 3)
106   static INSTANCE_DE<MED_MED_RDWR_DRIVER> inst_med ;
107   static INSTANCE_DE<VTK_MED_DRIVER> inst_vtk ;
108   static const INSTANCE * const instances[] ;
109
110 public:
111
112   int  addDriver     (driverTypes driverType, const string & fileName);
113   int  addDriver     (GENDRIVER & driver);
114   void rmDriver      (int index=0) throw (MEDEXCEPTION) ;
115
116   void readFileStruct(int index=0) throw (MEDEXCEPTION) ;
117   void read          (int index=0) throw (MEDEXCEPTION) ;
118   void writeFrom     (int index=0) throw (MEDEXCEPTION) ; 
119   void write         (int index=0) throw (MEDEXCEPTION) ; 
120   
121   // ------ End Of Drivers Management Part
122
123   int        getNumberOfMeshes ( void ) const;       
124   int        getNumberOfFields ( void ) const;       
125   void       getMeshNames      ( string * meshNames ) const throw (MEDEXCEPTION) ;
126   deque<string> getMeshNames   () const;
127   MESH     * getMesh           ( const string & meshName ) const throw (MEDEXCEPTION) ;
128   MESH     * getMesh           ( const  FIELD_ * const field ) const throw (MEDEXCEPTION) ;
129   void       getFieldNames     ( string * fieldNames        ) const throw (MEDEXCEPTION) ;
130   deque<string> getFieldNames  () const;
131   // A FAIRE DES ROUTINES QUI DONNENT LES PDT ET ITE
132   deque<DT_IT_> getFieldIteration (const string & fieldName) const throw (MEDEXCEPTION) ;
133   FIELD_   * getField          ( const string & fieldName,
134                                  const int dt,  const int it) const throw (MEDEXCEPTION) ;
135
136   const map<MED_FR::med_entite_maillage,SUPPORT *> & getSupports(const string & meshName) const throw (MEDEXCEPTION) ;
137
138   SUPPORT *  getSupport (const string & meshName,MED_FR::med_entite_maillage entity) const throw (MEDEXCEPTION) ;
139
140   void       updateSupport () ;
141
142   // GERER LE CAS DE L'APPARITION DES MEMES NOMS DS DES FICHIERS <> !!!!!
143  
144   //friend ostream & operator<<(ostream &os,const MED & med);
145
146 };
147
148 #endif
149
150 //REM : AJOUTER DS LES DRIVERS des attributes INTERLACE, NO INTERLACE .........
151 //      AJOUTER L'OPERATEUR DE RECOPIE