Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
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 #include "erreurs.hpp"
00035 
00036 namespace libdar
00037 {
00038 
00041 
00043     extern const char *dar_gettext(const char *);
00044 
00046 
00052     class Egeneric
00053     {
00054     public :
00056         Egeneric(const std::string &source, const std::string &message);
00058         virtual ~Egeneric() {};
00059 
00061         virtual void stack(const std::string & passage, const std::string & message = "") { pile.push_back(niveau(passage, message)); };
00062 
00064 
00069         const std::string & get_message() const { return pile.front().objet; };
00070 
00072     const std::string & get_source() const { return pile.front().lieu; };
00073 
00075 
00078     const std::string & find_object(const std::string & location) const;
00079 
00081     void prepend_message(const std::string & context);
00082 
00086     void dump() const;
00087 
00089     std::string dump_str() const;
00090 
00091     protected :
00092         virtual std::string exceptionID() const = 0;
00093 
00094     private :
00095         struct niveau
00096         {
00097             niveau(const std::string &ou, const std::string &quoi) { lieu = ou; objet = quoi; };
00098             std::string lieu, objet;
00099         };
00100 
00101         std::list<niveau> pile;
00102 
00103     static const std::string empty_string;
00104     };
00105 
00106 
00108 
00111     class Ememory : public Egeneric
00112     {
00113     public:
00114         Ememory(const std::string &source) : Egeneric(source, dar_gettext("Lack of Memory")) {};
00115 
00116     protected:
00117         Ememory(const std::string &source, const std::string & message) : Egeneric(source, message) {};
00118         std::string exceptionID() const { return "MEMORY"; };
00119     };
00120 
00122 
00123     class Esecu_memory : public Ememory
00124     {
00125     public:
00126         Esecu_memory(const std::string &source) : Ememory(source, dar_gettext("Lack of Secured Memory")) {};
00127 
00128     protected:
00129         std::string exceptionID() const { return "SECU_MEMORY"; };
00130     };
00131 
00132 
00133 #define SRC_BUG Ebug(__FILE__, __LINE__)
00134 // #define XMT_BUG(exception, call) exception.stack(call, __FILE__, __LINE__)
00135 
00137     class Ebug : public Egeneric
00138     {
00139     public :
00140         Ebug(const std::string & file, S_I line);
00141 
00142     using Egeneric::stack; // to avoid warning with clang
00143         void stack(const std::string & passage, const std::string & file, const std::string & line);
00144 
00145     protected :
00146         std::string exceptionID() const { return "BUG"; };
00147     };
00148 
00150 
00153     class Einfinint : public Egeneric
00154     {
00155     public :
00156         Einfinint(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00157 
00158     protected :
00159         std::string exceptionID() const { return "INFININT"; };
00160     };
00161 
00163 
00166     class Elimitint : public Egeneric
00167     {
00168     public :
00169         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")) {};
00170 
00171     protected :
00172         std::string exceptionID() const { return "LIMITINT"; };
00173     };
00174 
00176 
00179     class Erange : public Egeneric
00180     {
00181     public :
00182         Erange(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00183 
00184     protected :
00185         std::string exceptionID() const { return "RANGE"; };
00186     };
00187 
00189 
00193     class Edeci : public Egeneric
00194     {
00195     public :
00196         Edeci(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00197 
00198     protected :
00199         std::string exceptionID() const { return "DECI"; };
00200     };
00201 
00203 
00206     class Efeature : public Egeneric
00207     {
00208     public :
00209         Efeature(const std::string & message) : Egeneric("", message) {};
00210 
00211     protected :
00212         std::string exceptionID() const { return "UNIMPLEMENTED FEATURE"; };
00213     };
00214 
00216 
00219     class Ehardware : public Egeneric
00220     {
00221     public :
00222         Ehardware(const std::string & source, const std::string & message) : Egeneric(source, message) {};
00223 
00224     protected :
00225         std::string exceptionID() const { return "HARDWARE ERROR"; };
00226     };
00227 
00229 
00232     class Euser_abort : public Egeneric
00233     {
00234     public :
00235         Euser_abort(const std::string & msg) : Egeneric("",msg) {};
00236 
00237     protected :
00238         std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00239     };
00240 
00241 
00243 
00246     class Edata : public Egeneric
00247     {
00248     public :
00249         Edata(const std::string & msg) : Egeneric("", msg) {};
00250 
00251     protected :
00252         std::string exceptionID() const { return "ERROR IN TREATED DATA"; };
00253     };
00254 
00256 
00259     class Escript : public Egeneric
00260     {
00261     public :
00262         Escript(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
00263 
00264     protected :
00265         std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00266     };
00267 
00269 
00272     class Elibcall : public Egeneric
00273     {
00274     public :
00275         Elibcall(const std::string & source, const std::string & msg) : Egeneric(source ,msg) {};
00276 
00277     protected :
00278         std::string exceptionID() const { return "USER ABORTED OPERATION"; };
00279     };
00280 
00282 
00285     class Ecompilation : public Egeneric
00286     {
00287     public :
00288         Ecompilation(const std::string & msg) : Egeneric("" ,msg) {};
00289 
00290     protected :
00291         std::string exceptionID() const { return "FEATURE DISABLED AT COMPILATION TIME"; };
00292     };
00293 
00294 
00296 
00297     class Ethread_cancel : public Egeneric
00298     {
00299     public:
00300     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; };
00301 
00302     bool immediate_cancel() const { return immediate; };
00303     U_64 get_flag() const { return flag; };
00304 
00305     protected:
00306     std::string exceptionID() const { return "THREAD CANCELLATION REQUESTED, ABORTING"; };
00307 
00308     private:
00309     bool immediate;
00310     U_64 flag;
00311     };
00312 
00314 
00315     class Esystem : public Egeneric
00316     {
00317     public:
00318     enum io_error
00319     {
00320         io_exist,  //< file already exists (write mode)
00321         io_absent, //< file does not exist (read mode)
00322         io_access  //< permission denied (any mode)
00323     };
00324 
00325     Esystem(const std::string & source, const std::string & message, io_error code);
00326 
00327     io_error get_code() const { return x_code; };
00328 
00329     protected:
00330     virtual std::string exceptionID() const { return "SYSTEM ERROR MET"; };
00331 
00332     private:
00333     io_error x_code;
00334     };
00335 
00336 
00338 
00339 } // end of namespace
00340 
00341 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines