]> Dogcows Code - chaz/yoink/blob - src/Moof/Error.hh
494dd60f8cf925c65f38ed8762e1218d31632980
[chaz/yoink] / src / Moof / Error.hh
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #ifndef _MOOF_ERROR_HH_
13 #define _MOOF_ERROR_HH_
14
15 #include <cstring> // strncpy
16 #include <exception>
17 #include <string>
18
19
20 namespace Mf {
21
22
23 class Error : public std::exception
24 {
25 public:
26
27 enum Code
28 {
29 UNINITIALIZED = -1, // -
30 NONE = 0, // -
31 ALC_INIT, // description
32 FASTEVENTS_INIT, // description
33 FILE_NOT_FOUND, // path of missing file
34 OPENAL_INIT, // description
35 RESOURCE_NOT_FOUND, // name of missing resource
36 SCRIPT_ERROR, // description
37 SDL_INIT, // description
38 SDL_VIDEOMODE, // -
39 UNKNOWN_AUDIO_FORMAT, // name of resource
40 UNKNOWN_IMAGE_FORMAT, // name of resource
41 };
42
43 explicit Error(unsigned code = NONE, const std::string& what = "")
44 {
45 init(code, what);
46 }
47 virtual ~Error() throw() {}
48
49 void init(unsigned code = NONE, const std::string& what = "")
50 {
51 strncpy(mWhat, what.c_str(), sizeof(mWhat)-1);
52 mWhat[sizeof(mWhat)-1] = '\0';
53 mCode = code;
54 }
55
56 virtual void raise() const
57 {
58 throw *this;
59 }
60
61 unsigned code() const throw()
62 {
63 return mCode;
64 }
65
66 const char* what() const throw()
67 {
68 return mWhat;
69 }
70
71 operator bool () const
72 {
73 // resolves to true if error code is not NONE
74 return mCode != NONE;
75 }
76
77 void reset() throw()
78 {
79 mCode = NONE;
80 mWhat[0] = '\0';
81 }
82
83 private:
84
85 unsigned mCode;
86 char mWhat[1024];
87 };
88
89
90 } // namespace Mf
91
92 #endif // _MOOF_ERROR_HH_
93
This page took 0.036766 seconds and 3 git commands to generate.