IN2OSM  1.0.1
Schema< SchemaDocumentType >

#include <schema.h>

Collaboration diagram for Schema< SchemaDocumentType >:
Collaboration graph

Classes

struct  PatternProperty
 
struct  Property
 
struct  SchemaArray
 

Public Types

typedef SchemaDocumentType::ValueType ValueType
 
typedef SchemaDocumentType::AllocatorType AllocatorType
 
typedef SchemaDocumentType::PointerType PointerType
 
typedef ValueType::EncodingType EncodingType
 
typedef EncodingType::Ch Ch
 
typedef SchemaValidationContext< SchemaDocumentType > Context
 
typedef Schema< SchemaDocumentType > SchemaType
 
typedef GenericValue< EncodingType, AllocatorTypeSValue
 
typedef IValidationErrorHandler< SchemaErrorHandler
 

Public Member Functions

 Schema (SchemaDocumentType *schemaDocument, const PointerType &p, const ValueType &value, const ValueType &document, AllocatorType *allocator)
 
 ~Schema ()
 
const SValueGetURI () const
 
const PointerTypeGetPointer () const
 
bool BeginValue (Context &context) const
 
RAPIDJSON_FORCEINLINE bool EndValue (Context &context) const
 
bool Null (Context &context) const
 
bool Bool (Context &context, bool) const
 
bool Int (Context &context, int i) const
 
bool Uint (Context &context, unsigned u) const
 
bool Int64 (Context &context, int64_t i) const
 
bool Uint64 (Context &context, uint64_t u) const
 
bool Double (Context &context, double d) const
 
bool String (Context &context, const Ch *str, SizeType length, bool) const
 
bool StartObject (Context &context) const
 
bool Key (Context &context, const Ch *str, SizeType len, bool) const
 
bool EndObject (Context &context, SizeType memberCount) const
 
bool StartArray (Context &context) const
 
bool EndArray (Context &context, SizeType elementCount) const
 

Private Types

enum  SchemaValueType {
  kNullSchemaType, kBooleanSchemaType, kObjectSchemaType, kArraySchemaType,
  kStringSchemaType, kNumberSchemaType, kIntegerSchemaType, kTotalSchemaType
}
 
typedef internal::GenericRegex< EncodingType, AllocatorTypeRegexType
 

Private Member Functions

template<typename V1 , typename V2 >
void AddUniqueElement (V1 &a, const V2 &v)
 
void AssignIfExist (SchemaArray &out, SchemaDocumentType &schemaDocument, const PointerType &p, const ValueType &value, const ValueType &name, const ValueType &document)
 
template<typename ValueType >
RegexTypeCreatePattern (const ValueType &value)
 
void AddType (const ValueType &type)
 
bool CreateParallelValidator (Context &context) const
 
void CreateSchemaValidators (Context &context, const SchemaArray &schemas) const
 
bool FindPropertyIndex (const ValueType &name, SizeType *outIndex) const
 
bool CheckInt (Context &context, int64_t i) const
 
bool CheckUint (Context &context, uint64_t i) const
 
bool CheckDoubleMinimum (Context &context, double d) const
 
bool CheckDoubleMaximum (Context &context, double d) const
 
bool CheckDoubleMultipleOf (Context &context, double d) const
 
void DisallowedType (Context &context, const ValueType &actualType) const
 

Static Private Member Functions

static const ValueTypeGetMember (const ValueType &value, const ValueType &name)
 
static void AssignIfExist (bool &out, const ValueType &value, const ValueType &name)
 
static void AssignIfExist (SizeType &out, const ValueType &value, const ValueType &name)
 
static bool IsPatternMatch (const RegexType *pattern, const Ch *str, SizeType)
 

Private Attributes

AllocatorTypeallocator_
 
SValue uri_
 
PointerType pointer_
 
const SchemaTypetypeless_
 
uint64_tenum_
 
SizeType enumCount_
 
SchemaArray allOf_
 
SchemaArray anyOf_
 
SchemaArray oneOf_
 
const SchemaTypenot_
 
unsigned type_
 
SizeType validatorCount_
 
SizeType notValidatorIndex_
 
Propertyproperties_
 
const SchemaTypeadditionalPropertiesSchema_
 
PatternPropertypatternProperties_
 
SizeType patternPropertyCount_
 
SizeType propertyCount_
 
SizeType minProperties_
 
SizeType maxProperties_
 
bool additionalProperties_
 
bool hasDependencies_
 
bool hasRequired_
 
bool hasSchemaDependencies_
 
const SchemaTypeadditionalItemsSchema_
 
const SchemaTypeitemsList_
 
const SchemaType ** itemsTuple_
 
SizeType itemsTupleCount_
 
SizeType minItems_
 
SizeType maxItems_
 
bool additionalItems_
 
bool uniqueItems_
 
RegexTypepattern_
 
SizeType minLength_
 
SizeType maxLength_
 
SValue minimum_
 
SValue maximum_
 
SValue multipleOf_
 
bool exclusiveMinimum_
 
bool exclusiveMaximum_
 
SizeType defaultValueLength_
 

Friends

class GenericSchemaDocument< ValueType, AllocatorType >
 

Detailed Description

template<typename SchemaDocumentType>
class internal::Schema< SchemaDocumentType >

Definition at line 132 of file schema.h.

Member Typedef Documentation

◆ AllocatorType

typedef SchemaDocumentType::AllocatorType AllocatorType

Definition at line 399 of file schema.h.

◆ Ch

typedef EncodingType::Ch Ch

Definition at line 402 of file schema.h.

◆ Context

typedef SchemaValidationContext<SchemaDocumentType> Context

Definition at line 403 of file schema.h.

◆ EncodingType

typedef ValueType::EncodingType EncodingType

Definition at line 401 of file schema.h.

◆ ErrorHandler

Definition at line 406 of file schema.h.

◆ PointerType

typedef SchemaDocumentType::PointerType PointerType

Definition at line 400 of file schema.h.

◆ RegexType

Definition at line 1074 of file schema.h.

◆ SchemaType

typedef Schema<SchemaDocumentType> SchemaType

Definition at line 404 of file schema.h.

◆ SValue

Definition at line 405 of file schema.h.

◆ ValueType

typedef SchemaDocumentType::ValueType ValueType

Definition at line 398 of file schema.h.

Member Enumeration Documentation

◆ SchemaValueType

enum SchemaValueType
private
Enumerator
kNullSchemaType 
kBooleanSchemaType 
kObjectSchemaType 
kArraySchemaType 
kStringSchemaType 
kNumberSchemaType 
kIntegerSchemaType 
kTotalSchemaType 

Definition at line 1062 of file schema.h.

Constructor & Destructor Documentation

◆ Schema()

Schema ( SchemaDocumentType *  schemaDocument,
const PointerType p,
const ValueType value,
const ValueType document,
AllocatorType allocator 
)
inline

Definition at line 409 of file schema.h.

409  :
410  allocator_(allocator),
411  uri_(schemaDocument->GetURI(), *allocator),
412  pointer_(p, allocator),
413  typeless_(schemaDocument->GetTypeless()),
414  enum_(),
415  enumCount_(),
416  not_(),
417  type_((1 << kTotalSchemaType) - 1), // typeless
418  validatorCount_(),
420  properties_(),
424  propertyCount_(),
425  minProperties_(),
427  additionalProperties_(true),
429  hasRequired_(),
432  itemsList_(),
433  itemsTuple_(),
435  minItems_(),
436  maxItems_(SizeType(~0)),
437  additionalItems_(true),
438  uniqueItems_(false),
439  pattern_(),
440  minLength_(0),
441  maxLength_(~SizeType(0)),
442  exclusiveMinimum_(false),
443  exclusiveMaximum_(false),
445  {
446  typedef typename SchemaDocumentType::ValueType ValueType;
447  typedef typename ValueType::ConstValueIterator ConstValueIterator;
448  typedef typename ValueType::ConstMemberIterator ConstMemberIterator;
449 
450  if (!value.IsObject())
451  return;
452 
453  if (const ValueType* v = GetMember(value, GetTypeString())) {
454  type_ = 0;
455  if (v->IsString())
456  AddType(*v);
457  else if (v->IsArray())
458  for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr)
459  AddType(*itr);
460  }
461 
462  if (const ValueType* v = GetMember(value, GetEnumString()))
463  if (v->IsArray() && v->Size() > 0) {
464  enum_ = static_cast<uint64_t*>(allocator_->Malloc(sizeof(uint64_t) * v->Size()));
465  for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr) {
466  typedef Hasher<EncodingType, MemoryPoolAllocator<> > EnumHasherType;
467  char buffer[256u + 24];
468  MemoryPoolAllocator<> hasherAllocator(buffer, sizeof(buffer));
469  EnumHasherType h(&hasherAllocator, 256);
470  itr->Accept(h);
471  enum_[enumCount_++] = h.GetHashCode();
472  }
473  }
474 
475  if (schemaDocument) {
476  AssignIfExist(allOf_, *schemaDocument, p, value, GetAllOfString(), document);
477  AssignIfExist(anyOf_, *schemaDocument, p, value, GetAnyOfString(), document);
478  AssignIfExist(oneOf_, *schemaDocument, p, value, GetOneOfString(), document);
479  }
480 
481  if (const ValueType* v = GetMember(value, GetNotString())) {
482  schemaDocument->CreateSchema(&not_, p.Append(GetNotString(), allocator_), *v, document);
484  validatorCount_++;
485  }
486 
487  // Object
488 
489  const ValueType* properties = GetMember(value, GetPropertiesString());
490  const ValueType* required = GetMember(value, GetRequiredString());
491  const ValueType* dependencies = GetMember(value, GetDependenciesString());
492  {
493  // Gather properties from properties/required/dependencies
494  SValue allProperties(kArrayType);
495 
496  if (properties && properties->IsObject())
497  for (ConstMemberIterator itr = properties->MemberBegin(); itr != properties->MemberEnd(); ++itr)
498  AddUniqueElement(allProperties, itr->name);
499 
500  if (required && required->IsArray())
501  for (ConstValueIterator itr = required->Begin(); itr != required->End(); ++itr)
502  if (itr->IsString())
503  AddUniqueElement(allProperties, *itr);
504 
505  if (dependencies && dependencies->IsObject())
506  for (ConstMemberIterator itr = dependencies->MemberBegin(); itr != dependencies->MemberEnd(); ++itr) {
507  AddUniqueElement(allProperties, itr->name);
508  if (itr->value.IsArray())
509  for (ConstValueIterator i = itr->value.Begin(); i != itr->value.End(); ++i)
510  if (i->IsString())
511  AddUniqueElement(allProperties, *i);
512  }
513 
514  if (allProperties.Size() > 0) {
515  propertyCount_ = allProperties.Size();
516  properties_ = static_cast<Property*>(allocator_->Malloc(sizeof(Property) * propertyCount_));
517  for (SizeType i = 0; i < propertyCount_; i++) {
518  new (&properties_[i]) Property();
519  properties_[i].name = allProperties[i];
521  }
522  }
523  }
524 
525  if (properties && properties->IsObject()) {
526  PointerType q = p.Append(GetPropertiesString(), allocator_);
527  for (ConstMemberIterator itr = properties->MemberBegin(); itr != properties->MemberEnd(); ++itr) {
528  SizeType index;
529  if (FindPropertyIndex(itr->name, &index))
530  schemaDocument->CreateSchema(&properties_[index].schema, q.Append(itr->name, allocator_), itr->value, document);
531  }
532  }
533 
534  if (const ValueType* v = GetMember(value, GetPatternPropertiesString())) {
535  PointerType q = p.Append(GetPatternPropertiesString(), allocator_);
536  patternProperties_ = static_cast<PatternProperty*>(allocator_->Malloc(sizeof(PatternProperty) * v->MemberCount()));
538 
539  for (ConstMemberIterator itr = v->MemberBegin(); itr != v->MemberEnd(); ++itr) {
540  new (&patternProperties_[patternPropertyCount_]) PatternProperty();
542  schemaDocument->CreateSchema(&patternProperties_[patternPropertyCount_].schema, q.Append(itr->name, allocator_), itr->value, document);
544  }
545  }
546 
547  if (required && required->IsArray())
548  for (ConstValueIterator itr = required->Begin(); itr != required->End(); ++itr)
549  if (itr->IsString()) {
550  SizeType index;
551  if (FindPropertyIndex(*itr, &index)) {
552  properties_[index].required = true;
553  hasRequired_ = true;
554  }
555  }
556 
557  if (dependencies && dependencies->IsObject()) {
558  PointerType q = p.Append(GetDependenciesString(), allocator_);
559  hasDependencies_ = true;
560  for (ConstMemberIterator itr = dependencies->MemberBegin(); itr != dependencies->MemberEnd(); ++itr) {
561  SizeType sourceIndex;
562  if (FindPropertyIndex(itr->name, &sourceIndex)) {
563  if (itr->value.IsArray()) {
564  properties_[sourceIndex].dependencies = static_cast<bool*>(allocator_->Malloc(sizeof(bool) * propertyCount_));
565  std::memset(properties_[sourceIndex].dependencies, 0, sizeof(bool)* propertyCount_);
566  for (ConstValueIterator targetItr = itr->value.Begin(); targetItr != itr->value.End(); ++targetItr) {
567  SizeType targetIndex;
568  if (FindPropertyIndex(*targetItr, &targetIndex))
569  properties_[sourceIndex].dependencies[targetIndex] = true;
570  }
571  }
572  else if (itr->value.IsObject()) {
573  hasSchemaDependencies_ = true;
574  schemaDocument->CreateSchema(&properties_[sourceIndex].dependenciesSchema, q.Append(itr->name, allocator_), itr->value, document);
576  validatorCount_++;
577  }
578  }
579  }
580  }
581 
582  if (const ValueType* v = GetMember(value, GetAdditionalPropertiesString())) {
583  if (v->IsBool())
584  additionalProperties_ = v->GetBool();
585  else if (v->IsObject())
586  schemaDocument->CreateSchema(&additionalPropertiesSchema_, p.Append(GetAdditionalPropertiesString(), allocator_), *v, document);
587  }
588 
589  AssignIfExist(minProperties_, value, GetMinPropertiesString());
590  AssignIfExist(maxProperties_, value, GetMaxPropertiesString());
591 
592  // Array
593  if (const ValueType* v = GetMember(value, GetItemsString())) {
594  PointerType q = p.Append(GetItemsString(), allocator_);
595  if (v->IsObject()) // List validation
596  schemaDocument->CreateSchema(&itemsList_, q, *v, document);
597  else if (v->IsArray()) { // Tuple validation
598  itemsTuple_ = static_cast<const Schema**>(allocator_->Malloc(sizeof(const Schema*) * v->Size()));
599  SizeType index = 0;
600  for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr, index++)
601  schemaDocument->CreateSchema(&itemsTuple_[itemsTupleCount_++], q.Append(index, allocator_), *itr, document);
602  }
603  }
604 
605  AssignIfExist(minItems_, value, GetMinItemsString());
606  AssignIfExist(maxItems_, value, GetMaxItemsString());
607 
608  if (const ValueType* v = GetMember(value, GetAdditionalItemsString())) {
609  if (v->IsBool())
610  additionalItems_ = v->GetBool();
611  else if (v->IsObject())
612  schemaDocument->CreateSchema(&additionalItemsSchema_, p.Append(GetAdditionalItemsString(), allocator_), *v, document);
613  }
614 
615  AssignIfExist(uniqueItems_, value, GetUniqueItemsString());
616 
617  // String
618  AssignIfExist(minLength_, value, GetMinLengthString());
619  AssignIfExist(maxLength_, value, GetMaxLengthString());
620 
621  if (const ValueType* v = GetMember(value, GetPatternString()))
622  pattern_ = CreatePattern(*v);
623 
624  // Number
625  if (const ValueType* v = GetMember(value, GetMinimumString()))
626  if (v->IsNumber())
627  minimum_.CopyFrom(*v, *allocator_);
628 
629  if (const ValueType* v = GetMember(value, GetMaximumString()))
630  if (v->IsNumber())
631  maximum_.CopyFrom(*v, *allocator_);
632 
633  AssignIfExist(exclusiveMinimum_, value, GetExclusiveMinimumString());
634  AssignIfExist(exclusiveMaximum_, value, GetExclusiveMaximumString());
635 
636  if (const ValueType* v = GetMember(value, GetMultipleOfString()))
637  if (v->IsNumber() && v->GetDouble() > 0.0)
638  multipleOf_.CopyFrom(*v, *allocator_);
639 
640  // Default
641  if (const ValueType* v = GetMember(value, GetDefaultValueString()))
642  if (v->IsString())
643  defaultValueLength_ = v->GetStringLength();
644 
645  }
bool hasDependencies_
Definition: schema.h:1418
RegexType * pattern_
Definition: schema.h:1431
bool FindPropertyIndex(const ValueType &name, SizeType *outIndex) const
Definition: schema.h:1221
bool additionalItems_
Definition: schema.h:1428
SizeType propertyCount_
Definition: schema.h:1414
bool exclusiveMaximum_
Definition: schema.h:1439
Schema(SchemaDocumentType *schemaDocument, const PointerType &p, const ValueType &value, const ValueType &document, AllocatorType *allocator)
Definition: schema.h:409
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
static void AssignIfExist(bool &out, const ValueType &value, const ValueType &name)
Definition: schema.h:1103
SizeType maxItems_
Definition: schema.h:1427
Property * properties_
Definition: schema.h:1410
static const ValueType * GetMember(const ValueType &value, const ValueType &name)
Definition: schema.h:1098
SchemaDocumentType::PointerType PointerType
Definition: schema.h:400
SizeType minProperties_
Definition: schema.h:1415
bool hasSchemaDependencies_
Definition: schema.h:1420
SValue minimum_
Definition: schema.h:1435
SchemaDocumentType::ValueType ValueType
Definition: schema.h:398
array
Definition: rapidjson.h:647
const SchemaType * itemsList_
Definition: schema.h:1423
SchemaArray oneOf_
Definition: schema.h:1404
GenericValue< EncodingType, AllocatorType > SValue
Definition: schema.h:405
const SchemaType * typeless_
Definition: schema.h:1399
SchemaArray anyOf_
Definition: schema.h:1403
RegexType * CreatePattern(const ValueType &value)
Definition: schema.h:1132
SValue maximum_
Definition: schema.h:1436
bool uniqueItems_
Definition: schema.h:1429
unsigned type_
Definition: schema.h:1406
void AddType(const ValueType &type)
Definition: schema.h:1174
const SchemaType * schema
Definition: schema.h:1377
PatternProperty * patternProperties_
Definition: schema.h:1412
SchemaArray allOf_
Definition: schema.h:1402
bool exclusiveMinimum_
Definition: schema.h:1438
SizeType notValidatorIndex_
Definition: schema.h:1408
const SchemaType * additionalPropertiesSchema_
Definition: schema.h:1411
SizeType enumCount_
Definition: schema.h:1401
Default memory allocator used by the parser and DOM.
Definition: allocators.h:115
SizeType maxLength_
Definition: schema.h:1433
unsigned __int64 uint64_t
Definition: stdint.h:136
bool hasRequired_
Definition: schema.h:1419
SValue multipleOf_
Definition: schema.h:1437
SizeType minItems_
Definition: schema.h:1426
SizeType defaultValueLength_
Definition: schema.h:1441
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1282
void AddUniqueElement(V1 &a, const V2 &v)
Definition: schema.h:1090
bool additionalProperties_
Definition: schema.h:1417
SizeType validatorCount_
Definition: schema.h:1407
SizeType minLength_
Definition: schema.h:1432
SizeType dependenciesValidatorIndex
Definition: schema.h:1379
const SchemaType * not_
Definition: schema.h:1405
const SchemaType * additionalItemsSchema_
Definition: schema.h:1422
PointerType pointer_
Definition: schema.h:1398
SizeType maxProperties_
Definition: schema.h:1416
const SchemaType ** itemsTuple_
Definition: schema.h:1424
uint64_t * enum_
Definition: schema.h:1400
SizeType patternPropertyCount_
Definition: schema.h:1413
AllocatorType * allocator_
Definition: schema.h:1396
SizeType itemsTupleCount_
Definition: schema.h:1425

◆ ~Schema()

~Schema ( )
inline

Definition at line 647 of file schema.h.

647  {
648  AllocatorType::Free(enum_);
649  if (properties_) {
650  for (SizeType i = 0; i < propertyCount_; i++)
651  properties_[i].~Property();
652  AllocatorType::Free(properties_);
653  }
654  if (patternProperties_) {
655  for (SizeType i = 0; i < patternPropertyCount_; i++)
656  patternProperties_[i].~PatternProperty();
657  AllocatorType::Free(patternProperties_);
658  }
659  AllocatorType::Free(itemsTuple_);
660 #if RAPIDJSON_SCHEMA_HAS_REGEX
661  if (pattern_) {
662  pattern_->~RegexType();
663  AllocatorType::Free(pattern_);
664  }
665 #endif
666  }
RegexType * pattern_
Definition: schema.h:1431
SizeType propertyCount_
Definition: schema.h:1414
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
Property * properties_
Definition: schema.h:1410
PatternProperty * patternProperties_
Definition: schema.h:1412
const SchemaType ** itemsTuple_
Definition: schema.h:1424
uint64_t * enum_
Definition: schema.h:1400
SizeType patternPropertyCount_
Definition: schema.h:1413

Member Function Documentation

◆ AddType()

void AddType ( const ValueType type)
inlineprivate

Definition at line 1174 of file schema.h.

1174  {
1175  if (type == GetNullString() ) type_ |= 1 << kNullSchemaType;
1176  else if (type == GetBooleanString()) type_ |= 1 << kBooleanSchemaType;
1177  else if (type == GetObjectString() ) type_ |= 1 << kObjectSchemaType;
1178  else if (type == GetArrayString() ) type_ |= 1 << kArraySchemaType;
1179  else if (type == GetStringString() ) type_ |= 1 << kStringSchemaType;
1180  else if (type == GetIntegerString()) type_ |= 1 << kIntegerSchemaType;
1181  else if (type == GetNumberString() ) type_ |= (1 << kNumberSchemaType) | (1 << kIntegerSchemaType);
1182  }
unsigned type_
Definition: schema.h:1406

◆ AddUniqueElement()

void AddUniqueElement ( V1 &  a,
const V2 &  v 
)
inlineprivate

Definition at line 1090 of file schema.h.

1090  {
1091  for (typename V1::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr)
1092  if (*itr == v)
1093  return;
1094  V1 c(v, *allocator_);
1095  a.PushBack(c, *allocator_);
1096  }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1181
AllocatorType * allocator_
Definition: schema.h:1396

◆ AssignIfExist() [1/3]

static void AssignIfExist ( bool &  out,
const ValueType value,
const ValueType name 
)
inlinestaticprivate

Definition at line 1103 of file schema.h.

1103  {
1104  if (const ValueType* v = GetMember(value, name))
1105  if (v->IsBool())
1106  out = v->GetBool();
1107  }
static const ValueType * GetMember(const ValueType &value, const ValueType &name)
Definition: schema.h:1098
SchemaDocumentType::ValueType ValueType
Definition: schema.h:398
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1282

◆ AssignIfExist() [2/3]

static void AssignIfExist ( SizeType out,
const ValueType value,
const ValueType name 
)
inlinestaticprivate

Definition at line 1109 of file schema.h.

1109  {
1110  if (const ValueType* v = GetMember(value, name))
1111  if (v->IsUint64() && v->GetUint64() <= SizeType(~0))
1112  out = static_cast<SizeType>(v->GetUint64());
1113  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
static const ValueType * GetMember(const ValueType &value, const ValueType &name)
Definition: schema.h:1098
SchemaDocumentType::ValueType ValueType
Definition: schema.h:398
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1282

◆ AssignIfExist() [3/3]

void AssignIfExist ( SchemaArray out,
SchemaDocumentType &  schemaDocument,
const PointerType p,
const ValueType value,
const ValueType name,
const ValueType document 
)
inlineprivate

Definition at line 1115 of file schema.h.

1115  {
1116  if (const ValueType* v = GetMember(value, name)) {
1117  if (v->IsArray() && v->Size() > 0) {
1118  PointerType q = p.Append(name, allocator_);
1119  out.count = v->Size();
1120  out.schemas = static_cast<const Schema**>(allocator_->Malloc(out.count * sizeof(const Schema*)));
1121  memset(out.schemas, 0, sizeof(Schema*)* out.count);
1122  for (SizeType i = 0; i < out.count; i++)
1123  schemaDocument.CreateSchema(&out.schemas[i], q.Append(i, allocator_), (*v)[i], document);
1124  out.begin = validatorCount_;
1125  validatorCount_ += out.count;
1126  }
1127  }
1128  }
Schema(SchemaDocumentType *schemaDocument, const PointerType &p, const ValueType &value, const ValueType &document, AllocatorType *allocator)
Definition: schema.h:409
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
static const ValueType * GetMember(const ValueType &value, const ValueType &name)
Definition: schema.h:1098
SchemaDocumentType::PointerType PointerType
Definition: schema.h:400
SchemaDocumentType::ValueType ValueType
Definition: schema.h:398
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1282
SizeType validatorCount_
Definition: schema.h:1407
AllocatorType * allocator_
Definition: schema.h:1396

◆ BeginValue()

bool BeginValue ( Context context) const
inline

Definition at line 676 of file schema.h.

676  {
677  if (context.inArray) {
678  if (uniqueItems_)
679  context.valueUniqueness = true;
680 
681  if (itemsList_)
682  context.valueSchema = itemsList_;
683  else if (itemsTuple_) {
684  if (context.arrayElementIndex < itemsTupleCount_)
685  context.valueSchema = itemsTuple_[context.arrayElementIndex];
686  else if (additionalItemsSchema_)
687  context.valueSchema = additionalItemsSchema_;
688  else if (additionalItems_)
689  context.valueSchema = typeless_;
690  else {
691  context.error_handler.DisallowedItem(context.arrayElementIndex);
692  RAPIDJSON_INVALID_KEYWORD_RETURN(GetItemsString());
693  }
694  }
695  else
696  context.valueSchema = typeless_;
697 
698  context.arrayElementIndex++;
699  }
700  return true;
701  }
bool additionalItems_
Definition: schema.h:1428
const SchemaType * itemsList_
Definition: schema.h:1423
const SchemaType * typeless_
Definition: schema.h:1399
bool uniqueItems_
Definition: schema.h:1429
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
const SchemaType * additionalItemsSchema_
Definition: schema.h:1422
const SchemaType ** itemsTuple_
Definition: schema.h:1424
SizeType itemsTupleCount_
Definition: schema.h:1425
Here is the call graph for this function:

◆ Bool()

bool Bool ( Context context,
bool   
) const
inline

Definition at line 793 of file schema.h.

793  {
794  if (!(type_ & (1 << kBooleanSchemaType))) {
795  DisallowedType(context, GetBooleanString());
796  RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
797  }
798  return CreateParallelValidator(context);
799  }
bool CreateParallelValidator(Context &context) const
Definition: schema.h:1184
unsigned type_
Definition: schema.h:1406
void DisallowedType(Context &context, const ValueType &actualType) const
Definition: schema.h:1357
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116

◆ CheckDoubleMaximum()

bool CheckDoubleMaximum ( Context context,
double  d 
) const
inlineprivate

Definition at line 1338 of file schema.h.

1338  {
1339  if (exclusiveMaximum_ ? d >= maximum_.GetDouble() : d > maximum_.GetDouble()) {
1340  context.error_handler.AboveMaximum(d, maximum_, exclusiveMaximum_);
1341  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaximumString());
1342  }
1343  return true;
1344  }
bool exclusiveMaximum_
Definition: schema.h:1439
SValue maximum_
Definition: schema.h:1436
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
Here is the call graph for this function:

◆ CheckDoubleMinimum()

bool CheckDoubleMinimum ( Context context,
double  d 
) const
inlineprivate

Definition at line 1330 of file schema.h.

1330  {
1331  if (exclusiveMinimum_ ? d <= minimum_.GetDouble() : d < minimum_.GetDouble()) {
1332  context.error_handler.BelowMinimum(d, minimum_, exclusiveMinimum_);
1333  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinimumString());
1334  }
1335  return true;
1336  }
SValue minimum_
Definition: schema.h:1435
bool exclusiveMinimum_
Definition: schema.h:1438
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
Here is the call graph for this function:

◆ CheckDoubleMultipleOf()

bool CheckDoubleMultipleOf ( Context context,
double  d 
) const
inlineprivate

Definition at line 1346 of file schema.h.

1346  {
1347  double a = std::abs(d), b = std::abs(multipleOf_.GetDouble());
1348  double q = std::floor(a / b);
1349  double r = a - q * b;
1350  if (r > 0.0) {
1351  context.error_handler.NotMultipleOf(d, multipleOf_);
1352  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMultipleOfString());
1353  }
1354  return true;
1355  }
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
SValue multipleOf_
Definition: schema.h:1437
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1181
Here is the call graph for this function:

◆ CheckInt()

bool CheckInt ( Context context,
int64_t  i 
) const
inlineprivate

Definition at line 1234 of file schema.h.

1234  {
1235  if (!(type_ & ((1 << kIntegerSchemaType) | (1 << kNumberSchemaType)))) {
1236  DisallowedType(context, GetIntegerString());
1237  RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
1238  }
1239 
1240  if (!minimum_.IsNull()) {
1241  if (minimum_.IsInt64()) {
1242  if (exclusiveMinimum_ ? i <= minimum_.GetInt64() : i < minimum_.GetInt64()) {
1243  context.error_handler.BelowMinimum(i, minimum_, exclusiveMinimum_);
1244  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinimumString());
1245  }
1246  }
1247  else if (minimum_.IsUint64()) {
1248  context.error_handler.BelowMinimum(i, minimum_, exclusiveMinimum_);
1249  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinimumString()); // i <= max(int64_t) < minimum.GetUint64()
1250  }
1251  else if (!CheckDoubleMinimum(context, static_cast<double>(i)))
1252  return false;
1253  }
1254 
1255  if (!maximum_.IsNull()) {
1256  if (maximum_.IsInt64()) {
1257  if (exclusiveMaximum_ ? i >= maximum_.GetInt64() : i > maximum_.GetInt64()) {
1258  context.error_handler.AboveMaximum(i, maximum_, exclusiveMaximum_);
1259  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaximumString());
1260  }
1261  }
1262  else if (maximum_.IsUint64()) { }
1263  /* do nothing */ // i <= max(int64_t) < maximum_.GetUint64()
1264  else if (!CheckDoubleMaximum(context, static_cast<double>(i)))
1265  return false;
1266  }
1267 
1268  if (!multipleOf_.IsNull()) {
1269  if (multipleOf_.IsUint64()) {
1270  if (static_cast<uint64_t>(i >= 0 ? i : -i) % multipleOf_.GetUint64() != 0) {
1271  context.error_handler.NotMultipleOf(i, multipleOf_);
1272  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMultipleOfString());
1273  }
1274  }
1275  else if (!CheckDoubleMultipleOf(context, static_cast<double>(i)))
1276  return false;
1277  }
1278 
1279  return true;
1280  }
bool exclusiveMaximum_
Definition: schema.h:1439
SValue minimum_
Definition: schema.h:1435
bool CheckDoubleMinimum(Context &context, double d) const
Definition: schema.h:1330
SValue maximum_
Definition: schema.h:1436
unsigned type_
Definition: schema.h:1406
bool exclusiveMinimum_
Definition: schema.h:1438
void DisallowedType(Context &context, const ValueType &actualType) const
Definition: schema.h:1357
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
SValue multipleOf_
Definition: schema.h:1437
bool CheckDoubleMultipleOf(Context &context, double d) const
Definition: schema.h:1346
bool CheckDoubleMaximum(Context &context, double d) const
Definition: schema.h:1338
Here is the call graph for this function:

◆ CheckUint()

bool CheckUint ( Context context,
uint64_t  i 
) const
inlineprivate

Definition at line 1282 of file schema.h.

1282  {
1283  if (!(type_ & ((1 << kIntegerSchemaType) | (1 << kNumberSchemaType)))) {
1284  DisallowedType(context, GetIntegerString());
1285  RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
1286  }
1287 
1288  if (!minimum_.IsNull()) {
1289  if (minimum_.IsUint64()) {
1290  if (exclusiveMinimum_ ? i <= minimum_.GetUint64() : i < minimum_.GetUint64()) {
1291  context.error_handler.BelowMinimum(i, minimum_, exclusiveMinimum_);
1292  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinimumString());
1293  }
1294  }
1295  else if (minimum_.IsInt64())
1296  /* do nothing */; // i >= 0 > minimum.Getint64()
1297  else if (!CheckDoubleMinimum(context, static_cast<double>(i)))
1298  return false;
1299  }
1300 
1301  if (!maximum_.IsNull()) {
1302  if (maximum_.IsUint64()) {
1303  if (exclusiveMaximum_ ? i >= maximum_.GetUint64() : i > maximum_.GetUint64()) {
1304  context.error_handler.AboveMaximum(i, maximum_, exclusiveMaximum_);
1305  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaximumString());
1306  }
1307  }
1308  else if (maximum_.IsInt64()) {
1309  context.error_handler.AboveMaximum(i, maximum_, exclusiveMaximum_);
1310  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaximumString()); // i >= 0 > maximum_
1311  }
1312  else if (!CheckDoubleMaximum(context, static_cast<double>(i)))
1313  return false;
1314  }
1315 
1316  if (!multipleOf_.IsNull()) {
1317  if (multipleOf_.IsUint64()) {
1318  if (i % multipleOf_.GetUint64() != 0) {
1319  context.error_handler.NotMultipleOf(i, multipleOf_);
1320  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMultipleOfString());
1321  }
1322  }
1323  else if (!CheckDoubleMultipleOf(context, static_cast<double>(i)))
1324  return false;
1325  }
1326 
1327  return true;
1328  }
bool exclusiveMaximum_
Definition: schema.h:1439
SValue minimum_
Definition: schema.h:1435
bool CheckDoubleMinimum(Context &context, double d) const
Definition: schema.h:1330
SValue maximum_
Definition: schema.h:1436
unsigned type_
Definition: schema.h:1406
bool exclusiveMinimum_
Definition: schema.h:1438
void DisallowedType(Context &context, const ValueType &actualType) const
Definition: schema.h:1357
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
SValue multipleOf_
Definition: schema.h:1437
bool CheckDoubleMultipleOf(Context &context, double d) const
Definition: schema.h:1346
bool CheckDoubleMaximum(Context &context, double d) const
Definition: schema.h:1338
Here is the call graph for this function:

◆ CreateParallelValidator()

bool CreateParallelValidator ( Context context) const
inlineprivate

Definition at line 1184 of file schema.h.

1184  {
1185  if (enum_ || context.arrayUniqueness)
1186  context.hasher = context.factory.CreateHasher();
1187 
1188  if (validatorCount_) {
1189  RAPIDJSON_ASSERT(context.validators == 0);
1190  context.validators = static_cast<ISchemaValidator**>(context.factory.MallocState(sizeof(ISchemaValidator*) * validatorCount_));
1191  context.validatorCount = validatorCount_;
1192 
1193  if (allOf_.schemas)
1194  CreateSchemaValidators(context, allOf_);
1195 
1196  if (anyOf_.schemas)
1197  CreateSchemaValidators(context, anyOf_);
1198 
1199  if (oneOf_.schemas)
1200  CreateSchemaValidators(context, oneOf_);
1201 
1202  if (not_)
1203  context.validators[notValidatorIndex_] = context.factory.CreateSchemaValidator(*not_);
1204 
1205  if (hasSchemaDependencies_) {
1206  for (SizeType i = 0; i < propertyCount_; i++)
1207  if (properties_[i].dependenciesSchema)
1208  context.validators[properties_[i].dependenciesValidatorIndex] = context.factory.CreateSchemaValidator(*properties_[i].dependenciesSchema);
1209  }
1210  }
1211 
1212  return true;
1213  }
SizeType propertyCount_
Definition: schema.h:1414
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
Property * properties_
Definition: schema.h:1410
bool hasSchemaDependencies_
Definition: schema.h:1420
SchemaArray oneOf_
Definition: schema.h:1404
const SchemaType ** schemas
Definition: schema.h:1084
SchemaArray anyOf_
Definition: schema.h:1403
SchemaArray allOf_
Definition: schema.h:1402
SizeType notValidatorIndex_
Definition: schema.h:1408
void CreateSchemaValidators(Context &context, const SchemaArray &schemas) const
Definition: schema.h:1215
SizeType validatorCount_
Definition: schema.h:1407
SizeType dependenciesValidatorIndex
Definition: schema.h:1379
const SchemaType * not_
Definition: schema.h:1405
uint64_t * enum_
Definition: schema.h:1400
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:406
Here is the call graph for this function:

◆ CreatePattern()

RegexType* CreatePattern ( const ValueType value)
inlineprivate

Definition at line 1132 of file schema.h.

1132  {
1133  if (value.IsString()) {
1134  RegexType* r = new (allocator_->Malloc(sizeof(RegexType))) RegexType(value.GetString(), allocator_);
1135  if (!r->IsValid()) {
1136  r->~RegexType();
1137  AllocatorType::Free(r);
1138  r = 0;
1139  }
1140  return r;
1141  }
1142  return 0;
1143  }
internal::GenericRegex< EncodingType, AllocatorType > RegexType
Definition: schema.h:1074
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1282
AllocatorType * allocator_
Definition: schema.h:1396
Here is the call graph for this function:

◆ CreateSchemaValidators()

void CreateSchemaValidators ( Context context,
const SchemaArray schemas 
) const
inlineprivate

Definition at line 1215 of file schema.h.

1215  {
1216  for (SizeType i = 0; i < schemas.count; i++)
1217  context.validators[schemas.begin + i] = context.factory.CreateSchemaValidator(*schemas.schemas[i]);
1218  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
Here is the call graph for this function:

◆ DisallowedType()

void DisallowedType ( Context context,
const ValueType actualType 
) const
inlineprivate

Definition at line 1357 of file schema.h.

1357  {
1358  ErrorHandler& eh = context.error_handler;
1359  eh.StartDisallowedType();
1360 
1361  if (type_ & (1 << kNullSchemaType)) eh.AddExpectedType(GetNullString());
1362  if (type_ & (1 << kBooleanSchemaType)) eh.AddExpectedType(GetBooleanString());
1363  if (type_ & (1 << kObjectSchemaType)) eh.AddExpectedType(GetObjectString());
1364  if (type_ & (1 << kArraySchemaType)) eh.AddExpectedType(GetArrayString());
1365  if (type_ & (1 << kStringSchemaType)) eh.AddExpectedType(GetStringString());
1366 
1367  if (type_ & (1 << kNumberSchemaType)) eh.AddExpectedType(GetNumberString());
1368  else if (type_ & (1 << kIntegerSchemaType)) eh.AddExpectedType(GetIntegerString());
1369 
1370  eh.EndDisallowedType(actualType);
1371  }
unsigned type_
Definition: schema.h:1406
IValidationErrorHandler< Schema > ErrorHandler
Definition: schema.h:406
Here is the call graph for this function:

◆ Double()

bool Double ( Context context,
double  d 
) const
inline

Definition at line 825 of file schema.h.

825  {
826  if (!(type_ & (1 << kNumberSchemaType))) {
827  DisallowedType(context, GetNumberString());
828  RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
829  }
830 
831  if (!minimum_.IsNull() && !CheckDoubleMinimum(context, d))
832  return false;
833 
834  if (!maximum_.IsNull() && !CheckDoubleMaximum(context, d))
835  return false;
836 
837  if (!multipleOf_.IsNull() && !CheckDoubleMultipleOf(context, d))
838  return false;
839 
840  return CreateParallelValidator(context);
841  }
SValue minimum_
Definition: schema.h:1435
bool CheckDoubleMinimum(Context &context, double d) const
Definition: schema.h:1330
bool CreateParallelValidator(Context &context) const
Definition: schema.h:1184
SValue maximum_
Definition: schema.h:1436
unsigned type_
Definition: schema.h:1406
void DisallowedType(Context &context, const ValueType &actualType) const
Definition: schema.h:1357
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
SValue multipleOf_
Definition: schema.h:1437
bool CheckDoubleMultipleOf(Context &context, double d) const
Definition: schema.h:1346
bool CheckDoubleMaximum(Context &context, double d) const
Definition: schema.h:1338

◆ EndArray()

bool EndArray ( Context context,
SizeType  elementCount 
) const
inline

Definition at line 1000 of file schema.h.

1000  {
1001  context.inArray = false;
1002 
1003  if (elementCount < minItems_) {
1004  context.error_handler.TooFewItems(elementCount, minItems_);
1005  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinItemsString());
1006  }
1007 
1008  if (elementCount > maxItems_) {
1009  context.error_handler.TooManyItems(elementCount, maxItems_);
1010  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaxItemsString());
1011  }
1012 
1013  return true;
1014  }
SizeType maxItems_
Definition: schema.h:1427
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
SizeType minItems_
Definition: schema.h:1426
Here is the call graph for this function:

◆ EndObject()

bool EndObject ( Context context,
SizeType  memberCount 
) const
inline

Definition at line 941 of file schema.h.

941  {
942  if (hasRequired_) {
943  context.error_handler.StartMissingProperties();
944  for (SizeType index = 0; index < propertyCount_; index++)
945  if (properties_[index].required && !context.propertyExist[index])
946  if (properties_[index].schema->defaultValueLength_ == 0 )
947  context.error_handler.AddMissingProperty(properties_[index].name);
948  if (context.error_handler.EndMissingProperties())
949  RAPIDJSON_INVALID_KEYWORD_RETURN(GetRequiredString());
950  }
951 
952  if (memberCount < minProperties_) {
953  context.error_handler.TooFewProperties(memberCount, minProperties_);
954  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinPropertiesString());
955  }
956 
957  if (memberCount > maxProperties_) {
958  context.error_handler.TooManyProperties(memberCount, maxProperties_);
959  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaxPropertiesString());
960  }
961 
962  if (hasDependencies_) {
963  context.error_handler.StartDependencyErrors();
964  for (SizeType sourceIndex = 0; sourceIndex < propertyCount_; sourceIndex++) {
965  const Property& source = properties_[sourceIndex];
966  if (context.propertyExist[sourceIndex]) {
967  if (source.dependencies) {
968  context.error_handler.StartMissingDependentProperties();
969  for (SizeType targetIndex = 0; targetIndex < propertyCount_; targetIndex++)
970  if (source.dependencies[targetIndex] && !context.propertyExist[targetIndex])
971  context.error_handler.AddMissingDependentProperty(properties_[targetIndex].name);
972  context.error_handler.EndMissingDependentProperties(source.name);
973  }
974  else if (source.dependenciesSchema) {
975  ISchemaValidator* dependenciesValidator = context.validators[source.dependenciesValidatorIndex];
976  if (!dependenciesValidator->IsValid())
977  context.error_handler.AddDependencySchemaError(source.name, dependenciesValidator);
978  }
979  }
980  }
981  if (context.error_handler.EndDependencyErrors())
982  RAPIDJSON_INVALID_KEYWORD_RETURN(GetDependenciesString());
983  }
984 
985  return true;
986  }
bool hasDependencies_
Definition: schema.h:1418
const CharType(& source)[N]
Definition: pointer.h:1204
SizeType propertyCount_
Definition: schema.h:1414
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
Property * properties_
Definition: schema.h:1410
SizeType minProperties_
Definition: schema.h:1415
bool hasRequired_
Definition: schema.h:1419
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
SizeType maxProperties_
Definition: schema.h:1416
Here is the call graph for this function:

◆ EndValue()

RAPIDJSON_FORCEINLINE bool EndValue ( Context context) const
inline

Definition at line 703 of file schema.h.

703  {
704  if (context.patternPropertiesValidatorCount > 0) {
705  bool otherValid = false;
706  SizeType count = context.patternPropertiesValidatorCount;
707  if (context.objectPatternValidatorType != Context::kPatternValidatorOnly)
708  otherValid = context.patternPropertiesValidators[--count]->IsValid();
709 
710  bool patternValid = true;
711  for (SizeType i = 0; i < count; i++)
712  if (!context.patternPropertiesValidators[i]->IsValid()) {
713  patternValid = false;
714  break;
715  }
716 
717  if (context.objectPatternValidatorType == Context::kPatternValidatorOnly) {
718  if (!patternValid) {
719  context.error_handler.PropertyViolations(context.patternPropertiesValidators, count);
720  RAPIDJSON_INVALID_KEYWORD_RETURN(GetPatternPropertiesString());
721  }
722  }
723  else if (context.objectPatternValidatorType == Context::kPatternValidatorWithProperty) {
724  if (!patternValid || !otherValid) {
725  context.error_handler.PropertyViolations(context.patternPropertiesValidators, count + 1);
726  RAPIDJSON_INVALID_KEYWORD_RETURN(GetPatternPropertiesString());
727  }
728  }
729  else if (!patternValid && !otherValid) { // kPatternValidatorWithAdditionalProperty)
730  context.error_handler.PropertyViolations(context.patternPropertiesValidators, count + 1);
731  RAPIDJSON_INVALID_KEYWORD_RETURN(GetPatternPropertiesString());
732  }
733  }
734 
735  if (enum_) {
736  const uint64_t h = context.factory.GetHashCode(context.hasher);
737  for (SizeType i = 0; i < enumCount_; i++)
738  if (enum_[i] == h)
739  goto foundEnum;
740  context.error_handler.DisallowedValue();
741  RAPIDJSON_INVALID_KEYWORD_RETURN(GetEnumString());
742  foundEnum:;
743  }
744 
745  if (allOf_.schemas)
746  for (SizeType i = allOf_.begin; i < allOf_.begin + allOf_.count; i++)
747  if (!context.validators[i]->IsValid()) {
748  context.error_handler.NotAllOf(&context.validators[allOf_.begin], allOf_.count);
749  RAPIDJSON_INVALID_KEYWORD_RETURN(GetAllOfString());
750  }
751 
752  if (anyOf_.schemas) {
753  for (SizeType i = anyOf_.begin; i < anyOf_.begin + anyOf_.count; i++)
754  if (context.validators[i]->IsValid())
755  goto foundAny;
756  context.error_handler.NoneOf(&context.validators[anyOf_.begin], anyOf_.count);
757  RAPIDJSON_INVALID_KEYWORD_RETURN(GetAnyOfString());
758  foundAny:;
759  }
760 
761  if (oneOf_.schemas) {
762  bool oneValid = false;
763  for (SizeType i = oneOf_.begin; i < oneOf_.begin + oneOf_.count; i++)
764  if (context.validators[i]->IsValid()) {
765  if (oneValid) {
766  context.error_handler.NotOneOf(&context.validators[oneOf_.begin], oneOf_.count);
767  RAPIDJSON_INVALID_KEYWORD_RETURN(GetOneOfString());
768  } else
769  oneValid = true;
770  }
771  if (!oneValid) {
772  context.error_handler.NotOneOf(&context.validators[oneOf_.begin], oneOf_.count);
773  RAPIDJSON_INVALID_KEYWORD_RETURN(GetOneOfString());
774  }
775  }
776 
777  if (not_ && context.validators[notValidatorIndex_]->IsValid()) {
778  context.error_handler.Disallowed();
779  RAPIDJSON_INVALID_KEYWORD_RETURN(GetNotString());
780  }
781 
782  return true;
783  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
SchemaArray oneOf_
Definition: schema.h:1404
const SchemaType ** schemas
Definition: schema.h:1084
SchemaArray anyOf_
Definition: schema.h:1403
SchemaArray allOf_
Definition: schema.h:1402
SizeType notValidatorIndex_
Definition: schema.h:1408
SizeType enumCount_
Definition: schema.h:1401
unsigned __int64 uint64_t
Definition: stdint.h:136
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
const SchemaType * not_
Definition: schema.h:1405
uint64_t * enum_
Definition: schema.h:1400
Here is the call graph for this function:

◆ FindPropertyIndex()

bool FindPropertyIndex ( const ValueType name,
SizeType outIndex 
) const
inlineprivate

Definition at line 1221 of file schema.h.

1221  {
1222  SizeType len = name.GetStringLength();
1223  const Ch* str = name.GetString();
1224  for (SizeType index = 0; index < propertyCount_; index++)
1225  if (properties_[index].name.GetStringLength() == len &&
1226  (std::memcmp(properties_[index].name.GetString(), str, sizeof(Ch) * len) == 0))
1227  {
1228  *outIndex = index;
1229  return true;
1230  }
1231  return false;
1232  }
SizeType propertyCount_
Definition: schema.h:1414
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
Property * properties_
Definition: schema.h:1410
EncodingType::Ch Ch
Definition: schema.h:402

◆ GetMember()

static const ValueType* GetMember ( const ValueType value,
const ValueType name 
)
inlinestaticprivate

Definition at line 1098 of file schema.h.

1098  {
1099  typename ValueType::ConstMemberIterator itr = value.FindMember(name);
1100  return itr != value.MemberEnd() ? &(itr->value) : 0;
1101  }
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1282

◆ GetPointer()

const PointerType& GetPointer ( ) const
inline

Definition at line 672 of file schema.h.

672  {
673  return pointer_;
674  }
PointerType pointer_
Definition: schema.h:1398

◆ GetURI()

const SValue& GetURI ( ) const
inline

Definition at line 668 of file schema.h.

668  {
669  return uri_;
670  }

◆ Int()

bool Int ( Context context,
int  i 
) const
inline

Definition at line 801 of file schema.h.

801  {
802  if (!CheckInt(context, i))
803  return false;
804  return CreateParallelValidator(context);
805  }
bool CreateParallelValidator(Context &context) const
Definition: schema.h:1184
bool CheckInt(Context &context, int64_t i) const
Definition: schema.h:1234

◆ Int64()

bool Int64 ( Context context,
int64_t  i 
) const
inline

Definition at line 813 of file schema.h.

813  {
814  if (!CheckInt(context, i))
815  return false;
816  return CreateParallelValidator(context);
817  }
bool CreateParallelValidator(Context &context) const
Definition: schema.h:1184
bool CheckInt(Context &context, int64_t i) const
Definition: schema.h:1234

◆ IsPatternMatch()

static bool IsPatternMatch ( const RegexType pattern,
const Ch str,
SizeType   
)
inlinestaticprivate

Definition at line 1145 of file schema.h.

1145  {
1146  GenericRegexSearch<RegexType> rs(*pattern);
1147  return rs.Search(str);
1148  }
Here is the call graph for this function:

◆ Key()

bool Key ( Context context,
const Ch str,
SizeType  len,
bool   
) const
inline

Definition at line 892 of file schema.h.

892  {
893  if (patternProperties_) {
894  context.patternPropertiesSchemaCount = 0;
895  for (SizeType i = 0; i < patternPropertyCount_; i++)
896  if (patternProperties_[i].pattern && IsPatternMatch(patternProperties_[i].pattern, str, len)) {
897  context.patternPropertiesSchemas[context.patternPropertiesSchemaCount++] = patternProperties_[i].schema;
898  context.valueSchema = typeless_;
899  }
900  }
901 
902  SizeType index;
903  if (FindPropertyIndex(ValueType(str, len).Move(), &index)) {
904  if (context.patternPropertiesSchemaCount > 0) {
905  context.patternPropertiesSchemas[context.patternPropertiesSchemaCount++] = properties_[index].schema;
906  context.valueSchema = typeless_;
907  context.valuePatternValidatorType = Context::kPatternValidatorWithProperty;
908  }
909  else
910  context.valueSchema = properties_[index].schema;
911 
912  if (context.propertyExist)
913  context.propertyExist[index] = true;
914 
915  return true;
916  }
917 
919  if (additionalPropertiesSchema_ && context.patternPropertiesSchemaCount > 0) {
920  context.patternPropertiesSchemas[context.patternPropertiesSchemaCount++] = additionalPropertiesSchema_;
921  context.valueSchema = typeless_;
922  context.valuePatternValidatorType = Context::kPatternValidatorWithAdditionalProperty;
923  }
924  else
925  context.valueSchema = additionalPropertiesSchema_;
926  return true;
927  }
928  else if (additionalProperties_) {
929  context.valueSchema = typeless_;
930  return true;
931  }
932 
933  if (context.patternPropertiesSchemaCount == 0) { // patternProperties are not additional properties
934  context.error_handler.DisallowedProperty(str, len);
935  RAPIDJSON_INVALID_KEYWORD_RETURN(GetAdditionalPropertiesString());
936  }
937 
938  return true;
939  }
bool FindPropertyIndex(const ValueType &name, SizeType *outIndex) const
Definition: schema.h:1221
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
Property * properties_
Definition: schema.h:1410
SchemaDocumentType::ValueType ValueType
Definition: schema.h:398
const SchemaType * typeless_
Definition: schema.h:1399
const SchemaType * schema
Definition: schema.h:1392
const SchemaType * schema
Definition: schema.h:1377
PatternProperty * patternProperties_
Definition: schema.h:1412
static bool IsPatternMatch(const RegexType *pattern, const Ch *str, SizeType)
Definition: schema.h:1145
const SchemaType * additionalPropertiesSchema_
Definition: schema.h:1411
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
bool additionalProperties_
Definition: schema.h:1417
SizeType patternPropertyCount_
Definition: schema.h:1413
Here is the call graph for this function:

◆ Null()

bool Null ( Context context) const
inline

Definition at line 785 of file schema.h.

785  {
786  if (!(type_ & (1 << kNullSchemaType))) {
787  DisallowedType(context, GetNullString());
788  RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
789  }
790  return CreateParallelValidator(context);
791  }
bool CreateParallelValidator(Context &context) const
Definition: schema.h:1184
unsigned type_
Definition: schema.h:1406
void DisallowedType(Context &context, const ValueType &actualType) const
Definition: schema.h:1357
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116

◆ StartArray()

bool StartArray ( Context context) const
inline

Definition at line 988 of file schema.h.

988  {
989  if (!(type_ & (1 << kArraySchemaType))) {
990  DisallowedType(context, GetArrayString());
991  RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
992  }
993 
994  context.arrayElementIndex = 0;
995  context.inArray = true;
996 
997  return CreateParallelValidator(context);
998  }
bool CreateParallelValidator(Context &context) const
Definition: schema.h:1184
unsigned type_
Definition: schema.h:1406
void DisallowedType(Context &context, const ValueType &actualType) const
Definition: schema.h:1357
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116

◆ StartObject()

bool StartObject ( Context context) const
inline

Definition at line 871 of file schema.h.

871  {
872  if (!(type_ & (1 << kObjectSchemaType))) {
873  DisallowedType(context, GetObjectString());
874  RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
875  }
876 
878  context.propertyExist = static_cast<bool*>(context.factory.MallocState(sizeof(bool) * propertyCount_));
879  std::memset(context.propertyExist, 0, sizeof(bool) * propertyCount_);
880  }
881 
882  if (patternProperties_) { // pre-allocate schema array
883  SizeType count = patternPropertyCount_ + 1; // extra for valuePatternValidatorType
884  context.patternPropertiesSchemas = static_cast<const SchemaType**>(context.factory.MallocState(sizeof(const SchemaType*) * count));
885  context.patternPropertiesSchemaCount = 0;
886  std::memset(context.patternPropertiesSchemas, 0, sizeof(SchemaType*) * count);
887  }
888 
889  return CreateParallelValidator(context);
890  }
bool hasDependencies_
Definition: schema.h:1418
SizeType propertyCount_
Definition: schema.h:1414
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
bool CreateParallelValidator(Context &context) const
Definition: schema.h:1184
unsigned type_
Definition: schema.h:1406
PatternProperty * patternProperties_
Definition: schema.h:1412
bool hasRequired_
Definition: schema.h:1419
void DisallowedType(Context &context, const ValueType &actualType) const
Definition: schema.h:1357
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
Schema< SchemaDocumentType > SchemaType
Definition: schema.h:404
SizeType patternPropertyCount_
Definition: schema.h:1413
Here is the call graph for this function:

◆ String()

bool String ( Context context,
const Ch str,
SizeType  length,
bool   
) const
inline

Definition at line 843 of file schema.h.

843  {
844  if (!(type_ & (1 << kStringSchemaType))) {
845  DisallowedType(context, GetStringString());
846  RAPIDJSON_INVALID_KEYWORD_RETURN(GetTypeString());
847  }
848 
849  if (minLength_ != 0 || maxLength_ != SizeType(~0)) {
850  SizeType count;
851  if (internal::CountStringCodePoint<EncodingType>(str, length, &count)) {
852  if (count < minLength_) {
853  context.error_handler.TooShort(str, length, minLength_);
854  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMinLengthString());
855  }
856  if (count > maxLength_) {
857  context.error_handler.TooLong(str, length, maxLength_);
858  RAPIDJSON_INVALID_KEYWORD_RETURN(GetMaxLengthString());
859  }
860  }
861  }
862 
863  if (pattern_ && !IsPatternMatch(pattern_, str, length)) {
864  context.error_handler.DoesNotMatch(str, length);
865  RAPIDJSON_INVALID_KEYWORD_RETURN(GetPatternString());
866  }
867 
868  return CreateParallelValidator(context);
869  }
RegexType * pattern_
Definition: schema.h:1431
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:384
bool CreateParallelValidator(Context &context) const
Definition: schema.h:1184
unsigned type_
Definition: schema.h:1406
static bool IsPatternMatch(const RegexType *pattern, const Ch *str, SizeType)
Definition: schema.h:1145
SizeType maxLength_
Definition: schema.h:1433
void DisallowedType(Context &context, const ValueType &actualType) const
Definition: schema.h:1357
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
SizeType minLength_
Definition: schema.h:1432
Here is the call graph for this function:

◆ Uint()

bool Uint ( Context context,
unsigned  u 
) const
inline

Definition at line 807 of file schema.h.

807  {
808  if (!CheckUint(context, u))
809  return false;
810  return CreateParallelValidator(context);
811  }
bool CreateParallelValidator(Context &context) const
Definition: schema.h:1184
bool CheckUint(Context &context, uint64_t i) const
Definition: schema.h:1282

◆ Uint64()

bool Uint64 ( Context context,
uint64_t  u 
) const
inline

Definition at line 819 of file schema.h.

819  {
820  if (!CheckUint(context, u))
821  return false;
822  return CreateParallelValidator(context);
823  }
bool CreateParallelValidator(Context &context) const
Definition: schema.h:1184
bool CheckUint(Context &context, uint64_t i) const
Definition: schema.h:1282

Friends And Related Function Documentation

◆ GenericSchemaDocument< ValueType, AllocatorType >

Definition at line 407 of file schema.h.

Member Data Documentation

◆ additionalItems_

bool additionalItems_
private

Definition at line 1428 of file schema.h.

◆ additionalItemsSchema_

const SchemaType* additionalItemsSchema_
private

Definition at line 1422 of file schema.h.

◆ additionalProperties_

bool additionalProperties_
private

Definition at line 1417 of file schema.h.

◆ additionalPropertiesSchema_

const SchemaType* additionalPropertiesSchema_
private

Definition at line 1411 of file schema.h.

◆ allocator_

AllocatorType* allocator_
private

Definition at line 1396 of file schema.h.

◆ allOf_

SchemaArray allOf_
private

Definition at line 1402 of file schema.h.

◆ anyOf_

SchemaArray anyOf_
private

Definition at line 1403 of file schema.h.

◆ defaultValueLength_

SizeType defaultValueLength_
private

Definition at line 1441 of file schema.h.

◆ enum_

uint64_t* enum_
private

Definition at line 1400 of file schema.h.

◆ enumCount_

SizeType enumCount_
private

Definition at line 1401 of file schema.h.

◆ exclusiveMaximum_

bool exclusiveMaximum_
private

Definition at line 1439 of file schema.h.

◆ exclusiveMinimum_

bool exclusiveMinimum_
private

Definition at line 1438 of file schema.h.

◆ hasDependencies_

bool hasDependencies_
private

Definition at line 1418 of file schema.h.

◆ hasRequired_

bool hasRequired_
private

Definition at line 1419 of file schema.h.

◆ hasSchemaDependencies_

bool hasSchemaDependencies_
private

Definition at line 1420 of file schema.h.

◆ itemsList_

const SchemaType* itemsList_
private

Definition at line 1423 of file schema.h.

◆ itemsTuple_

const SchemaType** itemsTuple_
private

Definition at line 1424 of file schema.h.

◆ itemsTupleCount_

SizeType itemsTupleCount_
private

Definition at line 1425 of file schema.h.

◆ maximum_

SValue maximum_
private

Definition at line 1436 of file schema.h.

◆ maxItems_

SizeType maxItems_
private

Definition at line 1427 of file schema.h.

◆ maxLength_

SizeType maxLength_
private

Definition at line 1433 of file schema.h.

◆ maxProperties_

SizeType maxProperties_
private

Definition at line 1416 of file schema.h.

◆ minimum_

SValue minimum_
private

Definition at line 1435 of file schema.h.

◆ minItems_

SizeType minItems_
private

Definition at line 1426 of file schema.h.

◆ minLength_

SizeType minLength_
private

Definition at line 1432 of file schema.h.

◆ minProperties_

SizeType minProperties_
private

Definition at line 1415 of file schema.h.

◆ multipleOf_

SValue multipleOf_
private

Definition at line 1437 of file schema.h.

◆ not_

const SchemaType* not_
private

Definition at line 1405 of file schema.h.

◆ notValidatorIndex_

SizeType notValidatorIndex_
private

Definition at line 1408 of file schema.h.

◆ oneOf_

SchemaArray oneOf_
private

Definition at line 1404 of file schema.h.

◆ pattern_

RegexType* pattern_
private

Definition at line 1431 of file schema.h.

◆ patternProperties_

PatternProperty* patternProperties_
private

Definition at line 1412 of file schema.h.

◆ patternPropertyCount_

SizeType patternPropertyCount_
private

Definition at line 1413 of file schema.h.

◆ pointer_

PointerType pointer_
private

Definition at line 1398 of file schema.h.

◆ properties_

Property* properties_
private

Definition at line 1410 of file schema.h.

◆ propertyCount_

SizeType propertyCount_
private

Definition at line 1414 of file schema.h.

◆ type_

unsigned type_
private

Definition at line 1406 of file schema.h.

◆ typeless_

const SchemaType* typeless_
private

Definition at line 1399 of file schema.h.

◆ uniqueItems_

bool uniqueItems_
private

Definition at line 1429 of file schema.h.

◆ uri_

SValue uri_
private

Definition at line 1397 of file schema.h.

◆ validatorCount_

SizeType validatorCount_
private

Definition at line 1407 of file schema.h.


The documentation for this class was generated from the following file: