Disk ARchive  2.4.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
erreurs.hpp
Go to the documentation of this file.
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 
00025 
00026 #ifndef ERREURS_HPP
00027 #define ERREURS_HPP
00028 
00029 #include "../my_config.h"
00030 
00031 #include <string>
00032 #include <list>
00033 #include "integers.hpp"
00034 
00035 namespace libdar
00036 {
00037 
00040 
00042     extern const char *dar_gettext(const char *);
00043 
00045 
00051     class Egeneric
00052     {
00053     public :
00055         Egeneric(const std::string &source, const std::string &message);
00057         virtual ~Egeneric() {};
00058 
00060         virtual void stack(const std::string & passage, const std::string & message = "") { pile.push_back(niveau(passage, message)); };
00061 
00063 
00068         const std::string & get_message() const { return pile.front().objet; };
00069 
00071         const std::string & get_source() const { return pile.front().lieu; };
00072 
00074 
00077         const std::string & find_object(const std::string & location) const;
00078 
00080         void prepend_message(const std::string & context);
00081 
00083         void dump() const;
00084 
00085     protected :
00086         virtual std::string exceptionID() const = 0;
00087 
00088     private :
00089         struct niveau
00090         {
00091             niveau(const std::string &ou, const std::string &quoi) { lieu = ou; objet = quoi; };
00092             std::string lieu, objet;
00093         };
00094 
00095         std::list<niveau> pile;
00096 
00097         static const std::string empty_string;
00098     };
00099 
00100 
00102 
00105     class Ememory : public Egeneric
00106     {
00107     public:
00108         Ememory(const std::string &source) : Egeneric(source, dar_gettext("Lack of Memory")) {};
00109 
00110     protected:
00111         Ememory(const std::string &source, const std::string & message) : Egeneric(source, message) {};
00112         std::string exceptionID() const { return "MEMORY"; };
00113     };
00114 
00116 
00117     class Esecu_memory : public Ememory
00118     {
00119     public:
00120         Esecu_memory(const std::string &source) : Ememory(source, dar_gettext("Lack of Secured Memory")) {};
00121 
00122     protected:
00123         std::string exceptionID() const { return "SECU_MEMORY"; };
00124     };
00125 
00126 
00127 #define SRC_BUG Ebug(__FILE__, __LINE__)
00128 // #define XMT_BUG(exception, call) exception.stack(call, __FILE__, __LINE__)
00129 
00131     class Ebug : public Egeneric
00132     {
00133     public :
00134         Ebug(const std::string & file, S_I line);
00135 
00136         void stack(const std::string & passage, const std::string & file, const std::string & line);
00137 
00138     protected :
00139         std::string exceptionID() const { return "BUG"; };
00140     };
00141 
00143 
00146     class Einfinint : public Egeneric
00147     {
00148     public :
00149         Einfinint(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00150 
00151     protected :
00152         std::string exceptionID() const { return "INFININT"; };
00153     };
00154 
00156 
00159     class Elimitint : public Egeneric
00160     {
00161     public :
00162         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")) {};
00163 
00164     protected :
00165         std::string exceptionID() const { return "LIMITINT"; };
00166     };
00167 
00169 
00172     class Erange : public Egeneric
00173     {
00174     public :
00175         Erange(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00176 
00177     protected :
00178         std::string exceptionID() const { return "RANGE"; };
00179     };
00180 
00182 
00186     class Edeci : public Egeneric
00187     {
00188     public :
00189         Edeci(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00190 
00191     protected :
00192         std::string exceptionID() const { return "DECI"; };
00193     };
00194 
00196 
00199     class Efeature : public Egeneric
00200     {
00201     public :
00202         Efeature(const std::string & message) : Egeneric("", message) {};
00203 
00204     protected :
00205         std::string exceptionID() const { return "UNIMPLEMENTED FEATURE"; };
00206     };
00207 
00209 
00212     class Ehardware : public Egeneric
00213     {
00214     public :
00215         Ehardware(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00216 
00217     protected :
00218         std::string exceptionID() const { return "HARDWARE ERROR"; };
00219     };
00220 
00222 
00225     class Euser_abort : public Egeneric
00226     {
00227     public :
00228         Euser_abort(const std::string & msg) : Egeneric("",msg) {};
00229 
00230     protected :
00231         std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00232     };
00233 
00234 
00236 
00239     class Edata : public Egeneric
00240     {
00241     public :
00242         Edata(const std::string & msg) : Egeneric("", msg) {};
00243 
00244     protected :
00245         std::string exceptionID() const { return "ERROR IN TREATED DATA"; };
00246     };
00247 
00249 
00252     class Escript : public Egeneric
00253     {
00254     public :
00255         Escript(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
00256 
00257     protected :
00258         std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00259     };
00260 
00262 
00265     class Elibcall : public Egeneric
00266     {
00267     public :
00268         Elibcall(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
00269 
00270     protected :
00271         std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00272     };
00273 
00275 
00278     class Ecompilation : public Egeneric
00279     {
00280     public :
00281         Ecompilation(const std::string & msg) : Egeneric("" ,msg) {};
00282 
00283     protected :
00284         std::string exceptionID() const { return "FEATURE DISABLED AT COMPILATION TIME"; };
00285     };
00286 
00287 
00289 
00290     class Ethread_cancel : public Egeneric
00291     {
00292     public:
00293         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; };
00294 
00295         bool immediate_cancel() const { return immediate; };
00296         U_64 get_flag() const { return flag; };
00297 
00298     protected:
00299         std::string exceptionID() const { return "THREAD CANCELLATION REQUESTED, ABORTING"; };
00300 
00301     private:
00302         bool immediate;
00303         U_64 flag;
00304     };
00305 
00306 
00308 
00309 } // end of namespace
00310 
00311 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines