itassert.cpp
Go to the documentation of this file.
#ifndef _MSC_VER
# include <itpp/config.h>
#else
# include <itpp/config_msvc.h>
#endif
#include <itpp/base/itassert.h>
#include <iostream>
#include <stdexcept>
#include <cstdlib>
namespace itpp
{
static bool warnings_enabled = true;
static bool file_line_info_enabled = true;
static std::ostream *warn = &std::cerr;
void it_assert_f(std::string ass, std::string msg, std::string file, int line)
{
std::ostringstream error;
if (file_line_info_enabled) {
error << "*** Assertion failed in " << file << " on line " << line
<< ":\n" << msg << " (" << ass << ")\n";
}
else {
error << msg << " (" << ass << ")\n";
}
std::cerr << error.str() << std::flush;
#ifdef ITPP_EXCEPTIONS
throw std::runtime_error(error.str());
#else
abort();
#endif
}
void it_error_f(std::string msg, std::string file, int line)
{
std::ostringstream error;
if (file_line_info_enabled) {
error << "*** Error in " << file << " on line " << line << ":\n"
<< msg << "\n";
}
else {
error << msg << "\n";
}
std::cerr << error.str() << std::flush;
#ifdef ITPP_EXCEPTIONS
throw std::runtime_error(error.str());
#else
abort();
#endif
}
void it_info_f(std::string msg)
{
std::cerr << msg << std::flush;
}
void it_warning_f(std::string msg, std::string file, int line)
{
if (warnings_enabled) {
if (file_line_info_enabled) {
(*warn) << "*** Warning in " << file << " on line " << line << ":\n"
<< msg << std::endl << std::flush;
}
else {
(*warn) << msg << std::endl << std::flush;
}
}
}
void it_enable_warnings()
{
warnings_enabled = true;
}
void it_disable_warnings()
{
warnings_enabled = false;
}
void it_redirect_warnings(std::ostream *warn_stream)
{
warn = warn_stream;
}
void it_error_msg_style(error_msg_style style)
{
switch (style) {
case Full:
file_line_info_enabled = true;
break;
case Minimum:
file_line_info_enabled = false;
break;
default:
file_line_info_enabled = true;
}
}
} //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 on for IT++ by Doxygen 1.15.0