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

macro_Libcwd_macros.h
Go to the documentation of this file.
1 // $Header$
2 //
3 // Copyright (C) 2000 - 2004, by
4 //
5 // Carlo Wood, Run on IRC <carlo@alinoe.com>
6 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
7 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
8 //
9 // This file may be distributed under the terms of the Q Public License
10 // version 1.0 as appearing in the file LICENSE.QPL included in the
11 // packaging of this file.
12 //
13 
18 #ifndef LIBCWD_MACRO_LIBCWD_MACROS_H
19 #define LIBCWD_MACRO_LIBCWD_MACROS_H
20 
21 #ifndef LIBCWD_CONFIG_H
22 #include <libcwd/config.h>
23 #endif
24 #ifndef LIBCW_CSTDDEF
25 #define LIBCW_CSTDDEF
26 #include <cstddef> // Needed for size_t
27 #endif
28 
29 #if CWDEBUG_DEBUGM
30 // Dout may not be called while 'internal' anymore.
31 #define LIBCWD_ASSERT_NOT_INTERNAL LIBCWD_ASSERT(!__libcwd_tsd.internal)
32 #else
33 #define LIBCWD_ASSERT_NOT_INTERNAL
34 #endif
35 
36 //===================================================================================================
37 // Macro LibcwDebug
38 //
39 
48 #define LibcwDebug(dc_namespace, x) \
49  do { \
50  using namespace ::libcwd; \
51  using namespace dc_namespace; \
52  { \
53  x; \
54  } \
55  } while(0)
56 
57 //===================================================================================================
58 // Macro LibcwDout
59 //
60 
61 // This is debugging libcwd itself.
62 #ifndef LIBCWD_LibcwDoutScopeBegin_MARKER
63 #if CWDEBUG_DEBUGOUTPUT
64 #include <sys/types.h>
65 extern "C" ssize_t write(int fd, const void *buf, size_t count);
66 #define LIBCWD_STR1(x) #x
67 #define LIBCWD_STR2(x) LIBCWD_STR1(x)
68 #define LIBCWD_STR3 "LibcwDout at " __FILE__ ":" LIBCWD_STR2(__LINE__) "\n"
69 #define LIBCWD_LibcwDoutScopeBegin_MARKER LibcwDebugThreads( ++__libcwd_tsd.internal_debugging_code ); ::write(2, LIBCWD_STR3, sizeof(LIBCWD_STR3) - 1); LibcwDebugThreads( --__libcwd_tsd.internal_debugging_code )
70 #else // !CWDEBUG_DEBUGOUTPUT
71 #define LIBCWD_LibcwDoutScopeBegin_MARKER
72 #endif // !CWDEBUG_DEBUGOUTPUT
73 #endif // !LIBCWD_LibcwDoutScopeBegin_MARKER
74 
83 #define LibcwDout( dc_namespace, debug_obj, cntrl, data ) \
84  LibcwDoutScopeBegin(dc_namespace, debug_obj, cntrl) \
85  LibcwDoutStream << data; \
86  LibcwDoutScopeEnd
87 
88 #define LibcwDoutScopeBegin( dc_namespace, debug_obj, cntrl ) \
89  do \
90  { \
91  LIBCWD_TSD_DECLARATION; \
92  LIBCWD_ASSERT_NOT_INTERNAL; \
93  LIBCWD_LibcwDoutScopeBegin_MARKER; \
94  if (LIBCWD_DO_TSD_MEMBER_OFF(debug_obj) < 0) \
95  { \
96  using namespace ::libcwd; \
97  ::libcwd::channel_set_bootstrap_st __libcwd_channel_set(LIBCWD_DO_TSD(debug_obj) LIBCWD_COMMA_TSD); \
98  bool on; \
99  { \
100  using namespace dc_namespace; \
101  on = (__libcwd_channel_set|cntrl).on; \
102  } \
103  if (on) \
104  { \
105  ::libcwd::debug_ct& __libcwd_debug_object(debug_obj); \
106  LIBCWD_DO_TSD(__libcwd_debug_object).start(__libcwd_debug_object, __libcwd_channel_set LIBCWD_COMMA_TSD);
107 
108 // Note: LibcwDoutStream is *not* equal to the ostream that was set with set_ostream. It is a temporary stringstream.
109 #define LibcwDoutStream \
110  (*LIBCWD_DO_TSD_MEMBER(__libcwd_debug_object, current_bufferstream))
111 
112 #define LibcwDoutScopeEnd \
113  LIBCWD_DO_TSD(__libcwd_debug_object).finish(__libcwd_debug_object, __libcwd_channel_set LIBCWD_COMMA_TSD); \
114  } \
115  } \
116  } while(0)
117 
118 //===================================================================================================
119 // Macro LibcwDoutFatal
120 //
121 
122 // This is debugging libcwd itself.
123 #ifndef LIBCWD_LibcwDoutFatalScopeBegin_MARKER
124 #if CWDEBUG_DEBUGOUTPUT
125 #define LIBCWD_STR4 "LibcwDoutFatal at " __FILE__ ":" LIBCWD_STR2(__LINE__) "\n"
126 #define LIBCWD_LibcwDoutFatalScopeBegin_MARKER LibcwDebugThreads( ++__libcwd_tsd.internal_debugging_code ); ::write(2, LIBCWD_STR4, sizeof(LIBCWD_STR4) - 1); LibcwDebugThreads( --__libcwd_tsd.internal_debugging_code )
127 #else
128 #define LIBCWD_LibcwDoutFatalScopeBegin_MARKER
129 #endif
130 #endif // !LIBCWD_LibcwDoutFatalScopeBegin_MARKER
131 
140 #define LibcwDoutFatal( dc_namespace, debug_obj, cntrl, data ) \
141  LibcwDoutFatalScopeBegin(dc_namespace, debug_obj, cntrl) \
142  LibcwDoutFatalStream << data; \
143  LibcwDoutFatalScopeEnd
144 
145 #define LibcwDoutFatalScopeBegin( dc_namespace, debug_obj, cntrl ) \
146  do \
147  { \
148  LIBCWD_TSD_DECLARATION; \
149  LIBCWD_LibcwDoutFatalScopeBegin_MARKER; \
150  using namespace ::libcwd; \
151  ::libcwd::channel_set_bootstrap_fatal_st __libcwd_channel_set(LIBCWD_DO_TSD(debug_obj) LIBCWD_COMMA_TSD); \
152  { \
153  using namespace dc_namespace; \
154  __libcwd_channel_set|cntrl; \
155  } \
156  ::libcwd::debug_ct& __libcwd_debug_object(debug_obj); \
157  LIBCWD_DO_TSD(__libcwd_debug_object).start(__libcwd_debug_object, __libcwd_channel_set LIBCWD_COMMA_TSD);
158 
159 #define LibcwDoutFatalStream LibcwDoutStream
160 
161 #define LibcwDoutFatalScopeEnd \
162  LIBCWD_DO_TSD(__libcwd_debug_object).fatal_finish(__libcwd_debug_object, __libcwd_channel_set LIBCWD_COMMA_TSD); \
163  } while(0)
164 
165 #endif // LIBCWD_MACRO_LIBCWD_MACROS_H
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.