From 5eca67b6cab7031d8203b1403ba5cddaef833e76 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Sun, 8 Feb 2015 19:37:51 +0100 Subject: restructured the FieldDescriptor mechanism. --- src/core/model/Domain.hpp | 64 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 17 deletions(-) (limited to 'src/core/model/Domain.hpp') diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index 53579bd..63f4c5d 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -485,17 +485,51 @@ public: } /** - * Returns a const reference to the NodeVector of all FieldDescriptors of - * this Descriptor. + * Returns the NodeVector of all FieldDescriptors of this Descriptor. * - * @return a const reference to the NodeVector of all FieldDescriptors of - * this Descriptor. + * @return the NodeVector of all FieldDescriptors of this Descriptor. */ - const NodeVector &getFieldDescriptors() const + virtual NodeVector getFieldDescriptors() const { return fieldDescriptors; } + /** + * Returns the index of the FieldDescriptor with the given name or -1 if no + * such FieldDescriptor was found. + * + * @param name the name of a FieldDescriptor. + + * @return the index of the FieldDescriptor with the given name or -1 if + * no such FieldDescriptor was found. + */ + int getFieldDescriptorIndex( + const std::string &name = DEFAULT_FIELD_NAME) const; + /** + * Returns the index of the given FieldDescriptor or -1 of the given + * FieldDescriptor is not registered at this Descriptor. + * + * @param fd a FieldDescriptor. + + * @return the index of the given FieldDescriptor or -1 of the given + * FieldDescriptor is not registered at this Descriptor. + */ + int getFieldDescriptorIndex(Handle fd) const; + + /** + * This returns true if this Descriptor has a FieldDescriptor with the + * given name. + * + * @param name the name of a FieldDescriptor. + + * @return true if this Descriptor has a FieldDescriptor with the given + * name + */ + bool hasField(const std::string &fieldName = DEFAULT_FIELD_NAME) const + { + return getFieldDescriptorIndex(fieldName) != -1; + } + /** * Adds the given FieldDescriptor to this Descriptor. This also sets the * parent of the given FieldDescriptor if it is not set yet. @@ -697,10 +731,7 @@ public: * Finally we allow StructuredClasses to inherit attributes of other * StructuredClasses. Inheritance also implies that instance of the inheriting * class can be used wherever an instance of the inherited class is allowed. - * Inheritance therefore also goes for fields. TODO: What is the specification - * for field inheritance? Is the child allowed to specify children at all? - * Is that interpreted as overriding the parent fields or constructing a union? - * What about the cardinality? + * Inheritance therefore also goes for fields. */ class StructuredClass : public Descriptor { friend Domain; @@ -825,7 +856,7 @@ public: * new subclasses AttributesDescriptor will be written into * this logger. */ - void addSubclass(Handle sc, Logger& logger); + void addSubclass(Handle sc, Logger &logger); /** * Removes a subclass from this StructuredClass. This also calls @@ -836,18 +867,17 @@ public: * removed subclasses AttributesDescriptor will be written * into this logger. */ - void removeSubclass(Handle sc, Logger& logger); + void removeSubclass(Handle sc, Logger &logger); /** * Returns a const reference to the NodeVector of all FieldDescriptors of - * this StructuredClass. This does more than the getter for FieldDescriptor, - * because in this method we gather the FieldDescriptors of all superclasses - * as well that have not been overridden in child classes. + * this StructuredClass. This also merges the FieldDescriptors directly + * belonging to this StructuredClass with all FieldDescritptors of its + * Superclass (and so on recurvively). * - * @return a const reference to the NodeVector of all FieldDescriptors of - * this StructuredClass. + * @return a NodeVector of all FieldDescriptors of this StructuredClass. */ - NodeVector getEffectiveFieldDescriptors() const; + NodeVector getFieldDescriptors() const override; bool isTransparent() const { return transparent; } -- cgit v1.2.3