-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJP2_Exception.hh
302 lines (269 loc) · 7.96 KB
/
JP2_Exception.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/* Jp2_Exception
HiROC CVS ID: $Id: JP2_Exception.hh,v 1.6 2010/10/03 03:21:20 castalia Exp $
Copyright (C) 2009-2010 Arizona Board of Regents on behalf of the
Planetary Image Research Laboratory, Lunar and Planetary Laboratory at
the University of Arizona.
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License, version 2.1,
as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*******************************************************************************/
#ifndef _JP2_Exception_
#define _JP2_Exception_
#include <exception>
#include <stdexcept>
#include <string>
#include <ios>
namespace UA
{
namespace HiRISE
{
/** A <i>JP2_Exception</i> is thrown by a JP2 class.
For all JP2_Exceptions a message string is provided that describes the
reason for the Exception. The message method will return this message,
while the what method will prepend the JP2_Exception class ID to the
message.
@author Bradford Castalia, UA/HiROC
@version $Revision: 1.6 $
*/
class JP2_Exception
: public std::exception
{
public:
/*==============================================================================
Constants:
*/
//! Class identification name with source code version and date.
static const char* const
ID;
/*==============================================================================
Constructor
*/
/** Creates a JP2_Exception containing a message.
If the message ends with a new-line character ('\\n'), it is removed
(but only one is removed). If a caller_ID is provided, it preceeds
the message string separated by a new-line character.
@param message The message string.
@param caller_ID An optional C-string (NULL terminated char*)
identifying the source of the Exception.
*/
explicit JP2_Exception
(
const std::string& message = "",
const char* caller_ID = NULL
);
// Destructor
virtual ~JP2_Exception () throw ()
{}
/*==============================================================================
Accessors:
*/
/** Gets a C-string describing what produced the Exception.
@return The C-string (NULL terminated char*) that includes the
Exception ID as the first line followed by the caller_ID and
message string.
*/
const char* what () const throw ();
/** Gets the user-provided caller_ID and message string.
@return The message string. The caller_ID followed by the user
message.
*/
std::string message () const throw ();
/** Sets a new message string.
If the message ends with a new-line character ('\\n'), it is removed
(but only one is removed). If a caller_ID was provided when the
Exception was created it remains; the new message is appended in
place of the previous message.
@param message A string to replace the previous message.
*/
void message (const std::string& message);
/*==============================================================================
Private Data.
*/
private:
std::string
Message;
std::string::size_type
User_Message_Index;
};
/*------------------------------------------------------------------------------
JP2_Invalid_Argument
*/
//! A JP2_Exception for an invalid argument.
struct JP2_Invalid_Argument
: public JP2_Exception,
public std::invalid_argument
{
explicit JP2_Invalid_Argument
(
const std::string& message = "",
const char* caller_ID = NULL
)
: JP2_Exception (std::string ("JP2_Invalid_Argument\n") + message,
caller_ID),
std::invalid_argument
(
std::string (JP2_Exception::ID)
+ (message.empty () ?
"" : (std::string ("\nJP2_Invalid_Argument\n") + message))
+ (caller_ID ?
(std::string ("\n") + caller_ID) : "")
)
{}
};
/*------------------------------------------------------------------------------
JP2_Out_of_Range
*/
/** A JP2_Out_of_Range exception is thrown when a value is found to be out
of its allowable range.
*/
struct JP2_Out_of_Range
: public JP2_Exception,
public std::out_of_range
{
explicit JP2_Out_of_Range
(
const std::string& message = "",
const char* caller_ID = NULL
)
: JP2_Exception (std::string ("JP2_Out_of_Range\n") + message, caller_ID),
std::out_of_range
(
std::string (JP2_Exception::ID)
+ (message.empty () ?
"" : (std::string ("\nJP2_Out_of_Range\n") + message))
+ (caller_ID ?
(std::string ("\n") + caller_ID) : "")
)
{}
};
/*------------------------------------------------------------------------------
JP2_Logic_Error
*/
/** A <i>JP2_Logic_Error</i> indicates a logical inconsistency in the object.
Typically a JP2_Logic_Error is thrown when the object affected is not in
a state that can carry out the requested operation. For example, this
exception will be thrown if a JP2_Reader is requested to render from its
source by the object is not ready due to an incomplete or inconsistent
configuration.
*/
struct JP2_Logic_Error
: public JP2_Exception,
public std::logic_error
{
explicit JP2_Logic_Error
(
const std::string& message = "",
const char* caller_ID = NULL
)
: JP2_Exception (std::string ("JP2_Logic_Error\n") + message, caller_ID),
std::logic_error
(
std::string (JP2_Exception::ID)
+ (message.empty () ?
"" : (std::string ("\nJP2_Logic_Error\n") + message))
+ (caller_ID ?
(std::string ("\n") + caller_ID) : "")
)
{}
};
/*------------------------------------------------------------------------------
IO_Failure
*/
//! A JP2_IO_Failure exception is for an I/O failure condtion.
struct JP2_IO_Failure
: public JP2_Exception,
public std::ios::failure
{
explicit JP2_IO_Failure
(
const std::string& message = "",
const char* caller_ID = NULL
)
: JP2_Exception (std::string ("JP2_IO_Failure\n") + message, caller_ID),
std::ios_base::failure
(
std::string (JP2_Exception::ID)
+ (message.empty () ?
"" : (std::string ("\nJP2_IO_Failure\n") + message))
+ (caller_ID ?
(std::string ("\n") + caller_ID) : "")
)
{}
};
/*=*****************************************************************************
JPIP_Exception
*/
//! A JPIP_Exception is associated with the interaction with a JPIP server.
struct JPIP_Exception
: public JP2_Exception
{
explicit JPIP_Exception
(
const std::string& message = "",
const char* caller_ID = NULL
)
: JP2_Exception (std::string ("JPIP_Exception\n") + message, caller_ID)
{}
};
/*------------------------------------------------------------------------------
JPIP_Timeout
*/
/** A JPIP_Timeout occurs when a request does not complete within the
allowed time.
*/
struct JPIP_Timeout
: public JPIP_Exception,
public std::overflow_error
{
explicit JPIP_Timeout
(
const std::string& message = "",
const char* caller_ID = NULL
)
: JPIP_Exception (std::string ("JPIP_Timeout\n") + message, caller_ID),
std::overflow_error
(
std::string (JP2_Exception::ID)
+ (message.empty () ?
"" : (std::string ("\nJPIP_Timeout\n") + message))
+ (caller_ID ?
(std::string ("\n") + caller_ID) : "")
)
{}
};
/*------------------------------------------------------------------------------
JPIP_Disconnected
*/
/** A JPIP_Disconnected occurs when a JPIP server connection can not be
accomplished or a JPIP server disconnection occurs.
*/
struct JPIP_Disconnected
: public JPIP_Exception,
public std::ios::failure
{
explicit JPIP_Disconnected
(
const std::string& message = "",
const char* caller_ID = NULL
)
: JPIP_Exception (std::string ("JPIP_Disconnected\n") + message, caller_ID),
std::ios::failure
(
std::string (JP2_Exception::ID)
+ (message.empty () ?
"" : (std::string ("\nJPIP_Disconnected\n") + message))
+ (caller_ID ?
(std::string ("\n") + caller_ID) : "")
)
{}
};
} // namespace HiRISE
} // namespace UA
#endif // _JP2_Exception_