Disk ARchive
2.4.5
|
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 : dar.linux@free.fr 00020 /*********************************************************************/ 00021 // $Id$ 00022 // 00023 /*********************************************************************/ 00024 00025 #ifndef ERREURS_HPP 00026 #define ERREURS_HPP 00027 00028 #pragma interface 00029 00030 #include <string> 00031 #include <list> 00032 #include "integers.hpp" 00033 00034 using namespace std; 00035 00036 #define E_BEGIN try { 00037 #define E_END(passage, message) } catch(Egeneric & e) { e.stack(passage, message); throw; } 00038 00039 class Egeneric 00040 { 00041 public : 00042 Egeneric(const string &source, const string &message); 00043 Egeneric(const Egeneric & ref); 00044 virtual ~Egeneric() { all_instances.remove(this); }; 00045 00046 virtual void stack(const string & passage, const string & message = "") { pile.push_back(niveau(passage, message)); }; 00047 string get_message() const { return pile.front().objet; }; 00048 void dump() const; 00049 00050 static U_I total() { return all_instances.size(); }; 00051 static U_I zombies() { return destroyed.size(); }; 00052 static U_I alive(); 00053 static void clear_last_destroyed(); 00054 static void display_last_destroyed(); // displays and clear the last destroyed exceptions fifo 00055 static void display_alive(); 00056 00057 protected : 00058 bool zombie; 00059 00060 virtual string exceptionID() const = 0; 00061 void add_to_last_destroyed(Egeneric *obj); 00062 00063 private : 00064 struct niveau 00065 { 00066 niveau(const string &ou, const string &quoi) { lieu = ou; objet = quoi; }; 00067 string lieu, objet; 00068 }; 00069 list<niveau> pile; 00070 00071 static const U_I fifo_size = 10; // number of last destroyed exceptions recorded 00072 static list<Egeneric *> destroyed; // copies of destroyed last execeptions 00073 static list<Egeneric *> all_instances; 00074 }; 00075 00076 class Ememory : public Egeneric 00077 { 00078 public: 00079 Ememory(const string &source) : Egeneric(source, "Lack of Memory") {}; 00080 ~Ememory() { if(!zombie) add_to_last_destroyed(new Ememory(*this)); }; 00081 00082 protected : 00083 string exceptionID() const { return "MEMORY"; }; 00084 Ememory *dup() const { return new Ememory(*this); }; 00085 }; 00086 00087 #define SRC_BUG Ebug(__FILE__, __LINE__) 00088 #define XMT_BUG(exception, call) exception.stack(call, __FILE__, __LINE__) 00089 00090 class Ebug : public Egeneric 00091 { 00092 public : 00093 Ebug(const string & file, S_I line); 00094 ~Ebug() { if(!zombie) add_to_last_destroyed(new Ebug(*this)); }; 00095 00096 void stack(const string & passage, const string & file, const string & line); 00097 protected : 00098 string exceptionID() const { return "BUG"; }; 00099 Ebug *dup() const { return new Ebug(*this); }; 00100 }; 00101 00102 class Einfinint : public Egeneric 00103 { 00104 public : 00105 Einfinint(const string & source, const string & message) : Egeneric(source, message) {}; 00106 ~Einfinint() { if(!zombie) add_to_last_destroyed(new Einfinint(*this)); }; 00107 00108 protected : 00109 string exceptionID() const { return "INFININT"; }; 00110 Einfinint *dup() const { return new Einfinint(*this); }; 00111 }; 00112 00113 class Erange : public Egeneric 00114 { 00115 public : 00116 Erange(const string & source, const string & message) : Egeneric(source, message) {}; 00117 ~Erange() { if(!zombie) add_to_last_destroyed(new Erange(*this)); }; 00118 00119 protected : 00120 string exceptionID() const { return "RANGE"; }; 00121 Erange *dup() const { return new Erange(*this); }; 00122 }; 00123 00124 class Edeci : public Egeneric 00125 { 00126 public : 00127 Edeci(const string & source, const string & message) : Egeneric(source, message) {}; 00128 ~Edeci() { if(!zombie) add_to_last_destroyed(new Edeci(*this)); }; 00129 00130 protected : 00131 string exceptionID() const { return "DECI"; }; 00132 Edeci *dup() const { return new Edeci(*this); }; 00133 }; 00134 00135 class Efeature : public Egeneric 00136 { 00137 public : 00138 Efeature(const string & message) : Egeneric("", message) {}; 00139 ~Efeature() { if(!zombie) add_to_last_destroyed(new Efeature(*this)); }; 00140 00141 protected : 00142 string exceptionID() const { return "UNIMPLEMENTED FEATURE"; }; 00143 Efeature *dup() const { return new Efeature(*this); }; 00144 }; 00145 00146 class Ehardware : public Egeneric 00147 { 00148 public : 00149 Ehardware(const string & source, const string & message) : Egeneric(source, message) {}; 00150 ~Ehardware() { if(!zombie) add_to_last_destroyed(new Ehardware(*this)); }; 00151 00152 protected : 00153 string exceptionID() const { return "HARDWARE ERROR"; }; 00154 Ehardware *dup() const { return new Ehardware(*this); }; 00155 }; 00156 00157 class Euser_abort : public Egeneric 00158 { 00159 public : 00160 Euser_abort(const string & msg) : Egeneric("",msg) {}; 00161 ~Euser_abort() { if(!zombie) add_to_last_destroyed(new Euser_abort(*this)); }; 00162 00163 protected : 00164 string exceptionID() const { return "USER ABORTED OPERATION"; }; 00165 Euser_abort *dup() const { return new Euser_abort(*this); }; 00166 }; 00167 00168 00169 class Edata : public Egeneric 00170 { 00171 public : 00172 Edata(const string & msg) : Egeneric("", msg) {}; 00173 ~Edata() { if(!zombie) add_to_last_destroyed(new Edata(*this)); }; 00174 00175 protected : 00176 string exceptionID() const { return "ERROR IN TREATED DATA"; }; 00177 Edata *dup() const { return new Edata(*this); }; 00178 }; 00179 00180 00181 class Escript : public Egeneric 00182 { 00183 public : 00184 Escript(const string & source, const string & msg) : Egeneric(source ,msg) {}; 00185 ~Escript() { if(!zombie) add_to_last_destroyed(new Escript(*this)); }; 00186 00187 protected : 00188 string exceptionID() const { return "USER ABORTED OPERATION"; }; 00189 Escript *dup() const { return new Escript(*this); }; 00190 }; 00191 00192 #endif