Salome HOME
2150df37bd1878b311d4d79667cab6296040e2e7
[tools/medcoupling.git] / src / MEDLoader / SauvUtilities.hxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // File      : SauvUtilities.hxx
20 // Created   : Mon Aug 22 18:27:34 2011
21 // Author    : Edward AGAPOV (eap)
22
23 #ifndef __SAUVUTILITIES_HXX__
24 #define __SAUVUTILITIES_HXX__
25
26 #include "MEDLoaderDefines.hxx"
27 #include "MEDCouplingRefCountObject.hxx"
28 #include "NormalizedUnstructuredMesh.hxx"
29
30 #include <string>
31 #include <sstream>
32
33 #define THROW_IK_EXCEPTION(text)                        \
34   {                                                     \
35     std::ostringstream oss; oss << text;                \
36     throw INTERP_KERNEL::Exception(oss.str().c_str());  \
37   }
38
39 namespace SauvUtilities
40 {
41   INTERP_KERNEL::NormalizedCellType MEDLOADER_EXPORT gibi2medGeom( size_t gibiType );
42   int med2gibiGeom( INTERP_KERNEL::NormalizedCellType medGeomType );
43   const int * getGibi2MedQuadraticInterlace( INTERP_KERNEL::NormalizedCellType type );
44   unsigned getDimension( INTERP_KERNEL::NormalizedCellType type );
45
46   enum Readable_Piles
47     {
48       PILE_SOUS_MAILLAGE=1 ,
49       PILE_NODES_FIELD  =2 ,
50       PILE_TABLES       =10,
51       PILE_LREEL        =18,
52       PILE_LOGIQUES     =24,
53       PILE_FLOATS       =25,
54       PILE_INTEGERS     =26,
55       PILE_STRINGS      =27,
56       PILE_LMOTS        =29,
57       PILE_NOEUDS       =32,
58       PILE_COORDONNEES  =33,
59       PILE_MODL         =38,
60       PILE_FIELD        =39,
61       PILE_LAST_READABLE=39
62     };
63
64   //================================================================================
65   /*!
66    * \brief Converts anything to string
67    */
68   //================================================================================
69
70   template<class T> std::string toString(const T& anything)
71   {
72     std::ostringstream s; s << anything; return s.str();
73   }
74
75   // ==============================================================================
76   // IMP 0020434: mapping GIBI names to MED names
77   struct nameGIBItoMED
78   {
79     // GIBI value
80     int gibi_pile;    // PILE_SOUS_MAILLAGE or PILE_FIELD/PILE_NODES_FIELD, or PILE_STRINGS(for components)
81     int gibi_id;
82     std::string gibi_name; // used only for components
83     // MED value
84     // med_pile = 27; // PILE_STRINGS
85     int         med_id;    // used only on reading
86     std::string med_name;  // used only on writing
87   };
88
89   // ==============================================================================
90   /*!
91    * \brief Base class for ASCII and XDR file readers
92    */
93   class FileReader : public MEDCoupling::RefCountObject
94   {
95   public:
96     FileReader(const char* fileName);
97     virtual ~FileReader() {}
98     virtual bool isASCII() const = 0;
99
100     virtual bool open() = 0;
101     virtual bool getNextLine (char* & line, bool raiseOEF = true ) = 0;
102     virtual void initNameReading(int nbValues, int width = 8) = 0;
103     virtual void initIntReading(int nbValues) = 0;
104     virtual void initDoubleReading(int nbValues) = 0;
105     virtual bool more() const = 0;
106     virtual void next() = 0;
107     virtual int  index() const { return _iRead; }
108     virtual int    getInt() const = 0;
109     virtual float  getFloat() const = 0;
110     virtual double getDouble() const = 0;
111     virtual std::string getName() const = 0;
112   protected:
113     std::size_t getHeapMemorySizeWithoutChildren() const { return 0; }
114     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const { return std::vector<const BigMemoryObject *>(); }
115   protected:
116     std::string _fileName;
117     int _iRead, _nbToRead;
118   };
119 }
120 #endif