1 #ifndef s11n_DEBUGGERING_MACROS_H 2 #define s11n_DEBUGGERING_MACROS_H 1 3 4 // CERR is a drop-in replacement for std::cerr, but slightly more 5 // decorative. 6 #ifndef CERR 7 #define CERR std::cerr << __FILE__ << ":" << std::dec << __LINE__ << " : " 8 #endif 9 10 #ifndef COUT 11 #define COUT std::cout << __FILE__ << ":" << std::dec << __LINE__ << " : " 12 #endif 13 14 #include <iostream> 15 16 //Added by Damien to make Windows compile work 17 #include <s11n.net/s11n/export.hpp> // S11N_EXPORT_API 18 19 20 //////////////////////////////////////////////////////////////////////// 21 // Debuggering/tracing macros for the s11n internals... 22 // The xxx_PROFILE_xxx macros are NOT part of the API: 23 // they are to allow me to quickly switch between various 24 // debuggering modes. 25 #define S11N_TRACE_PROFILE_QUIET (::s11n::debug::TRACE_NEVER) 26 #define S11N_TRACE_PROFILE_DEFAULT (::s11n::debug::TRACE_ERROR | ::s11n::debug::TRACE_WARNING ) 27 #define S11N_TRACE_PROFILE_MAINTAINER (S11N_TRACE_PROFILE_DEFAULT | ::s11n::debug::TRACE_FACTORY_REG ) 28 29 //////////////////////////////////////////////////////////////////////// 30 // S11N_TRACE_LEVELS defines the default, compiled-in tracing level 31 // When set to 0 (TRACE_NONE), tracing will be unavailable even if 32 // trace_mask() is later used to change it, and a smart compiler will 33 // optimize out all such S11N_TRACE calls. 34 #ifndef S11N_TRACE_LEVELS // allow client code to change compile-time default 35 //# define S11N_TRACE_LEVELS (S11N_TRACE_PROFILE_MAINTAINER) 36 # define S11N_TRACE_LEVELS (S11N_TRACE_PROFILE_DEFAULT) 37 #endif 38 39 // The S11N_TRACE macro is described in the s11n::debug namespace docs 40 #define S11N_TRACE(LVL) if((S11N_TRACE_LEVELS) && ((LVL) & ::s11n::debug::trace_mask())) \ 41 ::s11n::debug::trace_stream() << "S11N_TRACE["<<# LVL<<"]: "<<__FILE__<<":"<<std::dec<<__LINE__<<":\n\t" 42 43 44 namespace s11n { 45 /** 46 The s11n::debug namespace holds some code for debugging and tracing 47 s11n internals. It is not intended for client-side use. 48 49 Debuggering macros: 50 51 S11N_TRACE_LEVELS is a bitmask of TraceFlags values. It defines 52 which types of tracing are enabled by default. Code which should be 53 "traced" should use the S11N_TRACE macro like this: 54 55 S11N_TRACE(TRACE_LEVEL) << "output ...\n"; 56 57 The output will only be generated when S11N_TRACE_LEVELS is 58 non-zero and the given TRACE_LEVEL mask matches the current 59 value of trace_mask(). 60 61 The mask may be changed at runtime by using the 62 trace_mask() function, and set the default at compile time 63 by defining S11N_TRACE_LEVELS before including 64 s11n_debuggering_macros.hpp. 65 */ 66 namespace debug { 67 68 /** 69 For use with the S11N_TRACE macro. 70 */ 71 enum TraceFlags { 72 TRACE_NEVER = 0x00000000, // always off 73 TRACE_TRIVIAL = 0x00000001, // absolutely trivial info which mainly serves to clutter the console 74 TRACE_INFO = 0x00000002, // flag for 'info' traces 75 TRACE_WARNING = 0x00000004, // ditto for 'warning' 76 TRACE_ERROR = 0x00000008, // ditto for 'error' 77 TRACE_CTOR = 0x00000010, // tracer for ctors 78 TRACE_DTOR = 0x00000020, // tracer for dtors 79 TRACE_CLEANUP = 0x00000040, // tracer for cleanup-on-failed-deser 80 TRACE_FACTORY_REG = 0x00000100, // factory registrations 81 TRACE_FACTORY_LOOKUP = 0x00000200, // factory lookups 82 TRACE_FACTORY_PLUGINS = 0x00000400, // trace plugin-related stuff 83 TRACE_FACTORY = 0x00000F00, // trace all factory ops 84 TRACE_IO = 0x00001000, // for s11n::io 85 TRACE_NYI = 0x00010000, // NYI == Not Yet Implemented 86 TRACE_FIXME = 0x00020000, // FIXME/TODO notices 87 TRACE_SATAN = 0x00040000, // for chasing down really nasty buggers 88 TRACE_ALWAYS = 0xffffffff // matches all flags except TRACE_NEVER 89 }; 90 91 /** 92 Sets the active trace mask and returns the previous 93 mask. 94 */ 95 unsigned long trace_mask( unsigned long f ); 96 97 /** 98 Returns the current trace mask. 99 */ 100 //Added by Damien to make Windows compile work 101 S11N_EXPORT_API unsigned long trace_mask(); 102 103 /** 104 Returns the ostream used for tracing 105 messages. Default is std::cerr. 106 */ 107 //Added by Damien to make Windows compile work 108 S11N_EXPORT_API std::ostream & trace_stream(); 109 110 /** Sets the ostream used for tracing messages. */ 111 void trace_stream( std::ostream & ); 112 113 /** 114 A helper type to temporarily change the debug mask, 115 then revert it at destruction. 116 */ 117 struct trace_mask_changer 118 { 119 /** 120 Stores the current trace mask. 121 */ 122 trace_mask_changer(); 123 /** 124 Stores the current trace mask then 125 sets then calls trace_mask(m). 126 */ 127 trace_mask_changer( unsigned long m ); 128 /** 129 Sets the trace_mask() to the value it 130 had when this object was constructed. 131 */ 132 ~trace_mask_changer(); 133 private: 134 unsigned long m_mask; 135 }; 136 137 } // namespace 138 } // namespaces 139 140 #endif // s11n_DEBUGGERING_MACROS_H 141