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),
418 validatorCount_(),
419 notValidatorIndex_(),
420 properties_(),
421 additionalPropertiesSchema_(),
422 patternProperties_(),
423 patternPropertyCount_(),
424 propertyCount_(),
425 minProperties_(),
427 additionalProperties_(true),
428 hasDependencies_(),
429 hasRequired_(),
430 hasSchemaDependencies_(),
431 additionalItemsSchema_(),
432 itemsList_(),
433 itemsTuple_(),
434 itemsTupleCount_(),
435 minItems_(),
437 additionalItems_(true),
438 uniqueItems_(false),
439 pattern_(),
440 minLength_(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
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
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];
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
482 schemaDocument->CreateSchema(¬_,
p.Append(GetNotString(), allocator_), *v, document);
483 notValidatorIndex_ = validatorCount_;
484 validatorCount_++;
485 }
486
487
488
489 const ValueType* properties = GetMember(
value, GetPropertiesString());
490 const ValueType* required = GetMember(
value, GetRequiredString());
491 const ValueType* dependencies = GetMember(
value, GetDependenciesString());
492 {
493
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) {
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()) {
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) {
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) {
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
595 if (v->IsObject())
596 schemaDocument->CreateSchema(&itemsList_, q, *v, document);
597 else if (v->IsArray()) {
598 itemsTuple_ =
static_cast<const Schema**
>(allocator_->Malloc(
sizeof(
const Schema*) * v->Size()));
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
618 AssignIfExist(minLength_,
value, GetMinLengthString());
619 AssignIfExist(maxLength_,
value, GetMaxLengthString());
620
622 pattern_ = CreatePattern(*v);
623
624
626 if (v->IsNumber())
627 minimum_.CopyFrom(*v, *allocator_);
628
630 if (v->IsNumber())
631 maximum_.CopyFrom(*v, *allocator_);
632
633 AssignIfExist(exclusiveMinimum_,
value, GetExclusiveMinimumString());
634 AssignIfExist(exclusiveMaximum_,
value, GetExclusiveMaximumString());
635
637 if (v->IsNumber() && v->GetDouble() > 0.0)
638 multipleOf_.CopyFrom(*v, *allocator_);
639
640
641 if (
const ValueType* v = GetMember(
value, GetDefaultValueString()))
642 if (v->IsString())
643 defaultValueLength_ = v->GetStringLength();
644
645 }
Default memory allocator used by the parser and DOM.
SchemaDocumentType::PointerType PointerType
SchemaDocumentType::ValueType ValueType
GenericValue< EncodingType, AllocatorType > SValue
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
unsigned __int64 uint64_t