diff options
Diffstat (limited to 'src/core/model/Domain.cpp')
| -rw-r--r-- | src/core/model/Domain.cpp | 54 | 
1 files changed, 42 insertions, 12 deletions
diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index 55f05b3..20a9d42 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -153,9 +153,22 @@ bool Descriptor::doValidate(Logger &logger) const  	} else {  		valid = valid & validateName(logger);  	} +	// ensure that no attribute with the key "name" exists. +	if (attributesDescriptor == nullptr) { +		logger.error("This Descriptor has no Attribute specification!"); +		valid = false; +	} else { +		if (attributesDescriptor->hasAttribute("name")) { +			logger.error( +			    "This Descriptor has an attribute \"name\" which is a reserved " +			    "word!"); +			valid = false; +		} +		valid = valid & attributesDescriptor->validate(logger); +	} +  	// check attributes and the FieldDescriptors -	return valid & attributesDescriptor->validate(logger) & -	       continueValidationCheckDuplicates(fieldDescriptors, logger); +	return valid & continueValidationCheckDuplicates(fieldDescriptors, logger);  }  std::vector<Rooted<Node>> Descriptor::pathTo( @@ -179,13 +192,7 @@ bool Descriptor::continuePath(Handle<StructuredClass> target,  	std::vector<Rooted<Node>> optimum;  	// use recursive depth-first search from the top to reach the given child  	// get the list of effective FieldDescriptors. -	NodeVector<FieldDescriptor> fields; -	if (isa(&RttiTypes::StructuredClass)) { -		const StructuredClass *tis = static_cast<const StructuredClass *>(this); -		fields = tis->getEffectiveFieldDescriptors(); -	} else { -		fields = getFieldDescriptors(); -	} +	NodeVector<FieldDescriptor> fields = getFieldDescriptors();  	for (auto &fd : fields) {  		for (auto &c : fd->getChildren()) { @@ -234,6 +241,30 @@ bool Descriptor::continuePath(Handle<StructuredClass> target,  	return found;  } +ssize_t Descriptor::getFieldDescriptorIndex(const std::string &name) const +{ +	size_t f = 0; +	for (auto &fd : getFieldDescriptors()) { +		if (fd->getName() == name) { +			return f; +		} +		f++; +	} +	return -1; +} + +ssize_t Descriptor::getFieldDescriptorIndex(Handle<FieldDescriptor> fd) const +{ +	size_t f = 0; +	for (auto &fd2 : getFieldDescriptors()) { +		if (fd == fd2) { +			return f; +		} +		f++; +	} +	return -1; +} +  void Descriptor::addFieldDescriptor(Handle<FieldDescriptor> fd)  {  	// only add it if we need to. @@ -444,14 +475,13 @@ const void StructuredClass::gatherFieldDescriptors(  	}  } -NodeVector<FieldDescriptor> StructuredClass::getEffectiveFieldDescriptors() -    const +NodeVector<FieldDescriptor> StructuredClass::getFieldDescriptors() const  {  	// in this case we return a NodeVector of Rooted entries without owner.  	NodeVector<FieldDescriptor> vec;  	std::set<std::string> overriddenFields;  	gatherFieldDescriptors(vec, overriddenFields); -	return std::move(vec); +	return vec;  }  /* Class AnnotationClass */  | 
