#!@PERL@ -w -I @srcdir@ # @configure_input@ # # generate-exceptions.in: details of the exception heirarchy used by Xapian. # # Copyright (C) 2003,2004,2006,2007 Olly Betts # Copyright (C) 2007 Richard Boulton # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA use strict; use exception_data qw($copyright $generated_warning @baseclasses @classes); open HDR, ">include/xapian/error.h" or die $!; open DISPATCH, ">include/xapian/errordispatch.h" or die $!; print HDR <<'EOF'; /** @file error.h * @brief Hierarchy of classes which Xapian can throw as exceptions. */ EOF print HDR $generated_warning; print DISPATCH $generated_warning; print HDR $copyright; print DISPATCH $copyright; print HDR <<'EOF'; #ifndef XAPIAN_INCLUDED_ERROR_H #define XAPIAN_INCLUDED_ERROR_H #include #include #include namespace Xapian { class ErrorHandler; /** All exceptions thrown by Xapian are subclasses of Xapian::Error. * * This class can not be instantiated directly - instead a subclass should * be used. */ class XAPIAN_VISIBILITY_DEFAULT Error { // ErrorHandler needs to be able to access Error::already_handled. friend class ErrorHandler; /// Message giving details of the error, intended for human consumption. std::string msg; /** Optional context information. * * This context is intended for use by Xapian::ErrorHandler (for example * so it can know which remote server is unreliable and report the problem * and remove that server from those being searched). But it's typically * a plain-text string, and so also fit for human consumption. */ std::string context; /// The type of this error (e.g. DocNotFoundError.) const char * type; /** Optional value of 'errno' associated with this error. * * If no value is associated, this member variable will be 0. * * On UNIX, if this value is < 0, it's a negated h_errno value (giving * an error from gethostbyname() or similar). * * On Windows, if this value is < 0, it's a negated Windows error code * (as given by GetLastError() or WSAGetLastError()). * * NB We don't just call this member "errno" to avoid problems on * platforms where errno is a preprocessor macro. */ int my_errno; /** The error string derived from my_errno. * * This string is generated from my_errno lazily. */ mutable std::string error_string; /// True if this error has already been passed to an ErrorHandler. bool already_handled; /// Don't allow assignment of the base class. void operator=(const Error &o); protected: /** @private @internal * @brief Constructor for use by constructors of derived classes. */ Error(const std::string &msg_, const std::string &context_, const char * type_, const char * error_string_); /** @private @internal * @brief Constructor for use by constructors of derived classes. */ Error(const std::string &msg_, const std::string &context_, const char * type_, int errno_) : msg(msg_), context(context_), type(type_), my_errno(errno_), error_string(), already_handled(false) { } public: /// The type of this error (e.g. "DocNotFoundError".) const char * get_type() const { return type; } /// Message giving details of the error, intended for human consumption. const std::string & get_msg() const { return msg; } /** Optional context information. * * This context is intended for use by Xapian::ErrorHandler (for example * so it can know which remote server is unreliable and report the problem * and remove that server from those being searched). But it's typically * a plain-text string, and so also fit for human consumption. */ const std::string & get_context() const { return context; } /** Returns any system error string associated with this exception. * * The system error string may come from errno, h_errno (on UNIX), or * GetLastError() (on MS Windows). If there is no associated system * error string, NULL is returned. */ const char * get_error_string() const; /** Optional value of 'errno' associated with this error. * * If no 'errno' value is associated, returns 0. If the returned value * is negative, it's a platform-specific error code (on UNIX, -h_errno; * on MS Windows, -GetLastError()). * * @deprecated This method is deprecated, because errno values aren't * portable between platforms, so we can't serialise them when passing * exceptions from a remote server to a client. Use the * get_error_string() method instead. */ XAPIAN_DEPRECATED(int get_errno() const); /// Return a string describing this object. std::string get_description() const; }; inline int Xapian::Error::get_errno() const { return my_errno; } EOF print DISPATCH <<'EOF'; /* Note that this file isn't an external header - it's located in * include/xapian in the source tree because it's generated so this * is the simplest way to make inclusion work in a VPATH build. */ // DOXYGEN gets confused by this header-with-code. #ifndef DOXYGEN EOF for (@baseclasses) { chomp; my ($class, $parent, $comment) = split /\t/, $_, 3; print HDR <