Salome HOME
update after merging trhe branches CEA_V3_0_x, OCC_V3_1_0_a1_x, and the main
[modules/med.git] / src / MEDWrapper / Base / MED_Common.hxx
1 //  
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : 
25 //  Author : 
26 //  Module : 
27 //  $Header$
28
29 #ifndef MED_Common_HeaderFile
30 #define MED_Common_HeaderFile
31
32 #include <stdexcept>
33 #include <valarray>
34 #include <vector>
35 #include <string>
36 #include <set>
37 #include <map>
38
39 extern "C"{
40 #include <hdf5.h>
41 }  
42
43 #include <boost/shared_ptr.hpp>
44
45 #include "SALOMEconfig.h"
46
47 namespace MED{
48
49   enum EVersion {eVUnknown = -1, eV2_1, eV2_2};
50   
51
52   template<class T> class SharedPtr: public boost::shared_ptr<T>
53   {
54   public:
55     SharedPtr() {}
56
57     template<class Y>
58     explicit SharedPtr(Y * p): 
59       boost::shared_ptr<T>(p) 
60     {}
61
62     template<class Y>
63     SharedPtr(SharedPtr<Y> const & r):
64       boost::shared_ptr<T>(r,boost::detail::polymorphic_cast_tag())
65     {}
66
67     template<class Y>
68     SharedPtr& operator=(SharedPtr<Y> const & r)
69     {
70       boost::shared_ptr<T>(r,boost::detail::polymorphic_cast_tag()).swap(*this);
71       return *this;
72     }
73
74     template<class Y> SharedPtr& operator()(Y * p) // Y must be complete
75     {
76       return operator=<Y>(SharedPtr<Y>(p));
77     }
78
79     operator const T& () const 
80     { 
81       return *(this->get());
82     }
83
84     operator T& () 
85     { 
86       return *(this->get());
87     }
88   };
89
90
91   template<class TContainer> 
92   class ConstSliceArray
93   {
94     const TContainer& myConstContainer;
95     std::slice mySlice;
96   protected:
97     size_t GetID(size_t theId) const
98     {
99       if(theId < mySlice.size()){
100         size_t anId = mySlice.start() + theId*mySlice.stride();
101         if(anId < myConstContainer.size())
102           return anId;
103       }
104       throw std::out_of_range();
105       return -1;
106     }
107     
108   public:
109     typedef typename TContainer::value_type TValue;
110
111     ConstSliceArray(const TContainer& theContainer,
112                     const std::slice& theSlice): 
113       myConstContainer(theContainer),
114       mySlice(theSlice)
115     {
116     }
117     
118     const TValue& operator[](size_t theId) const
119     {
120       return myConstContainer[GetID(theId)];
121     }
122     
123     size_t size() const
124     {
125       return mySlice.size();
126     }
127   };
128   
129
130   template<class TContainer> 
131   class SliceArray: public ConstSliceArray<TContainer>
132   {
133     TContainer& myContainer;
134     
135   public:
136     typedef ConstSliceArray<TContainer> TSupperClass;
137     SliceArray(TContainer& theContainer,
138                const std::slice& theSlice): 
139       TSupperClass(theContainer,theSlice),
140       myContainer(theContainer)
141     {
142     }
143     
144     typename TSupperClass::TValue& operator[](size_t theId)
145     {
146       return myContainer[this->GetID(theId)];
147     }
148   };
149   
150
151   typedef enum {eFAUX, eVRAI} EBooleen ; 
152   typedef double TFloat;
153 #if defined(SUN4SOL2) || defined(PCLINUX) || defined(OSF1_32) || defined(IRIX64_32) || defined(RS6000) || defined(HP9000)
154   typedef int TInt;
155 #endif
156 #if defined(IRIX64) || defined(OSF1)
157   typedef long TInt;
158 #endif
159   typedef hid_t TIdt;
160   typedef herr_t TErr;
161
162   typedef enum {eFLOAT64=6, eINT=26} ETypeChamp;
163
164   typedef enum {eNON_STRUCTURE, eSTRUCTURE} EMaillage;
165
166   typedef enum {eCART, eCYL, eSPHER} ERepere; 
167
168   typedef enum {eNOD, eDESC} EConnectivite ; 
169
170   typedef enum {ePOINT1=1, eSEG2=102, eSEG3=103, eTRIA3=203,
171                 eQUAD4=204, eTRIA6=206,eQUAD8=208, eTETRA4=304,
172                 ePYRA5=305, ePENTA6=306, eHEXA8=308, eTETRA10=310, 
173                 ePYRA13=313, ePENTA15=315, eHEXA20=320, 
174                 ePOLYGONE=400, ePOLYEDRE=500, eNONE=0} EGeometrieElement;
175
176   typedef enum {eMAILLE, eFACE, eARETE, eNOEUD} EEntiteMaillage; 
177
178   typedef enum {eNO_PFLMOD, eGLOBAL, eCOMPACT}  EModeProfil; 
179
180   typedef std::vector<TFloat> TFloatVector;
181   typedef std::vector<std::string> TStringVector;
182   typedef std::vector<TInt> TIntVector;
183   typedef std::set<std::string> TStringSet;
184   
185   typedef std::map<EGeometrieElement,TInt> TGeom;
186   typedef std::map<EEntiteMaillage,TGeom> TEntityInfo;
187
188   typedef std::set<EGeometrieElement> TGeomSet;
189   typedef std::map<EEntiteMaillage,TGeomSet> TEntity2GeomSet;
190
191   const TEntity2GeomSet& GetEntity2GeomSet();
192
193   template<int>
194
195   TInt GetNbConn(EGeometrieElement typmai,
196                  EEntiteMaillage typent,
197                  TInt mdim);
198   
199   template<>
200   TInt GetNbConn<eV2_1>(EGeometrieElement typmai,
201                         EEntiteMaillage typent,
202                         TInt mdim);
203
204   template<>
205   TInt GetNbConn<eV2_2>(EGeometrieElement typmai,
206                         EEntiteMaillage typent,
207                         TInt mdim);
208
209   TInt GetNbNodes(EGeometrieElement typmai);
210
211   struct TNameInfo;
212   typedef SharedPtr<TNameInfo> PNameInfo;
213   
214   struct TMeshInfo;
215   typedef SharedPtr<TMeshInfo> PMeshInfo;
216   
217   struct TFamilyInfo;
218   typedef SharedPtr<TFamilyInfo> PFamilyInfo;
219
220   struct TElemInfo;
221   typedef SharedPtr<TElemInfo> PElemInfo;
222
223   struct TNodeInfo;
224   typedef SharedPtr<TNodeInfo> PNodeInfo;
225
226   struct TPolygoneInfo;
227   typedef SharedPtr<TPolygoneInfo> PPolygoneInfo;
228
229   struct TPolyedreInfo;
230   typedef SharedPtr<TPolyedreInfo> PPolyedreInfo;
231
232   struct TCellInfo;
233   typedef SharedPtr<TCellInfo> PCellInfo;
234
235   struct TFieldInfo;
236   typedef SharedPtr<TFieldInfo> PFieldInfo;
237
238   struct TTimeStampInfo;
239   typedef SharedPtr<TTimeStampInfo> PTimeStampInfo;
240   
241   struct TTimeStampVal;
242   typedef SharedPtr<TTimeStampVal> PTimeStampVal;
243
244   class TWrapper;
245   typedef SharedPtr<TWrapper> PWrapper;
246 };
247
248
249 #endif