Ticket #580: implement-error-clone.patch

File implement-error-clone.patch, 2.0 KB (added by Olly Betts, 12 years ago)

patch implementing Error::clone()

  • generate-exceptions

     
    139139     */
    140140    const char * get_error_string() const;
    141141
     142    /** Allocate and return a copy of this object. */
     143    Xapian::Error * clone() const;
     144
    142145    /// Return a string describing this object.
    143146    std::string get_description() const;
    144147};
     
    153156
    154157// DOXYGEN gets confused by this header-with-code.
    155158#ifndef DOXYGEN
     159
     160// You must define XAPIAN_DISPATCH_ERROR(CLASS) before including this file.
     161
    156162EOF
    157163
    158164for (@baseclasses) {
     
    183189    my ($class, $parent, $comment) = split /\t/, $_, 3;
    184190    my $code = sprintf('\%03o', $classcode{$class});
    185191
    186     print DISPATCH "case '$code': throw Xapian::$class(msg, context, error_string);\n";
     192    print DISPATCH "case '$code': XAPIAN_DISPATCH_ERROR($class)\n";
    187193
    188194    print HDR <<EOF;
    189195
  • net/serialise.cc

     
    109109        }
    110110
    111111        switch (type) {
     112#define XAPIAN_DISPATCH_ERROR(CLASS) throw Xapian::CLASS(msg, context, error_string);
    112113#include "xapian/errordispatch.h"
    113114        }
    114115    }
  • api/error.cc

     
    3232#include <cstdio> // For sprintf().
    3333#include <cstring> // For strerror().
    3434
     35#include "omassert.h"
    3536#include "str.h"
    3637
    3738using namespace std;
     
    103104#endif
    104105}
    105106
     107Xapian::Error *
     108Xapian::Error::clone() const
     109{
     110    switch (*type) {
     111#define XAPIAN_DISPATCH_ERROR(CLASS) \
     112        return new Xapian::CLASS(static_cast<const Xapian::CLASS &>(*this));
     113#include "xapian/errordispatch.h"
     114    }
     115    Assert(false);
     116    return NULL; // FIXME: Shouldn't get here!
     117}
     118
    106119string
    107120Xapian::Error::get_description() const
    108121{