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
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_ENFORCER_H
00053 #define LASS_GUARDIAN_OF_INCLUSION_UTIL_ENFORCER_H
00054
00055 #include "util_common.h"
00056 #include "impl/lass_errno.h"
00057
00058 namespace lass
00059 {
00060 namespace util
00061 {
00062
00063
00064
00065
00066 class EnforceFailure: public Exception
00067 {
00068 public:
00069 EnforceFailure(const std::string& msg, const std::string& loc): Exception(msg, loc) {}
00070 private:
00071 LASS_UTIL_EXCEPTION_PRIVATE_IMPL(EnforceFailure)
00072 };
00073
00074 }
00075 }
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 #define LASS_ENFORCE(expression)\
00087 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00088 ::lass::util::impl::TruePredicate,\
00089 ::lass::util::impl::DefaultRaiser,\
00090 (expression), \
00091 int(0), \
00092 "Expression '" LASS_STRINGIFY(expression) "' failed in '" LASS_HERE "'.")
00093
00094
00095
00096
00097
00098
00099 #define LASS_ENFORCE_POINTER(pointer) \
00100 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00101 ::lass::util::impl::TruePredicate,\
00102 ::lass::util::impl::DefaultRaiser,\
00103 (pointer), \
00104 int(0), \
00105 "Null pointer '" LASS_STRINGIFY(pointer) "' detected in '" LASS_HERE "'.")
00106
00107
00108
00109
00110
00111
00112 #define LASS_ENFORCE_STREAM(stream)\
00113 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00114 ::lass::util::impl::StreamPredicate,\
00115 ::lass::util::impl::DefaultRaiser,\
00116 (stream),\
00117 int(0), \
00118 "Failing stream '" LASS_STRINGIFY(stream) "' detected in '" LASS_HERE "'.")
00119
00120
00121
00122
00123
00124
00125 #define LASS_ENFORCE_ZERO(expression) \
00126 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00127 ::lass::util::impl::EqualPredicate,\
00128 ::lass::util::impl::ZeroRaiser>(\
00129 (expression), \
00130 int(0), \
00131 "'" LASS_STRINGIFY(expression) "' in '" LASS_HERE "'.")
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 #define LASS_ENFORCE_CLIB(functionCall)\
00143 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00144 ::lass::util::impl::UnequalPredicate,\
00145 ::lass::util::impl::ClibRaiser,\
00146 (functionCall), \
00147 int(-1), \
00148 "'" LASS_STRINGIFY(functionCall) "' in '" LASS_HERE "'")
00149
00150 #define LASS_ENFORCE_CLIB_EX(functionCall, errorValue)\
00151 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00152 ::lass::util::impl::UnequalPredicate,\
00153 ::lass::util::impl::ClibRaiser,\
00154 (functionCall), \
00155 (errorValue), \
00156 "'" LASS_STRINGIFY(functionCall) "' in '" LASS_HERE "'")
00157
00158 #define LASS_WARN_CLIB(functionCall)\
00159 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00160 ::lass::util::impl::UnequalPredicate,\
00161 ::lass::util::impl::ClibWarner,\
00162 (functionCall), \
00163 int(-1), \
00164 "'" LASS_STRINGIFY(functionCall) "' in '" LASS_HERE "'")
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 #define LASS_ENFORCE_CLIB_RC(errorCode)\
00176 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00177 ::lass::util::impl::EqualPredicate,\
00178 ::lass::util::impl::ClibRcRaiser,\
00179 (errorCode), \
00180 int(0), \
00181 "'" LASS_STRINGIFY(errorCode) "' in '" LASS_HERE "'")
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 #define LASS_WARN_CLIB_RC(errorCode)\
00193 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00194 ::lass::util::impl::EqualPredicate,\
00195 ::lass::util::impl::ClibRcWarner,\
00196 (errorCode), \
00197 int(0), \
00198 "'" LASS_STRINGIFY(errorCode) "' in '" LASS_HERE "'")
00199
00200
00201
00202
00203
00204
00205 #define LASS_ENFORCE_COM(comResult) \
00206 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00207 ::lass::util::impl::GreaterEqualPredicate,\
00208 ::lass::util::impl::ComRaiser,\
00209 (comResult), \
00210 int(0), \
00211 "'" LASS_STRINGIFY(comResult) "' in '" LASS_HERE "'.")
00212
00213
00214
00215 #ifdef LASS_HAS_GETLASTERROR
00216
00217
00218
00219
00220 #define LASS_ENFORCE_WINAPI(functionCall)\
00221 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00222 ::lass::util::impl::WinAPIPredicate,\
00223 ::lass::util::impl::LastErrorRaiser,\
00224 (functionCall), \
00225 int(0), \
00226 "'" LASS_STRINGIFY(functionCall) "' in '" LASS_HERE "'")
00227
00228 #define LASS_WARN_WINAPI(functionCall)\
00229 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00230 ::lass::util::impl::WinAPIPredicate,\
00231 ::lass::util::impl::LastErrorWarner,\
00232 (functionCall), \
00233 int(0), \
00234 "'" LASS_STRINGIFY(functionCall) "' in '" LASS_HERE "'")
00235
00236
00237
00238
00239
00240 #define LASS_ENFORCE_HANDLE(handle) \
00241 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00242 ::lass::util::impl::UnequalPredicate,\
00243 ::lass::util::impl::LastErrorRaiser,\
00244 (handle),\
00245 INVALID_HANDLE_VALUE, \
00246 "Invalid handle '" LASS_STRINGIFY(handle) "' in '" LASS_HERE "'.")
00247
00248 #endif
00249
00250
00251
00252
00253
00254
00255 #define LASS_ENFORCE_INDEX(index, size)\
00256 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00257 ::lass::util::impl::IndexPredicate,\
00258 ::lass::util::impl::IndexRaiser,\
00259 (index), (size), LASS_HERE)
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 #define LASS_ENFORCE_DYNAMIC_CAST(t_DestPointer, v_pointer)\
00272 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00273 ::lass::util::impl::TruePredicate,\
00274 ::lass::util::impl::DefaultRaiser,\
00275 (dynamic_cast<t_DestPointer>(v_pointer)),\
00276 int(0), \
00277 "Unable to cast to '" LASS_STRINGIFY(t_DestPointer) "': '" LASS_STRINGIFY(v_pointer)\
00278 "' is a null pointer or is not of the correct type, '" LASS_HERE "'.")
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 #define LASS_ENFORCE_DYNAMIC_PY_CAST(t_DestPyObjectPtr, v_pyObjectPtr)\
00292 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00293 ::lass::util::impl::TruePredicate,\
00294 ::lass::util::impl::DefaultRaiser,\
00295 ::lass::python::dynamicPyCast<t_DestPyObjectPtr>(v_pyObjectPtr),\
00296 int(0), \
00297 "Unable to cast to '" LASS_STRINGIFY(t_DestPyObjectPtr) "': '" LASS_STRINGIFY(v_pyObjectPtr)\
00298 "' is a null pointer or is not of the correct type, '" LASS_HERE "'.")
00299
00300
00301
00302
00303
00304 #define LASS_ENFORCE_UNREACHABLE\
00305 *LASS_UTIL_IMPL_MAKE_ENFORCER(\
00306 ::lass::util::impl::TruePredicate,\
00307 ::lass::util::impl::DefaultRaiser,\
00308 (false),\
00309 int(0), \
00310 "You have reached unreachable code in '" LASS_HERE "'.")
00311
00312 #include "impl/enforcer_impl.h"
00313 #include <string>
00314 #include <sstream>
00315
00316 #endif