Flow123d
JS_before_hm-978-gf0793cd
|
Class defining debugging messages. More...
#include <asserts.hh>
Public Member Functions | |
Assert (const std::string &expression) | |
Constructor. More... | |
Assert (const Assert &other) | |
Copy constructor. More... | |
~Assert () | |
Destructor. More... | |
template<typename T > | |
Assert & | add_value (T var_current_val, const char *var_name) |
Adds name and value of variable. More... | |
Assert & | set_context (const char *file_name, const char *function, const int line) |
Stores values for printing out line number, function, etc. More... | |
void | error (std::string error_msg="") |
Generate error with given message. More... | |
void | warning (std::string warning_msg="") |
Generate warning with given message. More... | |
Public Attributes | |
Assert & | _FEAL_ASSERT_A |
clever macro A More... | |
Assert & | _FEAL_ASSERT_B |
clever macro B More... | |
Protected Attributes | |
Exc_assert | exception_ |
Exception object. More... | |
bool | thrown_ |
Flag marked if Assert thrown error, warning, ... More... | |
Class defining debugging messages.
Allows define assert, warning etc. either only for debug mode or for release mode also.
Definition of asserts is designed using macros FEAL_ASSERT and FEAL_ASSERT_DBG. First macro is used for both modes, second is only for debug. Definition allows to printout given variables too. For simplifying are designed shorter names of macros ASSERT and ASSERT_DBG, these names can be used if thea aren't in conflicts with external libraries.
Examples of usage:
1) We expect empty stings 's1' and 's2', if condition is not satisfied exception will be thrown. Condition is indicated in first parentheses, variables designed for printout follow as (s1)(s2). Each variable must be defined in separate parentheses. The last step is calling of the appropriate assert type, in this case error(). This assert is performed for debug and release mode.
2) Parameter of error method is optional.
3) This example is same as previous, but assert is performed only for debug mode.
4) Example is same as case 1). Assert type error is called automatically if any other is not listed. This case is not recommended, rather use explicitly calling of error() method.
5) Example with same condition as all previous but with other type - warning. Any exception is not thrown, only warning is printed. Parameter of warning method is optional.
For simplifying we have defined several macros for comparsion of values:
All macros allow easier declaration of assert. Following example shows declarations of same cases with usage of different macros:
Definition at line 121 of file asserts.hh.
|
inline |
Constructor.
Definition at line 124 of file asserts.hh.
|
inline |
Copy constructor.
Definition at line 134 of file asserts.hh.
feal::Assert::~Assert | ( | ) |
Destructor.
Definition at line 69 of file asserts.cc.
|
inline |
Adds name and value of variable.
Definition at line 148 of file asserts.hh.
void feal::Assert::error | ( | std::string | error_msg = "" | ) |
Generate error with given message.
Definition at line 88 of file asserts.cc.
Assert & feal::Assert::set_context | ( | const char * | file_name, |
const char * | function, | ||
const int | line | ||
) |
Stores values for printing out line number, function, etc.
Definition at line 78 of file asserts.cc.
void feal::Assert::warning | ( | std::string | warning_msg = "" | ) |
Generate warning with given message.
Definition at line 96 of file asserts.cc.
Assert& feal::Assert::_FEAL_ASSERT_A |
clever macro A
Definition at line 143 of file asserts.hh.
Assert& feal::Assert::_FEAL_ASSERT_B |
clever macro B
Definition at line 144 of file asserts.hh.
|
protected |
Exception object.
Definition at line 167 of file asserts.hh.
|
protected |
Flag marked if Assert thrown error, warning, ...
Definition at line 168 of file asserts.hh.