Fix testcase unsupportedcheck1 for --disable-backend-remote
[xapian.git] / xapian-letor / generate-exceptions
blobbd5cfaa9a73560770067c172400fb82041b901ac
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
21 use strict;
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 $!;
31 print HDR <<'EOF';
32 /** @file
33  *  @brief Hierarchy of classes which xapian-letor can throw as exceptions.
34  */
35 EOF
37 print HDR $generated_warning;
38 print DISPATCH $generated_warning;
40 print HDR $copyright;
41 print DISPATCH $copyright;
43 print HDR <<'EOF';
45 #ifndef XAPIAN_INCLUDED_LETOR_ERROR_H
46 #define XAPIAN_INCLUDED_LETOR_ERROR_H
48 #include <xapian.h>
50 #include <string>
51 #include <xapian/attributes.h>
52 #include <xapian/visibility.h>
54 namespace Xapian {
56 /** All exceptions thrown by xapian-letor are subclasses of Xapian::Error.
57  *
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
60  */
62 EOF
64 for (@classes) {
65     chomp;
66     my ($class, $parent, $synopsis, $description) = @{$_};
67     $description //= '';
68     if ($description ne '') {
69         $description =~ s!^! *  !mg;
70         $description =~ s! +$!!mg;
71         $description = " *\n" . $description;
72     }
73     my $code = sprintf('\%03o', $classcode{$class});
75     print DISPATCH "case '$code': throw Xapian::$class(msg, context, error_string);\n";
77     print HDR <<EOF;
79 /** $synopsis
80 $description */
81 class XAPIAN_VISIBILITY_DEFAULT $class : public $parent {
82   public:
83     /** \@private \@internal
84      *  \@brief Private constructor for use by remote backend.
85      *
86      *  \@param error_string_   Optional string describing error.  May be NULL.
87      */
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.
91      *
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.
96      */
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.
100      *
101      *  \@param msg_            Message giving details of the error, intended
102      *                          for human consumption.
103      *  \@param errno_          Optional errno value associated with this error.
104      */
105     $class(const std::string \&msg_, int errno_)
106         : $parent(msg_, std::string(), "$code$class", errno_) {}
107   protected:
108     /** \@private \@internal
109      *  \@brief Constructor for use by constructors of derived classes.
110      */
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.
116      */
117     $class(const std::string \&msg_, const std::string \&context_, const char * type_, int errno_)
118         : $parent(msg_, context_, type_, errno_) {}
123 print HDR <<'EOF';
127 #endif /* XAPIAN_INCLUDED_LETOR_ERROR_H */
130 print DISPATCH <<'EOF';
131 #endif /* DOXYGEN */
134 close HDR or die $!;
135 close DISPATCH or die $!;
137 # vim: set syntax=perl: