Commit 5c93e64c authored by miloyip's avatar miloyip

Fix clang compilation

parent c1bcccb1
...@@ -38,7 +38,7 @@ struct SchemaValidationContext { ...@@ -38,7 +38,7 @@ struct SchemaValidationContext {
template <typename Encoding> template <typename Encoding>
class BaseSchema { class BaseSchema {
public: public:
typedef typename Encoding::Ch Ch; //!< Character type derived from Encoding. typedef typename Encoding::Ch Ch;
typedef SchemaValidationContext<Encoding> Context; typedef SchemaValidationContext<Encoding> Context;
BaseSchema() {} BaseSchema() {}
...@@ -46,7 +46,7 @@ public: ...@@ -46,7 +46,7 @@ public:
template <typename ValueType> template <typename ValueType>
BaseSchema(const ValueType& value) BaseSchema(const ValueType& value)
{ {
ValueType::ConstMemberIterator enumItr = value.FindMember("enum"); typename ValueType::ConstMemberIterator enumItr = value.FindMember("enum");
if (enumItr != value.MemberEnd()) { if (enumItr != value.MemberEnd()) {
if (enumItr->value.IsArray() && enumItr->value.Size() > 0) if (enumItr->value.IsArray() && enumItr->value.Size() > 0)
enum_.CopyFrom(enumItr->value, allocator_); enum_.CopyFrom(enumItr->value, allocator_);
...@@ -58,16 +58,16 @@ public: ...@@ -58,16 +58,16 @@ public:
virtual ~BaseSchema() {} virtual ~BaseSchema() {}
virtual void BeginValue(Context& context) const {} virtual void BeginValue(Context&) const {}
virtual bool Null() const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>()) : true; } virtual bool Null() const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>().Move()) : true; }
virtual bool Bool(bool b) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(b)) : true; } virtual bool Bool(bool b) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(b).Move()) : true; }
virtual bool Int(int i) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(i)) : true; } virtual bool Int(int i) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(i).Move()) : true; }
virtual bool Uint(unsigned u) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(u)) : true; } virtual bool Uint(unsigned u) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(u).Move()) : true; }
virtual bool Int64(int64_t i) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(i)) : true; } virtual bool Int64(int64_t i) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(i).Move()) : true; }
virtual bool Uint64(uint64_t u) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(u)) : true; } virtual bool Uint64(uint64_t u) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(u).Move()) : true; }
virtual bool Double(double d) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(d)) : true; } virtual bool Double(double d) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(d).Move()) : true; }
virtual bool String(const Ch* s, SizeType length, bool) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(s, length)) : true; } virtual bool String(const Ch* s, SizeType length, bool) const { return enum_.IsArray() ? CheckEnum(GenericValue<Encoding>(s, length).Move()) : true; }
virtual bool StartObject(Context&) const { return true; } virtual bool StartObject(Context&) const { return true; }
virtual bool Key(Context&, const Ch*, SizeType, bool) const { return true; } virtual bool Key(Context&, const Ch*, SizeType, bool) const { return true; }
virtual bool EndObject(Context&, SizeType) const { return true; } virtual bool EndObject(Context&, SizeType) const { return true; }
...@@ -76,7 +76,7 @@ public: ...@@ -76,7 +76,7 @@ public:
protected: protected:
bool CheckEnum(const GenericValue<Encoding>& v) const { bool CheckEnum(const GenericValue<Encoding>& v) const {
for (GenericValue<Encoding>::ConstValueIterator itr = enum_.Begin(); itr != enum_.End(); ++itr) for (typename GenericValue<Encoding>::ConstValueIterator itr = enum_.Begin(); itr != enum_.End(); ++itr)
if (v == *itr) if (v == *itr)
return true; return true;
return false; return false;
...@@ -87,30 +87,17 @@ protected: ...@@ -87,30 +87,17 @@ protected:
}; };
template <typename Encoding, typename ValueType> template <typename Encoding, typename ValueType>
inline BaseSchema<Encoding>* CreateSchema(const ValueType& value) { inline BaseSchema<Encoding>* CreateSchema(const ValueType& value);
if (!value.IsObject())
return 0;
ValueType::ConstMemberIterator typeItr = value.FindMember("type");
if (typeItr == value.MemberEnd()) return new TypelessSchema<Encoding>(value);
else if (typeItr->value == Value("null")) return new NullSchema<Encoding>(value);
else if (typeItr->value == Value("boolean")) return new BooleanSchema<Encoding>(value);
else if (typeItr->value == Value("object")) return new ObjectSchema<Encoding>(value);
else if (typeItr->value == Value("array")) return new ArraySchema<Encoding>(value);
else if (typeItr->value == Value("string")) return new StringSchema<Encoding>(value);
else if (typeItr->value == Value("integer")) return new IntegerSchema<Encoding>(value);
else if (typeItr->value == Value("number")) return new NumberSchema<Encoding>(value);
else return 0;
}
template <typename Encoding> template <typename Encoding>
class TypelessSchema : public BaseSchema<Encoding> { class TypelessSchema : public BaseSchema<Encoding> {
public: public:
typedef SchemaValidationContext<Encoding> Context;
TypelessSchema() {} TypelessSchema() {}
template <typename ValueType> template <typename ValueType>
TypelessSchema(const ValueType& value) : BaseSchema(value) {} TypelessSchema(const ValueType& value) : BaseSchema<Encoding>(value) {}
virtual void BeginValue(Context& context) const { context.valueSchema = this; } virtual void BeginValue(Context& context) const { context.valueSchema = this; }
}; };
...@@ -118,10 +105,13 @@ public: ...@@ -118,10 +105,13 @@ public:
template <typename Encoding> template <typename Encoding>
class NullSchema : public BaseSchema<Encoding> { class NullSchema : public BaseSchema<Encoding> {
public: public:
typedef typename Encoding::Ch Ch;
typedef SchemaValidationContext<Encoding> Context;
template <typename ValueType> template <typename ValueType>
NullSchema(const ValueType& value) : BaseSchema<Encoding>(value) {} NullSchema(const ValueType& value) : BaseSchema<Encoding>(value) {}
virtual bool Null() const { return BaseSchema::Null(); } virtual bool Null() const { return BaseSchema<Encoding>::Null(); }
virtual bool Bool(bool) const { return false; } virtual bool Bool(bool) const { return false; }
virtual bool Int(int) const { return false; } virtual bool Int(int) const { return false; }
virtual bool Uint(unsigned) const { return false; } virtual bool Uint(unsigned) const { return false; }
...@@ -139,22 +129,33 @@ public: ...@@ -139,22 +129,33 @@ public:
template <typename Encoding> template <typename Encoding>
class BooleanSchema : public BaseSchema<Encoding> { class BooleanSchema : public BaseSchema<Encoding> {
public: public:
typedef typename Encoding::Ch Ch;
typedef SchemaValidationContext<Encoding> Context;
template <typename ValueType> template <typename ValueType>
BooleanSchema(const ValueType& value) : BaseSchema<Encoding>(value) {} BooleanSchema(const ValueType& value) : BaseSchema<Encoding>(value) {}
virtual bool Null() const { return false; } virtual bool Null() const { return false; }
virtual bool Bool(bool b) const { return BaseSchema::Bool(b); } virtual bool Bool(bool b) const { return BaseSchema<Encoding>::Bool(b); }
virtual bool Int(int) const { return false; } virtual bool Int(int) const { return false; }
virtual bool Uint(unsigned) const { return false; } virtual bool Uint(unsigned) const { return false; }
virtual bool Int64(int64_t) const { return false; } virtual bool Int64(int64_t) const { return false; }
virtual bool Uint64(uint64_t) const { return false; } virtual bool Uint64(uint64_t) const { return false; }
virtual bool Double(double) const { return false; } virtual bool Double(double) const { return false; }
virtual bool String(const Ch*, SizeType, bool) const { return false; } virtual bool String(const Ch*, SizeType, bool) const { return false; }
virtual bool StartObject(Context&) const { return false; }
virtual bool Key(Context&, const Ch*, SizeType, bool) const { return false; }
virtual bool EndObject(Context&, SizeType) const { return false; }
virtual bool StartArray(Context&) const { return false; }
virtual bool EndArray(Context&, SizeType) const { return false; }
}; };
template <typename Encoding> template <typename Encoding>
class ObjectSchema : public BaseSchema<Encoding> { class ObjectSchema : public BaseSchema<Encoding> {
public: public:
typedef typename Encoding::Ch Ch;
typedef SchemaValidationContext<Encoding> Context;
template <typename ValueType> template <typename ValueType>
ObjectSchema(const ValueType& value) : ObjectSchema(const ValueType& value) :
BaseSchema<Encoding>(value), BaseSchema<Encoding>(value),
...@@ -166,24 +167,24 @@ public: ...@@ -166,24 +167,24 @@ public:
maxProperties_(SizeType(~0)), maxProperties_(SizeType(~0)),
additionalProperty_(true) additionalProperty_(true)
{ {
ValueType::ConstMemberIterator propretiesItr = value.FindMember(Value("properties")); typename ValueType::ConstMemberIterator propretiesItr = value.FindMember(Value("properties").Move());
if (propretiesItr != value.MemberEnd()) { if (propretiesItr != value.MemberEnd()) {
const ValueType& properties = propretiesItr->value; const ValueType& properties = propretiesItr->value;
properties_ = new Property[properties.MemberCount()]; properties_ = new Property[properties.MemberCount()];
propertyCount_ = 0; propertyCount_ = 0;
for (ValueType::ConstMemberIterator propertyItr = properties.MemberBegin(); propertyItr != properties.MemberEnd(); ++propertyItr) { for (typename ValueType::ConstMemberIterator propertyItr = properties.MemberBegin(); propertyItr != properties.MemberEnd(); ++propertyItr) {
properties_[propertyCount_].name.SetString(propertyItr->name.GetString(), propertyItr->name.GetStringLength(), allocator_); properties_[propertyCount_].name.SetString(propertyItr->name.GetString(), propertyItr->name.GetStringLength(), BaseSchema<Encoding>::allocator_);
properties_[propertyCount_].schema = CreateSchema<Encoding>(propertyItr->value); // TODO: Check error properties_[propertyCount_].schema = CreateSchema<Encoding>(propertyItr->value); // TODO: Check error
propertyCount_++; propertyCount_++;
} }
} }
// Establish required after properties // Establish required after properties
ValueType::ConstMemberIterator requiredItr = value.FindMember(Value("required")); typename ValueType::ConstMemberIterator requiredItr = value.FindMember(Value("required").Move());
if (requiredItr != value.MemberEnd()) { if (requiredItr != value.MemberEnd()) {
if (requiredItr->value.IsArray()) { if (requiredItr->value.IsArray()) {
for (ValueType::ConstValueIterator itr = requiredItr->value.Begin(); itr != requiredItr->value.End(); ++itr) { for (typename ValueType::ConstValueIterator itr = requiredItr->value.Begin(); itr != requiredItr->value.End(); ++itr) {
if (itr->IsString()) { if (itr->IsString()) {
SizeType index; SizeType index;
if (FindPropertyIndex(*itr, &index)) { if (FindPropertyIndex(*itr, &index)) {
...@@ -199,7 +200,7 @@ public: ...@@ -199,7 +200,7 @@ public:
} }
} }
ValueType::ConstMemberIterator additionalPropretiesItr = value.FindMember(Value("additionalProperties")); typename ValueType::ConstMemberIterator additionalPropretiesItr = value.FindMember(Value("additionalProperties").Move());
if (additionalPropretiesItr != value.MemberEnd()) { if (additionalPropretiesItr != value.MemberEnd()) {
if (additionalPropretiesItr->value.IsBool()) if (additionalPropretiesItr->value.IsBool())
additionalProperty_ = additionalPropretiesItr->value.GetBool(); additionalProperty_ = additionalPropretiesItr->value.GetBool();
...@@ -210,7 +211,7 @@ public: ...@@ -210,7 +211,7 @@ public:
} }
} }
ValueType::ConstMemberIterator minPropertiesItr = value.FindMember(Value("minProperties")); typename ValueType::ConstMemberIterator minPropertiesItr = value.FindMember(Value("minProperties").Move());
if (minPropertiesItr != value.MemberEnd()) { if (minPropertiesItr != value.MemberEnd()) {
if (minPropertiesItr->value.IsUint64() && minPropertiesItr->value.GetUint64() <= SizeType(~0)) if (minPropertiesItr->value.IsUint64() && minPropertiesItr->value.GetUint64() <= SizeType(~0))
minProperties_ = static_cast<SizeType>(minPropertiesItr->value.GetUint64()); minProperties_ = static_cast<SizeType>(minPropertiesItr->value.GetUint64());
...@@ -219,7 +220,7 @@ public: ...@@ -219,7 +220,7 @@ public:
} }
} }
ValueType::ConstMemberIterator maxPropertiesItr = value.FindMember(Value("maxProperties")); typename ValueType::ConstMemberIterator maxPropertiesItr = value.FindMember(Value("maxProperties").Move());
if (maxPropertiesItr != value.MemberEnd()) { if (maxPropertiesItr != value.MemberEnd()) {
if (maxPropertiesItr->value.IsUint64() && maxPropertiesItr->value.GetUint64() <= SizeType(~0)) if (maxPropertiesItr->value.IsUint64() && maxPropertiesItr->value.GetUint64() <= SizeType(~0))
maxProperties_ = static_cast<SizeType>(maxPropertiesItr->value.GetUint64()); maxProperties_ = static_cast<SizeType>(maxPropertiesItr->value.GetUint64());
...@@ -248,7 +249,7 @@ public: ...@@ -248,7 +249,7 @@ public:
return true; return true;
} }
virtual bool Key(Context& context, const Ch* str, SizeType len, bool copy) const { virtual bool Key(Context& context, const Ch* str, SizeType len, bool) const {
SizeType index; SizeType index;
if (FindPropertyIndex(str, len, &index)) { if (FindPropertyIndex(str, len, &index)) {
context.valueSchema = properties_[index].schema; context.valueSchema = properties_[index].schema;
...@@ -313,13 +314,13 @@ private: ...@@ -313,13 +314,13 @@ private:
} }
GenericValue<Encoding> name; GenericValue<Encoding> name;
BaseSchema* schema; BaseSchema<Encoding>* schema;
bool required; bool required;
}; };
TypelessSchema<Encoding> typeless_; TypelessSchema<Encoding> typeless_;
Property* properties_; Property* properties_;
BaseSchema* additionalPropertySchema_; BaseSchema<Encoding>* additionalPropertySchema_;
SizeType propertyCount_; SizeType propertyCount_;
SizeType requiredCount_; SizeType requiredCount_;
SizeType minProperties_; SizeType minProperties_;
...@@ -330,6 +331,9 @@ private: ...@@ -330,6 +331,9 @@ private:
template <typename Encoding> template <typename Encoding>
class ArraySchema : public BaseSchema<Encoding> { class ArraySchema : public BaseSchema<Encoding> {
public: public:
typedef typename Encoding::Ch Ch;
typedef SchemaValidationContext<Encoding> Context;
template <typename ValueType> template <typename ValueType>
ArraySchema(const ValueType& value) : ArraySchema(const ValueType& value) :
BaseSchema<Encoding>(value), BaseSchema<Encoding>(value),
...@@ -339,14 +343,14 @@ public: ...@@ -339,14 +343,14 @@ public:
minItems_(), minItems_(),
maxItems_(SizeType(~0)) maxItems_(SizeType(~0))
{ {
ValueType::ConstMemberIterator itemsItr = value.FindMember(Value("items")); typename ValueType::ConstMemberIterator itemsItr = value.FindMember(Value("items").Move());
if (itemsItr != value.MemberEnd()) { if (itemsItr != value.MemberEnd()) {
if (itemsItr->value.IsObject()) if (itemsItr->value.IsObject())
itemsList_ = CreateSchema<Encoding>(itemsItr->value); // List validation itemsList_ = CreateSchema<Encoding>(itemsItr->value); // List validation
else if (itemsItr->value.IsArray()) { else if (itemsItr->value.IsArray()) {
// Tuple validation // Tuple validation
itemsTuple_ = new BaseSchema*[itemsItr->value.Size()]; itemsTuple_ = new BaseSchema<Encoding>*[itemsItr->value.Size()];
for (ValueType::ConstValueIterator itr = itemsItr->value.Begin(); itr != itemsItr->value.End(); ++itr) { for (typename ValueType::ConstValueIterator itr = itemsItr->value.Begin(); itr != itemsItr->value.End(); ++itr) {
itemsTuple_[itemsTupleCount_] = CreateSchema<Encoding>(*itr); itemsTuple_[itemsTupleCount_] = CreateSchema<Encoding>(*itr);
itemsTupleCount_++; itemsTupleCount_++;
} }
...@@ -356,7 +360,7 @@ public: ...@@ -356,7 +360,7 @@ public:
} }
} }
ValueType::ConstMemberIterator minItemsItr = value.FindMember(Value("minItems")); typename ValueType::ConstMemberIterator minItemsItr = value.FindMember(Value("minItems").Move());
if (minItemsItr != value.MemberEnd()) { if (minItemsItr != value.MemberEnd()) {
if (minItemsItr->value.IsUint64() && minItemsItr->value.GetUint64() <= SizeType(~0)) if (minItemsItr->value.IsUint64() && minItemsItr->value.GetUint64() <= SizeType(~0))
minItems_ = static_cast<SizeType>(minItemsItr->value.GetUint64()); minItems_ = static_cast<SizeType>(minItemsItr->value.GetUint64());
...@@ -365,7 +369,7 @@ public: ...@@ -365,7 +369,7 @@ public:
} }
} }
ValueType::ConstMemberIterator maxItemsItr = value.FindMember(Value("maxItems")); typename ValueType::ConstMemberIterator maxItemsItr = value.FindMember(Value("maxItems").Move());
if (maxItemsItr != value.MemberEnd()) { if (maxItemsItr != value.MemberEnd()) {
if (maxItemsItr->value.IsUint64() && maxItemsItr->value.GetUint64() <= SizeType(~0)) if (maxItemsItr->value.IsUint64() && maxItemsItr->value.GetUint64() <= SizeType(~0))
maxItems_ = static_cast<SizeType>(maxItemsItr->value.GetUint64()); maxItems_ = static_cast<SizeType>(maxItemsItr->value.GetUint64());
...@@ -416,8 +420,8 @@ public: ...@@ -416,8 +420,8 @@ public:
private: private:
TypelessSchema<Encoding> typeless_; TypelessSchema<Encoding> typeless_;
BaseSchema* itemsList_; BaseSchema<Encoding>* itemsList_;
BaseSchema** itemsTuple_; BaseSchema<Encoding>** itemsTuple_;
SizeType itemsTupleCount_; SizeType itemsTupleCount_;
SizeType minItems_; SizeType minItems_;
SizeType maxItems_; SizeType maxItems_;
...@@ -426,13 +430,16 @@ private: ...@@ -426,13 +430,16 @@ private:
template <typename Encoding> template <typename Encoding>
class StringSchema : public BaseSchema<Encoding> { class StringSchema : public BaseSchema<Encoding> {
public: public:
typedef typename Encoding::Ch Ch;
typedef SchemaValidationContext<Encoding> Context;
template <typename ValueType> template <typename ValueType>
StringSchema(const ValueType& value) : StringSchema(const ValueType& value) :
BaseSchema<Encoding>(value), BaseSchema<Encoding>(value),
minLength_(0), minLength_(0),
maxLength_(~SizeType(0)) maxLength_(~SizeType(0))
{ {
ValueType::ConstMemberIterator minLengthItr = value.FindMember(Value("minLength")); typename ValueType::ConstMemberIterator minLengthItr = value.FindMember(Value("minLength").Move());
if (minLengthItr != value.MemberEnd()) { if (minLengthItr != value.MemberEnd()) {
if (minLengthItr->value.IsUint64() && minLengthItr->value.GetUint64() <= ~SizeType(0)) if (minLengthItr->value.IsUint64() && minLengthItr->value.GetUint64() <= ~SizeType(0))
minLength_ = static_cast<SizeType>(minLengthItr->value.GetUint64()); minLength_ = static_cast<SizeType>(minLengthItr->value.GetUint64());
...@@ -441,7 +448,7 @@ public: ...@@ -441,7 +448,7 @@ public:
} }
} }
ValueType::ConstMemberIterator maxLengthItr = value.FindMember(Value("maxLength")); typename ValueType::ConstMemberIterator maxLengthItr = value.FindMember(Value("maxLength").Move());
if (maxLengthItr != value.MemberEnd()) { if (maxLengthItr != value.MemberEnd()) {
if (maxLengthItr->value.IsUint64() && maxLengthItr->value.GetUint64() <= ~SizeType(0)) if (maxLengthItr->value.IsUint64() && maxLengthItr->value.GetUint64() <= ~SizeType(0))
maxLength_ = static_cast<SizeType>(maxLengthItr->value.GetUint64()); maxLength_ = static_cast<SizeType>(maxLengthItr->value.GetUint64());
...@@ -460,7 +467,7 @@ public: ...@@ -460,7 +467,7 @@ public:
virtual bool Double(double) const { return false; } virtual bool Double(double) const { return false; }
virtual bool String(const Ch* str, SizeType length, bool copy) const { virtual bool String(const Ch* str, SizeType length, bool copy) const {
return BaseSchema::String(str, length, copy) && length >= minLength_ && length <= maxLength_; return BaseSchema<Encoding>::String(str, length, copy) && length >= minLength_ && length <= maxLength_;
} }
virtual bool StartArray(Context&) const { return true; } virtual bool StartArray(Context&) const { return true; }
...@@ -474,6 +481,9 @@ private: ...@@ -474,6 +481,9 @@ private:
template <typename Encoding> template <typename Encoding>
class IntegerSchema : public BaseSchema<Encoding> { class IntegerSchema : public BaseSchema<Encoding> {
public: public:
typedef typename Encoding::Ch Ch;
typedef SchemaValidationContext<Encoding> Context;
template <typename ValueType> template <typename ValueType>
IntegerSchema(const ValueType& value) : IntegerSchema(const ValueType& value) :
BaseSchema<Encoding>(value), BaseSchema<Encoding>(value),
...@@ -481,7 +491,7 @@ public: ...@@ -481,7 +491,7 @@ public:
exclusiveMinimum_(false), exclusiveMinimum_(false),
exclusiveMaximum_(false) exclusiveMaximum_(false)
{ {
ValueType::ConstMemberIterator minimumItr = value.FindMember(Value("minimum")); typename ValueType::ConstMemberIterator minimumItr = value.FindMember(Value("minimum").Move());
if (minimumItr != value.MemberEnd()) { if (minimumItr != value.MemberEnd()) {
if (minimumItr->value.IsInt64()) if (minimumItr->value.IsInt64())
minimum_.SetInt64(minimumItr->value.GetInt64()); minimum_.SetInt64(minimumItr->value.GetInt64());
...@@ -492,7 +502,7 @@ public: ...@@ -492,7 +502,7 @@ public:
} }
} }
ValueType::ConstMemberIterator maximumItr = value.FindMember(Value("maximum")); typename ValueType::ConstMemberIterator maximumItr = value.FindMember(Value("maximum").Move());
if (maximumItr != value.MemberEnd()) { if (maximumItr != value.MemberEnd()) {
if (maximumItr->value.IsInt64()) if (maximumItr->value.IsInt64())
maximum_.SetInt64(maximumItr->value.GetInt64()); maximum_.SetInt64(maximumItr->value.GetInt64());
...@@ -503,7 +513,7 @@ public: ...@@ -503,7 +513,7 @@ public:
} }
} }
ValueType::ConstMemberIterator exclusiveMinimumItr = value.FindMember(Value("exclusiveMinimum")); typename ValueType::ConstMemberIterator exclusiveMinimumItr = value.FindMember(Value("exclusiveMinimum").Move());
if (exclusiveMinimumItr != value.MemberEnd()) { if (exclusiveMinimumItr != value.MemberEnd()) {
if (exclusiveMinimumItr->value.IsBool()) if (exclusiveMinimumItr->value.IsBool())
exclusiveMinimum_ = exclusiveMinimumItr->value.GetBool(); exclusiveMinimum_ = exclusiveMinimumItr->value.GetBool();
...@@ -512,7 +522,7 @@ public: ...@@ -512,7 +522,7 @@ public:
} }
} }
ValueType::ConstMemberIterator exclusiveMaximumItr = value.FindMember(Value("exclusiveMaximum")); typename ValueType::ConstMemberIterator exclusiveMaximumItr = value.FindMember(Value("exclusiveMaximum").Move());
if (exclusiveMaximumItr != value.MemberEnd()) { if (exclusiveMaximumItr != value.MemberEnd()) {
if (exclusiveMaximumItr->value.IsBool()) if (exclusiveMaximumItr->value.IsBool())
exclusiveMaximum_ = exclusiveMaximumItr->value.GetBool(); exclusiveMaximum_ = exclusiveMaximumItr->value.GetBool();
...@@ -521,7 +531,7 @@ public: ...@@ -521,7 +531,7 @@ public:
} }
} }
ValueType::ConstMemberIterator multipleOfItr = value.FindMember(Value("multipleOf")); typename ValueType::ConstMemberIterator multipleOfItr = value.FindMember(Value("multipleOf").Move());
if (multipleOfItr != value.MemberEnd()) { if (multipleOfItr != value.MemberEnd()) {
if (multipleOfItr->value.IsUint64()) if (multipleOfItr->value.IsUint64())
multipleOf_ = multipleOfItr->value.GetUint64(); multipleOf_ = multipleOfItr->value.GetUint64();
...@@ -534,10 +544,10 @@ public: ...@@ -534,10 +544,10 @@ public:
virtual bool Null() const { return false; } virtual bool Null() const { return false; }
virtual bool Bool(bool) const { return false; } virtual bool Bool(bool) const { return false; }
virtual bool Int(int i) const { return BaseSchema::Int64(i) && Int64(i); } virtual bool Int(int i) const { return BaseSchema<Encoding>::Int64(i) && Int64(i); }
virtual bool Uint(unsigned u) const { return BaseSchema::Uint64(u) && Uint64(u); } virtual bool Uint(unsigned u) const { return BaseSchema<Encoding>::Uint64(u) && Uint64(u); }
virtual bool Int64(int64_t i) const { return BaseSchema::Int64(i) && CheckInt64(i); } virtual bool Int64(int64_t i) const { return BaseSchema<Encoding>::Int64(i) && CheckInt64(i); }
virtual bool Uint64(uint64_t u) const { return BaseSchema::Uint64(u) && CheckUint64(u); } virtual bool Uint64(uint64_t u) const { return BaseSchema<Encoding>::Uint64(u) && CheckUint64(u); }
virtual bool Double(double) const { return false; } virtual bool Double(double) const { return false; }
virtual bool String(const Ch*, SizeType, bool) const { return false; } virtual bool String(const Ch*, SizeType, bool) const { return false; }
...@@ -615,6 +625,9 @@ private: ...@@ -615,6 +625,9 @@ private:
template <typename Encoding> template <typename Encoding>
class NumberSchema : public BaseSchema<Encoding> { class NumberSchema : public BaseSchema<Encoding> {
public: public:
typedef typename Encoding::Ch Ch;
typedef SchemaValidationContext<Encoding> Context;
template <typename ValueType> template <typename ValueType>
NumberSchema(const ValueType& value) : NumberSchema(const ValueType& value) :
BaseSchema<Encoding>(value), BaseSchema<Encoding>(value),
...@@ -625,7 +638,7 @@ public: ...@@ -625,7 +638,7 @@ public:
exclusiveMinimum_(false), exclusiveMinimum_(false),
exclusiveMaximum_(false) exclusiveMaximum_(false)
{ {
ValueType::ConstMemberIterator minimumItr = value.FindMember(Value("minimum")); typename ValueType::ConstMemberIterator minimumItr = value.FindMember(Value("minimum").Move());
if (minimumItr != value.MemberEnd()) { if (minimumItr != value.MemberEnd()) {
if (minimumItr->value.IsNumber()) if (minimumItr->value.IsNumber())
minimum_ = minimumItr->value.GetDouble(); minimum_ = minimumItr->value.GetDouble();
...@@ -634,7 +647,7 @@ public: ...@@ -634,7 +647,7 @@ public:
} }
} }
ValueType::ConstMemberIterator maximumItr = value.FindMember(Value("maximum")); typename ValueType::ConstMemberIterator maximumItr = value.FindMember(Value("maximum").Move());
if (maximumItr != value.MemberEnd()) { if (maximumItr != value.MemberEnd()) {
if (maximumItr->value.IsNumber()) if (maximumItr->value.IsNumber())
maximum_ = maximumItr->value.GetDouble(); maximum_ = maximumItr->value.GetDouble();
...@@ -643,7 +656,7 @@ public: ...@@ -643,7 +656,7 @@ public:
} }
} }
ValueType::ConstMemberIterator exclusiveMinimumItr = value.FindMember(Value("exclusiveMinimum")); typename ValueType::ConstMemberIterator exclusiveMinimumItr = value.FindMember(Value("exclusiveMinimum").Move());
if (exclusiveMinimumItr != value.MemberEnd()) { if (exclusiveMinimumItr != value.MemberEnd()) {
if (exclusiveMinimumItr->value.IsBool()) if (exclusiveMinimumItr->value.IsBool())
exclusiveMinimum_ = exclusiveMinimumItr->value.GetBool(); exclusiveMinimum_ = exclusiveMinimumItr->value.GetBool();
...@@ -652,7 +665,7 @@ public: ...@@ -652,7 +665,7 @@ public:
} }
} }
ValueType::ConstMemberIterator exclusiveMaximumItr = value.FindMember(Value("exclusiveMaximum")); typename ValueType::ConstMemberIterator exclusiveMaximumItr = value.FindMember(Value("exclusiveMaximum").Move());
if (exclusiveMaximumItr != value.MemberEnd()) { if (exclusiveMaximumItr != value.MemberEnd()) {
if (exclusiveMaximumItr->value.IsBool()) if (exclusiveMaximumItr->value.IsBool())
exclusiveMaximum_ = exclusiveMaximumItr->value.GetBool(); exclusiveMaximum_ = exclusiveMaximumItr->value.GetBool();
...@@ -661,7 +674,7 @@ public: ...@@ -661,7 +674,7 @@ public:
} }
} }
ValueType::ConstMemberIterator multipleOfItr = value.FindMember(Value("multipleOf")); typename ValueType::ConstMemberIterator multipleOfItr = value.FindMember(Value("multipleOf").Move());
if (multipleOfItr != value.MemberEnd()) { if (multipleOfItr != value.MemberEnd()) {
if (multipleOfItr->value.IsNumber()) { if (multipleOfItr->value.IsNumber()) {
multipleOf_ = multipleOfItr->value.GetDouble(); multipleOf_ = multipleOfItr->value.GetDouble();
...@@ -676,11 +689,11 @@ public: ...@@ -676,11 +689,11 @@ public:
virtual bool Null() const { return false; } virtual bool Null() const { return false; }
virtual bool Bool(bool) const { return false; } virtual bool Bool(bool) const { return false; }
virtual bool Int(int i) const { return BaseSchema::Int(i) && CheckDouble(i); } virtual bool Int(int i) const { return BaseSchema<Encoding>::Int(i) && CheckDouble(i); }
virtual bool Uint(unsigned u) const { return BaseSchema::Uint(u) && CheckDouble(u); } virtual bool Uint(unsigned u) const { return BaseSchema<Encoding>::Uint(u) && CheckDouble(u); }
virtual bool Int64(int64_t i) const { return BaseSchema::Int64(i) && CheckDouble(i); } virtual bool Int64(int64_t i) const { return BaseSchema<Encoding>::Int64(i) && CheckDouble(i); }
virtual bool Uint64(uint64_t u) const { return BaseSchema::Uint64(u) && CheckDouble(u); } virtual bool Uint64(uint64_t u) const { return BaseSchema<Encoding>::Uint64(u) && CheckDouble(u); }
virtual bool Double(double d) const { return BaseSchema::Double(d) && CheckDouble(d); } virtual bool Double(double d) const { return BaseSchema<Encoding>::Double(d) && CheckDouble(d); }
virtual bool String(const Ch*, SizeType, bool) const { return false; } virtual bool String(const Ch*, SizeType, bool) const { return false; }
virtual bool StartObject(Context&) const { return false; } virtual bool StartObject(Context&) const { return false; }
...@@ -705,15 +718,33 @@ private: ...@@ -705,15 +718,33 @@ private:
bool exclusiveMaximum_; bool exclusiveMaximum_;
}; };
template <typename Encoding, typename ValueType>
inline BaseSchema<Encoding>* CreateSchema(const ValueType& value) {
if (!value.IsObject())
return 0;
typename ValueType::ConstMemberIterator typeItr = value.FindMember("type");
if (typeItr == value.MemberEnd()) return new TypelessSchema<Encoding>(value);
else if (typeItr->value == Value("null" ).Move()) return new NullSchema<Encoding>(value);
else if (typeItr->value == Value("boolean").Move()) return new BooleanSchema<Encoding>(value);
else if (typeItr->value == Value("object" ).Move()) return new ObjectSchema<Encoding>(value);
else if (typeItr->value == Value("array" ).Move()) return new ArraySchema<Encoding>(value);
else if (typeItr->value == Value("string" ).Move()) return new StringSchema<Encoding>(value);
else if (typeItr->value == Value("integer").Move()) return new IntegerSchema<Encoding>(value);
else if (typeItr->value == Value("number" ).Move()) return new NumberSchema<Encoding>(value);
else return 0;
}
template <typename Encoding, typename Allocator = MemoryPoolAllocator<> > template <typename Encoding, typename Allocator = MemoryPoolAllocator<> >
class GenericSchema { class GenericSchema {
public: public:
template <typename Encoding, typename OutputHandler, typename Allocator> template <typename T1, typename T2, typename T3>
friend class GenericSchemaValidator; friend class GenericSchemaValidator;
template <typename DocumentType> template <typename DocumentType>
GenericSchema(const DocumentType& document) : root_() { GenericSchema(const DocumentType& document) : root_() {
root_ = CreateSchema<Encoding, DocumentType::ValueType>(document); root_ = CreateSchema<Encoding, typename DocumentType::ValueType>(document);
} }
~GenericSchema() { ~GenericSchema() {
...@@ -767,13 +798,13 @@ public: ...@@ -767,13 +798,13 @@ public:
documentStack_.Clear(); documentStack_.Clear();
}; };
bool Null() { BeginValue(); return PopSchema().Null() ? outputHandler_.Null() : false; } bool Null() { BeginValue(); return PopSchema().Null() ? outputHandler_.Null() : false; }
bool Bool(bool b) { BeginValue(); return PopSchema().Bool(b) ? outputHandler_.Bool(b) : false; } bool Bool(bool b) { BeginValue(); return PopSchema().Bool(b) ? outputHandler_.Bool(b) : false; }
bool Int(int i) { BeginValue(); return PopSchema().Int(i) ? outputHandler_.Int(i) : false; } bool Int(int i) { BeginValue(); return PopSchema().Int(i) ? outputHandler_.Int(i) : false; }
bool Uint(unsigned u) { BeginValue(); return PopSchema().Uint(u) ? outputHandler_.Uint(u) : false; } bool Uint(unsigned u) { BeginValue(); return PopSchema().Uint(u) ? outputHandler_.Uint(u) : false; }
bool Int64(int64_t i64) { BeginValue(); return PopSchema().Int64(i64) ? outputHandler_.Int64(i64) : false; } bool Int64(int64_t i64) { BeginValue(); return PopSchema().Int64(i64) ? outputHandler_.Int64(i64) : false; }
bool Uint64(uint64_t u64) { BeginValue(); return PopSchema().Uint64(u64) ? outputHandler_.Uint64(u64) : false; } bool Uint64(uint64_t u64) { BeginValue(); return PopSchema().Uint64(u64) ? outputHandler_.Uint64(u64) : false; }
bool Double(double d) { BeginValue(); return PopSchema().Double(d) ? outputHandler_.Double(d) : false; } bool Double(double d) { BeginValue(); return PopSchema().Double(d) ? outputHandler_.Double(d) : false; }
bool String(const Ch* str, SizeType length, bool copy) { BeginValue(); return PopSchema().String(str, length, copy) ? outputHandler_.String(str, length, copy) : false; } bool String(const Ch* str, SizeType length, bool copy) { BeginValue(); return PopSchema().String(str, length, copy) ? outputHandler_.String(str, length, copy) : false; }
bool StartObject() { BeginValue(); return CurrentSchema().StartObject(CurrentContext()) ? outputHandler_.StartObject() : false; } bool StartObject() { BeginValue(); return CurrentSchema().StartObject(CurrentContext()) ? outputHandler_.StartObject() : false; }
bool Key(const Ch* str, SizeType len, bool copy) { return CurrentSchema().Key(CurrentContext(), str, len, copy) ? outputHandler_.Key(str, len, copy) : false; } bool Key(const Ch* str, SizeType len, bool copy) { return CurrentSchema().Key(CurrentContext(), str, len, copy) ? outputHandler_.Key(str, len, copy) : false; }
...@@ -815,8 +846,8 @@ private: ...@@ -815,8 +846,8 @@ private:
void PushSchema(const BaseSchemaType& schema) { *schemaStack_.template Push<Context>() = Context(&schema); } void PushSchema(const BaseSchemaType& schema) { *schemaStack_.template Push<Context>() = Context(&schema); }
const BaseSchemaType& PopSchema() { return *schemaStack_.template Pop<Context>(1)->schema; } const BaseSchemaType& PopSchema() { return *schemaStack_.template Pop<Context>(1)->schema; }
const BaseSchemaType& CurrentSchema() { return *schemaStack_.Top<Context>()->schema; } const BaseSchemaType& CurrentSchema() { return *schemaStack_.template Top<Context>()->schema; }
Context& CurrentContext() { return *schemaStack_.Top<Context>(); } Context& CurrentContext() { return *schemaStack_.template Top<Context>(); }
static const size_t kDefaultSchemaStackCapacity = 256; static const size_t kDefaultSchemaStackCapacity = 256;
static const size_t kDefaultDocumentStackCapacity = 256; static const size_t kDefaultDocumentStackCapacity = 256;
......
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