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

Generated on Sat Mar 20 12:29:24 2010 for libs11n-1.2.10 by  doxygen 1.6.1