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