Main Page   Reference Manual   Namespace List   Compound List   Namespace Members   Compound Members   File Members  

libcwd/macro_Libcwd_macros.h

Go to the documentation of this file.
00001 // $Header: /cvsroot/libcwd/libcwd/include/libcwd/macro_Libcwd_macros.h,v 1.6 2004/05/27 03:03:52 libcw Exp $
00002 //
00003 // Copyright (C) 2000 - 2003, by
00004 // 
00005 // Carlo Wood, Run on IRC <carlo@alinoe.com>
00006 // RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
00007 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61
00008 //
00009 // This file may be distributed under the terms of the Q Public License
00010 // version 1.0 as appearing in the file LICENSE.QPL included in the
00011 // packaging of this file.
00012 //
00013 
00018 #ifndef LIBCWD_MACRO_LIBCWD_MACROS_H
00019 #define LIBCWD_MACRO_LIBCWD_MACROS_H
00020 
00021 #ifndef LIBCWD_CONFIG_H
00022 #include <libcwd/config.h>
00023 #endif
00024 #ifndef LIBCW_CSTDDEF
00025 #define LIBCW_CSTDDEF
00026 #include <cstddef>              // Needed for size_t
00027 #endif
00028 
00029 #if CWDEBUG_DEBUGM
00030 // Dout may not be called while 'internal' anymore.
00031 #define LIBCWD_ASSERT_NOT_INTERNAL LIBCWD_ASSERT(!__libcwd_tsd.internal)
00032 #else
00033 #define LIBCWD_ASSERT_NOT_INTERNAL
00034 #endif
00035 
00036 //===================================================================================================
00037 // Macro LibcwDebug
00038 //
00039 
00048 #define LibcwDebug(dc_namespace, x)             \
00049         do {                                    \
00050           using namespace ::libcwd;     \
00051           using namespace dc_namespace;         \
00052           {                                     \
00053             x;                                  \
00054           }                                     \
00055         } while(0)
00056 
00057 //===================================================================================================
00058 // Macro LibcwDout
00059 //
00060 
00061 // This is debugging libcwd itself.
00062 #ifndef LIBCWD_LibcwDoutScopeBegin_MARKER
00063 #if CWDEBUG_DEBUGOUTPUT
00064 #include <sys/types.h>
00065 extern "C" ssize_t write(int fd, const void *buf, size_t count);
00066 #define LIBCWD_STR1(x) #x
00067 #define LIBCWD_STR2(x) LIBCWD_STR1(x)
00068 #define LIBCWD_STR3 "LibcwDout at " __FILE__ ":" LIBCWD_STR2(__LINE__) "\n"
00069 #define LIBCWD_LibcwDoutScopeBegin_MARKER LibcwDebugThreads( ++__libcwd_tsd.internal_debugging_code ); ::write(2, LIBCWD_STR3, sizeof(LIBCWD_STR3) - 1); LibcwDebugThreads( --__libcwd_tsd.internal_debugging_code )
00070 #else // !CWDEBUG_DEBUGOUTPUT
00071 #define LIBCWD_LibcwDoutScopeBegin_MARKER
00072 #endif // !CWDEBUG_DEBUGOUTPUT
00073 #endif // !LIBCWD_LibcwDoutScopeBegin_MARKER
00074 
00083 #define LibcwDout( dc_namespace, debug_obj, cntrl, data )       \
00084     LibcwDoutScopeBegin(dc_namespace, debug_obj, cntrl)         \
00085     LibcwDoutStream << data;                                    \
00086     LibcwDoutScopeEnd
00087 
00088 #define LibcwDoutScopeBegin( dc_namespace, debug_obj, cntrl )                                                                   \
00089   do                                                                                                                            \
00090   {                                                                                                                             \
00091     LIBCWD_TSD_DECLARATION;                                                                                                     \
00092     LIBCWD_ASSERT_NOT_INTERNAL;                                                                                                 \
00093     LIBCWD_LibcwDoutScopeBegin_MARKER;                                                                                          \
00094     if (LIBCWD_DO_TSD_MEMBER_OFF(debug_obj) < 0)                                                                                \
00095     {                                                                                                                           \
00096       using namespace ::libcwd;                                                                                         \
00097       ::libcwd::channel_set_bootstrap_st __libcwd_channel_set(LIBCWD_DO_TSD(debug_obj) LIBCWD_COMMA_TSD);                       \
00098       bool on;                                                                                                                  \
00099       {                                                                                                                         \
00100         using namespace dc_namespace;                                                                                           \
00101         on = (__libcwd_channel_set|cntrl).on;                                                                                   \
00102       }                                                                                                                         \
00103       if (on)                                                                                                                   \
00104       {                                                                                                                         \
00105         ::libcwd::debug_ct& __libcwd_debug_object(debug_obj);                                                           \
00106         LIBCWD_DO_TSD(__libcwd_debug_object).start(__libcwd_debug_object, __libcwd_channel_set LIBCWD_COMMA_TSD);
00107 
00108 // Note: LibcwDoutStream is *not* equal to the ostream that was set with set_ostream.  It is a temporary stringstream.
00109 #define LibcwDoutStream                                                                                                         \
00110         (*LIBCWD_DO_TSD_MEMBER(__libcwd_debug_object, current_bufferstream))
00111 
00112 #define LibcwDoutScopeEnd                                                                                                       \
00113         LIBCWD_DO_TSD(__libcwd_debug_object).finish(__libcwd_debug_object, __libcwd_channel_set LIBCWD_COMMA_TSD);              \
00114       }                                                                                                                         \
00115     }                                                                                                                           \
00116   } while(0)
00117 
00118 //===================================================================================================
00119 // Macro LibcwDoutFatal
00120 //
00121 
00122 // This is debugging libcwd itself.
00123 #ifndef LIBCWD_LibcwDoutFatalScopeBegin_MARKER
00124 #if CWDEBUG_DEBUGOUTPUT
00125 #define LIBCWD_STR4 "LibcwDoutFatal at " __FILE__ ":" LIBCWD_STR2(__LINE__) "\n"
00126 #define LIBCWD_LibcwDoutFatalScopeBegin_MARKER LibcwDebugThreads( ++__libcwd_tsd.internal_debugging_code ); ::write(2, LIBCWD_STR4, sizeof(LIBCWD_STR4) - 1); LibcwDebugThreads( --__libcwd_tsd.internal_debugging_code )
00127 #else
00128 #define LIBCWD_LibcwDoutFatalScopeBegin_MARKER
00129 #endif
00130 #endif // !LIBCWD_LibcwDoutFatalScopeBegin_MARKER
00131 
00140 #define LibcwDoutFatal( dc_namespace, debug_obj, cntrl, data )  \
00141     LibcwDoutFatalScopeBegin(dc_namespace, debug_obj, cntrl)    \
00142     LibcwDoutFatalStream << data;                               \
00143     LibcwDoutFatalScopeEnd
00144 
00145 #define LibcwDoutFatalScopeBegin( dc_namespace, debug_obj, cntrl )                                                              \
00146   do                                                                                                                            \
00147   {                                                                                                                             \
00148     LIBCWD_TSD_DECLARATION;                                                                                                     \
00149     LIBCWD_LibcwDoutFatalScopeBegin_MARKER;                                                                                     \
00150     using namespace ::libcwd;                                                                                           \
00151     ::libcwd::channel_set_bootstrap_st __libcwd_channel_set(LIBCWD_DO_TSD(debug_obj) LIBCWD_COMMA_TSD);                 \
00152     {                                                                                                                           \
00153       using namespace dc_namespace;                                                                                             \
00154       __libcwd_channel_set&cntrl;                                                                                               \
00155     }                                                                                                                           \
00156     ::libcwd::debug_ct& __libcwd_debug_object(debug_obj);                                                                       \
00157     LIBCWD_DO_TSD(__libcwd_debug_object).start(__libcwd_debug_object, __libcwd_channel_set LIBCWD_COMMA_TSD);
00158 
00159 #define LibcwDoutFatalStream LibcwDoutStream
00160 
00161 #define LibcwDoutFatalScopeEnd                                                                                                  \
00162     LIBCWD_DO_TSD(__libcwd_debug_object).fatal_finish(__libcwd_debug_object, __libcwd_channel_set LIBCWD_COMMA_TSD);            \
00163   } while(0)
00164 
00165 #endif // LIBCWD_MACRO_LIBCWD_MACROS_H
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.