diff options
Diffstat (limited to 'src')
| -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  | 
