Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __MEDMEM_UTILITIES
00024 #define __MEDMEM_UTILITIES
00025
00026
00027 #include <string>
00028
00029 #ifndef WIN32
00030 #include <libgen.h>
00031 #endif
00032
00033 namespace MEDMEM
00034 {
00035 inline std::string getBaseName( const std::string& dataname )
00036 {
00037 std::string aBaseName = "";
00038 #ifndef WIN32
00039 aBaseName = basename((char*)dataname.c_str());
00040 #else
00041 for ( int i = dataname.size()-1; i >= 0; i-- ) {
00042 char aSymb = dataname[i];
00043 if ( dataname[i] == '\\' || dataname[i] == '/' )
00044 break;
00045 aBaseName = dataname[i] + aBaseName;
00046 }
00047 #endif
00048 return aBaseName;
00049 }
00050
00051 inline std::string getDirName(const std::string& dataname )
00052 {
00053 std::string aDirName = "";
00054 #ifndef WIN32
00055 aDirName = dirname((char*)dataname.c_str());
00056 #else
00057 bool aFindLine = false;
00058 for ( int i = dataname.size()-1; i >= 0; i-- ) {
00059 char aSymb = dataname[i];
00060 if ( !aFindLine )
00061 aFindLine = dataname[i] == '\\' || dataname[i] == '/';
00062 else
00063 aDirName = dataname[i] + aDirName;
00064 }
00065 if ( !aFindLine )
00066 aDirName = '.';
00067 #endif
00068 return aDirName;
00069 }
00070
00074 inline std::string healName(const std::string& name )
00075 {
00076 size_t last = name.size()-1;
00077 while ( last >= 0 && ( isspace( name[last] ) || !name[last] ))
00078 last--;
00079 return name.substr( 0, last + 1 );
00080 }
00081
00085 inline int swapBytes(const int theValue)
00086 {
00087 return (0 | (( theValue & 0x000000ff ) << 24 )
00088 | (( theValue & 0x0000ff00 ) << 8 )
00089 | (( theValue & 0x00ff0000 ) >> 8 )
00090 | (( theValue >> 24 ) & 0x000000ff ) );
00091 }
00092 }
00093
00094 # include <cstdlib>
00095 # include <iostream>
00096 using namespace std;
00097
00098
00099
00100 # define HEREWEARE_MED {cout<<flush ; cerr << __FILE__ << " [" << __LINE__ << "] : " << flush ;}
00101 # define INFOS_MED(chain) {HEREWEARE_MED ; cerr << chain << endl ;}
00102 # define PYSCRIPT_MED(chain) {cout<<flush ; cerr << "---PYSCRIPT--- " << chain << endl ;}
00103
00104
00105
00106
00107 # if defined ( __GNUC__ )
00108 # define COMPILER_MED "g++" ;
00109 # elif defined ( __sun )
00110 # define COMPILER_MED "CC" ;
00111 # elif defined ( __KCC )
00112 # define COMPILER_MED "KCC" ;
00113 # elif defined ( __PGI )
00114 # define COMPILER_MED "pgCC" ;
00115 # else
00116 # define COMPILER_MED "undefined" ;
00117 # endif
00118
00119 # ifdef INFOS_COMPILATION_MED
00120 # undef INFOS_COMPILATION_MED
00121 # endif
00122 # define INFOS_COMPILATION_MED {\
00123 cerr << flush;\
00124 cout << __FILE__ ;\
00125 cout << " [" << __LINE__ << "] : " ;\
00126 cout << "COMPILED with " << COMPILER_MED ;\
00127 cout << ", " << __DATE__ ; \
00128 cout << " at " << __TIME__ << endl ;\
00129 cout << "\n\n" ;\
00130 cout << flush ;\
00131 }
00132
00133 #if ( defined(_DEBUG_) || defined(_DEBUG) ) && !defined(_NO_MED_TRACE_)
00134
00135
00136
00137 # define HERE_MED {cout<<flush ; cerr << "- Trace " << __FILE__ << " [" << __LINE__ << "] : " << flush ;}
00138 # define SCRUTE_MED(var) {HERE_MED ; cerr << #var << "=" << var << endl ;}
00139 # define MESSAGE_MED(chain) {HERE_MED ; cerr << chain << endl ;}
00140 # define INTERRUPTION_MED(code) {HERE_MED ; cerr << "INTERRUPTION return code= " << code << endl ; exit(code) ;}
00141
00142 # ifndef ASSERT_MED
00143 # define ASSERT_MED(condition) if (!(condition)){ HERE_MED ; cerr << "CONDITION " << #condition << " NOT VERIFIED"<< endl ; INTERRUPTION_MED(1) ;}
00144 # endif
00145 #define REPERE_MED {cout<<flush ; cerr << " --------------" << endl << flush ;}
00146 #define __PREFIX_MED const char* __LOC_MED
00147 #define PREFIX_MED __LOC_MED
00148 #define BEGIN_OF_MED(chain) __PREFIX_MED = chain; {REPERE_MED ; HERE_MED ; cerr << "Begin of: " << PREFIX_MED << endl ; REPERE_MED ; }
00149 #define END_OF_MED(chain) {REPERE_MED ; HERE_MED ; cerr << "Normal end of: " << chain << endl ; REPERE_MED ; }
00150
00151
00152 # else
00153
00154
00155 # define HERE_MED
00156 # define SCRUTE_MED(var) {}
00157 # define MESSAGE_MED(chain) {}
00158 # define INTERRUPTION_MED(code) {}
00159
00160 # ifndef ASSERT_MED
00161 # define ASSERT_MED(condition) {}
00162 # endif
00163
00164 # define REPERE_MED
00165 # define BEGIN_OF_MED(chain) const char* __LOC_MED; {__LOC_MED=chain;}
00166 # define END_OF_MED(chain) const char* __LOC_END_MED; {__LOC_END_MED=chain;}
00167
00168
00169 #endif
00170
00171 #endif