include/xapian/error.h

Go to the documentation of this file.
00001 
00004 /* Copyright (C) 2003,2004,2006 Olly Betts
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00019  */
00020 
00021 #ifndef XAPIAN_INCLUDED_ERROR_H
00022 #define XAPIAN_INCLUDED_ERROR_H
00023 
00024 #include <string>
00025 
00026 namespace Xapian {
00027 
00028 class ErrorHandler;
00029 
00035 class Error {
00036     // ErrorHandler needs to be able to access Error::already_handled.
00037     friend class ErrorHandler;
00038 
00040     std::string msg;
00041 
00049     std::string context;
00050 
00052     const char * type;
00053 
00061     int my_errno;
00062 
00064     bool already_handled;
00065 
00067     void operator=(const Error &o);
00068 
00069   protected:
00073     Error(const std::string &msg_, const std::string &context_,
00074           const char * type_, int errno_)
00075         : msg(msg_), context(context_), type(type_), my_errno(errno_),
00076           already_handled(false) { }
00077 
00078   public:
00080     std::string get_type() const { return std::string(type); }
00081 
00083     const std::string & get_msg() const { return msg; }
00084 
00092     const std::string & get_context() const { return context; }
00093 
00098     int get_errno() const { return my_errno; }
00099 };
00100 
00101 /* This hook is needed to allow SWIG generated-bindings to use GCC's
00102  * visibility support.  This can go away once we add GCC visibility support
00103  * to the main library.
00104  */
00105 #if defined(SWIGEXPORT) && defined(__GNUC__) && (__GNUC__ >= 4)
00106 # define XAPIAN_EXCEPTION_EXPORT SWIGEXPORT
00107 #else
00108 # define XAPIAN_EXCEPTION_EXPORT
00109 #endif
00110 
00112 #define XAPIAN_DEFINE_ERROR_BASECLASS(CLASS, PARENT) \
00113 class XAPIAN_EXCEPTION_EXPORT CLASS : public PARENT { \
00114   protected: \
00115  \
00116     CLASS(const std::string &msg_, const std::string &context_, \
00117           const char * type_, int errno_) \
00118         : PARENT(msg_, context_, type_, errno_) {} \
00119 }
00120 
00122 #define XAPIAN_DEFINE_ERROR_CLASS(CLASS, PARENT) \
00123 class XAPIAN_EXCEPTION_EXPORT CLASS : public PARENT { \
00124   public: \
00125  \
00126     CLASS(const std::string &msg_, const std::string &context_ = "", \
00127           int errno_ = 0) \
00128         : PARENT(msg_, context_, #CLASS, errno_) {} \
00129  \
00130     CLASS(const std::string &msg_, int errno_) \
00131         : PARENT(msg_, "", #CLASS, errno_) {} \
00132   protected: \
00133  \
00134     CLASS(const std::string &msg_, const std::string &context_, \
00135           const char * type_, int errno_) \
00136         : PARENT(msg_, context_, type_, errno_) {} \
00137 }
00138 
00139 #include <xapian/errortypes.h>
00140 
00141 #undef XAPIAN_DEFINE_ERROR_BASECLASS
00142 #undef XAPIAN_DEFINE_ERROR_CLASS
00143 #undef XAPIAN_EXCEPTION_EXPORT
00144 
00145 }
00146 
00147 #endif /* XAPIAN_INCLUDED_ERROR_H */

Documentation for Xapian (version 0.9.9).
Generated on 9 Nov 2006 by Doxygen 1.4.6.