8#include "ioss_export.h"
16#pragma warning(disable : 4786)
20#pragma warning(disable : 4355)
69 void set_expr(
const string &str) { expr_ = str; }
70 const string &
get_expr()
const {
return expr_; }
78 void add_val(
const string &val,
const string &str) { vals_.emplace_back(val, str); }
87 if (strMsg !=
nullptr) {
110 namespace SmartAssert {
138 bool is(
const T & )
const {
return false; }
143 bool is(
char *
const &val) {
return val ==
nullptr; }
148 bool is(
const char *
const &val) {
return val ==
nullptr; }
163 context_.set_expr(expr);
165 if ((logger() ==
nullptr) || handlers().size() < 4) {
179 if (needs_handling_) {
186 std::ostringstream out;
189 bool bIsNull = f.
is(val);
197 context_.add_val(out.str(), my_msg);
203 context_.set_file_line(file, line);
209 context_.set_level_msg(strMsg);
215 context_.set_level(nLevel);
216 context_.set_level_msg(strMsg);
233 logger() = &SmartAssert::default_logger;
241 logger() = &SmartAssert::default_logger;
253 get_handler(context_.get_level())(context_);
283 const auto found = handlers().find(nLevel);
284 if (found != handlers().end()) {
285 return (*found).second;
289 return (*handlers().find(
lvl_debug)).second;
293 mutable bool needs_handling_{
true};
296 namespace SmartAssert {
308#ifdef SMART_ASSERT_DEBUG_MODE
309#if SMART_ASSERT_DEBUG_MODE == 1
310#define SMART_ASSERT_DEBUG
312#undef SMART_ASSERT_DEBUG
319#define SMART_ASSERT_DEBUG
321#undef SMART_ASSERT_DEBUG
325#ifdef SMART_ASSERT_DEBUG
327#define SMART_ASSERT(expr) \
331 (void)::Ioss::SmartAssert::make_assert(#expr) \
332 .print_context(__FILE__, __LINE__) \
337#define SMART_ASSERT(expr) \
341 (void)::Ioss::SmartAssert::make_assert("").SMART_ASSERT_A
345#define SMART_VERIFY(expr) \
349 (void)::Ioss::SmartAssert::make_assert(#expr) \
351 .print_context(__FILE__, __LINE__) \
354#define SMART_ASSERT_A(x) SMART_ASSERT_OP(x, B)
355#define SMART_ASSERT_B(x) SMART_ASSERT_OP(x, A)
357#define SMART_ASSERT_OP(x, next) SMART_ASSERT_A.print_current_val((x), #x).SMART_ASSERT_##next
#define SMART_ASSERT_A(x)
Definition Ioss_SmartAssert.h:354
#define SMART_ASSERT_B(x)
Definition Ioss_SmartAssert.h:355
Definition Ioss_SmartAssert.h:53
const string & get_level_msg() const
Definition Ioss_SmartAssert.h:94
int get_context_line() const
Definition Ioss_SmartAssert.h:66
const vals_array & get_vals_array() const
Definition Ioss_SmartAssert.h:76
const string & get_expr() const
Definition Ioss_SmartAssert.h:70
int get_level() const
Definition Ioss_SmartAssert.h:82
std::string string
Definition Ioss_SmartAssert.h:54
std::vector< val_and_str > vals_array
Definition Ioss_SmartAssert.h:73
void set_level(int nLevel)
Definition Ioss_SmartAssert.h:81
std::pair< string, string > val_and_str
Definition Ioss_SmartAssert.h:72
void set_level_msg(const char *strMsg)
Definition Ioss_SmartAssert.h:85
void set_expr(const string &str)
Definition Ioss_SmartAssert.h:69
const string & get_context_file() const
Definition Ioss_SmartAssert.h:65
void set_file_line(const char *file, int line)
Definition Ioss_SmartAssert.h:60
void add_val(const string &val, const string &str)
Definition Ioss_SmartAssert.h:78
void init_assert()
Definition Ioss_SmartAssert.C:190
void set_default_log_name(const char *str)
Definition Ioss_SmartAssert.C:207
void set_default_log_stream(std::ostream &out)
Definition Ioss_SmartAssert.C:200
void dump_context_summary(const assert_context &context, std::ostream &out)
Definition Ioss_SmartAssert.C:52
void default_warn_handler(const assert_context &context)
Definition Ioss_SmartAssert.C:113
void default_fatal_handler(const assert_context &context)
Definition Ioss_SmartAssert.C:180
void default_debug_handler(const assert_context &context)
Definition Ioss_SmartAssert.C:119
void(*)(const assert_context &) assert_func
Definition Ioss_SmartAssert.h:112
void default_error_handler(const assert_context &context)
Definition Ioss_SmartAssert.C:172
Assert make_assert(const char *expr)
Definition Ioss_SmartAssert.h:297
void default_logger(const assert_context &context)
Definition Ioss_SmartAssert.C:101
void dump_context_detail(const assert_context &context, std::ostream &out)
Definition Ioss_SmartAssert.C:67
std::string get_typeof_level(int nLevel)
Definition Ioss_SmartAssert.C:36
The main namespace for the Ioss library.
Definition Ioad_DatabaseIO.C:40
@ lvl_debug
Definition Ioss_SmartAssert.h:39
@ lvl_warn
Definition Ioss_SmartAssert.h:35
@ lvl_error
Definition Ioss_SmartAssert.h:42
@ lvl_fatal
Definition Ioss_SmartAssert.h:46
Definition Ioss_SmartAssert.h:154
std::map< int, assert_func > handlers_collection
Definition Ioss_SmartAssert.h:274
Assert & level(int nLevel, const char *strMsg=nullptr)
Definition Ioss_SmartAssert.h:213
static void set_log(const char *strFileName)
Definition Ioss_SmartAssert.h:230
Assert & SMART_ASSERT_A
Definition Ioss_SmartAssert.h:158
Assert & warn(const char *strMsg=nullptr)
Definition Ioss_SmartAssert.h:220
static assert_func & logger()
Definition Ioss_SmartAssert.h:267
Assert & debug(const char *strMsg=nullptr)
Definition Ioss_SmartAssert.h:222
bool needs_handling_
Definition Ioss_SmartAssert.h:293
static void set_log(assert_func log)
Definition Ioss_SmartAssert.h:244
Assert & print_current_val(const type &val, const char *my_msg)
Definition Ioss_SmartAssert.h:184
Assert(const char *expr)
Definition Ioss_SmartAssert.h:161
Assert & SMART_ASSERT_B
Definition Ioss_SmartAssert.h:159
static assert_func get_handler(int nLevel)
Definition Ioss_SmartAssert.h:281
static void set_handler(int nLevel, assert_func handler)
Definition Ioss_SmartAssert.h:246
Assert & error(const char *strMsg=nullptr)
Definition Ioss_SmartAssert.h:224
Assert & fatal(const char *strMsg=nullptr)
Definition Ioss_SmartAssert.h:226
SmartAssert::assert_func assert_func
Definition Ioss_SmartAssert.h:155
Assert & print_context(const char *file, int line)
Definition Ioss_SmartAssert.h:201
static void set_log(std::ostream &out)
Definition Ioss_SmartAssert.h:238
static handlers_collection & handlers()
Definition Ioss_SmartAssert.h:275
void handle_assert()
Definition Ioss_SmartAssert.h:250
Assert(const Assert &other)
Definition Ioss_SmartAssert.h:171
Assert & msg(const char *strMsg)
Definition Ioss_SmartAssert.h:207
~Assert()
Definition Ioss_SmartAssert.h:177
assert_context context_
Definition Ioss_SmartAssert.h:292
bool is(char *const &val)
Definition Ioss_SmartAssert.h:143
bool is(const char *const &val)
Definition Ioss_SmartAssert.h:148
Definition Ioss_SmartAssert.h:137
bool is(const T &) const
Definition Ioss_SmartAssert.h:138