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 #ifndef _ERROR_REP_HH_
00026 #define _ERROR_REP_HH_
00027
00028 #include <stdlib.h>
00029 #include "matrix_global.hh"
00030
00031 #if (defined USING_VCC || (defined __GNUC__ && (__GNUC__ == 3)))
00032 #include <sstream>
00033 typedef std::ostringstream ErrorStream;
00034 #else
00035 #include <strstream>
00036 typedef ostrstream ErrorStream;
00037 #endif
00038
00041 namespace PLib {
00042
00043 struct MatrixErr {
00044 MatrixErr() { print_debug(); }
00045 void print_debug() {
00046 #ifdef VERBOSE_EXCEPTION
00047 print();
00048 #else
00049 ;
00050 #endif
00051 }
00052 virtual void print() { cerr << "Matrix error.\n" ; }
00053 };
00054
00055 struct MatrixInputError : public MatrixErr {
00056 MatrixInputError() { print_debug();}
00057 virtual void print(){
00058 cerr << "One of the input value is not in appropriate.\n";
00059 }
00060 };
00061
00062 struct OutOfBound : public MatrixInputError {
00063 int i ;
00064 int s,e ;
00065 OutOfBound(int index, int from, int to): i(index), s(from), e(to) { print_debug(); }
00066 virtual void print() {
00067 cerr << "Out of bound error, trying to access " << i <<
00068 " but the valid range is [ " << s << "," << e << "]\n" ;
00069 }
00070 };
00071
00072 struct OutOfBound2D : public MatrixInputError {
00073 int i,j ;
00074 int s_i,e_i ;
00075 int s_j,e_j ;
00076 OutOfBound2D(int I, int J, int fI, int tI, int fJ, int tJ): i(I), j(J), s_i(fI), e_i(tI), s_j(fJ), e_j(tJ) { print_debug(); }
00077 virtual void print() {
00078 cerr << "Out of bound error, trying to access (" << i << ',' << j <<
00079 ") but the valid range is ([ " << s_i << "," << e_i << "], [" <<
00080 s_j << ',' << e_j << "])\n" ;
00081 }
00082
00083 };
00084
00085 struct WrongSize : public MatrixInputError {
00086 int s1,s2 ;
00087 WrongSize(int a, int b) : s1(a), s2(b) { print_debug();}
00088 virtual void print(){
00089 cerr << "The vector sizes " << s1 << " and " << s2 << " are incompatible.\n" ;
00090 }
00091 };
00092
00093 struct WrongSize2D : public MatrixInputError {
00094 int rows,cols ;
00095 int bad_rows, bad_cols ;
00096 WrongSize2D(int r, int c, int br, int bc) : rows(r), cols(c), bad_rows(br), bad_cols(bc) { print_debug();}
00097 virtual void print(){
00098 cerr << "The matrix sizes (" << rows << " x " << cols << ") and (" << bad_rows << " x " << bad_cols << ") are incompatible.\n" ;
00099 }
00100 };
00101
00109 class Error : public ErrorStream
00110 {
00111 private:
00112 char* prog;
00113 void report(const char *msg = NULL);
00114 public:
00115 Error(): ErrorStream(), prog(0) {}
00116 Error(const char *s);
00117 ~Error(){ if (prog) delete []prog ; }
00118
00119 void warning(const char *msg = 0);
00120 void nonfatal(const char *msg = 0) { warning(msg); }
00121 void fatal(const char * = 0 );
00122 void memory(const void * = 0 );
00123
00124 };
00125
00126 }
00127
00128 #ifdef INCLUDE_TEMPLATE_SOURCE
00129 #if !(defined USING_VCC || (defined __GNUC__ && (__GNUC__ == 3)))
00130
00131 #include "error.cc"
00132 #endif
00133 #endif
00134
00135
00136
00137 #endif
00138