Commit 3755470f authored by Philipp A. Hartmann's avatar Philipp A. Hartmann

BaseReaderHandler: allow overriding of Default() implementation

By adding an optional CRTP template parameter, the BaseReaderHandler
can call the "overridden" `Default()` function from the `Derived`
class.

See https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
parent e29a4521
......@@ -21,6 +21,11 @@
#ifndef RAPIDJSON_INTERNAL_META_H_
#define RAPIDJSON_INTERNAL_META_H_
#ifdef __GNUC__
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(effc++)
#endif
//@cond RAPIDJSON_INTERNAL
namespace rapidjson {
namespace internal {
......@@ -94,4 +99,8 @@ template <typename T> struct RemoveSfinaeFptr<SfinaeResultTag&(*)(T)> { typedef
} // namespace rapidjson
//@endcond
#ifdef __GNUC__
RAPIDJSON_DIAG_POP
#endif
#endif // RAPIDJSON_INTERNAL_META_H_
......@@ -26,6 +26,7 @@
#include "rapidjson.h"
#include "encodings.h"
#include "internal/meta.h"
#include "internal/pow10.h"
#include "internal/stack.h"
......@@ -122,23 +123,23 @@ concept Handler {
/*! This can be used as base class of any reader handler.
\note implements Handler concept
*/
template<typename Encoding = UTF8<> >
template<typename Encoding = UTF8<>, typename Derived = void>
struct BaseReaderHandler {
typedef typename Encoding::Ch Ch;
bool Default() { return true; }
bool Null() { return Default(); }
bool Bool(bool) { return Default(); }
bool Int(int) { return Default(); }
bool Uint(unsigned) { return Default(); }
bool Int64(int64_t) { return Default(); }
bool Uint64(uint64_t) { return Default(); }
bool Double(double) { return Default(); }
bool String(const Ch*, SizeType, bool) { return Default(); }
bool StartObject() { return Default(); }
bool EndObject(SizeType) { return Default(); }
bool StartArray() { return Default(); }
bool EndArray(SizeType) { return Default(); }
bool Null() { return static_cast<Override&>(*this).Default(); }
bool Bool(bool) { return static_cast<Override&>(*this).Default(); }
bool Int(int) { return static_cast<Override&>(*this).Default(); }
bool Uint(unsigned) { return static_cast<Override&>(*this).Default(); }
bool Int64(int64_t) { return static_cast<Override&>(*this).Default(); }
bool Uint64(uint64_t) { return static_cast<Override&>(*this).Default(); }
bool Double(double) { return static_cast<Override&>(*this).Default(); }
bool String(const Ch*, SizeType, bool) { return static_cast<Override&>(*this).Default(); }
bool StartObject() { return static_cast<Override&>(*this).Default(); }
bool EndObject(SizeType) { return static_cast<Override&>(*this).Default(); }
bool StartArray() { return static_cast<Override&>(*this).Default(); }
bool EndArray(SizeType) { return static_cast<Override&>(*this).Default(); }
};
///////////////////////////////////////////////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment