itpp_sci  1.0.0
it++ based simulation framework for scicoslab, scilab and scipy
_sci_assert.hpp
1 
29 #ifndef ITPP_SCI_ASSERT_H
30 #define ITPP_SCI_ASSERT_H
31 
32 #define nITPP_EXCEPTIONS
33 #define SCI_EXCEPTIONS
34 
35 #include <sstream>
36 #include <string>
37 
38 #include "sci\_sci_exception.hpp"
39 
40 namespace itpp
41 {
42 
69 
72 void itpp_sci_assert_f(std::string ass, std::string msg, std::string file, int line);
74 void itpp_sci_error_f(std::string msg, std::string file, int line);
76 void itpp_sci_info_f(std::string msg);
78 void itpp_sci_warning_f(std::string msg, std::string file, int line);
79 
81 void itpp_sci_enable_exceptions(bool on);
83 void itpp_sci_enable_warnings();
85 void itpp_sci_disable_warnings();
87 void itpp_sci_redirect_warnings(std::ostream *warn_stream);
88 
90 enum itpp_sci_error_msg_style_t { msg_style_full, msg_style_minimum };
91 
93 void itpp_sci_error_msg_style(itpp_sci_error_msg_style_t style);
94 
95 
97 #define itpp_sci_assert(t,s) \
98  if (!(t)) { \
99  std::ostringstream m_sout; \
100  m_sout << s; \
101  itpp::itpp_sci_assert_f(#t,m_sout.str(),__FILE__,__LINE__); \
102  } else \
103  ((void) 0)
104 
105 #if defined(NDEBUG)
106 # define itpp_sci_assert_debug(t,s) ((void) (t))
108 #else
109 # define itpp_sci_assert_debug(t,s) itpp_sci_assert(t,s)
111 #endif // if defined(NDEBUG)
112 
114 #define itpp_sci_assert0(t,s) itpp_sci_assert_debug(t,s)
115 #define itpp_sci_assert1(t,s) itpp_sci_assert_debug(t,s)
117 
118 
120 #define itpp_sci_error_if(t,s) \
121  if((t)) { \
122  std::ostringstream m_sout; \
123  m_sout << s; \
124  itpp::itpp_sci_error_f(m_sout.str(),__FILE__,__LINE__); \
125  } else \
126  ((void) 0)
127 
129 #define itpp_sci_error(s) \
130  if (true) { \
131  std::ostringstream m_sout; \
132  m_sout << s; \
133  itpp::itpp_sci_error_f(m_sout.str(),__FILE__,__LINE__); \
134  } else \
135  ((void) 0)
136 
137 
139 #define itpp_sci_info(s) \
140  if (true) { \
141  std::ostringstream m_sout; \
142  m_sout << s << std::endl; \
143  itpp::itpp_sci_info_f(m_sout.str()); \
144  } else \
145  ((void) 0)
146 
148 #define itpp_sci_info_no_endl(s) \
149  if (true) { \
150  std::ostringstream m_sout; \
151  m_sout << s; \
152  itpp::itpp_sci_info_f(m_sout.str()); \
153  } else \
154  ((void) 0)
155 
156 #if defined(NDEBUG)
157 # define itpp_sci_info_debug(s) ((void) 0)
159 
163 # define itpp_sci_info_no_endl_debug(s) ((void) 0)
164 #else
165 # define itpp_sci_info_debug(s) itpp_sci_info(s)
167 
171 # define itpp_sci_info_no_endl_debug(s) itpp_sci_info_no_endl(s)
172 #endif // if defined(NDEBUG)
173 
174 
176 #define itpp_sci_warning(s) \
177  if (true) { \
178  std::ostringstream m_sout; \
179  m_sout << s; \
180  itpp::itpp_sci_warning_f(m_sout.str(),__FILE__,__LINE__); \
181  } else \
182  ((void) 0)
183 
184 class itpp_sci_assert_exception : public std::exception
185 {
186  int info_;
187  std::string msg_;
188 
189 public:
190 
191  int get_info() const
192  {
193  return info_;
194  };
195  std::string get_msg()
196  {
197  return msg_;
198  };
199 
200  itpp_sci_assert_exception(std::string msg, int info) : msg_(msg), info_(info)
201  {
202 
203  };
204 
205  itpp_sci_assert_exception(std::string msg) : msg_(msg)
206  {
207  info_ = 0;
208  };
209 
210  itpp_sci_assert_exception()
211  {
212  msg_ = "Unknown Error";
213  info_ = -1;
214  };
215 
216 };
217 
218 
219 
221 
222 } // namespace itpp
223 
224 #endif // #ifndef ITASSERT_H
Definition: _sci_assert.cpp:35