Back to index

salome-med  6.5.0
MEDMEM_Utilities.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #ifndef __MEDMEM_UTILITIES
00024 #define __MEDMEM_UTILITIES
00025 
00026 // standart Linux/Unix functions 
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 /* ---  INFOS is always defined (without _DEBUG_): to be used for warnings, with release version --- */
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 /* --- To print date and time of compilation of current source on stdout --- */
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 /* --- the following MACROS are useful at debug time --- */
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 /* ASSERT_MED */
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 /* ifdef _DEBUG_*/
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 /* ASSERT */
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 /* ifdef _DEBUG_*/
00170 
00171 #endif