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