Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

s11n_debuggering_macros.hpp

Go to the documentation of this file.
00001 #ifndef s11n_DEBUGGERING_MACROS_H
00002 #define s11n_DEBUGGERING_MACROS_H 1
00003 
00004 // CERR is a drop-in replacement for std::cerr, but slightly more
00005 // decorative.
00006 #ifndef CERR
00007 #define CERR std::cerr << __FILE__ << ":" << std::dec << __LINE__ << " : "
00008 #endif
00009 
00010 #ifndef COUT
00011 #define COUT std::cout << __FILE__ << ":" << std::dec << __LINE__ << " : "
00012 #endif
00013 
00014 #include <iostream>
00015 
00016 ////////////////////////////////////////////////////////////////////////
00017 // Debuggering/tracing macros for the s11n internals...
00018 // The xxx_PROFILE_xxx macros are NOT part of the API:
00019 // they are to allow me to quickly switch between various
00020 // debuggering modes.
00021 #define S11N_TRACE_PROFILE_QUIET (::s11n::debug::TRACE_NEVER)
00022 #define S11N_TRACE_PROFILE_DEFAULT (::s11n::debug::TRACE_ERROR | ::s11n::debug::TRACE_WARNING )
00023 #define S11N_TRACE_PROFILE_MAINTAINER (S11N_TRACE_PROFILE_DEFAULT | ::s11n::debug::TRACE_FACTORY )
00024 
00025 ////////////////////////////////////////////////////////////////////////
00026 // S11N_TRACE_LEVELS defines the default, compiled-in tracing level
00027 // When set to 0 (TRACE_NONE), tracing will be unavailable even if
00028 // trace_mask() is later used to change it, and a smart compiler will
00029 // optimize out all such S11N_TRACE calls.
00030 #ifndef S11N_TRACE_LEVELS // allow client code to change compile-time default
00031 //#  define S11N_TRACE_LEVELS (S11N_TRACE_PROFILE_MAINTAINER)
00032 #  define S11N_TRACE_LEVELS (S11N_TRACE_PROFILE_DEFAULT)
00033 #endif
00034 
00035 // The S11N_TRACE macro is described in the s11n::debug namespace docs
00036 #define S11N_TRACE(LVL) if((S11N_TRACE_LEVELS) && ((LVL) & ::s11n::debug::trace_mask())) \
00037         ::s11n::debug::trace_stream() << "S11N_TRACE["<<# LVL<<"]: "<<__FILE__<<":"<<std::dec<<__LINE__<<":\n\t"
00038 
00039 
00040 namespace s11n {
00041     /**
00042        The s11n::debug namespace holds some code for debugging and tracing
00043        s11n internals. It is not intended for client-side use.
00044 
00045        Debuggering macros:
00046 
00047        S11N_TRACE_LEVELS is a bitmask of TraceFlags values. It defines
00048        which types of tracing are enabled by default. Code which should be
00049        "traced" should use the S11N_TRACE macro like this:
00050 
00051        S11N_TRACE(TRACE_LEVEL) << "output ...\n";
00052 
00053        The output will only be generated when S11N_TRACE_LEVELS is
00054        non-zero and the given TRACE_LEVEL mask matches the current
00055        value of trace_mask().
00056 
00057        The mask may be changed at runtime by using the
00058        trace_mask() function, and set the default at compile time
00059        by defining S11N_TRACE_LEVELS before including
00060        s11n_debuggering_macros.hpp.
00061     */
00062     namespace debug {
00063 
00064         /**
00065            For use with the S11N_TRACE macro.
00066         */
00067         enum TraceFlags {
00068         TRACE_NEVER = 0x00000000, // always off
00069         TRACE_TRIVIAL = 0x00000001, // absolutely trivial info which mainly serves to clutter the console
00070         TRACE_INFO = 0x00000002, // flag for 'info' traces
00071         TRACE_WARNING = 0x00000004, // ditto for 'warning'
00072         TRACE_ERROR = 0x00000008, // ditto for 'error'
00073         TRACE_CTOR = 0x00000010, // tracer for ctors
00074         TRACE_DTOR = 0x00000020, // tracer for dtors
00075         TRACE_CLEANUP = 0x00000040, // tracer for cleanup-on-failed-deser
00076         TRACE_FACTORY_REG = 0x00000100, // factory registrations
00077         TRACE_FACTORY_LOOKUP = 0x00000200, // factory lookups
00078         TRACE_FACTORY_PLUGINS = 0x00000400, // trace plugin-related stuff
00079         TRACE_FACTORY = 0x00000F00, // trace all factory ops
00080         TRACE_IO = 0x00001000, // for s11n::io
00081         TRACE_NYI =   0x00010000, // NYI == Not Yet Implemented
00082         TRACE_FIXME = 0x00020000, // FIXME/TODO notices
00083         TRACE_SATAN = 0x00040000, // for chasing down really nasty buggers
00084         TRACE_ALWAYS = 0xffffffff // matches all flags except TRACE_NEVER
00085         };
00086 
00087         /**
00088            Sets the active trace mask and returns the previous
00089            mask.
00090         */
00091         unsigned long trace_mask( unsigned long f );
00092 
00093         /**
00094            Returns the current trace mask.
00095         */
00096         unsigned long trace_mask();
00097 
00098         /**
00099            Returns the ostream used for tracing
00100            messages. Default is std::cerr.
00101         */
00102         std::ostream & trace_stream();
00103 
00104         /** Sets the ostream used for tracing messages. */
00105         void trace_stream( std::ostream & );
00106 
00107         /**
00108            A helper type to temporarily change the debug mask,
00109            then revert it at destruction.
00110         */
00111         struct trace_mask_changer
00112         {
00113             /**
00114                Stores the current trace mask.
00115              */
00116             trace_mask_changer();
00117             /**
00118                Stores the current trace mask then
00119                sets then calls trace_mask(m).
00120              */
00121             trace_mask_changer( unsigned long m );
00122             /**
00123                Sets the trace_mask() to the value it
00124                had when this object was constructed.
00125             */
00126             ~trace_mask_changer();
00127         private:
00128             unsigned long m_mask;
00129         };
00130 
00131     } // namespace
00132 } // namespaces
00133 
00134 #endif //  s11n_DEBUGGERING_MACROS_H

Generated on Thu Sep 29 20:01:14 2005 for libs11n-1.1.3-dev by  doxygen 1.4.1