Errors.hxx

00001 // Copyright (C) 2003-2007, Vivien Mallet
00002 //
00003 // This file is part of SeldonData library, used for data processing.
00004 //
00005 // SeldonData is free software; you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation; either version 2 of the License, or (at your option)
00008 // any later version.
00009 //
00010 // SeldonData is distributed in the hope that it will be useful, but WITHOUT
00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 // more details.
00014 //
00015 // For more information, visit the SeldonData home page:
00016 //      http://vivienmallet.net/lib/seldondata/
00017 
00018 #ifndef FILE_SELDONDATA_ERRORS_HXX
00019 
00020 #include <iostream>
00021 using std::cout;
00022 using std::endl;
00023 #include <string>
00024 
00025 namespace SeldonData
00026 {
00027   
00029   // ERROR //
00031 
00033   class Error
00034   {
00035 
00036   protected:
00038     string function;
00040     string comment;
00041 
00042   public:
00044     Error()
00045     {
00046       cout << "ERROR!" << endl;
00047       function = "";
00048       comment = "";
00049     }
00051 
00054     Error(string f)
00055     {
00056       cout << "ERROR!" << endl;
00057       function = f;
00058       comment = "";
00059     }
00061 
00065     Error(string f, string c)
00066     {
00067       cout << "ERROR!" << endl;
00068       function = f;
00069       comment = c;
00070     }
00071 
00073     virtual ~Error()
00074     {
00075     }
00076 
00078     virtual void What()
00079     {
00080       cout << "An unknown error occured";
00081       if (function.length()!=0)
00082         cout << " in " << function;
00083       cout << "." << endl;
00084       if (comment.length()!=0)
00085         cout << "   " << comment << endl;
00086       cout << endl;
00087     }
00088   };
00089 
00090 
00091 
00093   // NOMEMORY //
00095 
00096 
00098   class NoMemory: public Error
00099   {
00100 
00101   public:
00103     NoMemory(string f, string c): Error(f, c)
00104     {
00105     }
00107     NoMemory(string f): Error(f)
00108     {
00109     }
00110 
00112     virtual void What()
00113     {
00114       cout << "No more memory is available";
00115       if (this->function!="")
00116         cout << " in " << this->function;
00117       cout << "." << endl;
00118       if (this->comment!="")
00119         cout << "   " << this->comment << endl;
00120       cout << endl;
00121     }
00122 
00123   };
00124   
00125 
00126 
00128   // WRONGDIM //
00130 
00131 
00133 
00136   class WrongDim: public Error
00137   {
00138 
00139   public:
00141     WrongDim(string f, string c): Error(f, c)
00142     {
00143     }
00144 
00146     virtual void What()
00147     {
00148       cout << "Wrong dimension";
00149       if (this->function!="")
00150         cout << " in " << this->function;
00151       cout << "." << endl;
00152       if (this->comment!="")
00153         cout << "   " << this->comment << endl;
00154       cout << endl;
00155     }
00156 
00157   };
00158   
00159 
00160 
00162   // WRONGINDEX //
00164 
00165 
00167 
00170   class WrongIndex: public Error
00171   {
00172 
00173   public:
00175     WrongIndex(string f): Error(f)
00176     {
00177     }
00179     WrongIndex(string f, string c): Error(f, c)
00180     {
00181     }
00182 
00184     virtual void What()
00185     {
00186       cout << "Index out of range";
00187       if (this->function!="")
00188         cout << " in " << this->function;
00189       cout << "." << endl;
00190       if (this->comment!="")
00191         cout << "   " << this->comment << endl;
00192       cout << endl;
00193     }
00194 
00195   };
00196   
00197 
00198 
00200   // IOERROR //
00202 
00203 
00205   class IOError: public Error
00206   {
00207 
00208   public:
00210     IOError(string f, string c): Error(f, c)
00211     {
00212     }
00213 
00215     virtual void What()
00216     {
00217       cout << "An input/output operation failed";
00218       if (this->function!="")
00219         cout << " in " << this->function;
00220       cout << "." << endl;
00221       if (this->comment!="")
00222         cout << "   " << this->comment << endl;
00223       cout << endl;
00224     }
00225 
00226   };
00227 
00228 
00229 
00231   // UNDEFINED //
00233 
00234 
00236   class Undefined: public Error
00237   {
00238 
00239   public:
00241     Undefined(string f): Error(f)
00242     {
00243     }
00245     Undefined(string f, string c): Error(f, c)
00246     {
00247     }
00248 
00250     virtual void What()
00251     {
00252       if (this->function!="")
00253         cout << "Call to undefined function " << this->function;
00254       else
00255         cout << "An undefined function was called";
00256       cout << "." << endl;
00257       if (this->comment!="")
00258         cout << "   " << this->comment << endl;
00259       cout << endl;
00260     }
00261 
00262   };
00263 
00264   
00265 }  // namespace SeldonData.
00266 
00267 
00268 #define FILE_SELDONDATA_ERRORS_HXX
00269 #endif

Generated on Tue Nov 17 11:20:52 2009 for SeldonData by  doxygen 1.5.1