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