1 ////////////////////////////////////////////////////////////////////////////////
3 // Author: Artur Szostak
4 // Email: artur@alice.phy.uct.ac.za | artursz@iafrica.com
6 ////////////////////////////////////////////////////////////////////////////////
8 #ifndef dHLT_UTILITIES_HPP
9 #define dHLT_UTILITIES_HPP
11 /* Since c++ is missing a finally "keyword" we define one. Its usage is identical
12 to a try..finally statement in Java etc.. however, since it is officialy a macro
13 one must use the ( ) brackets instead of { }
16 // if the compiler supports __finally use it otherwise make our own
17 #if defined(__BORLANDC__)
19 # define finally(str) __finally{str}
23 # define finally(code) \
31 #endif // __BORLANDC__
34 /* Define logical operators that are easier to read.
54 // Define assert with a capital first letter to maintain coding style.
55 # define Assert(statement) assert(statement);
58 // Any code that should be compiled in only when the DEBUG macro is specified
59 // can be enclosed with this DebugCode macro.
60 # define DebugCode(code) code
67 # define Assert(statement)
70 # define DebugCode(code)
78 extern int DebugLevel;
83 /* Here we define the DebugMsg(level, message) macro for easy embedding of debug information
84 into a program. The output is only generated in programs compiled with the DEBUG macro
85 defined. Here is a usage example:
88 DebugMsg(2, "some debug information.");
91 One can also use C++ ostream operators << like so:
95 DebugMsg(2, "x = " << x << " and y = " << y );
102 // We are defining this DebugMsg_PREECODE macro to use in DebugMsg in such a way
103 // so that the code is removed when the LOG_NO_DEBUG macro is specified but
104 // compiled otherwise.
106 # ifndef LOG_NO_DEBUG
107 # define __DebugMsg_PREECODE__(message) std::ostringstream os; os << message;
108 # else // LOG_NO_DEBUG
109 # define __DebugMsg_PREECODE__(message)
110 # endif // LOG_NO_DEBUG
112 # define DebugMsg(level, message) \
114 __DebugMsg_PREECODE__(message) \
115 AliDebug(level, os.str()); \
121 # define DebugMsg(level, message) \
122 DebugCode( if (dHLT::DebugLevel > level) std::cout << message << std::endl; )
127 #endif // dHLT_BASIC_TYPES_HPP