Back to index

salome-kernel  6.5.0
utilities.h
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 //  SALOME Utils : general SALOME's definitions and tools
00024 //  File   : utilities.h
00025 //  Author : Antoine YESSAYAN, Paul RASCLE, EDF
00026 //  Module : SALOME
00027 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/SALOMELocalTrace/utilities.h,v 1.8.2.1.10.2.12.1 2012-04-12 14:05:31 vsr Exp $
00028 //
00029 /* ---  Definition macros file to print informations if _DEBUG_ is defined --- */
00030 
00031 #ifndef UTILITIES_H
00032 #define UTILITIES_H
00033 
00034 #include <iostream>
00035 #include <sstream>
00036 #include <cstdlib>
00037 
00038 
00039 #include "LocalTraceBufferPool.hxx"
00040 
00053 #define MESS_INIT(deb) std::ostringstream os; os<<deb
00054 #define MESS_BEGIN(deb) MESS_INIT(deb)<<__FILE__ <<" ["<<__LINE__<<"] : "
00055 #define MESS_END std::endl; LocalTraceBufferPool::instance()->insert(NORMAL_MESS, os.str().c_str());
00056 #define MESS_ABORT std::endl; LocalTraceBufferPool::instance()->insert(ABORT_MESS, os.str().c_str());
00057 
00058 // Macroses for messages with separated structure in c++ file in _DUBUG mode
00059 #define MESSAGE_BEGIN(msg) {std::ostringstream ss; ss <<__FILE__ <<" ["<<__LINE__<<"] : "<< msg; LocalTraceBufferPool::instance()->insert(NORMAL_MESS, ss.str().c_str());}
00060 #define MESSAGE_ADD(msg) {std::ostringstream ss; ss << msg; LocalTraceBufferPool::instance()->insert(NORMAL_MESS, ss.str().c_str());}
00061 #define MESSAGE_END(msg) {std::ostringstream ss; ss << msg << std::endl; LocalTraceBufferPool::instance()->insert(NORMAL_MESS, ss.str().c_str());}
00062 
00063 // --- Some macros are always defined (without _DEBUG_): for use with release version
00064 
00065 #define INFOS(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END}
00066 #define PYSCRIPT(msg) {MESS_INIT("---PYSCRIPT--- ") << msg << MESS_END}
00067 #define INTERRUPTION(msg) {MESS_BEGIN("- INTERRUPTION: ")<< msg << MESS_ABORT}
00068 
00069 #ifdef WIN32
00070 #define IMMEDIATE_ABORT(code) {std::cout <<std::flush; \
00071                                std::cerr << "- ABORT " << __FILE__ << " [" <<__LINE__<< "] : " << std::flush; \
00072                                std::cerr << "ABORT return code= "<< code << std::endl; \
00073                                /*std::*/exit(code);}
00074 #else
00075 #define IMMEDIATE_ABORT(code) {std::cout <<std::flush; \
00076                                std::cerr << "- ABORT " << __FILE__ << " [" <<__LINE__<< "] : " << std::flush; \
00077                                std::cerr << "ABORT return code= "<< code << std::endl; \
00078                                std::exit(code);}
00079 #endif
00080 
00081 /* --- To print date and time of compilation of current source --- */
00082 
00083 #if defined ( __GNUC__ )
00084 #define COMPILER                "g++" 
00085 #elif defined ( __sun )
00086 #define COMPILER                "CC" 
00087 #elif defined ( __KCC )
00088 #define COMPILER                "KCC" 
00089 #elif defined ( __PGI )
00090 #define COMPILER                "pgCC" 
00091 #elif defined ( __alpha )
00092 #define COMPILER                "cxx" 
00093 #else
00094 #define COMPILER                "undefined" 
00095 #endif
00096 
00097 #ifdef INFOS_COMPILATION
00098 #error INFOS_COMPILATION already defined
00099 #endif
00100 
00101 #if defined(_DEBUG_) || defined(_DEBUG)
00102 
00103 // --- the following MACROS are useful at debug time
00104 
00105 #define INFOS_COMPILATION { MESS_BEGIN("COMPILED with ") << COMPILER \
00106                                        << ", " << __DATE__ \
00107                                        << " at " << __TIME__ << MESS_END }
00108 
00109 #define MESSAGE(msg) {MESS_BEGIN("- Trace ") << msg << MESS_END}
00110 #define SCRUTE(var)  {MESS_BEGIN("- Trace ") << #var << "=" << var <<MESS_END}
00111 
00112 #define REPERE ("------- ")
00113 #define BEGIN_OF(msg) {MESS_BEGIN(REPERE) << "Begin of: "      << msg << MESS_END} 
00114 #define END_OF(msg)   {MESS_BEGIN(REPERE) << "Normal end of: " << msg << MESS_END} 
00115 
00116 #ifndef ASSERT
00117 #define ASSERT(condition) \
00118         if (!(condition)){INTERRUPTION("CONDITION "<<#condition<<" NOT VERIFIED")}
00119 #endif /* ASSERT */
00120 
00121 
00122 #else /* ifdef _DEBUG_*/
00123 
00124 #define INFOS_COMPILATION
00125 #define MESSAGE(msg) {}
00126 #define SCRUTE(var) {}
00127 #define REPERE
00128 #define BEGIN_OF(msg) {}
00129 #define END_OF(msg) {}
00130 
00131 #ifndef ASSERT
00132 #define ASSERT(condition) {}
00133 #endif /* ASSERT */
00134 
00135 #endif /* ifdef _DEBUG_*/
00136 
00137 #endif /* ifndef UTILITIES_H */