libcwd: The C++ Debugging Support Library - Reference Manual
Author: Carlo Wood
Description: C++ debugging support library with ostream debug output
Keywords: libcwd, debug output, debug facility, debug channel, object orientation, OO, C++, nested debug output, ostream, memory allocation, debugging, source file and line number

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

# libcwd/class_channel.h

Go to the documentation of this file.

    00001 // $Header$
    00002 //
    00003 // Copyright (C) 2000 - 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
    00018 #ifndef LIBCWD_CLASS_CHANNEL_H
    00019 #define LIBCWD_CLASS_CHANNEL_H
    00020
    00021 #ifndef LIBCWD_CONFIG_H
    00022 #include <libcwd/config.h>
    00023 #endif
    00024 #ifndef LIBCWD_MAX_LABEL_LEN_H
    00025 #include <libcwd/max_label_len.h>
    00026 #endif
    00027 #ifndef LIBCWD_CONTROL_FLAG_H
    00028 #include <libcwd/control_flag.h>
    00029 #endif
    00030 #ifndef LIBCWD_PRIVATE_STRUCT_TSD_H
    00031 #include <libcwd/private_struct_TSD.h>
    00032 #endif
    00033
    00034 namespace libcwd {
    00035
    00082 class channel_ct {
    00083 private:
    00084 #if LIBCWD_THREAD_SAFE
    00085   int WNS_index;
    00086     // A unique id that is used as index into the TSD array `off_cnt_array'.
    00087 #else // !LIBCWD_THREAD_SAFE
    00088   int off_cnt;
    00089     // A counter of the nested calls to off().
    00090     // The channel is turned off when the value of `off' is larger or equal then zero
    00091     // and `on' when it has the value -1.
    00092 #endif // !LIBCWD_THREAD_SAFE
    00093
    00094   char WNS_label[max_label_len_c + 1];                  // +1 for zero termination.
    00095     // A reference name for the represented debug channel
    00096     // This label will be printed in front of each output written to
    00097     // this debug channel.
    00098
    00099   bool WNS_initialized;
    00100     // Set to true when initialized.
    00101
    00102 public:
    00103   //---------------------------------------------------------------------------
    00104   // Constructor
    00105   //
    00106
    00107   // MT: All channel objects must be global so that `WNS_initialized' is false
    00108   //     at the start of the program and initialization occurs before other threads
    00109   //     share the object.
    00110   explicit channel_ct(char const* label, bool add_to_channel_list = true);
    00111
    00112   // MT: May only be called from the constructors of global objects (or single threaded functions).
    00113   void NS_initialize(char const* label LIBCWD_COMMA_TSD_PARAM, bool add_to_channel_list);
    00114     // Force initialization in case the constructor of this global object
    00115     // wasn't called yet.  Does nothing when the object was already initialized.
    00116
    00117 public:
    00118   //---------------------------------------------------------------------------
    00119   // Manipulators
    00120   //
    00121
    00122   void off(void);
    00123   void on(void);
    00124
    00125   struct OnOffState {
    00126     int off_cnt;
    00127   };
    00128
    00129   void force_on(OnOffState& state, char const* label);
    00130   void restore(OnOffState const& state);
    00131
    00132 public:
    00133   //---------------------------------------------------------------------------
    00134   // Accessors
    00135   //
    00136
    00137   char const* get_label(void) const;
    00138   bool is_on(void) const;
    00139 #if LIBCWD_THREAD_SAFE
    00140   bool is_on(LIBCWD_TSD_PARAM) const;
    00141 #endif
    00142 };
    00143
    00144 } // namespace libcwd
    00145
    00146 #endif // LIBCWD_CLASS_CHANNEL_H
    00147