-
Notifications
You must be signed in to change notification settings - Fork 1
/
JP2_Exception.cc
107 lines (89 loc) · 2.81 KB
/
JP2_Exception.cc
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
/* JP2_Exception
HiROC CVS ID: $Id: JP2_Exception.cc,v 1.3 2010/01/30 22:24:09 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.
*******************************************************************************/
#include "JP2_Exception.hh"
#include <exception>
#include <string>
using std::string;
#include <cstring>
namespace UA
{
namespace HiRISE
{
/*==============================================================================
Constants:
*/
const char* const
JP2_Exception::ID =
"UA::HiRISE::JP2_Exception ($Revision: 1.3 $ $Date: 2010/01/30 22:24:09 $)";
/*==============================================================================
Constructor
*/
JP2_Exception::JP2_Exception
(
const std::string& message,
const char* caller_ID
)
// Prepend the Exception ID to the Message.
: Message
(
string (ID)
+ (caller_ID ? (string ("\n") + caller_ID) : "")
+ '\n' + message
)
{
if (! Message.empty () && Message[Message.size () - 1] == '\n')
// Remove the trailing new-line.
Message.erase (Message.size () - 1);
User_Message_Index = strlen (ID) + (caller_ID ? (strlen (caller_ID) + 2) : 1);
}
/*==============================================================================
Accessors:
*/
const char*
JP2_Exception::what ()
const throw ()
{return Message.c_str ();}
std::string
JP2_Exception::message ()
const throw ()
{
// Exclude the JP2_Exception ID; include any caller_ID.
string::size_type
index = strlen (ID) + 1;
if (index > Message.size ())
index = 0; // No Exception ID!?!
return Message.substr (index);
}
void
JP2_Exception::message
(
const std::string& new_message
)
{
if (User_Message_Index >= Message.length ())
// No user message to replace; append on the next line.
(Message += '\n') += new_message;
else
// Replace the trailing user message portion of the Message.
Message.replace (User_Message_Index, Message.length () - User_Message_Index,
new_message);
if (! Message.empty () && Message[Message.size () - 1] == '\n')
// Remove the trailing new-line.
Message.erase (Message.size () - 1);
}
} // namespace HiRISE
} // namespace UA