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 void set_margin(std::string const& s);
00189 void set_marker(std::string const& s);
00190 std::string get_margin(void) const;
00191 std::string get_marker(void) const;
00192
00193
00194
00195
00196
00197 std::ostream* get_ostream(void) const;
00198
00199 private:
00200
00201
00202
00203
00204 friend class channel_ct;
00205 friend class fatal_channel_ct;
00206 friend void ST_initialize_globals(LIBCWD_TSD_PARAM);
00207 #if CWDEBUG_LOCATION
00208 friend bool cwbfd::ST_init(LIBCWD_TSD_PARAM);
00209 #endif
00210 bool NS_init(LIBCWD_TSD_PARAM);
00211
00212
00213
00214
00215
00216
00217
00218
00219 public:
00220
00221
00222
00223
00224 debug_ct(void);
00225
00226 private:
00227 void private_set_ostream(std::ostream* os);
00228
00229 public:
00230
00231
00232
00233
00234 void set_ostream(std::ostream* os);
00235 #if LIBCWD_THREAD_SAFE || defined(LIBCWD_DOXYGEN)
00236 template<class T>
00237 void set_ostream(std::ostream* os, T* mutex);
00238 #ifdef LIBCWD_DOXYGEN
00239
00240 template<>
00241 void set_ostream(std::ostream* os, pthread_mutex_t* mutex);
00242 #endif
00243 #endif
00244 void off(void);
00245 void on(void);
00246
00247 struct OnOffState {
00248 int _off;
00249 #if CWDEBUG_DEBUGOUTPUT
00250 bool first_time;
00251 #endif
00252 };
00253
00254 void force_on(OnOffState& state);
00255 void restore(OnOffState const& state);
00256 };
00257
00258 #if LIBCWD_THREAD_SAFE && !defined(LIBCWD_DOXYGEN)
00259
00260 template<>
00261 void debug_ct::set_ostream(std::ostream* os, pthread_mutex_t* mutex);
00262 #endif
00263
00264 }
00265
00266 #ifndef LIBCWD_SET_OSTREAM_INL
00267 #include <libcwd/set_ostream.inl>
00268 #endif
00269
00270 #endif // LIBCWD_CLASS_DEBUG_H
00271