Electroneum
internal::Schema< SchemaDocumentType > Class Template Reference

#include <schema.h>

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
 

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

template<typename SchemaDocumentType >
typedef SchemaDocumentType::AllocatorType internal::Schema< SchemaDocumentType >::AllocatorType

Definition at line 399 of file schema.h.

◆ Ch

template<typename SchemaDocumentType >
typedef EncodingType::Ch internal::Schema< SchemaDocumentType >::Ch

Definition at line 402 of file schema.h.

◆ Context

template<typename SchemaDocumentType >
typedef SchemaValidationContext<SchemaDocumentType> internal::Schema< SchemaDocumentType >::Context

Definition at line 403 of file schema.h.

◆ EncodingType

template<typename SchemaDocumentType >
typedef ValueType::EncodingType internal::Schema< SchemaDocumentType >::EncodingType

Definition at line 401 of file schema.h.

◆ ErrorHandler

template<typename SchemaDocumentType >
typedef IValidationErrorHandler<Schema> internal::Schema< SchemaDocumentType >::ErrorHandler

Definition at line 406 of file schema.h.

◆ PointerType

template<typename SchemaDocumentType >
typedef SchemaDocumentType::PointerType internal::Schema< SchemaDocumentType >::PointerType

Definition at line 400 of file schema.h.

◆ SchemaType

template<typename SchemaDocumentType >
typedef Schema<SchemaDocumentType> internal::Schema< SchemaDocumentType >::SchemaType

Definition at line 404 of file schema.h.

◆ SValue

template<typename SchemaDocumentType >
typedef GenericValue<EncodingType, AllocatorType> internal::Schema< SchemaDocumentType >::SValue

Definition at line 405 of file schema.h.

◆ ValueType

template<typename SchemaDocumentType >
typedef SchemaDocumentType::ValueType internal::Schema< SchemaDocumentType >::ValueType

Definition at line 398 of file schema.h.

Constructor & Destructor Documentation

◆ Schema()

template<typename SchemaDocumentType >
internal::Schema< SchemaDocumentType >::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),
413  typeless_(schemaDocument->GetTypeless()),
414  enum_(),
415  enumCount_(),
416  not_(),
417  type_((1 << kTotalSchemaType) - 1), // typeless
418  validatorCount_(),
419  notValidatorIndex_(),
420  properties_(),
421  additionalPropertiesSchema_(),
422  patternProperties_(),
423  patternPropertyCount_(),
424  propertyCount_(),
425  minProperties_(),
426  maxProperties_(SizeType(~0)),
427  additionalProperties_(true),
428  hasDependencies_(),
429  hasRequired_(),
430  hasSchemaDependencies_(),
431  additionalItemsSchema_(),
432  itemsList_(),
433  itemsTuple_(),
434  itemsTupleCount_(),
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),
444  defaultValueLength_(0)
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[256 + 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);
483  notValidatorIndex_ = validatorCount_;
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];
520  properties_[i].schema = typeless_;
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()));
537  patternPropertyCount_ = 0;
538 
539  for (ConstMemberIterator itr = v->MemberBegin(); itr != v->MemberEnd(); ++itr) {
540  new (&patternProperties_[patternPropertyCount_]) PatternProperty();
541  patternProperties_[patternPropertyCount_].pattern = CreatePattern(itr->name);
542  schemaDocument->CreateSchema(&patternProperties_[patternPropertyCount_].schema, q.Append(itr->name, allocator_), itr->value, document);
543  patternPropertyCount_++;
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);
575  properties_[sourceIndex].dependenciesValidatorIndex = validatorCount_;
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  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:389
array
Definition: rapidjson.h:625
SchemaDocumentType::ValueType ValueType
Definition: schema.h:398
PolymorphicMatcher< internal::PropertyMatcher< Class, PropertyType > > Property(PropertyType(Class::*property)() const, const PropertyMatcher &matcher)
SchemaDocumentType::PointerType PointerType
Definition: schema.h:400
unsigned __int64 uint64_t
Definition: stdint.h:136
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
GenericValue< EncodingType, AllocatorType > SValue
Definition: schema.h:405
Here is the call graph for this function:

◆ ~Schema()

template<typename SchemaDocumentType >
internal::Schema< SchemaDocumentType >::~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  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:389
PolymorphicMatcher< internal::PropertyMatcher< Class, PropertyType > > Property(PropertyType(Class::*property)() const, const PropertyMatcher &matcher)
Here is the call graph for this function:

Member Function Documentation

◆ BeginValue()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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  }
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116

◆ Bool()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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  }
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116

◆ Double()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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  }
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116

◆ EndArray()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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  }
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116

◆ EndObject()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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  }
const CharType(& source)[N]
Definition: pointer.h:1147
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:389
PolymorphicMatcher< internal::PropertyMatcher< Class, PropertyType > > Property(PropertyType(Class::*property)() const, const PropertyMatcher &matcher)
const char * name
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
Here is the call graph for this function:

◆ EndValue()

template<typename SchemaDocumentType >
RAPIDJSON_FORCEINLINE bool internal::Schema< SchemaDocumentType >::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:389
mdb_size_t count(MDB_cursor *cur)
unsigned __int64 uint64_t
Definition: stdint.h:136
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
Here is the call graph for this function:

◆ GetPointer()

template<typename SchemaDocumentType >
const PointerType& internal::Schema< SchemaDocumentType >::GetPointer ( ) const
inline

Definition at line 672 of file schema.h.

672  {
673  return pointer_;
674  }

◆ GetURI()

template<typename SchemaDocumentType >
const SValue& internal::Schema< SchemaDocumentType >::GetURI ( ) const
inline

Definition at line 668 of file schema.h.

668  {
669  return uri_;
670  }

◆ Int()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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  }
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98

◆ Int64()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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  }
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98

◆ Key()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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 
918  if (additionalPropertiesSchema_) {
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  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:389
SchemaDocumentType::ValueType ValueType
Definition: schema.h:398
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116

◆ Null()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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  }
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116

◆ StartArray()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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  }
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116

◆ StartObject()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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 
877  if (hasDependencies_ || hasRequired_) {
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  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:389
mdb_size_t count(MDB_cursor *cur)
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
Schema< SchemaDocumentType > SchemaType
Definition: schema.h:404
Here is the call graph for this function:

◆ String()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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  }
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:389
mdb_size_t count(MDB_cursor *cur)
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
#define RAPIDJSON_INVALID_KEYWORD_RETURN(keyword)
Definition: schema.h:116
Here is the call graph for this function:

◆ Uint()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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  }
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98

◆ Uint64()

template<typename SchemaDocumentType >
bool internal::Schema< SchemaDocumentType >::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  }
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98

Friends And Related Function Documentation

◆ GenericSchemaDocument< ValueType, AllocatorType >

template<typename SchemaDocumentType >
friend class GenericSchemaDocument< ValueType, AllocatorType >
friend

Definition at line 407 of file schema.h.


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