library of assembled shared sources

http://lass.cocamware.com

common_macros.h

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 
00044 /** @defgroup CommonMacros Common Macros
00045  *  @author Bramz
00046  *  @brief usefull macros to use all over the place.
00047  */
00048 
00049 
00050 
00051 #ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_MACRO_H
00052 #define LASS_GUARDIAN_OF_INCLUSION_UTIL_MACRO_H
00053 
00054 
00055 #define LASS_WRAP(x)                    x
00056 
00057 // first of all, the usual stuff on stringifying, concatenating and breakpoint preprocessor stuff.
00058 
00059 /** convert to string at preprocessor time.
00060  *  @ingroup CommonMacros
00061  */
00062 #define LASS_STRINGIFY(iA)              LASS_STRINGIFY_IMPL(iA)
00063 #define LASS_STRINGIFY_IMPL(iA)         #iA
00064 
00065 /** concatenate two words at preprocessor time.
00066  *  @ingroup CommonMacros
00067  */
00068 #define LASS_CONCATENATE( iA, iB )      LASS_CONCATENATE_IMPL(iA, iB)
00069 #define LASS_CONCATENATE_IMPL( iA, iB ) iA##iB
00070 
00071 /** concatenate three words at preprocessor time.
00072  *  @ingroup CommonMacros
00073  */
00074 #define LASS_CONCATENATE_3( iA, iB, iC )    LASS_CONCATENATE_3_IMPL(iA, iB, iC)
00075 #define LASS_CONCATENATE_3_IMPL( iA, iB, iC ) iA##iB##iC
00076 
00077 /** user breakpoint
00078  *  @ingroup CommonMacros
00079  */
00080 #if LASS_COMPILER_TYPE == LASS_COMPILER_TYPE_GCC
00081 #   define LASS_BREAK_HERE  __asm__("int3")
00082 #else
00083 #   if defined(_WIN64)
00084 #       define LASS_BREAK_HERE __debugbreak();
00085 #   else
00086 #       define LASS_BREAK_HERE  __asm { int 3 }
00087 #   endif
00088 #endif
00089 
00090 /** create a unique name based on a prefix and line number
00091  *  @ingroup CommonMacros
00092  */
00093 #define LASS_UNIQUENAME( iPrefix ) LASS_CONCATENATE(iPrefix,LASS_LINE)
00094 
00095 
00096 
00097 // second, the name of the game, where we are.
00098 
00099 /** current file
00100  *  @ingroup CommonMacros
00101  */
00102 #define LASS_FILE                       __FILE__
00103 
00104 /** current line (stringified!)
00105  *  @ingroup CommonMacros
00106  */
00107 #define LASS_LINE                       __LINE__
00108 
00109 #define LASS_HERE                       LASS_FILE "(" LASS_STRINGIFY(LASS_LINE) ")"
00110 
00111 /** current function
00112  *  @ingroup CommonMacros
00113  */
00114 #ifdef __FUNCTION__
00115 #   define LASS_FUNCTION            __FUNCTION__
00116 #   define LASS_PRETTY_FUNCTION     LASS_FUNCTION
00117 #else
00118 #   define LASS_FUNCTION            "??"
00119 #   define LASS_PRETTY_FUNCTION     LASS_HERE
00120 #endif
00121 
00122 
00123 
00124 
00125 // debug jumbo jambo
00126 
00127 #include "common_macros.inl"
00128 
00129 #if !defined(NDEBUG)
00130 #   define LASS_ASSERT( iExpression )           LASS_ASSERT_IMPL( iExpression )
00131 #   define LASS_ASSERT_UNREACHABLE              LASS_ASSERT_UNREACHABLE_IMPL
00132 #   define LASS_WARNING( iMessage )             LASS_WARNING_IMPL( iMessage )
00133 #   define LASS_WARNING_ONCE_EX( iMessage, iUniqueName ) LASS_WARNING_ONCE_IMPL( iMessage, LASS_UNIQUENAME(iUniqueName) )
00134 #   define LASS_WARNING_ONCE( iMessage )        LASS_WARNING_ONCE_EX( iMessage, lassWarnOnce )
00135 #   define LASS_EVAL( iExpression )             LASS_EVAL_IMPL( iExpression )
00136 #   define LASS_LOG( iMessage )                 LASS_LOG_IMPL( iMessage )
00137 #else
00138 #   define LASS_ASSERT( iExpression )
00139 #   define LASS_ASSERT_UNREACHABLE
00140 #   define LASS_WARNING( iMessage )             LASS_WARNING_IMPL( iMessage )
00141 #   define LASS_WARNING_ONCE_EX( iMessage, iUniqueName ) LASS_WARNING_ONCE_IMPL( iMessage, LASS_UNIQUENAME(iUniqueName) )
00142 #   define LASS_WARNING_ONCE( iMessage )        LASS_WARNING_ONCE_EX( iMessage, lassWarnOnce )
00143 #   define LASS_EVAL( iExpression )             LASS_EVAL_IMPL( iExpression )
00144 #   define LASS_LOG( iMessage )                 LASS_LOG_IMPL( iMessage )
00145 #endif
00146 
00147 /** Executes code before the main has actually begun.  The macro relies on line numbers, so
00148  *  only one LASS_EXECUTE_BEFORE_MAIN per line!
00149  *  @ingroup CommonMacros
00150  */
00151 #define LASS_EXECUTE_BEFORE_MAIN( x ) LASS_EXECUTE_BEFORE_MAIN_EX(lassDummyName, x)
00152 
00153 /** Same as LASS_EXECUTE_BEFORE_MAIN but with an additional parameter that let's you specify the
00154  *  used prefix.   Mmmh, let's use this as implementation of LASS_EXECUTE_BEFORE_MAIN :)
00155  *  @ingroup CommonMacros
00156  */
00157 #define LASS_EXECUTE_BEFORE_MAIN_EX( iPrefix, x ) \
00158     namespace \
00159     { \
00160         inline bool LASS_CONCATENATE( LASS_UNIQUENAME(iPrefix),func ) () \
00161         { \
00162             x \
00163             return true; \
00164         } \
00165         const bool LASS_CONCATENATE( LASS_UNIQUENAME(iPrefix),var ) = \
00166             LASS_CONCATENATE( LASS_UNIQUENAME(iPrefix),func ) (); \
00167     }
00168 
00169 
00170 // now some pragma's you can use to leave messages behind
00171 
00172 /** pragma for leaving notes in build window
00173  *  @ingroup CommonMacros
00174  */
00175 #define LASS_NOTE( iMessage )\
00176     message(LASS_FILE "(" LASS_STRINGIFY(LASS_LINE) "):\n[LASS BUILD MSG] " iMessage)
00177 
00178 
00179 /** pragma for leaving todo notes in build window
00180  *  @ingroup CommonMacros
00181  */
00182 #define LASS_TODO( iMessage )\
00183     message(LASS_FILE "(" LASS_STRINGIFY(LASS_LINE) "):\n[LASS BUILD MSG] *** TODO: " iMessage " ***")
00184 
00185 /** pragma for leaving fixme notes in build window
00186  *  @ingroup CommonMacros
00187  */
00188 #define LASS_FIXME( iMessage )\
00189     message(LASS_FILE "(" LASS_STRINGIFY(LASS_LINE) "):\n[LASS BUILD MSG] *** FIXME: " iMessage " ***")
00190 
00191 
00192 // some other usefull macros
00193 
00194 /** @def LASS_UNUSED
00195  *  tell the compiler that some variable may stay unused.
00196  *  @ingroup CommonMacros
00197  *  Some compilers throw warnings at us if a variable stays unused.
00198  *  Often this is a good thing, but sometimes that's exactly what we want.
00199  *  This macro will attempt to avoid the warning (as long as the 
00200  *  compiler suports such an attempt).
00201  *
00202  *  @code
00203  *  int LASS_UNUSED(foobar) = 0;
00204  *  @endcode
00205  */
00206 #if LASS_COMPILER_TYPE == LASS_COMPILER_TYPE_GCC
00207 #   define LASS_UNUSED(x) x __attribute__((unused))
00208 #else
00209 #   define LASS_UNUSED(x) x
00210 #endif
00211 
00212 #endif

Generated on Mon Nov 10 14:20:02 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo