Flow123d  DF_patch_fe_data_tables-18aea81
Public Member Functions | Public Attributes | Protected Attributes | List of all members
feal::Assert Class Reference

Class defining debugging messages. More...

#include <asserts.hh>

Collaboration diagram for feal::Assert:
Collaboration graph
[legend]

Public Member Functions

 Assert (const std::string &expression)
 Constructor. More...
 
 Assert (const Assert &other)
 Copy constructor. More...
 
 ~Assert ()
 Destructor. More...
 
template<typename T >
Assertadd_value (T var_current_val, const char *var_name)
 Adds name and value of variable. More...
 
Assertset_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...
 

Detailed Description

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_PERMANENT. 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_PERMANENT, 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.

std::string s1, s2;
...
FEAL_ASSERT_PERMANENT(s1.empty() && s2.empty())(s1)(s2).error("Both strings must be empty!");

2) Parameter of error method is optional.

FEAL_ASSERT_PERMANENT(s1.empty() && s2.empty())(s1)(s2).error();
#define FEAL_ASSERT_PERMANENT(expr)
Definition of assert for debug and release mode.
Definition: asserts.hh:281

3) This example is same as previous, but assert is performed only for debug mode.

FEAL_ASSERT(s1.empty() && s2.empty())(s1)(s2).error("Both strings must be empty!");
#define FEAL_ASSERT(expr)
Definition of assert for debug mode only.
Definition: asserts.hh:291

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.

FEAL_ASSERT_PERMANENT(s1.empty() && s2.empty())(s1)(s2);

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.

FEAL_ASSERT_PERMANENT(s1.empty() && s2.empty())(s1)(s2).warning("Both strings should be empty!");

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:

ASSERT_PERMANENT_LT( idx, arr.size() ).error("Index out of array!");
FEAL_ASSERT_PERMANENT( idx < arr.size() )(idx)(arr.size()).error("Index out of array!");
#define ASSERT_PERMANENT_LT(a, b)
Definition of comparative assert macro (Less Than)
Definition: asserts.hh:297
void error(std::string error_msg="")
Generate error with given message.
Definition: asserts.cc:88

Definition at line 122 of file asserts.hh.

Constructor & Destructor Documentation

◆ Assert() [1/2]

feal::Assert::Assert ( const std::string &  expression)
inline

Constructor.

Definition at line 125 of file asserts.hh.

◆ Assert() [2/2]

feal::Assert::Assert ( const Assert other)
inline

Copy constructor.

Definition at line 135 of file asserts.hh.

◆ ~Assert()

feal::Assert::~Assert ( )

Destructor.

Definition at line 69 of file asserts.cc.

Member Function Documentation

◆ add_value()

template<typename T >
Assert& feal::Assert::add_value ( var_current_val,
const char *  var_name 
)
inline

Adds name and value of variable.

Definition at line 149 of file asserts.hh.

◆ error()

void feal::Assert::error ( std::string  error_msg = "")

Generate error with given message.

Definition at line 88 of file asserts.cc.

◆ set_context()

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.

◆ warning()

void feal::Assert::warning ( std::string  warning_msg = "")

Generate warning with given message.

Definition at line 96 of file asserts.cc.

Member Data Documentation

◆ _FEAL_ASSERT_A

Assert& feal::Assert::_FEAL_ASSERT_A

clever macro A

Definition at line 144 of file asserts.hh.

◆ _FEAL_ASSERT_B

Assert& feal::Assert::_FEAL_ASSERT_B

clever macro B

Definition at line 145 of file asserts.hh.

◆ exception_

Exc_assert feal::Assert::exception_
protected

Exception object.

Definition at line 168 of file asserts.hh.

◆ thrown_

bool feal::Assert::thrown_
protected

Flag marked if Assert thrown error, warning, ...

Definition at line 169 of file asserts.hh.


The documentation for this class was generated from the following files: