Sync latest Indonesian stemmer from Snowball
[xapian.git] / xapian-letor / generate-exceptions
blobd3d60bca7c491b03473c954243f7cfe9383cbcd4
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
26 open HDR, ">include/xapian-letor/letor_error.h" or die $!;
27 open DISPATCH, ">include/xapian-letor/letor_errordispatch.h" or die $!;
29 print HDR <<'EOF';
30 /** @file letor_error.h
31  *  @brief Hierarchy of classes which xapian-letor can throw as exceptions.
32  */
33 EOF
35 print HDR $generated_warning;
36 print DISPATCH $generated_warning;
38 print HDR $copyright;
39 print DISPATCH $copyright;
41 print HDR <<'EOF';
43 #ifndef XAPIAN_INCLUDED_LETOR_ERROR_H
44 #define XAPIAN_INCLUDED_LETOR_ERROR_H
46 #include <xapian.h>
48 #include <string>
49 #include <xapian/attributes.h>
50 #include <xapian/visibility.h>
52 namespace Xapian {
54 /** All exceptions thrown by xapian-letor are subclasses of Xapian::Error.
55  *
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
58  */
60 EOF
62 for (@classes) {
63     chomp;
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";
69     print HDR <<EOF;
71 $comment
72 class XAPIAN_VISIBILITY_DEFAULT $class : public $parent {
73   public:
74     /** \@private \@internal
75      *  \@brief Private constructor for use by remote backend.
76      *
77      *  \@param error_string_   Optional string describing error.  May be NULL.
78      */
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.
82      *
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.
87      */
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.
91      *
92      *  \@param msg_            Message giving details of the error, intended
93      *                          for human consumption.
94      *  \@param errno_          Optional errno value associated with this error.
95      */
96     $class(const std::string \&msg_, int errno_)
97         : $parent(msg_, std::string(), "$code$class", errno_) {}
98   protected:
99     /** \@private \@internal
100      *  \@brief Constructor for use by constructors of derived classes.
101      */
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.
107      */
108     $class(const std::string \&msg_, const std::string \&context_, const char * type_, int errno_)
109         : $parent(msg_, context_, type_, errno_) {}
114 print HDR <<'EOF';
118 #endif /* XAPIAN_INCLUDED_LETOR_ERROR_H */
121 print DISPATCH <<'EOF';
122 #endif /* DOXYGEN */
125 close HDR or die $!;
126 close DISPATCH or die $!;
128 # vim: set syntax=perl: