]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Utilities.hxx
Salome HOME
Fix problem of make distcheck
[modules/med.git] / src / MEDMEM / MEDMEM_Utilities.hxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef __MEDMEM_UTILITIES
24 #define __MEDMEM_UTILITIES
25
26 // standart Linux/Unix functions 
27 #include <string>
28
29 #ifndef WIN32
30 #include <libgen.h>
31 #endif
32
33 namespace MEDMEM
34 {
35   inline std::string getBaseName( const std::string& dataname )
36   {
37     std::string aBaseName = "";
38 #ifndef WIN32
39     aBaseName = basename((char*)dataname.c_str());
40 #else
41     for ( int i = dataname.size()-1; i >= 0; i-- ) {
42       char aSymb = dataname[i];
43       if ( dataname[i] == '\\' || dataname[i] == '/' )
44         break;
45       aBaseName = dataname[i] + aBaseName;
46     }
47 #endif
48     return aBaseName;
49   }
50
51   inline std::string getDirName(const std::string& dataname )
52   {
53     std::string aDirName = "";
54 #ifndef WIN32
55     aDirName = dirname((char*)dataname.c_str());
56 #else
57     bool aFindLine = false;
58     for ( int i = dataname.size()-1; i >= 0; i-- ) {
59       char aSymb = dataname[i];
60       if ( !aFindLine )
61         aFindLine = dataname[i] == '\\' || dataname[i] == '/';
62       else
63         aDirName = dataname[i] + aDirName;
64     }
65     if ( !aFindLine )
66       aDirName = '.';
67 #endif
68     return aDirName;
69   }
70
71   /*!
72    * \brief Make a name valid. So far, removes white spaces from name end
73    */
74   inline std::string healName(const std::string& name )
75   {
76     size_t last = name.size()-1;
77     while ( last >= 0 && ( isspace( name[last] ) || !name[last] ))
78       last--;
79     return name.substr( 0, last + 1 );
80   }
81
82   /*!
83    * Change order of bytes for other endianness
84    */
85   inline int swapBytes(const int theValue)
86   {
87     return (0 | (( theValue & 0x000000ff ) << 24 )
88             |   (( theValue & 0x0000ff00 ) << 8  )
89             |   (( theValue & 0x00ff0000 ) >> 8  )
90             |   (( theValue >> 24 ) & 0x000000ff ) );
91   }
92 }
93
94 #  include <cstdlib>
95 #  include <iostream>
96 using namespace std;
97
98 /* ---  INFOS is always defined (without _DEBUG_): to be used for warnings, with release version --- */
99
100 # define HEREWEARE_MED {cout<<flush ; cerr << __FILE__ << " [" << __LINE__ << "] : " << flush ;}
101 # define INFOS_MED(chain) {HEREWEARE_MED ; cerr << chain << endl ;}
102 # define PYSCRIPT_MED(chain) {cout<<flush ; cerr << "---PYSCRIPT--- " << chain << endl ;}
103
104
105 /* --- To print date and time of compilation of current source on stdout --- */
106
107 # if defined ( __GNUC__ )
108 # define COMPILER_MED           "g++" ;
109 # elif defined ( __sun )
110 # define COMPILER_MED           "CC" ;
111 # elif defined ( __KCC )
112 # define COMPILER_MED           "KCC" ;
113 # elif defined ( __PGI )
114 # define COMPILER_MED           "pgCC" ;
115 # else
116 # define COMPILER_MED           "undefined" ;
117 # endif
118
119 # ifdef INFOS_COMPILATION_MED
120 # undef INFOS_COMPILATION_MED
121 # endif
122 # define INFOS_COMPILATION_MED  {\
123   cerr << flush;\
124   cout << __FILE__ ;\
125   cout << " [" << __LINE__ << "] : " ;\
126   cout << "COMPILED with " << COMPILER_MED ;\
127   cout << ", " << __DATE__ ; \
128   cout << " at " << __TIME__ << endl ;\
129   cout << "\n\n" ;\
130   cout << flush ;\
131 }
132
133 #if ( defined(_DEBUG_) || defined(_DEBUG) ) && !defined(_NO_MED_TRACE_)
134
135 /* --- the following MACROS are useful at debug time --- */
136
137 # define HERE_MED {cout<<flush ; cerr << "- Trace " << __FILE__ << " [" << __LINE__ << "] : " << flush ;}
138 # define SCRUTE_MED(var) {HERE_MED ; cerr << #var << "=" << var << endl ;}
139 # define MESSAGE_MED(chain) {HERE_MED ; cerr << chain << endl ;}
140 # define INTERRUPTION_MED(code) {HERE_MED ; cerr << "INTERRUPTION return code= " << code << endl ; exit(code) ;}
141
142 # ifndef ASSERT_MED
143 # define ASSERT_MED(condition) if (!(condition)){ HERE_MED ; cerr << "CONDITION " << #condition << " NOT VERIFIED"<< endl ; INTERRUPTION_MED(1) ;}
144 # endif /* ASSERT_MED */
145 #define REPERE_MED {cout<<flush ; cerr << "   --------------" << endl << flush ;}
146 #define __PREFIX_MED const char* __LOC_MED
147 #define PREFIX_MED __LOC_MED 
148 #define BEGIN_OF_MED(chain) __PREFIX_MED = chain; {REPERE_MED ; HERE_MED ; cerr << "Begin of: " << PREFIX_MED << endl ; REPERE_MED ; }
149 #define END_OF_MED(chain) {REPERE_MED ; HERE_MED ; cerr << "Normal end of: " << chain << endl ; REPERE_MED ; }
150
151
152 # else /* ifdef _DEBUG_*/
153
154
155 # define HERE_MED
156 # define SCRUTE_MED(var) {}
157 # define MESSAGE_MED(chain) {}
158 # define INTERRUPTION_MED(code) {}
159
160 # ifndef ASSERT_MED
161 # define ASSERT_MED(condition) {}
162 # endif /* ASSERT */
163
164 # define REPERE_MED
165 # define BEGIN_OF_MED(chain)  const char* __LOC_MED; {__LOC_MED=chain;}
166 # define END_OF_MED(chain) const char* __LOC_END_MED; {__LOC_END_MED=chain;}
167
168
169 #endif /* ifdef _DEBUG_*/
170
171 #endif