Refactor move pointer into schema
This commit is contained in:
parent
d452a548b8
commit
371b9286b1
@ -281,7 +281,8 @@ public:
|
|||||||
typedef GenericValue<EncodingType, AllocatorType> SValue;
|
typedef GenericValue<EncodingType, AllocatorType> SValue;
|
||||||
friend class GenericSchemaDocument<ValueType, AllocatorType>;
|
friend class GenericSchemaDocument<ValueType, AllocatorType>;
|
||||||
|
|
||||||
Schema(SchemaDocumentType* document, AllocatorType* allocator, const PointerType& p, const ValueType& value) :
|
Schema(SchemaDocumentType* document, const PointerType& p, const ValueType& value, AllocatorType* allocator) :
|
||||||
|
pointer_(p),
|
||||||
allocator_(allocator),
|
allocator_(allocator),
|
||||||
enum_(),
|
enum_(),
|
||||||
enumCount_(),
|
enumCount_(),
|
||||||
@ -522,6 +523,8 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PointerType& GetPointer() const { return pointer_; }
|
||||||
|
|
||||||
bool BeginValue(Context& context) const {
|
bool BeginValue(Context& context) const {
|
||||||
if (context.inArray) {
|
if (context.inArray) {
|
||||||
if (uniqueItems_)
|
if (uniqueItems_)
|
||||||
@ -833,7 +836,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const SchemaType* GetTypeless() {
|
static const SchemaType* GetTypeless() {
|
||||||
static SchemaType typeless(0, 0, PointerType(), Value(kObjectType).Move());
|
static SchemaType typeless(0, PointerType(), Value(kObjectType).Move(), 0);
|
||||||
return &typeless;
|
return &typeless;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1080,6 +1083,7 @@ private:
|
|||||||
RegexType* pattern;
|
RegexType* pattern;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PointerType pointer_;
|
||||||
AllocatorType* allocator_;
|
AllocatorType* allocator_;
|
||||||
uint64_t* enum_;
|
uint64_t* enum_;
|
||||||
SizeType enumCount_;
|
SizeType enumCount_;
|
||||||
@ -1177,7 +1181,7 @@ public:
|
|||||||
|
|
||||||
// Create entry in map if not exist
|
// Create entry in map if not exist
|
||||||
if (!GetSchema(refEntry->source)) {
|
if (!GetSchema(refEntry->source)) {
|
||||||
new (schemaMap_.template Push<SchemaEntry>()) SchemaEntry(refEntry->source, const_cast<SchemaType*>(s), false);
|
new (schemaMap_.template Push<SchemaEntry>()) SchemaEntry(const_cast<SchemaType*>(s), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
refEntry->~SchemaRefEntry();
|
refEntry->~SchemaRefEntry();
|
||||||
@ -1206,12 +1210,11 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct SchemaEntry {
|
struct SchemaEntry {
|
||||||
SchemaEntry(const PointerType& p, SchemaType* s, bool o) : pointer(p), schema(s), owned(o) {}
|
SchemaEntry(SchemaType* s, bool o) : schema(s), owned(o) {}
|
||||||
~SchemaEntry() {
|
~SchemaEntry() {
|
||||||
if (owned)
|
if (owned)
|
||||||
schema->~SchemaType();
|
schema->~SchemaType();
|
||||||
}
|
}
|
||||||
PointerType pointer;
|
|
||||||
SchemaType* schema;
|
SchemaType* schema;
|
||||||
bool owned;
|
bool owned;
|
||||||
};
|
};
|
||||||
@ -1239,8 +1242,8 @@ private:
|
|||||||
RAPIDJSON_ASSERT(pointer.IsValid());
|
RAPIDJSON_ASSERT(pointer.IsValid());
|
||||||
if (v.IsObject()) {
|
if (v.IsObject()) {
|
||||||
if (!schema || !HandleRefSchema(pointer, schema, v)) {
|
if (!schema || !HandleRefSchema(pointer, schema, v)) {
|
||||||
SchemaType* s = new (allocator_->Malloc(sizeof(SchemaType))) SchemaType(this, allocator_, pointer, v);
|
SchemaType* s = new (allocator_->Malloc(sizeof(SchemaType))) SchemaType(this, pointer, v, allocator_);
|
||||||
new (schemaMap_.template Push<SchemaEntry>()) SchemaEntry(pointer, s, true);
|
new (schemaMap_.template Push<SchemaEntry>()) SchemaEntry(s, true);
|
||||||
if (schema)
|
if (schema)
|
||||||
*schema = s;
|
*schema = s;
|
||||||
}
|
}
|
||||||
@ -1292,16 +1295,13 @@ private:
|
|||||||
|
|
||||||
const SchemaType* GetSchema(const PointerType& pointer) const {
|
const SchemaType* GetSchema(const PointerType& pointer) const {
|
||||||
for (const SchemaEntry* target = schemaMap_.template Bottom<SchemaEntry>(); target != schemaMap_.template End<SchemaEntry>(); ++target)
|
for (const SchemaEntry* target = schemaMap_.template Bottom<SchemaEntry>(); target != schemaMap_.template End<SchemaEntry>(); ++target)
|
||||||
if (pointer == target->pointer)
|
if (pointer == target->schema->pointer_)
|
||||||
return target->schema;
|
return target->schema;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PointerType GetPointer(const SchemaType* schema) const {
|
PointerType GetPointer(const SchemaType* schema) const {
|
||||||
for (const SchemaEntry* target = schemaMap_.template Bottom<SchemaEntry>(); target != schemaMap_.template End<SchemaEntry>(); ++target)
|
return schema->pointer_;
|
||||||
if (schema == target->schema)
|
|
||||||
return target->pointer;
|
|
||||||
return PointerType();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const size_t kInitialSchemaMapSize = 64;
|
static const size_t kInitialSchemaMapSize = 64;
|
||||||
@ -1385,7 +1385,7 @@ public:
|
|||||||
virtual bool IsValid() const { return valid_; }
|
virtual bool IsValid() const { return valid_; }
|
||||||
|
|
||||||
PointerType GetInvalidSchemaPointer() const {
|
PointerType GetInvalidSchemaPointer() const {
|
||||||
return schemaStack_.Empty() ? PointerType() : schemaDocument_->GetPointer(&CurrentSchema());
|
return schemaStack_.Empty() ? PointerType() : CurrentSchema().GetPointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* GetInvalidSchemaKeyword() const {
|
const char* GetInvalidSchemaKeyword() const {
|
||||||
@ -1551,8 +1551,7 @@ private:
|
|||||||
|
|
||||||
#if RAPIDJSON_SCHEMA_VERBOSE
|
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||||
StringBuffer sb;
|
StringBuffer sb;
|
||||||
const PointerType pointer = schemaDocument_->GetPointer(&CurrentSchema());
|
CurrentSchema().GetPointer().Stringify(sb);
|
||||||
pointer.Stringify(sb);
|
|
||||||
|
|
||||||
*documentStack_.template Push<Ch>() = '\0';
|
*documentStack_.template Push<Ch>() = '\0';
|
||||||
documentStack_.template Pop<Ch>(1);
|
documentStack_.template Pop<Ch>(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user