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/macro_ForAllDebugChannels.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_MACRO_FORALLDEBUGCHANNELS_H
    00019 #define LIBCWD_MACRO_FORALLDEBUGCHANNELS_H
    00020
    00021 #ifndef LIBCWD_CONFIG_H
    00022 #include <libcwd/config.h>
    00023 #endif
    00024 #ifndef LIBCWD_PRIVATE_ASSERT_H
    00025 #include <libcwd/private_assert.h>
    00026 #endif
    00027 #ifndef LIBCWD_PRIVATE_INTERNAL_VECTOR_H
    00028 #include <libcwd/private_internal_vector.h>
    00029 #endif
    00030
    00031 //===================================================================================================
    00032 // Macro ForAllDebugChannels
    00033 //
    00034
    00035 namespace libcwd {
    00036
    00037   class channel_ct;
    00038
    00039   namespace _private_ {
    00040
    00041 class debug_channels_ct {
    00042 public:
    00043   typedef internal_vector<channel_ct*> container_type;
    00044   container_type* WNS_debug_channels;
    00045 public:
    00046   void init(LIBCWD_TSD_PARAM);
    00047 #if LIBCWD_THREAD_SAFE
    00048   void init_and_rdlock(void);
    00049 #endif
    00050   container_type& write_locked(void);
    00051   container_type const& read_locked(void) const;
    00052 };
    00053
    00054 inline
    00055 debug_channels_ct::container_type&
    00056 debug_channels_ct::write_locked(void)
    00057 {
    00058 #if CWDEBUG_DEBUG
    00059   LIBCWD_ASSERT( WNS_debug_channels );
    00060 #endif
    00061   return *WNS_debug_channels;
    00062 }
    00063
    00064 inline
    00065 debug_channels_ct::container_type const&
    00066 debug_channels_ct::read_locked(void) const
    00067 {
    00068 #if CWDEBUG_DEBUG
    00069   LIBCWD_ASSERT( WNS_debug_channels );
    00070 #endif
    00071   return *WNS_debug_channels;
    00072 }
    00073
    00074 extern debug_channels_ct debug_channels;
    00075
    00076   } // namespace _private_
    00077 } // namespace libcwd
    00078
    00079 #if LIBCWD_THREAD_SAFE
    00080 #if CWDEBUG_DEBUGT
    00081 #define LIBCWD_ForAllDebugChannels_LOCK_TSD_DECLARATION LIBCWD_TSD_DECLARATION
    00082 #else
    00083 #define LIBCWD_ForAllDebugChannels_LOCK_TSD_DECLARATION
    00084 #endif
    00085 #define LIBCWD_ForAllDebugChannels_LOCK \
    00086     LIBCWD_ForAllDebugChannels_LOCK_TSD_DECLARATION; \
    00087     LIBCWD_DEFER_CLEANUP_PUSH(&::libcwd::_private_::rwlock_tct< ::libcwd::_private_::debug_channels_instance>::cleanup, NULL); \
    00088     ::libcwd::_private_::debug_channels.init_and_rdlock()
    00089 #define LIBCWD_ForAllDebugChannels_UNLOCK \
    00090     ::libcwd::_private_::rwlock_tct< ::libcwd::_private_::debug_channels_instance>::rdunlock(); \
    00091     LIBCWD_CLEANUP_POP_RESTORE(false);
    00092 #else // !LIBCWD_THREAD_SAFE
    00093 #define LIBCWD_ForAllDebugChannels_LOCK ::libcwd::_private_::debug_channels.init(LIBCWD_TSD)
    00094 #define LIBCWD_ForAllDebugChannels_UNLOCK
    00095 #endif // !LIBCWD_THREAD_SAFE
    00096
    00097 #define LibcwdForAllDebugChannels(dc_namespace, STATEMENT...) \
    00098        do { \
    00099          LIBCWD_ForAllDebugChannels_LOCK; \
    00100          for( ::libcwd::_private_::debug_channels_ct::container_type::\
    00101              const_iterator __libcwd_i(::libcwd::_private_::debug_channels.read_locked().begin());\
    00102              __libcwd_i != ::libcwd::_private_::debug_channels.read_locked().end(); ++__libcwd_i) \
    00103          { \
    00104            using namespace ::libcwd; \
    00105            using namespace dc_namespace; \
    00106            ::libcwd::channel_ct& debugChannel(*(*__libcwd_i)); \
    00107            { STATEMENT; } \
    00108          } \
    00109          LIBCWD_ForAllDebugChannels_UNLOCK \
    00110        } \
    00111        while(0)
    00112
    00113 #endif // LIBCWD_MACRO_FORALLDEBUGCHANNELS_H