IT++
4.3.1
Toggle main menu visibility
itpp
base
itassert.cpp
Go to the documentation of this file.
1
28
29
#ifndef _MSC_VER
30
# include <itpp/config.h>
31
#else
32
# include <itpp/config_msvc.h>
33
#endif
34
35
#include <
itpp/base/itassert.h
>
36
#include <iostream>
37
#include <stdexcept>
38
#include <cstdlib>
39
40
41
namespace
itpp
42
{
43
45
static
bool
warnings_enabled =
true
;
46
static
bool
file_line_info_enabled =
true
;
47
static
std::ostream *warn = &std::cerr;
49
50
void
it_assert_f
(std::string ass, std::string msg, std::string file,
int
line)
51
{
52
std::ostringstream error;
53
if
(file_line_info_enabled) {
54
error <<
"*** Assertion failed in "
<< file <<
" on line "
<< line
55
<<
":\n"
<< msg <<
" ("
<< ass <<
")\n"
;
56
}
57
else
{
58
error << msg <<
" ("
<< ass <<
")\n"
;
59
}
60
std::cerr << error.str() << std::flush;
61
#ifdef ITPP_EXCEPTIONS
62
throw
std::runtime_error(error.str());
63
#else
64
abort();
65
#endif
66
}
67
68
void
it_error_f
(std::string msg, std::string file,
int
line)
69
{
70
std::ostringstream error;
71
if
(file_line_info_enabled) {
72
error <<
"*** Error in "
<< file <<
" on line "
<< line <<
":\n"
73
<< msg <<
"\n"
;
74
}
75
else
{
76
error << msg <<
"\n"
;
77
}
78
std::cerr << error.str() << std::flush;
79
#ifdef ITPP_EXCEPTIONS
80
throw
std::runtime_error(error.str());
81
#else
82
abort();
83
#endif
84
}
85
86
void
it_info_f
(std::string msg)
87
{
88
std::cerr << msg << std::flush;
89
}
90
91
void
it_warning_f
(std::string msg, std::string file,
int
line)
92
{
93
if
(warnings_enabled) {
94
if
(file_line_info_enabled) {
95
(*warn) <<
"*** Warning in "
<< file <<
" on line "
<< line <<
":\n"
96
<< msg << std::endl << std::flush;
97
}
98
else
{
99
(*warn) << msg << std::endl << std::flush;
100
}
101
}
102
}
103
104
void
it_enable_warnings
()
105
{
106
warnings_enabled =
true
;
107
}
108
109
void
it_disable_warnings
()
110
{
111
warnings_enabled =
false
;
112
}
113
114
void
it_redirect_warnings
(std::ostream *warn_stream)
115
{
116
warn = warn_stream;
117
}
118
119
void
it_error_msg_style
(
error_msg_style
style)
120
{
121
switch
(style) {
122
case
Full:
123
file_line_info_enabled =
true
;
124
break
;
125
case
Minimum:
126
file_line_info_enabled =
false
;
127
break
;
128
default
:
129
file_line_info_enabled =
true
;
130
}
131
}
132
133
}
//namespace itpp
itpp::it_disable_warnings
void it_disable_warnings()
Disable warnings.
Definition
itassert.cpp:109
itpp::error_msg_style
error_msg_style
Style of assert, error and warning messages.
Definition
itassert.h:87
itpp::it_enable_warnings
void it_enable_warnings()
Enable warnings.
Definition
itassert.cpp:104
itpp::it_warning_f
void it_warning_f(std::string msg, std::string file, int line)
Helper function for the it_warning macro.
Definition
itassert.cpp:91
itpp::it_error_msg_style
void it_error_msg_style(error_msg_style style)
Set preferred style of assert, error and warning messages.
Definition
itassert.cpp:119
itpp::it_error_f
void it_error_f(std::string msg, std::string file, int line)
Helper function for the it_error and it_error_if macros.
Definition
itassert.cpp:68
itpp::it_redirect_warnings
void it_redirect_warnings(std::ostream *warn_stream)
Redirect warnings to the ostream warn_stream.
Definition
itassert.cpp:114
itpp::it_assert_f
void it_assert_f(std::string ass, std::string msg, std::string file, int line)
Helper function for the it_assert and it_assert_debug macros.
Definition
itassert.cpp:50
itpp::it_info_f
void it_info_f(std::string msg)
Helper function for the it_info and it_info_debug macros.
Definition
itassert.cpp:86
itassert.h
Error handling functions - header file.
itpp
itpp namespace
Definition
itmex.h:37
Generated by
1.17.0