00001
00002
00003 #ifndef _BASEEXCEPTION_H_
00004 #define _BASEEXCEPTION_H_
00005
00006
00007 #include <iostream>
00008 #include <string>
00009 #include <vector>
00010
00011
00012 namespace FD {
00013
00014
00015
00016
00017
00018
00019
00026 class BaseException {
00027 public:
00028
00031 virtual void print (std::ostream &out = std::cerr) = 0;
00032
00035 virtual void freeze() {}
00036
00038 virtual ~BaseException(){;}
00039
00040 virtual BaseException *add(BaseException *e);
00041
00042 };
00043
00044 class GenericCastException : public BaseException{
00045 public:
00046 virtual void print(std::ostream &out = std::cerr)=0;
00047 };
00048
00049
00050
00051
00052
00053
00054
00061 class GeneralException :public BaseException {
00062 public:
00063
00065 GeneralException(std::string _message, std::string _file, int _line)
00066 : message(_message)
00067 , file (_file)
00068 , line (_line)
00069 {}
00070
00072 virtual void print(std::ostream &out = std::cerr)
00073 {
00074 out << file << " line " << line << ": " << message << std::endl;
00075 }
00076
00077 protected:
00079 std::string message;
00080
00082 std::string file;
00083
00085 int line;
00086 };
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 class ExceptionStack : public BaseException {
00098 protected:
00099
00100 std::vector<BaseException *> stack;
00101
00102 public:
00103 ExceptionStack() {};
00104
00105 BaseException *add(BaseException *e)
00106 {
00107 stack.insert(stack.end(), e);
00108 return this;
00109 }
00110
00111 virtual ~ExceptionStack()
00112 {for (size_t i=0;i<stack.size();i++) delete stack[i];}
00114 virtual void print(std::ostream &out = std::cerr) {
00115 for (unsigned int i=0;i<stack.size();i++)
00116 stack[i]->print(out);
00117 }
00118
00119 virtual void freeze()
00120 {
00121 for (unsigned int i=0;i<stack.size();i++)
00122 stack[i]->freeze();
00123 }
00124 };
00125
00126 inline BaseException *BaseException::add(BaseException *e)
00127 {
00128 return (new ExceptionStack)->add(this)->add(e);
00129 }
00130
00131 }
00132
00133 #endif