TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/common/utils/global.hpp
Go to the documentation of this file.
00001 #ifndef _TUTTLE_COMMON_UTILS_GLOBAL_HPP_
00002 #define _TUTTLE_COMMON_UTILS_GLOBAL_HPP_
00003 
00004 #include "color.hpp"
00005 #include "Formatter.hpp"
00006 
00007 ////////////////////////////////////////////////////////////////////////////////
00008 // System stuff
00009 #include <tuttle/common/system/system.hpp>
00010 #include <tuttle/common/system/compatibility.hpp>
00011 #include <tuttle/common/system/windows/windows.h>
00012 
00013 ////////////////////////////////////////////////////////////////////////////////
00014 // Assert needs to be everywhere
00015 #include <boost/static_assert.hpp>
00016 #include <boost/type_traits.hpp>
00017 #include <boost/current_function.hpp>
00018 
00019 ////////////////////////////////////////////////////////////////////////////////
00020 // Define functions to display infos in the console
00021 #include <iostream>
00022 
00023 #ifdef NDEBUG
00024 #  if defined( _MSC_VER )
00025 #    define TUTTLE_FORCEINLINE __forceinline
00026 #  elif defined( __GNUC__ ) && __GNUC__ > 3
00027 #    define TUTTLE_FORCEINLINE inline __attribute__ ( ( always_inline ) )
00028 #  else
00029 #    define TUTTLE_FORCEINLINE inline
00030 #  endif
00031 #else
00032 #  define TUTTLE_FORCEINLINE inline
00033 #endif
00034 
00035 #define TUTTLE_COUT( ... ) std::cout << __VA_ARGS__ << std::endl
00036 
00037 
00038 #ifndef WITHOUT_BOOST_LOG
00039 #define TUTTLE_LOG( MODE, ... ) MODE << __VA_ARGS__
00040 
00041 #define TUTTLE_TRACE   BOOST_LOG_TRIVIAL(trace)
00042 #define TUTTLE_INFO    BOOST_LOG_TRIVIAL(info)
00043 #define TUTTLE_WARNING BOOST_LOG_TRIVIAL(warning)
00044 #define TUTTLE_ERROR   BOOST_LOG_TRIVIAL(error)
00045 #define TUTTLE_FATAL   BOOST_LOG_TRIVIAL(fatal)
00046 #else
00047 #define TUTTLE_LOG( MODE, ... ) TUTTLE_COUT(MODE << __VA_ARGS__)
00048 
00049 #define TUTTLE_TRACE   "Trace: "
00050 #define TUTTLE_INFO    "Info: "
00051 #define TUTTLE_WARNING "Warning: "
00052 #define TUTTLE_ERROR   "Error: "
00053 #define TUTTLE_FATAL   "Fatal: "
00054 #endif
00055 
00056 /**
00057  * @def   TUTTLE_INFOS
00058  * @brief informations : filename, line number, function name
00059  **/
00060 
00061 #define TUTTLE_GET_INFOS_FILE      "in file:  " << __FILE__ << ",  line: " << __LINE__
00062 #define TUTTLE_GET_INFOS_FUNCTION  "function: " << BOOST_CURRENT_FUNCTION
00063 #define TUTTLE_GET_INFOS           TUTTLE_GET_INFOS_FILE << TUTTLE_GET_INFOS_FUNCTION
00064 
00065 #define TUTTLE_GET_VAR( a )           #a << ": " << a
00066 #define TUTTLE_GET_VAR2( a, b )       TUTTLE_GET_VAR ( a ) << ", " << TUTTLE_GET_VAR ( b )
00067 #define TUTTLE_GET_VAR3( a, b, c )    TUTTLE_GET_VAR ( a ) << ", " << TUTTLE_GET_VAR ( b ) << ", " << TUTTLE_GET_VAR ( c )
00068 #define TUTTLE_GET_VAR4( a, b, c, d ) TUTTLE_GET_VAR ( a ) << ", " << TUTTLE_GET_VAR ( b ) << ", " << TUTTLE_GET_VAR ( c ) << ", " << TUTTLE_GET_VAR ( d )
00069 
00070 
00071 /**
00072  * @param[in] ... : all parameters with an output stream operator defined
00073  * @brief terminal display
00074  **/
00075 
00076 #define TUTTLE_LOG_TRACE( ... )   TUTTLE_LOG( TUTTLE_TRACE, __VA_ARGS__ )
00077 #define TUTTLE_LOG_INFO( ... )    TUTTLE_LOG( TUTTLE_INFO, __VA_ARGS__ )
00078 #define TUTTLE_LOG_WARNING( ... ) TUTTLE_LOG( TUTTLE_WARNING, tuttle::common::Color::get()->_yellow << __VA_ARGS__ << tuttle::common::Color::get()->_std )
00079 #define TUTTLE_LOG_ERROR( ... )   TUTTLE_LOG( TUTTLE_ERROR, tuttle::common::Color::get()->_error  << __VA_ARGS__ << tuttle::common::Color::get()->_std )
00080 #define TUTTLE_LOG_FATAL( ... )   TUTTLE_LOG( TUTTLE_FATAL, tuttle::common::Color::get()->_error  << __VA_ARGS__ << tuttle::common::Color::get()->_std )
00081 
00082 #define TUTTLE_LOG_VAR( MODE, a )           TUTTLE_LOG( MODE, TUTTLE_GET_VAR ( a ) )
00083 #define TUTTLE_LOG_VAR2( MODE, a, b )       TUTTLE_LOG( MODE, TUTTLE_GET_VAR2( a, b ) )
00084 #define TUTTLE_LOG_VAR3( MODE, a, b, c )    TUTTLE_LOG( MODE, TUTTLE_GET_VAR3( a, b, c ) )
00085 #define TUTTLE_LOG_VAR4( MODE, a, b, c, d ) TUTTLE_LOG( MODE, TUTTLE_GET_VAR4( a, b, c, d ) )
00086 
00087 /**
00088  * @brief terminal information display
00089  **/
00090  #define TUTTLE_LOG_INFOS TUTTLE_LOG_TRACE( TUTTLE_GET_INFOS_FILE ); TUTTLE_LOG_TRACE( TUTTLE_GET_INFOS_FUNCTION )
00091 
00092 ////////////////////////////////////////////////////////////////////////////////
00093 // Some specifics things to debug or release version
00094 #ifdef DEBUG
00095  #define TUTTLE_DEBUG
00096 
00097  #include "debug.hpp"
00098 
00099  // Create "*.dot" file during the process to get informations about the graph
00100  #define TUTTLE_EXPORT_PROCESSGRAPH_DOT 1
00101 
00102  // Log several times during the process
00103  #define TUTTLE_EXPORT_WITH_TIMER 1
00104 
00105  // Output all nodes in the graph as png
00106  #define TUTTLE_PNG_EXPORT_BETWEEN_NODES 1
00107 
00108  // Init dst buffer with red to highlight uninitialized pixels
00109  #define TUTTLE_INIT_IMAGE_BUFFERS 1
00110 
00111  // TUTTLE_TLOG* defines are used by developers for temporary displays during development stages.
00112  #define TUTTLE_TLOG TUTTLE_LOG
00113  #define TUTTLE_TLOG_TRACE TUTTLE_LOG_TRACE
00114  #define TUTTLE_TLOG_INFO TUTTLE_LOG_INFO
00115  #define TUTTLE_TLOG_VAR TUTTLE_LOG_VAR
00116  #define TUTTLE_TLOG_VAR2 TUTTLE_LOG_VAR2
00117  #define TUTTLE_TLOG_VAR3 TUTTLE_LOG_VAR3
00118  #define TUTTLE_TLOG_VAR4 TUTTLE_LOG_VAR4
00119  #define TUTTLE_TLOG_INFOS TUTTLE_LOG_INFOS
00120  #define TUTTLE_TLOG_WITHINFOS TUTTLE_LOG_WITHINFOS
00121  #define TUTTLE_TLOG_EXCEPTION TUTTLE_LOG_EXCEPTION
00122 #else
00123  #define TUTTLE_RELEASE
00124 
00125  #include "release.hpp"
00126 
00127  #define TUTTLE_EXPORT_PROCESSGRAPH_DOT 0
00128  #define TUTTLE_EXPORT_WITH_TIMER 0
00129  #define TUTTLE_PNG_EXPORT_BETWEEN_NODES 0
00130  #define TUTTLE_INIT_IMAGE_BUFFERS 0
00131 
00132 // TUTTLE_TLOG* are removed in release mode.
00133  #define TUTTLE_TLOG TUTTLE_LOG_DEBUG
00134  #define TUTTLE_TLOG_TRACE TUTTLE_LOG_TRACE_DEBUG
00135  #define TUTTLE_TLOG_INFO TUTTLE_LOG_INFO_DEBUG
00136  #define TUTTLE_TLOG_VAR TUTTLE_LOG_VAR_DEBUG
00137  #define TUTTLE_TLOG_VAR2 TUTTLE_LOG_VAR2_DEBUG
00138  #define TUTTLE_TLOG_VAR3 TUTTLE_LOG_VAR3_DEBUG
00139  #define TUTTLE_TLOG_VAR4 TUTTLE_LOG_VAR4_DEBUG
00140  #define TUTTLE_TLOG_INFOS TUTTLE_LOG_INFOS_DEBUG
00141  #define TUTTLE_TLOG_WITHINFOS TUTTLE_LOG_WITHINFOS_DEBUG
00142  #define TUTTLE_TLOG_EXCEPTION TUTTLE_LOG_EXCEPTION_DEBUG
00143 #endif
00144 
00145 #define TUTTLE_LOG_PLUGIN_NAME_WIDTH 30
00146 
00147 #endif