ldpk
ldpk_error.h
Go to the documentation of this file.
1 #ifndef ldpk_error_sdv
2 #define ldpk_error_sdv
3 
4 #include <exception>
5 #include <iostream>
6 #include <string.h>
7 #include <string>
8 #ifdef _WINDOWS
9 // Windows macros interfere with std library.
10 #define NOMINMAX
11 #include <windows.h>
12 #else
13 #include <pthread.h>
14 #endif
15 
18 
19 namespace ldpk
20  {
22  class error_base:public std::exception
23  {
24  public:
25  virtual const char* what() const throw() = 0;
26  virtual std::ostream& out(std::ostream& cout) const
27  { return cout; }
28  };
31  {
32  private:
33  int _i,_a,_b;
34  public:
35  error_index_out_of_range(int i,int a,int b):_i(i),_a(a),_b(b)
36  { }
37  ~error_index_out_of_range() throw()
38  { }
39  const char* what() const throw()
40  { return "ldpk::error: index out of range"; }
41  std::ostream& out(std::ostream& cout) const
42  { return cout << _i << ", range [" << _a << "," << _b << "]"; }
43  };
46  {
47  private:
48  public:
49  ~error_end_of_stream() throw()
50  { }
51  const char* what() const throw()
52  { return "ldpk::error: end of stream"; }
53  };
56  {
57  private:
58 // There's a general warning not to use strings in exceptions, which I ignore.
59 // The gain of clarity in error messages dominates the low risk of irregular termination.
60  std::string _obj;
61  public:
62  error_undefined_parameter(const std::string& obj):_obj(obj)
63  { }
64  ~error_undefined_parameter() throw()
65  { }
66  const char* what() const throw()
67  { return "ldpk::error: undefined parameter"; }
68  std::ostream& out(std::ostream& cout) const
69  { return cout << _obj; }
70  };
73  {
74  private:
75  std::string _parname;
76  public:
77  error_could_not_read_value(const std::string& parname):_parname(parname)
78  { }
80  { }
81  const char* what() const throw()
82  { return "ldpk::error: could not read value"; }
83  std::ostream& out(std::ostream& cout) const
84  { return cout << "for parameter '" << _parname << "'"; }
85  };
88  {
89  private:
90  public:
92  { }
93  const char* what() const throw()
94  { return "ldpk::error: could not read parameter name"; }
95  };
98  {
99  private:
100  public:
101  ~error_no_model_specified() throw()
102  { }
103  const char* what() const throw()
104  { return "ldpk::error: no model specified"; }
105  };
108  {
109  private:
110  char _dlmsg[256];
111  public:
112 // Windows complains about strncpy, using _CRT_SECURE_NO_WARNINGS
113  error_dynamic_link(const char* dlmsg)
114  { strncpy(_dlmsg,dlmsg,256); }
115  ~error_dynamic_link() throw()
116  { }
117  const char* what() const throw()
118  { return "ldpk::error: dynamic load/link"; }
119  };
120  }
121 
122 #endif
Some index was out of range.
Definition: ldpk_error.h:30
The namespace of (most of the) things related to the Lens Distortion Plugin Kit.
Definition: ldpk.h:19
Another parse error.
Definition: ldpk_error.h:87
Unexpected end of stream. This can occur in ldpk::model_parser.
Definition: ldpk_error.h:45
No model was set in one of the utility classes.
Definition: ldpk_error.h:97
Base class for errors.
Definition: ldpk_error.h:22
A parse error.
Definition: ldpk_error.h:72
Undefined parameter.
Definition: ldpk_error.h:55