src/util/Error.h

Go to the documentation of this file.
00001 
00014 #ifndef GERROR_H
00015 #define GERROR_H
00016 
00017 #include <string>
00018 #include <iostream>
00019 
00021 namespace green
00022 {
00030         class Error
00031         {
00032         public:
00037                 Error() : mLine(0) {}
00038 
00045                 Error(unsigned int line, std::string file, std::string message) :
00046                         mLine(line), mFile(file), mMessage(message) {}
00047 
00052                 virtual
00053                         ~Error() {}
00054 
00059                 virtual inline
00060                         void SetLine(unsigned int line) { mLine = line; }
00061 
00066                 virtual inline
00067                         unsigned int GetLine() const { return mLine; }
00068 
00069 
00074                 virtual inline
00075                         void SetFile(std::string file) { mFile = file; }
00076 
00081                 virtual inline
00082                         const std::string& GetFile() const { return mFile; }
00083 
00088                 virtual inline
00089                         void SetMessage(std::string message) { mMessage = message; }
00090 
00095                 virtual inline
00096                         const std::string& GetMessage() const { return mMessage; }
00097 
00102                 virtual inline
00103                         void Print(std::ostream& os) {
00104                                 using std::endl;
00105                                 os << "---" << endl;
00106                                 os << " File: " << mFile << endl;
00107                                 os << " Line: " << mLine << endl;
00108                                 os << " Message: " << mMessage << endl;
00109                                 os << "---" << endl;
00110                 }
00111         protected:
00112                 unsigned int mLine; 
00113                 std::string mFile; 
00114                 std::string mMessage; 
00115         };
00116         
00118         #define THROW_ERROR(msg) throw Error(__LINE__, __FILE__, (msg));
00119 
00120         #define ERROR_ASSERT(cond, msg) if(!(cond)) throw Error(__LINE__, __FILE__, (msg));
00121 
00122         #define CHECK_SHARED(x) ERROR_ASSERT((x).get(), std::string(#x) + " is NULL")
00123 }
00124 
00125 #endif

Generated on Fri Apr 27 10:27:38 2007 for Green Engine by  doxygen 1.5.1