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
00030
00031
00032
00033 #ifndef __RVL_EXCEPT
00034 #define __RVL_EXCEPT
00035
00036 #define BUFLEN 100
00037
00038 #include "std_cpp_includes.hh"
00039
00040 namespace RVL {
00041
00046 class RVLException: public std::exception {
00047 private:
00048 string msg;
00049 public:
00050 RVLException(): msg("") {}
00051 RVLException(const RVLException & s): msg("") { msg +=s.msg; }
00052 virtual ~RVLException() throw() {}
00053
00054 const char* what() const throw() { return msg.c_str(); }
00055
00056 RVLException & operator<< ( string str ) {
00057 msg += str;
00058 return *this;
00059 }
00060 RVLException & operator<< ( const char* str ) {
00061 msg += str;
00062 return *this;
00063 }
00064 RVLException & operator<< ( int i ) {
00065 char buf[ BUFLEN ];
00066 sprintf( buf, "%d", i );
00067 msg += buf;
00068 return *this;
00069 }
00070 RVLException & operator<< ( unsigned int i ) {
00071 char buf[ BUFLEN ];
00072 sprintf( buf, "%u", i );
00073 msg += buf;
00074 return *this;
00075 }
00076 RVLException & operator<< ( long i ) {
00077 char buf[ BUFLEN ];
00078 sprintf( buf, "%ld", i );
00079 msg += buf;
00080 return *this;
00081 }
00082 RVLException & operator<< ( unsigned long i ) {
00083 char buf[ BUFLEN ];
00084 sprintf( buf, "%lu", i );
00085 msg += buf;
00086 return *this;
00087 }
00088 RVLException & operator<< ( short i ) {
00089 char buf[ BUFLEN ];
00090 sprintf( buf, "%d", i );
00091 msg += buf;
00092 return *this;
00093 }
00094 RVLException & operator<< ( unsigned short i ) {
00095 char buf[ BUFLEN ];
00096 sprintf( buf, "%d", i );
00097 msg += buf;
00098 return *this;
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108 RVLException & operator<< ( double d ) {
00109 char buf[ BUFLEN ];
00110 sprintf( buf, "%g", d );
00111 msg += buf;
00112 return *this;
00113 }
00114 RVLException & operator<< ( float d ) {
00115 char buf[ BUFLEN ];
00116 sprintf( buf, "%g", d );
00117 msg += buf;
00118 return *this;
00119 }
00120 template<class T>
00121 RVLException & operator<< ( complex<T> d ) {
00122 char buf[ BUFLEN ];
00123 sprintf( buf, "(%g,%g)", d.real(),d.imag() );
00124 msg += buf;
00125 return *this;
00126 }
00127
00128 RVLException & operator<< ( char c ) {
00129 char buf[ BUFLEN ];
00130 buf[ 0 ] = c;
00131 buf[ 1 ] = '\0';
00132 msg += buf;
00133 return *this;
00134 }
00135
00136 ostream & write(ostream & str) const {
00137 str<<msg<<endl;
00138 return str;
00139 }
00140 };
00141
00142 }
00143
00144 #endif