]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/MEDLoader/MEDMESHConverterUtilities.hxx
Salome HOME
fix for OS Windows
[tools/medcoupling.git] / src / MEDLoader / MEDMESHConverterUtilities.hxx
1 // Copyright (C) 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
20 #ifndef MEDMESHCONVERTERUTILITIES_HXX
21 #define MEDMESHCONVERTERUTILITIES_HXX
22
23 #include "MEDLoaderDefines.hxx"
24
25 # include <string>
26 # include <sstream>
27 #include <iostream>
28 # include <vector>
29 #include <cstring>
30
31
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 MeshFormat
40 {
41 bool isMeshExtensionCorrect( const std::string& fileName );
42
43 //~void closeMeshFile(const int gmfMeshID);
44
45 enum Status {
46     DRS_OK,
47     DRS_EMPTY,          // a file contains no mesh with the given name
48     DRS_WARN_RENUMBER,  // a file has overlapped ranges of element numbers,
49     // so the numbers from the file are ignored
50     DRS_WARN_SKIP_ELEM, // some elements were skipped due to incorrect file data
51     DRS_WARN_DESCENDING, // some elements were skipped due to descending connectivity
52     DRS_FAIL            // general failure (exception etc.)
53 };
54 /*!
55  * \brief Class to generate string from any type
56  */
57 class Comment : public std::string
58 {
59     std::ostringstream _s ;
60
61 public :
62
63     Comment():std::string("") {}
64
65     Comment(const Comment& c):std::string() {
66         _s << c.c_str() ;
67         this->std::string::operator=( _s.str() );
68     }
69
70     Comment & operator=(const Comment& c) {
71         _s << c.c_str() ;
72         this->std::string::operator=( _s.str() );
73         return *this;
74     }
75
76     template <class T>
77     Comment( const T &anything ) {
78         _s << anything ;
79         this->std::string::operator=( _s.str() );
80     }
81
82     template <class T>
83     Comment & operator<<( const T &anything ) {
84         _s << anything ;
85         this->std::string::operator=( _s.str() );
86         return *this ;
87     }
88
89     operator char*() const {
90         return (char*)c_str();
91     }
92
93     std::ostream& Stream() {
94         return _s;
95     }
96 };
97 /*!
98    * \brief Enforce freeing memory allocated by std::vector
99    */
100 template <class TVECTOR>
101 void FreeVector(TVECTOR& vec)
102 {
103     TVECTOR v2;
104     vec.swap( v2 );
105 }
106 template <class TVECTOR>
107 void CompactVector(TVECTOR& vec)
108 {
109     TVECTOR v2( vec );
110     vec.swap( v2 );
111 }
112
113 class Localizer
114 {
115     std::string _locale;
116 public:
117         MEDLOADER_EXPORT Localizer();
118         MEDLOADER_EXPORT ~Localizer();
119 };
120 }
121
122
123 #endif // MEDMESHCONVERTERUTILITIES_HXX