diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2014-12-21 23:52:51 +0100 |
---|---|---|
committer | Andreas Stöckel <andreas@somweyr.de> | 2014-12-21 23:52:51 +0100 |
commit | 01ce9e24cc5953f44a7dd9a3d93347835e26030d (patch) | |
tree | 617a437d6d3e934c3f7ae9dba28260dabc70bcc2 /src/core/model | |
parent | 1a924c27789483ac43134d6fdedd80fa24a9d0b9 (diff) |
fixed crash bug in TestDomain -- if a class has an Owned handle the owner must point to the managed object directly responsible for the lifetime of this handle. Fixed this by making AttributeDescriptor a managed class (though this is not an optimal solution) and using a ManagedVector
Diffstat (limited to 'src/core/model')
-rw-r--r-- | src/core/model/Domain.hpp | 4 | ||||
-rw-r--r-- | src/core/model/Typesystem.hpp | 31 |
2 files changed, 19 insertions, 16 deletions
diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index 99ac6e1..31786c1 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -400,9 +400,9 @@ public: */ StructuredClass(Manager &mgr, std::string name, Handle<Domain> domain, const Cardinality &cardinality, - Handle<StructType> attributesDescriptor = {nullptr}, + Handle<StructType> attributesDescriptor = nullptr, // TODO: What would be a wise default value for isa? - Handle<StructuredClass> isa = {nullptr}, + Handle<StructuredClass> isa = nullptr, bool transparent = false, bool root = false) : Descriptor(mgr, std::move(name), domain, attributesDescriptor), diff --git a/src/core/model/Typesystem.hpp b/src/core/model/Typesystem.hpp index c9793e2..3832a0f 100644 --- a/src/core/model/Typesystem.hpp +++ b/src/core/model/Typesystem.hpp @@ -306,18 +306,21 @@ public: class StructType : public Type { public: - struct AttributeDescriptor { + class AttributeDescriptor : public Managed { + public: const std::string name; const Variant defaultValue; const bool optional; const Owned<Type> type; - AttributeDescriptor(std::string name, Variant defaultValue, - bool optional, Owned<Type> type) - : name(name), + AttributeDescriptor(Manager &mgr, std::string name, + Variant defaultValue, bool optional, + Handle<Type> type) + : Managed(mgr), + name(name), defaultValue(defaultValue), optional(optional), - type(type) + type(acquire(type)) { } }; @@ -332,7 +335,7 @@ protected: if (var.isArray()) { auto arr = var.asArray(); for (size_t a = 0; a < attrs.size(); a++) { - if (!attrs[a].type->build(arr[a], logger)) { + if (!attrs[a]->type->build(arr[a], logger)) { return false; } } @@ -345,13 +348,13 @@ protected: auto &map = var.asMap(); // We transform the map into an array with the correct values at the // correct places. - std::vector<Variant> vec; + Variant::arrayType vec; for (auto &a : attrs) { - auto it = map.find(a.name); + auto it = map.find(a->name); // we use the default if nothing is set. - if (it == map.end() || !a.type->build(it->second, logger)) { - logger.note(std::string("Using default value for ") + a.name); - vec.push_back(a.defaultValue); + if (it == map.end() || !a->type->build(it->second, logger)) { + logger.note(std::string("Using default value for ") + a->name); + vec.push_back(a->defaultValue); } else { vec.push_back(it->second); } @@ -361,11 +364,11 @@ protected: } public: - std::vector<AttributeDescriptor> attrs; + const ManagedVector<AttributeDescriptor> attrs; StructType(Manager &mgr, std::string name, Handle<Typesystem> system, - std::vector<AttributeDescriptor> attrs) - : Type(mgr, std::move(name), system, false), attrs(std::move(attrs)) + ManagedVector<AttributeDescriptor> attrs) + : Type(mgr, std::move(name), system, false), attrs(this, std::move(attrs)) { } // TODO |