tbx  0.7.6
resexcept.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 /*
25  * resexcept.h
26  *
27  * Created on: 5 Oct 2010
28  * Author: alanb
29  */
30 
31 #ifndef TBX_RES_RESEXCEPT_H_
32 #define TBX_RES_RESEXCEPT_H_
33 
34 #include <stdexcept>
35 #include "../handles.h"
36 #include "../stringutils.h"
37 
38 namespace tbx
39 {
40 namespace res
41 {
42 
47 class ResObjectClassMismatch : public std::invalid_argument
48 {
49 public:
57  ResObjectClassMismatch(std::string object, int class_id, int check_id)
58  : std::invalid_argument("Object " + object
59  + ", class id " + tbx::to_string(class_id)
60  + " does not match assigned class " + tbx::to_string(check_id))
61  {
62  }
63 };
64 
69 class ResGadgetTypeMismatch : public std::invalid_argument
70 {
71 public:
78  ResGadgetTypeMismatch(int type_id, int check_id)
79  : std::invalid_argument("Gadget with type id " + tbx::to_string(type_id)
80  + " does not match assigned type id " + tbx::to_string(check_id))
81  {
82  }
83 };
84 
88 class ResObjectNotFound : public std::invalid_argument
89 {
90 public:
96  ResObjectNotFound(std::string name)
97  : std::invalid_argument("Resource '" + name
98  + "' not found")
99  {
100  }
101 };
102 
107 class ResObjectExists : public std::invalid_argument
108 {
109 public:
116  ResObjectExists(std::string name)
117  : std::invalid_argument("Resource '" + name
118  + "' already exists")
119  {
120  }
121 };
122 
123 
127 class ResMenuItemNotFound : public std::invalid_argument
128 {
129 public:
136  ResMenuItemNotFound(std::string menu, tbx::ComponentId component_id)
137  : std::invalid_argument("Menu " + menu
138  + " does not contain menu item " + tbx::to_string(component_id))
139  {
140  }
141 };
142 
147 class ResMenuItemExists : public std::invalid_argument
148 {
149 public:
156  ResMenuItemExists(std::string menu, tbx::ComponentId component_id)
157  : std::invalid_argument("Menu " + menu
158  + " already contains menu item " + tbx::to_string(component_id))
159  {
160  }
161 };
162 
166 class ResGadgetNotFound : public std::invalid_argument
167 {
168 public:
176  ResGadgetNotFound(std::string window, tbx::ComponentId component_id)
177  : std::invalid_argument("Window " + window
178  + " does not contain gadget " + tbx::to_string(component_id))
179  {
180  }
181 };
182 
187 class ResGadgetExists : public std::invalid_argument
188 {
189 public:
197  ResGadgetExists(std::string window, tbx::ComponentId component_id)
198  : std::invalid_argument("Window " + window
199  + " already contains gadget " + tbx::to_string(component_id))
200  {
201  }
202 };
203 
207 class ResShortcutNotFound : public std::invalid_argument
208 {
209 public:
217  ResShortcutNotFound(std::string window, int key_code)
218  : std::invalid_argument("Window " + window
219  + " does not contain gadget " + tbx::to_string(key_code))
220  {
221  }
222 };
223 
228 class ResShortcutExists : public std::invalid_argument
229 {
230 public:
238  ResShortcutExists(std::string window, int key_code)
239  : std::invalid_argument("Window " + window
240  + " already contains gadget " + tbx::to_string(key_code))
241  {
242  }
243 };
244 
245 }
246 }
247 
248 
249 #endif /* TBX_RES_RESEXCEPT_H_ */
tbx::res::ResMenuItemExists
Exception thrown when a menu resource already contains an item with a component id.
Definition: resexcept.h:148
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::ComponentId
int ComponentId
Type for underlying toolbox component id.
Definition: handles.h:33
tbx::res::ResShortcutExists
Exception thrown when a window resource already contains a shortcut with a key code.
Definition: resexcept.h:229
tbx::res::ResMenuItemNotFound::ResMenuItemNotFound
ResMenuItemNotFound(std::string menu, tbx::ComponentId component_id)
Construct exception thrown when a component can not be found in a menu.
Definition: resexcept.h:136
tbx::res::ResGadgetTypeMismatch
Exception thrown when a ResObject is assigned to a subclass with the wrong class id.
Definition: resexcept.h:70
tbx::res::ResShortcutNotFound
Exception thrown when a shortcut key can't be found in a window.
Definition: resexcept.h:208
tbx::res::ResShortcutNotFound::ResShortcutNotFound
ResShortcutNotFound(std::string window, int key_code)
Construct exception thrown when a shortcut can not be found in a window resource.
Definition: resexcept.h:217
tbx::res::ResObjectNotFound::ResObjectNotFound
ResObjectNotFound(std::string name)
Construct resource not found exception.
Definition: resexcept.h:96
tbx::res::ResObjectClassMismatch
Exception thrown when a ResObject is assigned to a subclass with the wrong class id.
Definition: resexcept.h:48
tbx::to_string
std::string to_string(const T &value)
Convert a value to a string.
Definition: stringutils.h:44
tbx::res::ResGadgetNotFound
Exception thrown when a gadget can't be found in a window.
Definition: resexcept.h:167
tbx::res::ResGadgetExists::ResGadgetExists
ResGadgetExists(std::string window, tbx::ComponentId component_id)
Construct exception thrown when a gadget already exists in a window resource.
Definition: resexcept.h:197
tbx::res::ResMenuItemExists::ResMenuItemExists
ResMenuItemExists(std::string menu, tbx::ComponentId component_id)
Construct exception thrown when a menu item already exists.
Definition: resexcept.h:156
tbx::res::ResMenuItemNotFound
Exception thrown when an item can't be found in a menu.
Definition: resexcept.h:128
tbx::res::ResGadgetNotFound::ResGadgetNotFound
ResGadgetNotFound(std::string window, tbx::ComponentId component_id)
Construct exception thrown when a gadget can not be found in a window resource.
Definition: resexcept.h:176
tbx::res::ResGadgetTypeMismatch::ResGadgetTypeMismatch
ResGadgetTypeMismatch(int type_id, int check_id)
Construct exception when resource gadget types do not match.
Definition: resexcept.h:78
tbx::res::ResObjectExists
Exception thrown when the ResEditor already contains an object with a given name.
Definition: resexcept.h:108
tbx::res::ResObjectNotFound
Exception thrown when an object can't be found in a ResEditor or ResFile.
Definition: resexcept.h:89
tbx::res::ResShortcutExists::ResShortcutExists
ResShortcutExists(std::string window, int key_code)
Construct exception thrown when a shortcut already exists in a window resource.
Definition: resexcept.h:238
tbx::res::ResObjectExists::ResObjectExists
ResObjectExists(std::string name)
Construct exception thrown when a Toolbox object already exists in the editor.
Definition: resexcept.h:116
tbx::res::ResGadgetExists
Exception thrown when a window resource already contains a gadget with a component id.
Definition: resexcept.h:188
tbx::res::ResObjectClassMismatch::ResObjectClassMismatch
ResObjectClassMismatch(std::string object, int class_id, int check_id)
Construct a resource object mismatch exception.
Definition: resexcept.h:57