IT++ Logo
itassert.cpp
Go to the documentation of this file.
1
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
41namespace itpp
42{
43
45static bool warnings_enabled = true;
46static bool file_line_info_enabled = true;
47static std::ostream *warn = &std::cerr;
49
50void it_assert_f(std::string ass, std::string msg, std::string file, int line)
51{
52 std::ostringstream error;
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
68void it_error_f(std::string msg, std::string file, int line)
69{
70 std::ostringstream error;
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
86void it_info_f(std::string msg)
87{
88 std::cerr << msg << std::flush;
89}
90
91void it_warning_f(std::string msg, std::string file, int line)
92{
93 if (warnings_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
105{
106 warnings_enabled = true;
107}
108
110{
111 warnings_enabled = false;
112}
113
115{
117}
118
120{
121 switch (style) {
122 case Full:
124 break;
125 case Minimum:
127 break;
128 default:
130 }
131}
132
133} //namespace itpp
General array class.
Definition array.h:105
void it_disable_warnings()
Disable warnings.
Definition itassert.cpp:109
error_msg_style
Style of assert, error and warning messages.
Definition itassert.h:87
void it_enable_warnings()
Enable warnings.
Definition itassert.cpp:104
void it_warning_f(std::string msg, std::string file, int line)
Helper function for the it_warning macro.
Definition itassert.cpp:91
void it_error_msg_style(error_msg_style style)
Set preferred style of assert, error and warning messages.
Definition itassert.cpp:119
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
void it_redirect_warnings(std::ostream *warn_stream)
Redirect warnings to the ostream warn_stream.
Definition itassert.cpp:114
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
void it_info_f(std::string msg)
Helper function for the it_info and it_info_debug macros.
Definition itassert.cpp:86
Error handling functions - header file.
itpp namespace
Definition itmex.h:37

Generated on Tue Aug 17 2021 10:59:15 for IT++ by Doxygen 1.9.8