00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00018 #ifndef LIBCWD_CLASS_DEBUG_H
00019 #define LIBCWD_CLASS_DEBUG_H
00020
00021 #ifndef LIBCWD_CONFIG_H
00022 #include <libcwd/config.h>
00023 #endif
00024 #ifndef LIBCWD_CLASS_CHANNEL_SET_H
00025 #include <libcwd/class_channel_set.h>
00026 #endif
00027 #ifndef LIBCWD_PRIVATE_STRUCT_TSD_H
00028 #include <libcwd/private_struct_TSD.h>
00029 #endif
00030 #ifndef LIBCWD_STRUCT_DEBUG_TSD_H
00031 #include <libcwd/struct_debug_tsd.h>
00032 #endif
00033 #ifndef LIBCWD_PRIVATE_LOCK_INTERFACE_H
00034 #include <libcwd/private_lock_interface.h>
00035 #endif
00036 #ifndef LIBCW_IOSFWD
00037 #define LIBCW_IOSFWD
00038 #include <iosfwd>
00039 #endif
00040
00041 namespace libcwd {
00042
00043 class buffer_ct;
00044
00045 #if CWDEBUG_ALLOC
00046 namespace _private_ {
00047
00048 struct debug_message_st {
00049 struct debug_message_st* next;
00050 struct debug_message_st* prev;
00051 int curlen;
00052 char buf[sizeof(int)];
00053 };
00054
00055 }
00056 #endif
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00077 class debug_ct {
00078 friend void debug_tsd_st::start(debug_ct&, channel_set_data_st& LIBCWD_COMMA_TSD_PARAM);
00079 friend void debug_tsd_st::finish(debug_ct &, channel_set_data_st& LIBCWD_COMMA_TSD_PARAM);
00080 #ifdef LIBCWD_DOXYGEN
00081 protected:
00082 #else
00083 public:
00084 #endif
00085 #if LIBCWD_THREAD_SAFE
00086 int WNS_index;
00087 static int S_index_count;
00088 #else
00089
00090
00091
00092
00093
00094 debug_tsd_st tsd;
00095 #endif
00096
00097 protected:
00098
00099
00100
00101
00102 std::ostream* real_os;
00103
00104
00105 #if LIBCWD_THREAD_SAFE
00106 friend class libcwd::buffer_ct;
00107 _private_::lock_interface_base_ct* M_mutex;
00108
00109
00110
00111 buffer_ct* unfinished_oss;
00112 void const* newlineless_tsd;
00113 #endif
00114
00115 private:
00116
00117
00118
00119
00120 bool WNS_initialized;
00121
00122
00123 bool NS_being_initialized;
00124
00125
00126 #if CWDEBUG_DEBUG
00127 long init_magic;
00128
00129 #endif
00130
00131 bool interactive;
00132
00133
00134 #if CWDEBUG_ALLOC
00135 public:
00136 _private_::debug_message_st* queue;
00137 _private_::debug_message_st* queue_top;
00138
00139
00140 #endif
00141
00142 public:
00155 debug_string_ct& margin(void);
00156 debug_string_ct const& margin(void) const;
00157
00167 debug_string_ct& marker(void);
00168 debug_string_ct const& marker(void) const;
00169
00172 public:
00173
00174
00175
00176
00177 void set_indent(unsigned short indentation);
00178 void inc_indent(unsigned short indentation);
00179 void dec_indent(unsigned short indentation);
00180 unsigned short get_indent(void) const;
00181
00182 void push_margin(void);
00183 void pop_margin(void);
00184 void push_marker(void);
00185 void pop_marker(void);
00186
00187
00188
00189
00190
00191 std::ostream* get_ostream(void) const;
00192
00193 private:
00194
00195
00196
00197
00198 friend class channel_ct;
00199 friend class fatal_channel_ct;
00200 friend void ST_initialize_globals(LIBCWD_TSD_PARAM);
00201 #if CWDEBUG_LOCATION
00202 friend bool cwbfd::ST_init(LIBCWD_TSD_PARAM);
00203 #endif
00204 bool NS_init(LIBCWD_TSD_PARAM);
00205
00206
00207
00208
00209
00210
00211
00212
00213 public:
00214
00215
00216
00217
00218 debug_ct(void);
00219
00220 private:
00221 void private_set_ostream(std::ostream* os);
00222
00223 public:
00224
00225
00226
00227
00228 void set_ostream(std::ostream* os);
00229 #if LIBCWD_THREAD_SAFE || defined(LIBCWD_DOXYGEN)
00230 template<class T>
00231 void set_ostream(std::ostream* os, T* mutex);
00232 #ifdef LIBCWD_DOXYGEN
00233
00234 template<>
00235 void set_ostream(std::ostream* os, pthread_mutex_t* mutex);
00236 #endif
00237 #endif
00238 void off(void);
00239 void on(void);
00240
00241 struct OnOffState {
00242 int _off;
00243 #if CWDEBUG_DEBUGOUTPUT
00244 bool first_time;
00245 #endif
00246 };
00247
00248 void force_on(OnOffState& state);
00249 void restore(OnOffState const& state);
00250 };
00251
00252 #if LIBCWD_THREAD_SAFE && !defined(LIBCWD_DOXYGEN)
00253
00254 template<>
00255 void debug_ct::set_ostream(std::ostream* os, pthread_mutex_t* mutex);
00256 #endif
00257
00258 }
00259
00260 #ifndef LIBCWD_SET_OSTREAM_INL
00261 #include <libcwd/set_ostream.inl>
00262 #endif
00263
00264 #endif // LIBCWD_CLASS_DEBUG_H
00265