Warning: this documentation for the development version is under construction.

/home/vivien/public_html/.src_seldon/share/Errors.cxx

00001 // Copyright (C) 2001-2009 Vivien Mallet
00002 //
00003 // This file is part of the linear-algebra library Seldon,
00004 // http://seldon.sourceforge.net/.
00005 //
00006 // Seldon is free software; you can redistribute it and/or modify it under the
00007 // terms of the GNU Lesser General Public License as published by the Free
00008 // Software Foundation; either version 2.1 of the License, or (at your option)
00009 // any later version.
00010 //
00011 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
00012 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
00014 // more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public License
00017 // along with Seldon. If not, see http://www.gnu.org/licenses/.
00018 
00019 
00020 #ifndef SELDON_FILE_ERRORS_CXX
00021 
00022 #include "Errors.hxx"
00023 
00024 namespace Seldon
00025 {
00026 
00027 
00029   // ERROR //
00031 
00032 
00033   /****************
00034    * CONSTRUCTORS *
00035    ****************/
00036 
00037 
00039 
00043   Error::Error(string function, string comment):
00044     description_("ERROR!\nAn undefined error occurred"),
00045     function_(function), comment_(comment)
00046   {
00047 #ifdef SELDON_WITH_ABORT
00048     this->CoutWhat();
00049     abort();
00050 #endif
00051   }
00052 
00053 
00055 
00060   Error::Error(string description, string function, string comment):
00061     description_("ERROR!\n" + description),
00062     function_(function), comment_(comment)
00063   {
00064   }
00065 
00066 
00067   /**************
00068    * DESTRUCTOR *
00069    **************/
00070 
00071 
00073 
00076   Error::~Error()
00077   {
00078   }
00079 
00080 
00081   /***********
00082    * METHODS *
00083    ***********/
00084 
00085 
00087 
00090   string Error::What()
00091   {
00092     string message(description_);
00093     if (!function_.empty())
00094       message += " in " + function_;
00095     message += ".\n";
00096     if (!comment_.empty())
00097       message += "   " + comment_;
00098     return message;
00099   }
00100 
00101 
00103 
00106   void Error::CoutWhat()
00107   {
00108     cout << this->What() << endl;
00109   }
00110 
00111 
00112 
00114   // UNDEFINED //
00116 
00117 
00119 
00123   Undefined::Undefined(string function, string comment):
00124   Error("", function, comment)
00125   {
00126 #ifdef SELDON_WITH_ABORT
00127     this->CoutWhat();
00128     abort();
00129 #endif
00130   }
00131 
00132 
00134 
00137   string Undefined::What()
00138   {
00139     string message;
00140     if (!this->function_.empty())
00141       message = this->function_;
00142     else
00143       message = "A function or a method";
00144     message += " is undefined.\nEither its implementation is missing,"
00145       + string(" or it does not make sense or it is impossible ")
00146       + "to implement it.\n";
00147     if (!this->comment_.empty())
00148       message += "   " + this->comment_;
00149     return message;
00150   }
00151 
00152 
00154   // WRONGARGUMENT //
00156 
00157 
00159 
00163   WrongArgument::WrongArgument(string function, string comment):
00164   Error("Wrong argument given to ", function, comment)
00165   {
00166 #ifdef SELDON_WITH_ABORT
00167     this->CoutWhat();
00168     abort();
00169 #endif
00170   }
00171 
00172 
00174 
00177   string WrongArgument::What()
00178   {
00179     string message(this->description_);
00180     if (!this->function_.empty())
00181       message += this->function_;
00182     message += ".\n";
00183     if (!this->comment_.empty())
00184       message += "   " + this->comment_;
00185     return message;
00186   }
00187 
00188 
00190   // NOMEMORY //
00192 
00193 
00195 
00199   NoMemory::NoMemory(string function, string comment):
00200     Error("Out of memory", function, comment)
00201   {
00202 #ifdef SELDON_WITH_ABORT
00203     this->CoutWhat();
00204     abort();
00205 #endif
00206   }
00207 
00208 
00209 
00211   // WRONGDIM //
00213 
00214 
00216 
00220   WrongDim::WrongDim(string function, string comment):
00221     Error("Wrong dimensions involved", function, comment)
00222   {
00223 #ifdef SELDON_WITH_ABORT
00224     this->CoutWhat();
00225     abort();
00226 #endif
00227   }
00228 
00229 
00230 
00232   // WRONGINDEX //
00234 
00235 
00237 
00241   WrongIndex::WrongIndex(string function, string comment):
00242     Error("Index out of range", function, comment)
00243   {
00244 #ifdef SELDON_WITH_ABORT
00245     this->CoutWhat();
00246     abort();
00247 #endif
00248   }
00249 
00250 
00251 
00253   // WRONGROW //
00255 
00256 
00258 
00262   WrongRow::WrongRow(string function, string comment):
00263     Error("Row index out of range", function, comment)
00264   {
00265 #ifdef SELDON_WITH_ABORT
00266     this->CoutWhat();
00267     abort();
00268 #endif
00269   }
00270 
00271 
00272 
00274   // WRONGCOL //
00276 
00277 
00279 
00283   WrongCol::WrongCol(string function, string comment):
00284     Error("Column index out of range", function, comment)
00285   {
00286 #ifdef SELDON_WITH_ABORT
00287     this->CoutWhat();
00288     abort();
00289 #endif
00290   }
00291 
00292 
00293 
00295   // IOERROR //
00297 
00298 
00300 
00304   IOError::IOError(string function, string comment):
00305     Error("Error while performing an I/O operation", function, comment)
00306   {
00307 #ifdef SELDON_WITH_ABORT
00308     this->CoutWhat();
00309     abort();
00310 #endif
00311   }
00312 
00313 
00314 
00316   // LAPACKERROR //
00318 
00319 
00321 
00326   LapackError::LapackError(int info, string function, string comment):
00327   Error("Error returned by Lapack", function, comment), info_(info)
00328   {
00329 #ifdef SELDON_WITH_ABORT
00330     this->CoutWhat();
00331     abort();
00332 #endif
00333   }
00334 
00335 
00337 
00340   string LapackError::What()
00341   {
00342     string message(this->description_);
00343     if (!this->function_.empty())
00344       message += " in " + this->function_;
00345     message += ".\n";
00346     if (!this->comment_.empty())
00347       message += "   " + this->comment_;
00348     message += "   Diagnostic integer (\"info\"): " + to_str(info_)
00349       + ".\n";
00350     return message;
00351   }
00352 
00353 
00355   // LAPACKINFO //
00357 
00358 
00359   LapackInfo::LapackInfo(int info): info_(info)
00360   {
00361   }
00362 
00363 
00364   LapackInfo::operator int ()
00365   {
00366     return info_;
00367   }
00368 
00369 
00370   int LapackInfo::GetInfo()
00371   {
00372     return info_;
00373   }
00374 
00375 
00376   int& LapackInfo::GetInfoRef()
00377   {
00378     return info_;
00379   }
00380 
00381 
00382 #ifndef SELDON_WITH_COMPILED_LIBRARY
00383   LapackInfo lapack_info(0);
00384 #endif
00385 
00386 
00387 } // namespace Seldon.
00388 
00389 #define SELDON_FILE_ERRORS_CXX
00390 #endif