00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef RECLS_INCL_H_RECLS_DEBUG
00023 #define RECLS_INCL_H_RECLS_DEBUG
00024
00025
00026 #ifndef RECLS_DOCUMENTATION_SKIP_SECTION
00027 # define RECLS_VER_H_RECLS_DEBUG_MAJOR 3
00028 # define RECLS_VER_H_RECLS_DEBUG_MINOR 1
00029 # define RECLS_VER_H_RECLS_DEBUG_REVISION 4
00030 # define RECLS_VER_H_RECLS_DEBUG_EDIT 32
00031 #endif
00032
00036
00037
00038
00039
00040
00041 #include <recls/recls.h>
00042 #include "recls_impl.h"
00043
00044 #ifndef RECLS_DEBUG_LEVEL
00045 # error RECLS_DEBUG_LEVEL must be defined
00046 #endif
00047
00048
00049 #if RECLS_DEBUG_LEVEL > 0
00050 # if defined(RECLS_PLATFORM_IS_UNIX)
00051 # include <stlsoft/error/errno_scope.hpp>
00052 # if defined(_RECLS_MT)
00053 # include <unixstl/synch/tss_index.hpp>
00054 # endif
00055 # elif defined(RECLS_PLATFORM_IS_WIN32)
00056 # include <winstl/error/last_error_scope.hpp>
00057 # if defined(_RECLS_MT)
00058 # include <winstl/synch/tss_index.hpp>
00059 # endif
00060 # else
00061 # error Unrecognised platform
00062 # endif
00063 # include <stdarg.h>
00064 # if defined(RECLS_PLATFORM_IS_UNIX)
00065 # include <syslog.h>
00066 # endif
00067 #endif
00068
00069
00070 #include <stdio.h>
00071 #if RECLS_DEBUG_LEVEL > 0
00072 # include <string.h>
00073 #endif
00074
00075
00076
00077
00078
00079 #if !defined(RECLS_NO_NAMESPACE)
00080 namespace recls
00081 {
00082 #endif
00083
00084 #if RECLS_DEBUG_LEVEL >= 2
00085 # if defined(RECLS_PLATFORM_IS_UNIX)
00086 typedef stlsoft_ns_qual(errno_scope) error_scope_t;
00087 # if defined(WIN32) && \
00088 defined(EMULATE_UNIX_ON_WIN32)
00089 # else
00090
00091 inline void OutputDebugStringA(char const *s)
00092 {
00093 static_cast<void>(fprintf(stderr, s));
00094 }
00095 # endif
00096 # if defined(_RECLS_MT)
00097 unixstl_ns_using(tss_index)
00098 # endif
00099 # elif defined(RECLS_PLATFORM_IS_WIN32)
00100 typedef winstl_ns_qual(last_error_scope) error_scope_t;
00101 # if defined(_RECLS_MT)
00102 winstl_ns_using(tss_index)
00103 # endif
00104 # else
00105 # error Unrecognised platform
00106 # endif
00107 #endif
00108
00109
00110
00111
00112
00113 #if RECLS_DEBUG_LEVEL >= 1
00114 inline void debug_printf(char const *fmt, ...)
00115 {
00116 va_list args;
00117 char _sz[2048];
00118
00119 va_start(args, fmt);
00120
00121 # if defined(RECLS_PLATFORM_IS_UNIX) && \
00122 ( !defined(WIN32) || \
00123 !defined(EMULATE_UNIX_ON_WIN32))
00124 vsnprintf(_sz, RECLS_NUM_ELEMENTS(_sz), fmt, args);
00125 # else
00126 _vsnprintf(_sz, RECLS_NUM_ELEMENTS(_sz), fmt, args);
00127 # endif
00128 # if defined(RECLS_PLATFORM_IS_UNIX)
00129 syslog(LOG_DEBUG, _sz);
00130 # elif defined(RECLS_PLATFORM_IS_WIN32)
00131 OutputDebugStringA(_sz);
00132 # endif
00133
00134 va_end(args);
00135 }
00136
00137 #else
00138
00139 # ifdef __cplusplus
00140 inline
00141 # else
00142 static
00143 # endif
00144 void debug_printf_(char const *fmt, ...)
00145 {
00146 static_cast<void>(fmt);
00147 }
00148
00149 # define debug_printf (0) ? _RECLS_STATIC_CAST(void, 0) : debug_printf_
00150
00151 #endif
00152
00153 #if RECLS_DEBUG_LEVEL >= 2
00154 class function_scope
00155 {
00156 public:
00157 function_scope(char const *fn)
00158 {
00159 error_scope_t error_scope;
00160
00161 ::strncpy(m_fn, fn, RECLS_NUM_ELEMENTS(m_fn) - 1);
00162 debug_printf("%*s>> %s()\n", static_cast<int>(post_inc_()), "", m_fn);
00163 }
00164 ~function_scope()
00165 {
00166 error_scope_t error_scope;
00167
00168 debug_printf("%*s<< %s()\n", static_cast<int>(pre_dec_()), "", m_fn);
00169 }
00170
00171 private:
00172 typedef ::stlsoft::sint32_t int32_t;
00173
00174 union U
00175 {
00176 public:
00177 int32_t i;
00178 void *pv;
00179 };
00180
00181 # if defined(_RECLS_MT)
00182
00183 # if defined(RECLS_COMPILER_IS_INTEL)
00184 # pragma warning(push)
00185 # pragma warning(disable : 171)
00186 # endif
00187
00188 static int32_t tls_get_value_()
00189 {
00190 U u;
00191
00192 u.pv = get_index_().get_value();
00193
00194 return u.i;
00195 }
00196 static void tls_set_value_(int32_t i)
00197 {
00198 U u;
00199
00200 u.i = i;
00201
00202 get_index_().set_value(u.pv);
00203 }
00204
00205 # if defined(RECLS_COMPILER_IS_INTEL)
00206 # pragma warning(pop)
00207 # endif
00208
00209 # endif
00210
00211 static int32_t post_inc_()
00212 {
00213 # if defined(_RECLS_MT)
00214 int32_t i = (int32_t)(tls_get_value_());
00215 int32_t r = i++;
00216
00217 tls_set_value_(i);
00218
00219 return r;
00220 # else
00221 return get_index_()++;
00222 # endif
00223 }
00224 static int32_t pre_dec_()
00225 {
00226 # if defined(_RECLS_MT)
00227 int32_t i = (int32_t)(tls_get_value_());
00228 int32_t r = --i;
00229
00230 tls_set_value_(i);
00231
00232 return r;
00233 # else
00234 return --get_index_();
00235 # endif
00236 }
00237
00238 private:
00239 char m_fn[1024];
00240 # if defined(_RECLS_MT)
00241 static tss_index &get_index_()
00242 {
00243 static tss_index s_index;
00244
00245 return s_index;
00246 }
00247 # else
00248 static int32_t &get_index_()
00249 {
00250 static int32_t s_count;
00251
00252 return s_count;
00253 }
00254 # endif
00255 };
00256
00257 # define function_scope_trace(f) function_scope _scope_ ## __LINE__(f)
00258
00259 #else
00260
00261 # define function_scope_trace(f) do { ; } while(0)
00262
00263 #endif
00264
00265
00266
00267
00268
00269 #if !defined(RECLS_NO_NAMESPACE)
00270 }
00271 #endif
00272
00273
00274
00275 #endif
00276
00277