00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __exceptions_AMOS_HH
00011 #define __exceptions_AMOS_HH 1
00012
00013 #include "inttypes_AMOS.hh"
00014 #include <string>
00015 #include <exception>
00016 #include <iostream>
00017
00018
00019
00020
00021 namespace AMOS {
00022
00023
00029
00030 class Exception_t : public std::exception
00031 {
00032
00033 private:
00034
00035 std::string what_m;
00036 int line_m;
00037 std::string file_m;
00038
00039
00040
00041 public:
00042
00043
00050 Exception_t (const std::string & what,
00051 int line = 0,
00052 const std::string & file = NULL_STRING)
00053 : what_m (what), line_m (line), file_m (file)
00054 { }
00055
00056
00057
00060 ~Exception_t ( ) throw()
00061 { }
00062
00063
00064
00067 virtual const char * file ( ) const
00068 {
00069 return file_m . c_str( );
00070 }
00071
00072
00073
00076 virtual int line ( ) const
00077 {
00078 return line_m;
00079 }
00080
00081
00082
00085 virtual const char * what ( ) const throw( )
00086 {
00087 return what_m . c_str( );
00088 }
00089
00090 };
00091
00092
00093
00094
00095
00101
00102 class AlignmentException_t : public Exception_t
00103 {
00104
00105 private:
00106
00107 int a_id_m;
00108 int b_id_m;
00109
00110
00111 public:
00112
00113
00122 AlignmentException_t (const std::string & what,
00123 int line = 0,
00124 const std::string & file = NULL_STRING,
00125 int a_id = -1,
00126 int b_id = -1)
00127 : Exception_t (what, line, file), a_id_m (a_id), b_id_m (b_id)
00128 { }
00129
00130
00131
00134 virtual const int a_id ( ) const
00135 {
00136 return a_id_m;
00137 }
00138
00139
00140
00143 virtual const int b_id ( ) const
00144 {
00145 return b_id_m;
00146 }
00147
00148
00149 };
00150
00151
00152
00153
00154
00160
00161 class AllocException_t : public Exception_t
00162 {
00163
00164 public:
00165
00166
00173 AllocException_t (const std::string & what,
00174 int line = 0,
00175 const std::string & file = NULL_STRING)
00176 : Exception_t (what, line, file)
00177 { }
00178
00179 };
00180
00181
00182
00183
00184
00193
00194 class ArgumentException_t : public Exception_t
00195 {
00196
00197 public:
00198
00199
00206 ArgumentException_t (const std::string & what,
00207 int line = 0,
00208 const std::string & file = NULL_STRING)
00209 : Exception_t (what, line, file)
00210 { }
00211
00212 };
00213
00214
00215
00216
00217
00224
00225 class IOException_t : public Exception_t
00226 {
00227
00228 public:
00229
00230
00237 IOException_t (const std::string & what,
00238 int line = 0,
00239 const std::string & file = NULL_STRING)
00240 : Exception_t (what, line, file)
00241 { }
00242
00243 };
00244
00245
00246
00247
00248
00251 inline std::ostream & operator<< (std::ostream & out, const Exception_t & e)
00252 {
00253 out << "WHAT: " << e . what( ) << std::endl;
00254 out << "LINE: " << e . line( ) << std::endl;
00255 out << "FILE: " << e . file( ) << std::endl;
00256 return out;
00257 }
00258
00259
00260
00263 inline std::ostream & operator<< (std::ostream & out, const std::exception & e)
00264 {
00265 out << "WHAT: " << e . what( ) << std::endl;
00266 return out;
00267 }
00268
00269 }
00270
00271
00272
00273 #define AMOS_THROW(A) throw Exception_t(A,__LINE__,__FILE__)
00274 #define AMOS_THROW_ALLOC(A) throw AllocException_t(A,__LINE__,__FILE__)
00275 #define AMOS_THROW_ARGUMENT(A) throw ArgumentException_t(A,__LINE__,__FILE__)
00276 #define AMOS_THROW_IO(A) throw IOException_t(A,__LINE__,__FILE__)
00277
00278
00279 #endif // #ifndef __exceptions_AMOS_HH