00001 #ifndef SCT_OUTOFRANGEERROR_H
00002 #define SCT_OUTOFRANGEERROR_H
00003
00004 #include "LogicErrors.h"
00005
00006 namespace Sct {
00007
00015 template <class T=int>
00016 class OutOfRangeError : public LogicError {
00017 public:
00024 OutOfRangeError(const string& msg, const string& file, int line, T val, T lo, T hi) throw();
00025
00033 OutOfRangeError(Throwable& cause, const string& file, int line, T val, T lo, T hi) throw();
00034
00041 OutOfRangeError(const string& msg, Throwable& cause, const string& file, int line, T val, T lo, T hi) throw();
00042
00044 T getValue() const throw();
00046 T getLowLimit() const throw();
00048 T getHighLimit() const throw();
00049
00050 virtual shared_ptr<Throwable> clone() const throw();
00051
00052 protected:
00053 OutOfRangeError(T val, T lo, T hi) throw() {}
00054 virtual string getMessage() const throw();
00055
00056 T val, lo, hi;
00057
00058 };
00059
00060
00061 template <class T>
00062 OutOfRangeError<T>::OutOfRangeError(const string& msg, const string& file, int line, T val, T lo, T hi) throw()
00063 : val(val), lo(lo), hi(hi) {
00064 initialize("BAD_RANGE", "Sct::OutOfRangeError", msg, 0, file, line);
00065 }
00066
00067 template <class T>
00068 OutOfRangeError<T>::OutOfRangeError(Throwable& cause, const string& file, int line, T val, T lo, T hi) throw()
00069 : val(val), lo(lo), hi(hi) {
00070 initialize("BAD_RANGE", "Sct::OutOfRangeError", "", &cause, file, line);
00071 }
00072
00073 template <class T>
00074 OutOfRangeError<T>::OutOfRangeError(const string& msg, Throwable& cause, const string& file, int line, T val, T lo, T hi) throw()
00075 : val(val), lo(lo), hi(hi) {
00076 initialize("BAD_RANGE", "Sct::OutOfRangeError", msg, &cause, file, line);
00077 }
00078
00079 template <class T>
00080 string OutOfRangeError<T>::getMessage() const throw() {
00081 std::ostringstream output;
00082 output << msg << " [ value=" << val
00083 << " allowed range: "
00084 << lo << " -> " << hi << " ]";
00085
00086 return output.str();
00087 }
00088
00089 template <class T>
00090 T OutOfRangeError<T>::getValue() const throw() {
00091 return val;
00092 }
00093
00094 template <class T>
00095 T OutOfRangeError<T>::getLowLimit() const throw() {
00096 return lo;
00097 }
00098
00099 template <class T>
00100 T OutOfRangeError<T>::getHighLimit() const throw() {
00101 return high;
00102 }
00103
00104 template <class T>
00105 shared_ptr<Throwable> OutOfRangeError<T>::clone() const throw() {
00106 return shared_ptr<Throwable> ( new OutOfRangeError<T>(*this) );
00107 }
00108
00109 }
00110 #endif //SCT_OUTOFRANGEERROR_H