Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

include/om/omerror.h

00001 /* omerror.h
00002  *
00003  * ----START-LICENCE----
00004  * Copyright 1999,2000,2001 BrightStation PLC
00005  * Copyright 2002 Olly Betts
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as
00009  * published by the Free Software Foundation; either version 2 of the
00010  * License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00020  * USA
00021  * -----END-LICENCE-----
00022  */
00023 
00024 #ifndef OM_HGUARD_OMERROR_H
00025 #define OM_HGUARD_OMERROR_H
00026 
00027 #include <string>
00028 
00029 #include "om/omtypes.h"
00030 
00031 class OmErrorHandler;
00032 
00034 class OmError {
00035     friend class OmErrorHandler;
00036     private:
00038         std::string msg;
00039 
00041         std::string context;
00042 
00044         std::string type;
00045 
00047         int errno_value;
00048 
00050         bool has_been_handled;
00051 
00053         void operator=(const OmError &copyme);
00054     protected:
00058         OmError(const std::string &msg_,
00059                 const std::string &context_,
00060                 const std::string &type_,
00061                 int errno_value_);
00062 
00063         OmError(const OmError &copyme)
00064                 : msg(copyme.msg),
00065                   context(copyme.context),
00066                   type(copyme.type),
00067                   errno_value(copyme.errno_value),
00068                   has_been_handled(copyme.has_been_handled) {}
00069     public:
00073         std::string get_msg() const
00074         {
00075             return msg;
00076         }
00077 
00079         std::string get_type() const
00080         {
00081             return type;
00082         }
00083 
00085         std::string get_context() const
00086         {
00087             return context;
00088         }
00089 
00091         int get_errno() const
00092         {
00093             return errno_value;
00094         }
00095 
00097         // FIXME: no longer pure virtual as that stops us throwing OmError
00098         // objects
00099         virtual ~OmError();
00100 };
00101 
00102 inline OmError::~OmError() {}
00103 
00104 #define DEFINE_ERROR_BASECLASS(a, b) \
00105 class a : public b { \
00106     protected: \
00107  \
00108         a(const std::string &msg_, \
00109           const std::string &context_, \
00110           const std::string &type_, \
00111           int errno_value_) : b(msg_, context_, type_, errno_value_) {}; \
00112 }
00113 
00114 #define DEFINE_ERROR_CLASS(a, b) \
00115 class a : public b { \
00116     public: \
00117  \
00118         a(const std::string &msg_, \
00119           const std::string &context_ = "", \
00120           int errno_value_ = 0) : b(msg_, context_, #a, errno_value_) {}; \
00121  \
00122         a(const std::string &msg_, \
00123           int errno_value_) : b(msg_, "", #a, errno_value_) {}; \
00124     protected: \
00125  \
00126         a(const std::string &msg_, \
00127           const std::string &context_, \
00128           const std::string &type_, \
00129           int errno_value_) : b(msg_, context_, type_, errno_value_) {}; \
00130 }
00131 
00132 #include "om/omerrortypes.h"
00133 
00134 #undef DEFINE_ERROR_BASECLASS
00135 #undef DEFINE_ERROR_CLASS
00136 
00137 #endif /* OM_HGUARD_OMERROR_H */

Documentation for Xapian (version 0.6.0).
Generated on 26 Nov 2002 by Doxygen 1.2.15.