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
25 use File::Path qw(mkpath);
27 mkpath("include/xapian-letor");
28 open HDR, ">include/xapian-letor/letor_error.h" or die $!;
29 open DISPATCH, ">include/xapian-letor/letor_errordispatch.h" or die $!;
33 * @brief Hierarchy of classes which xapian-letor can throw as exceptions.
37 print HDR $generated_warning;
38 print DISPATCH $generated_warning;
41 print DISPATCH $copyright;
45 #ifndef XAPIAN_INCLUDED_LETOR_ERROR_H
46 #define XAPIAN_INCLUDED_LETOR_ERROR_H
51 #include <xapian/attributes.h>
52 #include <xapian/visibility.h>
56 /** All exceptions thrown by xapian-letor are subclasses of Xapian::Error.
58 * Xapian::Error is defined in xapian-core/include/xapian/error.h
59 * xapian-letor error subclasses simply derive from the infrastructure defined over there
66 my ($class, $parent, $synopsis, $description) = @{$_};
68 if ($description ne '') {
69 $description =~ s!^! * !mg;
70 $description =~ s! +$!!mg;
71 $description = " *\n" . $description;
73 my $code = sprintf('\%03o', $classcode{$class});
75 print DISPATCH "case '$code': throw Xapian::$class(msg, context, error_string);\n";
81 class XAPIAN_VISIBILITY_DEFAULT $class : public $parent {
83 /** \@private \@internal
84 * \@brief Private constructor for use by remote backend.
86 * \@param error_string_ Optional string describing error. May be NULL.
88 $class(const std::string \&msg_, const std::string \&context_, const char * error_string_)
89 : $parent(msg_, context_, "$code$class", error_string_) {}
90 /** General purpose constructor.
92 * \@param msg_ Message giving details of the error, intended
93 * for human consumption.
94 * \@param context_ Optional context information for this error.
95 * \@param errno_ Optional errno value associated with this error.
97 explicit $class(const std::string \&msg_, const std::string \&context_ = std::string(), int errno_ = 0)
98 : $parent(msg_, context_, "$code$class", errno_) {}
99 /** Construct from message and errno value.
101 * \@param msg_ Message giving details of the error, intended
102 * for human consumption.
103 * \@param errno_ Optional errno value associated with this error.
105 $class(const std::string \&msg_, int errno_)
106 : $parent(msg_, std::string(), "$code$class", errno_) {}
108 /** \@private \@internal
109 * \@brief Constructor for use by constructors of derived classes.
111 $class(const std::string \&msg_, const std::string \&context_, const char * type_, const char * error_string_)
112 : $parent(msg_, context_, type_, error_string_) {}
114 /** \@private \@internal
115 * \@brief Constructor for use by constructors of derived classes.
117 $class(const std::string \&msg_, const std::string \&context_, const char * type_, int errno_)
118 : $parent(msg_, context_, type_, errno_) {}
127 #endif /* XAPIAN_INCLUDED_LETOR_ERROR_H */
130 print DISPATCH <<'EOF';
135 close DISPATCH or die $!;
137 # vim: set syntax=perl: