00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef __SCIM_DEBUG_H
00036 #define __SCIM_DEBUG_H
00037
00038 #define SCIM_DEBUG_MAX_VERBOSE 7
00039
00040 namespace scim {
00041
00042
00043
00044
00045
00046 #define SCIM_DEBUG_AllMask (~0)
00047 #define SCIM_DEBUG_MainMask 1
00048 #define SCIM_DEBUG_ConfigMask 2
00049 #define SCIM_DEBUG_IMEngineMask 4
00050 #define SCIM_DEBUG_BackEndMask 8
00051 #define SCIM_DEBUG_FrontEndMask 16
00052 #define SCIM_DEBUG_ModuleMask 32
00053 #define SCIM_DEBUG_UtilityMask 64
00054 #define SCIM_DEBUG_IConvMask 128
00055 #define SCIM_DEBUG_LookupTableMask 256
00056 #define SCIM_DEBUG_SocketMask 512
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #define SCIM_DEBUG(mask,level) (scim::DebugOutput(mask,level) << __FILE__ << ":" << __LINE__ << " > ")
00070 #define SCIM_DEBUG_MAIN(level) SCIM_DEBUG(SCIM_DEBUG_MainMask,level)
00071 #define SCIM_DEBUG_CONFIG(level) SCIM_DEBUG(SCIM_DEBUG_ConfigMask,level)
00072 #define SCIM_DEBUG_IMENGINE(level) SCIM_DEBUG(SCIM_DEBUG_IMEngineMask,level)
00073 #define SCIM_DEBUG_BACKEND(level) SCIM_DEBUG(SCIM_DEBUG_BackEndMask,level)
00074 #define SCIM_DEBUG_FRONTEND(level) SCIM_DEBUG(SCIM_DEBUG_FrontEndMask,level)
00075 #define SCIM_DEBUG_MODULE(level) SCIM_DEBUG(SCIM_DEBUG_ModuleMask,level)
00076 #define SCIM_DEBUG_UTILITY(level) SCIM_DEBUG(SCIM_DEBUG_UtilityMask,level)
00077 #define SCIM_DEBUG_ICONV(level) SCIM_DEBUG(SCIM_DEBUG_IConvMask,level)
00078 #define SCIM_DEBUG_LOOKUPTABLE(level) SCIM_DEBUG(SCIM_DEBUG_LookupTableMask,level)
00079 #define SCIM_DEBUG_SOCKET(level) SCIM_DEBUG(SCIM_DEBUG_SocketMask,level)
00080
00081
00082
00083
00084
00085
00086
00087 #if ENABLE_DEBUG
00088 class DebugOutput
00089 {
00090 uint32 m_mask;
00091 uint32 m_verbose;
00092
00093 private:
00094 static uint32 verbose_level;
00095 static uint32 output_mask;
00096 static std::ostream *output_stream;
00097
00098 public:
00099
00100
00101
00102
00103
00104 DebugOutput (uint32 mask = SCIM_DEBUG_AllMask, uint32 verbose = 1)
00105 : m_mask (mask), m_verbose (verbose) { }
00106
00107
00108
00109
00110
00111
00112
00113 template <typename T>
00114 const DebugOutput& operator << (const T& t) const {
00115 if (output_stream && (m_mask & output_mask)
00116 && (m_verbose <= verbose_level))
00117 (*output_stream) << t;
00118 return *this;
00119 }
00120
00121 public:
00122
00123
00124
00125
00126
00127 static void enable_debug (uint32 debug);
00128
00129
00130
00131
00132
00133
00134
00135 static void enable_debug_by_name (const String &debug);
00136
00137
00138
00139
00140
00141 static void disable_debug (uint32 debug);
00142
00143
00144
00145
00146
00147 static void disable_debug_by_name (const String &debug);
00148
00149
00150
00151
00152
00153 static void set_verbose_level (uint32 verbose);
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 static void set_output (const String &file);
00165 };
00166 #else
00167 class DebugOutput
00168 {
00169 private:
00170 static uint32 verbose_level;
00171 static uint32 output_mask;
00172 static std::ostream *output_stream;
00173
00174 public:
00175 DebugOutput (uint32 mask = SCIM_DEBUG_AllMask, uint32 verbose = 1){ }
00176
00177 template <typename T>
00178 const DebugOutput& operator << (const T& t) const {
00179 return *this;
00180 }
00181
00182 public:
00183 static void enable_debug (uint32 debug);
00184 static void enable_debug_by_name (const String &debug);
00185
00186 static void disable_debug (uint32 debug);
00187 static void disable_debug_by_name (const String &debug);
00188
00189 static void set_verbose_level (uint32 verbose);
00190 static void set_output (const String &file);
00191 };
00192 #endif
00193
00194 }
00195
00196 #endif //__SCIM_DEBUG_H
00197
00198
00199