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

libcwd/struct_debug_tsd.h

00001 // $Header$
00002 //
00003 // Copyright (C) 2002 - 2004, 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 
00014 #ifndef LIBCWD_STRUCT_DEBUG_TSD_H
00015 #define LIBCWD_STRUCT_DEBUG_TSD_H
00016 
00017 #ifndef LIBCWD_CONFIG_H
00018 #include <libcwd/config.h>
00019 #endif
00020 #ifndef LIBCWD_CLASS_CHANNEL_SET_H
00021 #include <libcwd/class_channel_set.h>
00022 #endif
00023 #ifndef LIBCWD_PRIVATE_DEBUG_STACK_H
00024 #include <libcwd/private_debug_stack.h>
00025 #endif
00026 #ifndef LIBCWD_CLASS_DEBUG_STRING_H
00027 #include <libcwd/class_debug_string.h>
00028 #endif
00029 #ifndef LIBCWD_PRIVATE_STRUCT_TSD_H
00030 #include <libcwd/private_struct_TSD.h>
00031 #endif
00032 #ifndef LIBCW_IOSFWD
00033 #define LIBCW_IOSFWD
00034 #include <iosfwd>
00035 #endif
00036 
00037 namespace libcwd {
00038 
00039 #if CWDEBUG_LOCATION
00040     namespace cwbfd {
00041       bool ST_init(LIBCWD_TSD_PARAM);
00042     } // namespace cwbfd
00043 #endif
00044 
00045 class debug_ct;
00046 class channel_ct;
00047 class fatal_channel_ct;
00048 class laf_ct;
00049 
00050 //===================================================================================================
00051 // struct debug_tsd_st
00052 //
00053 // Structure with Thread Specific Data of a debug object.
00054 //
00055 
00056 struct debug_tsd_st {
00057   friend class debug_ct;
00058 
00059 #if !LIBCWD_THREAD_SAFE
00060   int _off;
00061     // Debug output is turned on when this variable is -1, otherwise it is off.
00062 #endif
00063 
00064   bool tsd_initialized;
00065     // Set after initialization is completed.
00066   
00067 #if CWDEBUG_DEBUGOUTPUT
00068   // Since we start with _off is -1 instead of 0 when CWDEBUG_DEBUG is set,
00069   // we need to ignore the call to on() the first time it is called.
00070   bool first_time;
00071 #endif
00072 
00073   laf_ct* current;
00074     // Current laf.
00075 
00076   std::ostream* current_bufferstream;
00077     // The stringstream of the current laf.
00078     // This should be set to current->bufferstream at all times.
00079 
00080   _private_::debug_stack_tst<laf_ct*> laf_stack;
00081     // Store for nested debug calls.
00082 
00083   bool start_expected;
00084     // Set to true when start() is expected, otherwise we expect a call to finish().
00085 
00086   bool unfinished_expected;
00087     // Set to true when start() should cause a <unfinished>.
00088 
00089   int off_count;
00090     // Number of nested and switched off continued channels till first switched on continued channel.
00091 
00092   _private_::debug_stack_tst<int> continued_stack;
00093     // Stores the number of nested and switched off continued channels.
00094 
00095   debug_string_ct margin;
00096     // The margin string.
00097 
00098   debug_string_ct marker;
00099     // The marker string.
00100 
00101   debug_string_stack_element_ct* M_margin_stack;
00102     // Pointer to list of pushed margins.
00103 
00104   debug_string_stack_element_ct* M_marker_stack;
00105     // Pointer to list of pushed markers.
00106 
00107   unsigned short indent;
00108     // Position at which debug message is printed.
00109     // A value of 0 means directly behind the marker.
00110 
00111   // Accessed from LibcwdDout.
00112   void start(debug_ct& debug_object, channel_set_data_st& channel_set LIBCWD_COMMA_TSD_PARAM);
00113   void finish(debug_ct& debug_object, channel_set_data_st& /*channel_set*/ LIBCWD_COMMA_TSD_PARAM);
00114   void fatal_finish(debug_ct& debug_object, channel_set_data_st& channel_set LIBCWD_COMMA_TSD_PARAM) __attribute__ ((__noreturn__));
00115 
00116   // Initialization and de-initialization.
00117   void init(void);
00118 #if LIBCWD_THREAD_SAFE
00119   // In the non-threaded case, debug_ct contains a debug_tsd_st which
00120   // may already be initialized before.  Therefore don't initialize
00121   // these in the non-threaded case, but rely on tsd_initialized,
00122   // current_bufferstream and _off to be zeroed as a result of being
00123   // part of a global object.
00124   debug_tsd_st(void) : tsd_initialized(false), current_bufferstream(NULL) { }
00125 #endif
00126   ~debug_tsd_st();
00127 };
00128 
00129 }  // namespace libcwd
00130 
00131 #endif // LIBCWD_STRUCT_DEBUG_TSD_H
00132 
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.