Centralise schema ownership to SchemaDocument
This commit is contained in:
parent
a576a0f5d5
commit
1e4a3818ed
@ -91,8 +91,6 @@ template <typename Encoding, typename Allocator>
|
|||||||
struct SchemaArray {
|
struct SchemaArray {
|
||||||
SchemaArray() : schemas(), count() {}
|
SchemaArray() : schemas(), count() {}
|
||||||
~SchemaArray() {
|
~SchemaArray() {
|
||||||
for (SizeType i = 0; i < count; i++)
|
|
||||||
delete schemas[i];
|
|
||||||
delete[] schemas;
|
delete[] schemas;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,14 +374,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~Schema() {
|
~Schema() {
|
||||||
delete not_;
|
|
||||||
delete [] properties_;
|
delete [] properties_;
|
||||||
delete additionalPropertiesSchema_;
|
|
||||||
delete [] patternProperties_;
|
delete [] patternProperties_;
|
||||||
delete additionalItemsSchema_;
|
|
||||||
delete itemsList_;
|
|
||||||
for (SizeType i = 0; i < itemsTupleCount_; i++)
|
|
||||||
delete itemsTuple_[i];
|
|
||||||
delete [] itemsTuple_;
|
delete [] itemsTuple_;
|
||||||
#if RAPIDJSON_SCHEMA_USE_STDREGEX
|
#if RAPIDJSON_SCHEMA_USE_STDREGEX
|
||||||
delete pattern_;
|
delete pattern_;
|
||||||
@ -803,12 +795,7 @@ private:
|
|||||||
|
|
||||||
struct Property {
|
struct Property {
|
||||||
Property() : schema(), dependenciesSchema(), dependencies(), required(false), typeless(true) {}
|
Property() : schema(), dependenciesSchema(), dependencies(), required(false), typeless(true) {}
|
||||||
~Property() {
|
~Property() { delete[] dependencies; }
|
||||||
delete schema;
|
|
||||||
delete dependenciesSchema;
|
|
||||||
delete[] dependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
GenericValue<Encoding> name;
|
GenericValue<Encoding> name;
|
||||||
const SchemaType* schema;
|
const SchemaType* schema;
|
||||||
const SchemaType* dependenciesSchema;
|
const SchemaType* dependenciesSchema;
|
||||||
@ -819,11 +806,7 @@ private:
|
|||||||
|
|
||||||
struct PatternProperty {
|
struct PatternProperty {
|
||||||
PatternProperty() : schema(), pattern() {}
|
PatternProperty() : schema(), pattern() {}
|
||||||
~PatternProperty() {
|
~PatternProperty() { delete pattern; }
|
||||||
delete schema;
|
|
||||||
delete pattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
SchemaType* schema;
|
SchemaType* schema;
|
||||||
RegexType* pattern;
|
RegexType* pattern;
|
||||||
};
|
};
|
||||||
@ -875,17 +858,25 @@ public:
|
|||||||
friend class Schema<Encoding, Allocator>;
|
friend class Schema<Encoding, Allocator>;
|
||||||
|
|
||||||
template <typename DocumentType>
|
template <typename DocumentType>
|
||||||
GenericSchemaDocument(const DocumentType& document, Allocator* allocator = 0) : root_(), schemaMap(allocator, kInitialSchemaMapSize) {
|
GenericSchemaDocument(const DocumentType& document, Allocator* allocator = 0) : root_(), schemas_(), schemaCount_(), schemaMap_(allocator, kInitialSchemaMapSize) {
|
||||||
typedef typename DocumentType::ValueType ValueType;
|
typedef typename DocumentType::ValueType ValueType;
|
||||||
|
|
||||||
root_ = CreateSchema(GenericPointer<ValueType>(), static_cast<const ValueType&>(document));
|
root_ = CreateSchema(GenericPointer<ValueType>(), static_cast<const ValueType&>(document));
|
||||||
|
|
||||||
while (!schemaMap.Empty())
|
// Copy to schemas and destroy the map
|
||||||
schemaMap.template Pop<SchemaEntry<ValueType> > (1)->~SchemaEntry<ValueType>();
|
schemas_ = new SchemaType*[schemaCount_];
|
||||||
|
size_t i = schemaCount_;
|
||||||
|
while (!schemaMap_.Empty()) {
|
||||||
|
SchemaEntry<ValueType>* e = schemaMap_.template Pop<SchemaEntry<ValueType> > (1);
|
||||||
|
schemas_[--i] = e->schema;
|
||||||
|
e->~SchemaEntry<ValueType>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~GenericSchemaDocument() {
|
~GenericSchemaDocument() {
|
||||||
delete root_;
|
for (size_t i = 0; i < schemaCount_; i++)
|
||||||
|
delete schemas_[i];
|
||||||
|
delete [] schemas_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SchemaType& GetRoot() const { return *root_; }
|
const SchemaType& GetRoot() const { return *root_; }
|
||||||
@ -901,14 +892,17 @@ private:
|
|||||||
template <typename ValueType>
|
template <typename ValueType>
|
||||||
SchemaType* CreateSchema(const GenericPointer<ValueType>& pointer, const ValueType& v) {
|
SchemaType* CreateSchema(const GenericPointer<ValueType>& pointer, const ValueType& v) {
|
||||||
SchemaType* schema = new SchemaType(this, pointer, v);
|
SchemaType* schema = new SchemaType(this, pointer, v);
|
||||||
new (schemaMap.template Push<SchemaEntry<ValueType> >()) SchemaEntry<ValueType>(pointer, schema);
|
new (schemaMap_.template Push<SchemaEntry<ValueType> >()) SchemaEntry<ValueType>(pointer, schema);
|
||||||
|
schemaCount_++;
|
||||||
return schema;
|
return schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const size_t kInitialSchemaMapSize = 1024;
|
static const size_t kInitialSchemaMapSize = 1024;
|
||||||
|
|
||||||
SchemaType* root_;
|
SchemaType* root_;
|
||||||
internal::Stack<Allocator> schemaMap; // Stores SchemaEntry<ValueType>
|
SchemaType** schemas_;
|
||||||
|
size_t schemaCount_;
|
||||||
|
internal::Stack<Allocator> schemaMap_; // Stores SchemaEntry<ValueType>
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef GenericSchemaDocument<UTF8<> > SchemaDocument;
|
typedef GenericSchemaDocument<UTF8<> > SchemaDocument;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user