Flow123d  release_1.8.2-1603-g0109a2b
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_DEBUG_ASSERT. First macro is used for both modes, second is only for debug. Definition allows to printout given variables too.

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(s1.empty() && s2.empty())(s1)(s2).error("Both strings must be empty!");

2) Parameter of error method is optional.

FEAL_ASSERT(s1.empty() && s2.empty())(s1)(s2).error();

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

FEAL_DEBUG_ASSERT(s1.empty() && s2.empty())(s1)(s2).error("Both strings must be empty!");

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(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(s1.empty() && s2.empty())(s1)(s2).warning("Both strings should be empty!");

Definition at line 102 of file asserts.hh.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 105 of file asserts.hh.

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

Copy constructor.

Definition at line 115 of file asserts.hh.

feal::Assert::~Assert ( )

Destructor.

Definition at line 54 of file asserts.cc.

Member Function Documentation

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 129 of file asserts.hh.

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

Generate error with given message.

Definition at line 73 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 63 of file asserts.cc.

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

Generate warning with given message.

Definition at line 81 of file asserts.cc.

Member Data Documentation

Assert& feal::Assert::_FEAL_ASSERT_A

clever macro A

Definition at line 124 of file asserts.hh.

Assert& feal::Assert::_FEAL_ASSERT_B

clever macro B

Definition at line 125 of file asserts.hh.

Exc_assert feal::Assert::exception_
protected

Exception object.

Definition at line 148 of file asserts.hh.

bool feal::Assert::thrown_
protected

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

Definition at line 149 of file asserts.hh.


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