1 # generate-exceptions: generate C++ files for xapian-letor's exception hierarchy.
3 # Copyright (C) 2003,2004,2006,2007,2008,2009,2011,2012,2013,2014,2015 Olly Betts
4 # Copyright (C) 2007 Richard Boulton
5 # Copyright (C) 2016 Ayush Tomar
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 use exception_data qw(
23 $copyright $generated_warning @baseclasses @classes %classcode
26 open HDR, ">include/xapian-letor/letor_error.h" or die $!;
27 open DISPATCH, ">include/xapian-letor/letor_errordispatch.h" or die $!;
30 /** @file letor_error.h
31 * @brief Hierarchy of classes which xapian-letor can throw as exceptions.
35 print HDR $generated_warning;
36 print DISPATCH $generated_warning;
39 print DISPATCH $copyright;
43 #ifndef XAPIAN_INCLUDED_LETOR_ERROR_H
44 #define XAPIAN_INCLUDED_LETOR_ERROR_H
49 #include <xapian/attributes.h>
50 #include <xapian/visibility.h>
54 /** All exceptions thrown by xapian-letor are subclasses of Xapian::Error.
56 * Xapian::Error is defined in xapian-core/include/xapian/error.h
57 * xapian-letor error subclasses simply derive from the infrastructure defined over there
64 my ($class, $parent, $comment) = split /\t/, $_, 3;
65 my $code = sprintf('\%03o', $classcode{$class});
67 print DISPATCH "case '$code': throw Xapian::$class(msg, context, error_string);\n";
72 class XAPIAN_VISIBILITY_DEFAULT $class : public $parent {
74 /** \@private \@internal
75 * \@brief Private constructor for use by remote backend.
77 * \@param error_string_ Optional string describing error. May be NULL.
79 $class(const std::string \&msg_, const std::string \&context_, const char * error_string_)
80 : $parent(msg_, context_, "$code$class", error_string_) {}
81 /** General purpose constructor.
83 * \@param msg_ Message giving details of the error, intended
84 * for human consumption.
85 * \@param context_ Optional context information for this error.
86 * \@param errno_ Optional errno value associated with this error.
88 explicit $class(const std::string \&msg_, const std::string \&context_ = std::string(), int errno_ = 0)
89 : $parent(msg_, context_, "$code$class", errno_) {}
90 /** Construct from message and errno value.
92 * \@param msg_ Message giving details of the error, intended
93 * for human consumption.
94 * \@param errno_ Optional errno value associated with this error.
96 $class(const std::string \&msg_, int errno_)
97 : $parent(msg_, std::string(), "$code$class", errno_) {}
99 /** \@private \@internal
100 * \@brief Constructor for use by constructors of derived classes.
102 $class(const std::string \&msg_, const std::string \&context_, const char * type_, const char * error_string_)
103 : $parent(msg_, context_, type_, error_string_) {}
105 /** \@private \@internal
106 * \@brief Constructor for use by constructors of derived classes.
108 $class(const std::string \&msg_, const std::string \&context_, const char * type_, int errno_)
109 : $parent(msg_, context_, type_, errno_) {}
118 #endif /* XAPIAN_INCLUDED_LETOR_ERROR_H */
121 print DISPATCH <<'EOF';
126 close DISPATCH or die $!;
128 # vim: set syntax=perl: