Salome HOME
implementation of useful DataArray::SplitStringInChuncks for SMESH 2 MC layer
[tools/medcoupling.git] / src / MEDLoader / SauvUtilities.hxx
1 // Copyright (C) 2007-2021  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 namespace SauvUtilities
34 {
35   INTERP_KERNEL::NormalizedCellType MEDLOADER_EXPORT gibi2medGeom( size_t gibiType );
36   int med2gibiGeom( INTERP_KERNEL::NormalizedCellType medGeomType );
37   const int * getGibi2MedQuadraticInterlace( INTERP_KERNEL::NormalizedCellType type );
38   unsigned getDimension( INTERP_KERNEL::NormalizedCellType type );
39
40   enum Readable_Piles
41     {
42       PILE_SOUS_MAILLAGE=1 ,
43       PILE_NODES_FIELD  =2 ,
44       PILE_TABLES       =10,
45       PILE_LREEL        =18,
46       PILE_LOGIQUES     =24,
47       PILE_FLOATS       =25,
48       PILE_INTEGERS     =26,
49       PILE_STRINGS      =27,
50       PILE_LMOTS        =29,
51       PILE_NOEUDS       =32,
52       PILE_COORDONNEES  =33,
53       PILE_MODL         =38,
54       PILE_FIELD        =39,
55       PILE_LAST_READABLE=39
56     };
57
58   //================================================================================
59   /*!
60    * \brief Converts anything to string
61    */
62   //================================================================================
63
64   template<class T> std::string toString(const T& anything)
65   {
66     std::ostringstream s; s << anything; return s.str();
67   }
68
69   // ==============================================================================
70   // IMP 0020434: mapping GIBI names to MED names
71   struct nameGIBItoMED
72   {
73     // GIBI value
74     int gibi_pile;    // PILE_SOUS_MAILLAGE or PILE_FIELD/PILE_NODES_FIELD, or PILE_STRINGS(for components)
75     int gibi_id;
76     std::string gibi_name; // used only for components
77     // MED value
78     // med_pile = 27; // PILE_STRINGS
79     int         med_id;    // used only on reading
80     std::string med_name;  // used only on writing
81   };
82
83   // ==============================================================================
84   /*!
85    * \brief Base class for ASCII and XDR file readers
86    */
87   class FileReader : public MEDCoupling::RefCountObject
88   {
89   public:
90     FileReader(const char* fileName);
91     virtual ~FileReader() {}
92     virtual bool isASCII() const = 0;
93
94     virtual bool open() = 0;
95     virtual bool getNextLine (char* & line, bool raiseOEF = true ) = 0;
96     virtual void initNameReading(int nbValues, int width = 8) = 0;
97     virtual void initIntReading(int nbValues) = 0;
98     virtual void initDoubleReading(int nbValues) = 0;
99     virtual bool more() const = 0;
100     virtual void next() = 0;
101     virtual int  index() const { return _iRead; }
102     virtual int    getInt() const = 0;
103     virtual float  getFloat() const = 0;
104     virtual double getDouble() const = 0;
105     virtual std::string getName() const = 0;
106   protected:
107     std::size_t getHeapMemorySizeWithoutChildren() const { return 0; }
108     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const { return std::vector<const BigMemoryObject *>(); }
109   protected:
110     std::string _fileName;
111     int _iRead, _nbToRead;
112   };
113 }
114 #endif