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 
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 
105 {
106  warnings_enabled = true;
107 }
108 
110 {
111  warnings_enabled = false;
112 }
113 
114 void it_redirect_warnings(std::ostream *warn_stream)
115 {
116  warn = warn_stream;
117 }
118 
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
SourceForge Logo

Generated on Sat May 25 2013 16:32:18 for IT++ by Doxygen 1.8.2