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 5
00030 # define RECLS_VER_H_RECLS_DEBUG_EDIT 33
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(STLSOFT_COMPILER_IS_DMC) || \
00080 ( defined(STLSOFT_COMPILER_IS_COMO) && \
00081 defined(_MSC_VER) && \
00082 defined(WIN32)) || \
00083 ( defined(STLSOFT_COMPILER_IS_INTEL) && \
00084 defined(WIN32)) || \
00085 defined(STLSOFT_COMPILER_IS_MSVC)
00086 # define snprintf _snprintf
00087 # define vsnprintf _vsnprintf
00088 #endif
00089
00090
00091
00092
00093
00094 #if !defined(RECLS_NO_NAMESPACE)
00095 namespace recls
00096 {
00097 #endif
00098
00099 #if RECLS_DEBUG_LEVEL >= 2
00100 # if defined(RECLS_PLATFORM_IS_UNIX)
00101 typedef stlsoft_ns_qual(errno_scope) error_scope_t;
00102 # if defined(_RECLS_MT)
00103 unixstl_ns_using(tss_index)
00104 # endif
00105 # elif defined(RECLS_PLATFORM_IS_WIN32)
00106 typedef winstl_ns_qual(last_error_scope) error_scope_t;
00107 # if defined(_RECLS_MT)
00108 winstl_ns_using(tss_index)
00109 # endif
00110 # else
00111 # error Unrecognised platform
00112 # endif
00113 #endif
00114
00115
00116
00117
00118
00119 #if RECLS_DEBUG_LEVEL >= 1
00120 inline void debug_printf(char const *fmt, ...)
00121 {
00122 va_list args;
00123 char _sz[2048];
00124
00125 va_start(args, fmt);
00126
00127 vsnprintf(_sz, RECLS_NUM_ELEMENTS(_sz), fmt, args);
00128
00129 # if defined(RECLS_PLATFORM_IS_UNIX)
00130 syslog(LOG_DEBUG, _sz);
00131 # elif defined(RECLS_PLATFORM_IS_WIN32)
00132 OutputDebugStringA(_sz);
00133 # endif
00134
00135 va_end(args);
00136 }
00137
00138 #else
00139
00140 # ifdef __cplusplus
00141 inline
00142 # else
00143 static
00144 # endif
00145 void debug_printf_(char const *fmt, ...)
00146 {
00147 static_cast<void>(fmt);
00148 }
00149
00150 # define debug_printf (0) ? _RECLS_STATIC_CAST(void, 0) : debug_printf_
00151
00152 #endif
00153
00154 #if RECLS_DEBUG_LEVEL >= 2
00155 class function_scope
00156 {
00157 public:
00158 function_scope(char const *fn)
00159 {
00160 error_scope_t error_scope;
00161
00162 ::strncpy(m_fn, fn, RECLS_NUM_ELEMENTS(m_fn) - 1);
00163 debug_printf("%*s>> %s()\n", static_cast<int>(post_inc_()), "", m_fn);
00164 }
00165 ~function_scope()
00166 {
00167 error_scope_t error_scope;
00168
00169 debug_printf("%*s<< %s()\n", static_cast<int>(pre_dec_()), "", m_fn);
00170 }
00171
00172 private:
00173 typedef ::stlsoft::sint32_t int32_t;
00174
00175 union U
00176 {
00177 public:
00178 int32_t i;
00179 void *pv;
00180 };
00181
00182 # if defined(_RECLS_MT)
00183
00184 # if defined(RECLS_COMPILER_IS_INTEL)
00185 # pragma warning(push)
00186 # pragma warning(disable : 171)
00187 # endif
00188
00189 static int32_t tls_get_value_()
00190 {
00191 U u;
00192
00193 u.pv = get_index_().get_value();
00194
00195 return u.i;
00196 }
00197 static void tls_set_value_(int32_t i)
00198 {
00199 U u;
00200
00201 u.i = i;
00202
00203 get_index_().set_value(u.pv);
00204 }
00205
00206 # if defined(RECLS_COMPILER_IS_INTEL)
00207 # pragma warning(pop)
00208 # endif
00209
00210 # endif
00211
00212 static int32_t post_inc_()
00213 {
00214 # if defined(_RECLS_MT)
00215 int32_t i = (int32_t)(tls_get_value_());
00216 int32_t r = i++;
00217
00218 tls_set_value_(i);
00219
00220 return r;
00221 # else
00222 return get_index_()++;
00223 # endif
00224 }
00225 static int32_t pre_dec_()
00226 {
00227 # if defined(_RECLS_MT)
00228 int32_t i = (int32_t)(tls_get_value_());
00229 int32_t r = --i;
00230
00231 tls_set_value_(i);
00232
00233 return r;
00234 # else
00235 return --get_index_();
00236 # endif
00237 }
00238
00239 private:
00240 char m_fn[1024];
00241 # if defined(_RECLS_MT)
00242 static tss_index &get_index_()
00243 {
00244 static tss_index s_index;
00245
00246 return s_index;
00247 }
00248 # else
00249 static int32_t &get_index_()
00250 {
00251 static int32_t s_count;
00252
00253 return s_count;
00254 }
00255 # endif
00256 };
00257
00258 # define function_scope_trace(f) function_scope _scope_ ## __LINE__(f)
00259
00260 #else
00261
00262 # define function_scope_trace(f) do { ; } while(0)
00263
00264 #endif
00265
00266
00267
00268
00269
00270 #if !defined(RECLS_NO_NAMESPACE)
00271 }
00272 #endif
00273
00274
00275
00276 #endif
00277
00278