rsvs3D  0.0.0
Codes for the c++ implementation of the 3D RSVS
warning.hpp
Go to the documentation of this file.
1 
6 #ifndef WARNING_H_INCLUDED
7 #define WARNING_H_INCLUDED
8 
9 //===============================================
10 // Levels of debuging Guards
11 #ifdef DEBUGLVL2 // All Debugging calls
12 #define DEBUGLVL1
13 
14 #endif
15 
16 #ifdef DEBUGLVL1 // Debugging of new features.
17 #define TEST_WARNING
18 #endif
19 
20 //=================================
21 // forward declared dependencies
22 // class foo; //when you only need a pointer not the actual object
23 // and to avoid circular dependencies
24 
25 //=================================
26 // included dependencies
27 #include <stdarg.h>
28 
29 #include <fstream>
30 #include <iostream>
31 #include <stdexcept>
32 
33 //==================================
34 // Code
35 // NOTE: function in a class definition are IMPLICITELY INLINED
36 // ie replaced by their code at compile time
37 
41 namespace rsvs3d
42 {
43 
47 class rsvs_exception : public std::logic_error
48 {
49  using std::logic_error::logic_error;
50 };
51 
75 template <class E = rsvs_exception>
76 void error(const char *message = "", const char *caller = "", const char *file = "", int line = 0,
77  bool throwError = true);
87 template <typename T> int sign(T val);
88 int TimeStamp(const char *str, int start_s);
103 double SignedLogScale(double in);
104 double Clock2ms(int clockCycles);
105 } // namespace rsvs3d
113 #define RSVS3D_ERROR(M) (rsvs3d::error(M, __PRETTY_FUNCTION__, __FILE__, __LINE__, true))
114 
120 #define RSVS3D_ERROR_NOTHROW(M) (rsvs3d::error(M, __PRETTY_FUNCTION__, __FILE__, __LINE__, false))
121 
130 #define RSVS3D_ERROR_TYPE(M, T) (rsvs3d::error<T>(M, __PRETTY_FUNCTION__, __FILE__, __LINE__, true))
131 
139 #define RSVS3D_ERROR_LOGIC(M) (rsvs3d::error<std::logic_error>(M, __PRETTY_FUNCTION__, __FILE__, __LINE__, true))
140 
148 #define RSVS3D_ERROR_ARGUMENT(M) \
149  (rsvs3d::error<std::invalid_argument>(M, __PRETTY_FUNCTION__, __FILE__, __LINE__, true))
150 
151 #ifndef RSVS_NO_ARGCHECK
152 #define RSVS3D_ARGCHECK(E, M) \
153  if (!(E)) \
154  { \
155  RSVS3D_ERROR_ARGUMENT(M); \
156  }
157 #define RSVS3D_ARGCHECK_WARN(E, M) \
158  if (!(E)) \
159  { \
160  RSVS3D_ERROR_NOTHROW(M); \
161  }
162 #else
163 #define RSVS3D_ARGCHECK(E, M)
164 #define RSVS3D_ARGCHECK_WARN(E, M)
165 #endif
173 #define RSVS3D_ERROR_RANGE(M) (rsvs3d::error<std::range_error>(M, __PRETTY_FUNCTION__, __FILE__, __LINE__, true))
174 
175 void ThrowWarning(const char *message);
187 template <class T> void CheckFStream(const T &file, const char *callerID, const std::string &fileName)
188 {
189  if (!file.is_open())
190  {
191  std::string errstr;
192  errstr = "Parameter file failed to open ";
193  errstr += "in ";
194  errstr += callerID;
195  errstr += " \n: " + fileName;
196  RSVS3D_ERROR_ARGUMENT(errstr.c_str());
197  }
198 }
199 
200 namespace rsvs3d
201 {
202 
203 template <class E> void error(const char *message, const char *caller, const char *file, int line, bool throwError)
204 {
205  std::cerr << std::endl << "Error at: " << file << ":" << line << std::endl << " " << caller << std::endl;
206  if (throwError)
207  {
208  throw E(message);
209  }
210  else
211  {
212  std::cerr << "Exception (not thrown)" << message << std::endl;
213  }
214 }
215 template <typename T> int sign(T val)
216 {
217  return (T(0) < val) - (val < T(0));
218 }
219 
220 } // namespace rsvs3d
221 #endif // WARNING_H_INCLUDED
Exception for signaling rsvs errors.
Definition: warning.hpp:48
Namespace for general purpose tools of the RSVS project.
Definition: snake.cpp:1464
int sign(T val)
Returns the sign of a type comparable to 0.
Definition: warning.hpp:215
double SignedLogScale(double in)
Returns a signed logscale useful for plotting data.
Definition: warning.cpp:40
void error(const char *message="", const char *caller="", const char *file="", int line=0, bool throwError=true)
Custom error function.
Definition: warning.hpp:203
void CheckFStream(const T &file, const char *callerID, const std::string &fileName)
Checks a file stream.
Definition: warning.hpp:187
#define RSVS3D_ERROR_ARGUMENT(M)
Throw a invalid_argument.
Definition: warning.hpp:148