00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __SEAL_EXCEPTION_H__
00030 #define __SEAL_EXCEPTION_H__
00031
00032 #include <string>
00033 #include <sstream>
00034 #include <iostream>
00035
00036 namespace seal
00037 {
00038
00041 class Exception
00042 {
00043 public:
00044
00047 Exception() {}
00048
00051 virtual ~Exception() {}
00052
00056 virtual std::string getMessage(void) = 0;
00057
00058 };
00059
00060
00061
00062
00063
00066 class OutOfBoundsException : public Exception
00067 {
00068 public:
00069
00072 OutOfBoundsException(void) : Exception()
00073 {
00074 #ifdef __SEAL_DEBUG__
00075
00076 std::cerr << "EXCEPTION:: You are trying to access memory "
00077 << "beyond the bounds of the collection.\n"
00078 << "If you dont see any further information, then this"
00079 << "message is through an OutOfBoundsException.\n\n";
00080
00081 #endif // __SEAL_DEBUG__
00082 }
00083
00086 virtual ~OutOfBoundsException() {}
00087
00090 virtual std::string getMessage(void)
00091 {
00092 return std::string("You are accessing memory beyond the bounds of the collection.\n");
00093 }
00094
00095 };
00096
00097
00098
00099
00100
00105 template <typename T>
00106 class OutOfRangeException : public OutOfBoundsException
00107 {
00108 public:
00114 OutOfRangeException(const T &lowerBound, const T &upperBound, const T &requestedValue);
00115
00118 virtual ~OutOfRangeException() {}
00119
00122 virtual std::string getMessage(void);
00123
00126 T getAllowedLowerLimit() { return lowerLimit; }
00127
00130 T getAllowedUpperLimit() { return upperLimit; }
00131
00132 private:
00133 OutOfRangeException() {}
00134 T lowerLimit, upperLimit, value;
00135
00136 };
00137
00139
00140 template <typename T>
00141 OutOfRangeException<T>::OutOfRangeException(const T &allowedLowerLimit, const T &allowedUpperLimit,
00142 const T &requestedValue)
00143 : OutOfBoundsException(),
00144 lowerLimit(allowedLowerLimit),
00145 upperLimit(allowedUpperLimit),
00146 value(requestedValue)
00147 {
00148 if (lowerLimit > upperLimit)
00149 {
00150 lowerLimit = allowedUpperLimit;
00151 upperLimit = allowedLowerLimit;
00152 }
00153
00154 #ifdef __SEAL_DEBUG__
00155
00156 std::cerr << "\nRange information is as follows (Generated from OutOfRangeException):\n"
00157 << "Allowed Lower Limit - " << lowerLimit << "\n"
00158 << "Allowed Upper Limit - " << upperLimit << "\n"
00159 << "Requested Value - " << requestedValue << "\n\n";
00160
00161 #endif // __SEAL_DEBUG__
00162
00163 }
00164
00165 template <typename T>
00166 std::string OutOfRangeException<T>::getMessage()
00167 {
00168 std::stringstream ss;
00169
00170 ss << "Allowed Lower Limit - " << lowerLimit << "\n"
00171 << "Allowed Upper Limit - " << upperLimit << "\n"
00172 << "Requested Value - " << value << "\n";
00173
00174 return ss.str();
00175 }
00176
00177
00178
00179
00180
00183 class EmptyCollectionException : public Exception
00184 {
00185 public:
00188 EmptyCollectionException(void) : Exception()
00189 {
00190 #ifdef __SEAL_DEBUG__
00191
00192 std::cerr << "The collection object whose members you are trying "
00193 << "to access in empty.\n";
00194 #endif // __SEAL_DEBUG__
00195 }
00196
00199 ~EmptyCollectionException() {}
00200
00203 virtual std::string getMessage(void)
00204 {
00205 std::stringstream ss;
00206 ss << "The collection object whose members you are trying to access is empty.\n";
00207
00208 return ss.str();
00209 }
00210 };
00211
00212
00213
00214
00215
00218 class MissingPriorityException : public Exception
00219 {
00220 public:
00223 MissingPriorityException(void) : Exception()
00224 {
00225 #ifdef __SEAL_DEBUG__
00226 std::cerr << "ERROR: Trying to access a element with a non-existant priority.\n";
00227 #endif // __SEAL_DEBUG__
00228 }
00229
00232 ~MissingPriorityException() {}
00233
00236 virtual std::string getMessage(void)
00237 {
00238 std::stringstream ss;
00239 ss << "Trying to access a element with a non-existant priority.\n";
00240
00241 return ss.str();
00242 }
00243 };
00244
00245 }
00246
00247 #endif // __SEAL_EXCEPTION_H__
00248