1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef __MEDMEM_UTILITIES
24 #define __MEDMEM_UTILITIES
26 // standart Linux/Unix functions
35 inline std::string getBaseName( const std::string& dataname )
37 std::string aBaseName = "";
39 aBaseName = basename((char*)dataname.c_str());
41 for ( int i = dataname.size()-1; i >= 0; i-- ) {
42 char aSymb = dataname[i];
43 if ( dataname[i] == '\\' || dataname[i] == '/' )
45 aBaseName = dataname[i] + aBaseName;
51 inline std::string getDirName(const std::string& dataname )
53 std::string aDirName = "";
55 aDirName = dirname((char*)dataname.c_str());
57 bool aFindLine = false;
58 for ( int i = dataname.size()-1; i >= 0; i-- ) {
59 char aSymb = dataname[i];
61 aFindLine = dataname[i] == '\\' || dataname[i] == '/';
63 aDirName = dataname[i] + aDirName;
72 * \brief Make a name valid. So far, removes white spaces from name end
74 inline std::string healName(const std::string& name )
76 size_t last = name.size()-1;
77 while ( last >= 0 && ( isspace( name[last] ) || !name[last] ))
79 return name.substr( 0, last + 1 );
83 * Change order of bytes for other endianness
85 inline int swapBytes(const int theValue)
87 return (0 | (( theValue & 0x000000ff ) << 24 )
88 | (( theValue & 0x0000ff00 ) << 8 )
89 | (( theValue & 0x00ff0000 ) >> 8 )
90 | (( theValue >> 24 ) & 0x000000ff ) );
98 /* --- INFOS is always defined (without _DEBUG_): to be used for warnings, with release version --- */
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 ;}
105 /* --- To print date and time of compilation of current source on stdout --- */
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" ;
116 # define COMPILER_MED "undefined" ;
119 # ifdef INFOS_COMPILATION_MED
120 # undef INFOS_COMPILATION_MED
122 # define INFOS_COMPILATION_MED {\
125 cout << " [" << __LINE__ << "] : " ;\
126 cout << "COMPILED with " << COMPILER_MED ;\
127 cout << ", " << __DATE__ ; \
128 cout << " at " << __TIME__ << endl ;\
133 #if ( defined(_DEBUG_) || defined(_DEBUG) ) && !defined(_NO_MED_TRACE_)
135 /* --- the following MACROS are useful at debug time --- */
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) ;}
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 ; }
152 # else /* ifdef _DEBUG_*/
156 # define SCRUTE_MED(var) {}
157 # define MESSAGE_MED(chain) {}
158 # define INTERRUPTION_MED(code) {}
161 # define ASSERT_MED(condition) {}
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;}
169 #endif /* ifdef _DEBUG_*/