Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

Assert.h

Go to the documentation of this file.
00001 
00046 #include <amire/common/Defines.h>
00047 
00048 #ifndef _AMIRE_COMMON_ASSERT_H
00049 #define _AMIRE_COMMON_ASSERT_H
00050 
00051 #include <exception>
00052 
00053 namespace amire {
00054   namespace common {
00058     class AMIRE_EXPORT_API AMIREException : public virtual std::exception {
00059     protected:
00063       std::string file;
00064 
00068       int line;
00069 
00073       char *message;
00074 
00075     public:
00079       AMIREException();
00080 
00084       AMIREException(const AMIREException &exception);
00085 
00089       AMIREException(const std::string &file, int line);
00090 
00094       AMIREException(const std::string &file, int line, const std::string &message);
00095 
00099       AMIREException(const std::string &file, int line, const std::string &message1, const std::string &message2);
00100 
00101       virtual ~AMIREException() throw ();
00102 
00106       virtual std::ostream &print(std::ostream &out) const;
00107 
00111       virtual const char *what() const throw ();
00112 
00116       AMIREException& operator=(const AMIREException& e);
00117 
00121       AMIRE_EXPORT_API friend std::ostream &operator<<(std::ostream &out, const AMIREException *ex);
00122 
00126       AMIRE_EXPORT_API friend std::ostream &operator<<(std::ostream &out, const AMIREException &ex);
00127     };
00128 
00132     #define INTERNAL_WARNING (std::cerr << "internal warning: \"" << __FILE__ << "\", " << __LINE__ << std::endl << std::flush)
00133 
00137     #define INTERNAL_WARNING1(message) (std::cerr << "internal warning: " << message << " \"" << __FILE__ << "\", " << __LINE__ << std::endl << std::flush)
00138 
00142     #define INTERNAL_WARNING2(message1, message2) (std::cerr << "internal warning: " << message1 << ": " << message2 << " \"" << __FILE__ << "\", " << __LINE__ << std::endl << std::flush)
00143 
00147     #define EXCEPTION amire::common::AMIREException(__FILE__, __LINE__)
00148 
00152     #define EXCEPTION1(message) amire::common::AMIREException(__FILE__, __LINE__, (message))
00153 
00157     #define EXCEPTION2(message1, message2) amire::common::AMIREException(__FILE__, __LINE__, (message1), (message2))
00158 
00162     #define THROW_EXCEPTION { \
00163       amire::common::AMIREException *____AMIRE_ASSERT_EXCEPTION = new EXCEPTION; \
00164       throw ____AMIRE_ASSERT_EXCEPTION; \
00165     }
00166 
00170     #define THROW_EXCEPTION1(message) { \
00171       amire::common::AMIREException *____AMIRE_ASSERT_EXCEPTION = new EXCEPTION1(message); \
00172       throw ____AMIRE_ASSERT_EXCEPTION; \
00173     }
00174 
00178     #define THROW_EXCEPTION2(message1, message2) { \
00179       amire::common::AMIREException *____AMIRE_ASSERT_EXCEPTION = new EXCEPTION2(message1, message2); \
00180       throw ____AMIRE_ASSERT_EXCEPTION; \
00181     }
00182 
00186     #define ABSTRACT_METHOD_ERROR { \
00187       amire::common::AMIREException *____AMIRE_ASSERT_EXCEPTION = new EXCEPTION1("abstract method error!"); \
00188       throw ____AMIRE_ASSERT_EXCEPTION; \
00189     }
00190 
00194     #define ABSTRACT_METHOD_ERROR1(message) { \
00195       amire::common::AMIREException *____AMIRE_ASSERT_EXCEPTION = new EXCEPTION2("abstract method error:", message); \
00196       throw ____AMIRE_ASSERT_EXCEPTION; \
00197     }
00198 
00202     #define INTERNAL_ERROR { \
00203       amire::common::AMIREException *____AMIRE_ASSERT_EXCEPTION = new EXCEPTION1("internal error!"); \
00204       throw ____AMIRE_ASSERT_EXCEPTION; \
00205     }
00206 
00210     #define INTERNAL_ERROR1(message) { \
00211       amire::common::AMIREException *____AMIRE_ASSERT_EXCEPTION = new EXCEPTION2("internal error:", message); \
00212       throw ____AMIRE_ASSERT_EXCEPTION; \
00213     }
00214 
00218     #define NOT_IMPLEMENTED_ERROR INTERNAL_ERROR1("not implemented")
00219 
00223     #define ASSERT(condition) { \
00224       if (!(condition)) { \
00225         amire::common::AMIREException *____AMIRE_ASSERT_EXCEPTION = new EXCEPTION; \
00226         throw ____AMIRE_ASSERT_EXCEPTION; \
00227       } \
00228     }
00229 
00233     #define ASSERT1(condition, message) { \
00234       if (!(condition)) { \
00235         amire::common::AMIREException *____AMIRE_ASSERT_EXCEPTION = new EXCEPTION1(message); \
00236         throw ____AMIRE_ASSERT_EXCEPTION; \
00237       } \
00238     }
00239 
00243     #define ASSERT2(condition, message1, message2) { \
00244       if (!(condition)) { \
00245         amire::common::AMIREException *____AMIRE_ASSERT_EXCEPTION = new EXCEPTION2(message1, message2); \
00246         throw ____AMIRE_ASSERT_EXCEPTION; \
00247       } \
00248     }
00249   }
00250 }
00251 
00252 #endif

Generated on Tue May 20 17:23:52 2003 for AMIRE-Framework by doxygen1.3