• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • htmesh
SpatialException.cpp
Go to the documentation of this file.
1 //# Filename: SpatialException.cpp
2 //#
3 //# Author: John Doug Reynolds, P. Kunszt
4 //#
5 //# Date: Mar 1997
6 //#
7 //# Copyright (C) 2000 Peter Z. Kunszt, Alex S. Szalay, Aniruddha R. Thakar
8 //# The Johns Hopkins University
9 //#
10 //# Modification history:
11 //#
12 //# Oct. 1998, P. Kunszt : remove Rogue Wave C-string dependency
13 //# almost all the interface had to be rewritten.
14 //# Also, use some of the inheritance to avoid
15 //# code duplication. Introduced defaultstr[].
16 //# Oct 18, 2001 : Dennis C. Dinge -- Replaced ValVec with std::vector
17 //#
18 
19 #include <cstdio>
20 #include <cstdlib>
21 #include <string.h>
22 #include <SpatialException.h>
23 
24 /* --- SpatialException methods ------------------------------------------------- */
25 const char *
26 SpatialException::defaultstr[] = {
27  "SDSS Science Archive",
28  "generic exception", // These specialized exceptions are
29  "unimplemented functionality", // currently implemented. If no string
30  "failed operation", // is given, this is the standard
31  "array bounds violation", // message.
32  "interface violation"
33 };
34 
35 #define CONTEXT 0 // indices of exceptions
36 #define GENERIC 1
37 #define UNIMPLEMENTED 2
38 #define FAILURE 3
39 #define BOUNDS 4
40 #define INTERFACE 5
41 
42 SpatialException::~SpatialException() throw() {
43  if(str_ != NULL)delete[] str_;
44 }
45 
46 SpatialException::SpatialException( const char *cstr, int defIndex ) throw()
47 {
48  try {
49  if ( cstr ) {
50  str_ = new char[slen(cstr) + 1];
51  strcpy(str_,cstr);
52  } else {
53  str_ = new char[50];
54  sprintf(str_,"%s : %s",defaultstr[CONTEXT],defaultstr[defIndex]);
55  }
56  }
57  catch (...) {
58  delete[] str_;
59  }
60 }
61 
62 SpatialException::SpatialException( const char *context, const char *because,
63  int defIndex) throw()
64 {
65  try {
66  const char * tmpc, * tmpb;
67  tmpc = context ? context : defaultstr[CONTEXT];
68  tmpb = because ? because : defaultstr[defIndex];
69  str_ = new char[slen(tmpc) + slen(tmpb) + 50]; // allow extensions
70  sprintf(str_,"%s : %s",tmpc,tmpb);
71  }
72  catch (...) {
73  delete[] str_;
74  }
75 }
76 
77 SpatialException::SpatialException( const SpatialException& oldX ) throw()
78 {
79  try {
80  if(oldX.str_) {
81  str_ = new char[slen(oldX.str_) + 1];
82  strcpy(str_,oldX.str_);
83  }
84  }
85  catch (...) {
86  delete[] str_;
87  }
88 }
89 
90 SpatialException& SpatialException::operator=( const SpatialException& oldX ) throw()
91 {
92  try {
93  if(&oldX != this) { // beware of self-assignment
94  if(oldX.str_) {
95  str_ = new char[slen(oldX.str_) + 1];
96  strcpy(str_,oldX.str_);
97  }
98  }
99  }
100  catch (...) {
101  delete[] str_;
102  }
103  return *this;
104 }
105 
106 const char *SpatialException::what() const throw()
107 {
108  try {
109  return str_;
110  }
111  catch (...) {
112  return "";
113  }
114 }
115 
116 int SpatialException::slen(const char *str) const
117 {
118  if(str)return strlen(str);
119  return 0;
120 }
121 
122 void SpatialException::clear()
123 {
124  if(str_)delete[] str_;
125 }
126 /* --- SpatialUnimplemented methods --------------------------------------------- */
127 
128 SpatialUnimplemented::SpatialUnimplemented( const char *cstr ) throw()
129 : SpatialException(cstr,UNIMPLEMENTED)
130 {
131 }
132 
133 SpatialUnimplemented::SpatialUnimplemented( const char *context, const char *because )
134  throw()
135  : SpatialException(context, because, UNIMPLEMENTED)
136 {
137 }
138 
139 SpatialUnimplemented::SpatialUnimplemented( const SpatialUnimplemented& oldX ) throw()
140  : SpatialException(oldX)
141 {
142 }
143 
144 /* --- SpatialFailure methods --------------------------------------------------- */
145 
146 SpatialFailure::SpatialFailure( const char *cstr ) throw()
147  : SpatialException(cstr, FAILURE)
148 {
149 }
150 
151 SpatialFailure::SpatialFailure( const char *context, const char *because ) throw()
152  : SpatialException(context,because,FAILURE)
153 {
154 }
155 
156 SpatialFailure::SpatialFailure( const char *context, const char *operation
157  , const char *resource, const char *because ) throw()
158 {
159  try {
160  delete[] str_;
161  if ( !operation && !resource && !because ) {
162  if ( !context ) context = defaultstr[CONTEXT];
163  because = "failed operation";
164  }
165  str_ = new char[ slen(context) + slen(operation) + slen(resource)
166  + slen(because) + 50];
167  *str_ = '\0';
168  if ( !context )
169  context = defaultstr[CONTEXT];
170  sprintf(str_,"%s: ",context);
171  if ( operation ) {
172  sprintf(str_,"%s %s failed ",str_, operation);
173  }
174  if ( resource ) {
175  if(operation)
176  sprintf(str_,"%s on \"%s\"",str_,resource);
177  else
178  sprintf(str_,"%s trouble with \"%s\"",str_,resource);
179  }
180  if ( because ) {
181  if ( operation || resource )
182  sprintf(str_,"%s because %s",str_,because);
183  else
184  sprintf(str_,"%s %s",str_,because);
185  }
186  }
187  catch (...) {
188  delete[] str_;
189  }
190 }
191 
192 SpatialFailure::SpatialFailure( const SpatialFailure& oldX ) throw()
193  : SpatialException(oldX)
194 {
195 }
196 
197 /* --- SpatialBoundsError methods ----------------------------------------------- */
198 
199 SpatialBoundsError::SpatialBoundsError( const char *cstr ) throw()
200  : SpatialException(cstr,BOUNDS)
201 {
202 }
203 
204 SpatialBoundsError::SpatialBoundsError( const char *context, const char *array
205  , int32 limit, int32 index ) throw()
206  : SpatialException(context,array,BOUNDS)
207 {
208  try {
209  if ( limit != -1 ) {
210  if ( array )
211  sprintf(str_,"%s[%d]",str_,index);
212  else
213  sprintf(str_, "%s array index %d ",str_, index );
214  if ( index > limit ) {
215  sprintf( str_, "%s over upper bound by %d",str_, index - limit );
216  }
217  else {
218  sprintf( str_, "%s under lower bound by %d",str_, limit - index );
219  }
220  }
221  }
222  catch (...) {
223  delete[] str_;
224  }
225 }
226 
227 SpatialBoundsError::SpatialBoundsError( const SpatialBoundsError& oldX ) throw()
228  : SpatialException(oldX)
229 {
230 }
231 
232 /* --- SpatialInterfaceError methods -------------------------------------------- */
233 
234 SpatialInterfaceError::SpatialInterfaceError( const char *cstr ) throw()
235  : SpatialException(cstr,INTERFACE)
236 {
237 }
238 
239 SpatialInterfaceError::SpatialInterfaceError( const char *context, const char *because )
240  throw()
241  : SpatialException(context,because,INTERFACE)
242 {
243 }
244 
245 SpatialInterfaceError::SpatialInterfaceError( const char *context, const char *argument
246  , const char *because ) throw()
247 {
248  try {
249  delete[] str_;
250  str_ = new char[slen(context) + slen(argument) + slen(because) + 128];
251  *str_ = '\0';
252  if ( !context )
253  context = defaultstr[CONTEXT];
254  sprintf(str_,"%s: ",context);
255  if ( argument && because ) {
256  sprintf(str_,"%s argument \"%s\" is invalid because %s ",str_,
257  argument, because);
258  }
259  else if ( argument && !because ) {
260  sprintf(str_,"%s invalid argument \"%s\" ",str_,
261  argument);
262  }
263  else if ( !argument ) {
264  if(because)
265  sprintf(str_,"%s %s",str_,because);
266  else
267  sprintf(str_,"%s interface violation",str_);
268  }
269  }
270  catch (...) {
271  delete[] str_;
272  }
273 }
274 
275 SpatialInterfaceError::SpatialInterfaceError( const SpatialInterfaceError& oldX ) throw()
276  : SpatialException(oldX)
277 {
278 }
FAILURE
#define FAILURE
Definition: SpatialException.cpp:38
SpatialException
HTM SpatialIndex Exception base class This is the base class for all Science Archive exceptions...
Definition: SpatialException.h:28
SpatialException::slen
int slen(const char *) const
return string length also for null strings
Definition: SpatialException.cpp:116
SpatialFailure
SpatialException thrown on operational failure.
Definition: SpatialException.h:102
SpatialBoundsError::SpatialBoundsError
SpatialBoundsError(const char *what=0)
Default and explicit constructors.
Definition: SpatialException.cpp:199
SpatialException::clear
void clear()
deallocate string
Definition: SpatialException.cpp:122
int32
int int32
Definition: SpatialGeneral.h:55
SpatialInterfaceError::SpatialInterfaceError
SpatialInterfaceError(const char *what=0)
Default and explicit constructors.
Definition: SpatialException.cpp:234
SpatialException::str_
char * str_
error string to assemble
Definition: SpatialException.h:73
SpatialException::what
virtual const char * what() const
Returns the message as set during construction.
Definition: SpatialException.cpp:106
SpatialUnimplemented::SpatialUnimplemented
SpatialUnimplemented(const char *what=0)
Default and explicit constructors.
Definition: SpatialException.cpp:128
SpatialException::defaultstr
static const char * defaultstr[]
default error string
Definition: SpatialException.h:69
SpatialInterfaceError
SpatialException thrown on violation of interface protocols.
Definition: SpatialException.h:152
UNIMPLEMENTED
#define UNIMPLEMENTED
Definition: SpatialException.cpp:37
SpatialException::SpatialException
SpatialException(const char *what=0, int defIndex=1)
Default and explicit constructor.
Definition: SpatialException.cpp:46
INTERFACE
#define INTERFACE
Definition: SpatialException.cpp:40
SpatialUnimplemented
SpatialException thrown by unimplemented functions.
Definition: SpatialException.h:82
SpatialException::operator=
SpatialException & operator=(const SpatialException &)
Assignment operator.
Definition: SpatialException.cpp:90
SpatialException::~SpatialException
virtual ~SpatialException()
Destructor.
Definition: SpatialException.cpp:42
SpatialFailure::SpatialFailure
SpatialFailure(const char *what=0)
Default and explicit constructors.
Definition: SpatialException.cpp:146
SpatialException.h
SpatialBoundsError
SpatialException thrown on violation of array bounds.
Definition: SpatialException.h:126
BOUNDS
#define BOUNDS
Definition: SpatialException.cpp:39
CONTEXT
#define CONTEXT
Definition: SpatialException.cpp:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal