Disk ARchive  2.4.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/libdar/erreurs.hpp
00001 /*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 // $Id$
00022 //
00023 /*********************************************************************/
00024 
00028 
00029 #ifndef ERREURS_HPP
00030 #define ERREURS_HPP
00031 
00032 #include "../my_config.h"
00033 #include <string>
00034 #include <list>
00035 #include "integers.hpp"
00036 
00037 namespace libdar
00038 {
00039 
00042 
00044     extern const char *dar_gettext(const char *);
00045 
00047 
00053     class Egeneric
00054     {
00055     public :
00057         Egeneric(const std::string &source, const std::string &message);
00059         virtual ~Egeneric() {};
00060 
00062         virtual void stack(const std::string & passage, const std::string & message = "") { pile.push_back(niveau(passage, message)); };
00063 
00065 
00070         const std::string & get_message() const { return pile.front().objet; };
00071 
00073         const std::string & get_source() const { return pile.front().lieu; };
00074 
00076 
00079         const std::string & find_object(const std::string & location) const;
00080 
00082         void prepend_message(const std::string & context);
00083 
00085         void dump() const;
00086 
00087     protected :
00088         virtual std::string exceptionID() const = 0;
00089 
00090     private :
00091         struct niveau
00092         {
00093             niveau(const std::string &ou, const std::string &quoi) { lieu = ou; objet = quoi; };
00094             std::string lieu, objet;
00095         };
00096 
00097         std::list<niveau> pile;
00098 
00099         static const std::string empty_string;
00100     };
00101 
00102 
00104 
00107     class Ememory : public Egeneric
00108     {
00109     public:
00110         Ememory(const std::string &source) : Egeneric(source, dar_gettext("Lack of Memory")) {};
00111 
00112     protected:
00113         Ememory(const std::string &source, const std::string & message) : Egeneric(source, message) {};
00114         std::string exceptionID() const { return "MEMORY"; };
00115     };
00116 
00118 
00119     class Esecu_memory : public Ememory
00120     {
00121     public:
00122         Esecu_memory(const std::string &source) : Ememory(source, dar_gettext("Lack of Secured Memory")) {};
00123 
00124     protected:
00125         std::string exceptionID() const { return "SECU_MEMORY"; };
00126     };
00127 
00128 
00129 #define SRC_BUG Ebug(__FILE__, __LINE__)
00130 // #define XMT_BUG(exception, call) exception.stack(call, __FILE__, __LINE__)
00131 
00133     class Ebug : public Egeneric
00134     {
00135     public :
00136         Ebug(const std::string & file, S_I line);
00137 
00138         void stack(const std::string & passage, const std::string & file, const std::string & line);
00139 
00140     protected :
00141         std::string exceptionID() const { return "BUG"; };
00142     };
00143 
00145 
00148     class Einfinint : public Egeneric
00149     {
00150     public :
00151         Einfinint(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00152 
00153     protected :
00154         std::string exceptionID() const { return "INFININT"; };
00155     };
00156 
00158 
00161     class Elimitint : public Egeneric
00162     {
00163     public :
00164         Elimitint() : Egeneric("", dar_gettext("Cannot handle such a too large integer. Use a full version of libdar (compiled to rely on the \"infinint\" integer type) to solve this problem")) {};
00165 
00166     protected :
00167         std::string exceptionID() const { return "LIMITINT"; };
00168     };
00169 
00171 
00174     class Erange : public Egeneric
00175     {
00176     public :
00177         Erange(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00178 
00179     protected :
00180         std::string exceptionID() const { return "RANGE"; };
00181     };
00182 
00184 
00188     class Edeci : public Egeneric
00189     {
00190     public :
00191         Edeci(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00192 
00193     protected :
00194         std::string exceptionID() const { return "DECI"; };
00195     };
00196 
00198 
00201     class Efeature : public Egeneric
00202     {
00203     public :
00204         Efeature(const std::string & message) : Egeneric("", message) {};
00205 
00206     protected :
00207         std::string exceptionID() const { return "UNIMPLEMENTED FEATURE"; };
00208     };
00209 
00211 
00214     class Ehardware : public Egeneric
00215     {
00216     public :
00217         Ehardware(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00218 
00219     protected :
00220         std::string exceptionID() const { return "HARDWARE ERROR"; };
00221     };
00222 
00224 
00227     class Euser_abort : public Egeneric
00228     {
00229     public :
00230         Euser_abort(const std::string & msg) : Egeneric("",msg) {};
00231 
00232     protected :
00233         std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00234     };
00235 
00236 
00238 
00241     class Edata : public Egeneric
00242     {
00243     public :
00244         Edata(const std::string & msg) : Egeneric("", msg) {};
00245 
00246     protected :
00247         std::string exceptionID() const { return "ERROR IN TREATED DATA"; };
00248     };
00249 
00251 
00254     class Escript : public Egeneric
00255     {
00256     public :
00257         Escript(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
00258 
00259     protected :
00260         std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00261     };
00262 
00264 
00267     class Elibcall : public Egeneric
00268     {
00269     public :
00270         Elibcall(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
00271 
00272     protected :
00273         std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00274     };
00275 
00277 
00280     class Ecompilation : public Egeneric
00281     {
00282     public :
00283         Ecompilation(const std::string & msg) : Egeneric("" ,msg) {};
00284 
00285     protected :
00286         std::string exceptionID() const { return "FEATURE DISABLED AT COMPILATION TIME"; };
00287     };
00288 
00289 
00291 
00292     class Ethread_cancel : public Egeneric
00293     {
00294     public:
00295         Ethread_cancel(bool now, U_64 x_flag) : Egeneric("", now ? dar_gettext("Thread cancellation requested, aborting as soon as possible") : dar_gettext("Thread cancellation requested, aborting as properly as possible")) { immediate = now; flag = x_flag; };
00296 
00297         bool immediate_cancel() const { return immediate; };
00298         U_64 get_flag() const { return flag; };
00299 
00300     protected:
00301         std::string exceptionID() const { return "THREAD CANCELLATION REQUESTED, ABORTING"; };
00302 
00303     private:
00304         bool immediate;
00305         U_64 flag;
00306     };
00307 
00308 
00310 
00311 } // end of namespace
00312 
00313 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines