From 3883e6df939ad1ecb9a788153e087fefd9f0e838 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Fri, 6 Feb 2015 16:47:49 +0100 Subject: corrected attributes descriptor handling. --- src/core/model/Domain.cpp | 67 +++++++++++++++++++++++----------------------- src/core/model/Domain.hpp | 68 +++++++++++++++++------------------------------ 2 files changed, 59 insertions(+), 76 deletions(-) (limited to 'src/core/model') diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index f8c0779..3284759 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -128,11 +128,9 @@ bool FieldDescriptor::removeChild(Handle c) void Descriptor::doResolve(ResolutionState &state) { - if (attributesDescriptor != nullptr) { - const NodeVector &attributes = - attributesDescriptor->getAttributes(); - continueResolveComposita(attributes, attributes.getIndex(), state); - } + const NodeVector &attributes = + attributesDescriptor->getAttributes(); + continueResolveComposita(attributes, attributes.getIndex(), state); continueResolveComposita(fieldDescriptors, fieldDescriptors.getIndex(), state); } @@ -155,8 +153,9 @@ bool Descriptor::doValidate(Logger &logger) const } else { valid = valid & validateName(logger); } - // check the FieldDescriptors themselves. - return valid & continueValidationCheckDuplicates(fieldDescriptors, logger); + // check attributes and the FieldDescriptors + return valid & attributesDescriptor->validate(logger) & + continueValidationCheckDuplicates(fieldDescriptors, logger); } std::vector> Descriptor::pathTo( @@ -235,7 +234,6 @@ bool Descriptor::continuePath(Handle target, return found; } - void Descriptor::addFieldDescriptor(Handle fd) { // only add it if we need to. @@ -319,18 +317,18 @@ Rooted Descriptor::createFieldDescriptor( StructuredClass::StructuredClass(Manager &mgr, std::string name, Handle domain, Variant cardinality, - Handle attributesDescriptor, Handle superclass, bool transparent, bool root) - : Descriptor(mgr, std::move(name), domain, attributesDescriptor), + : Descriptor(mgr, std::move(name), domain), cardinality(std::move(cardinality)), superclass(acquire(superclass)), subclasses(this), transparent(transparent), root(root) { + ExceptionLogger logger; if (superclass != nullptr) { - superclass->addSubclass(this); + superclass->addSubclass(this, logger); } if (domain != nullptr) { domain->addStructuredClass(this); @@ -368,21 +366,26 @@ bool StructuredClass::doValidate(Logger &logger) const return valid & Descriptor::doValidate(logger); } -void StructuredClass::setSuperclass(Handle sup) +void StructuredClass::setSuperclass(Handle sup, Logger &logger) { if (superclass == sup) { return; } // remove this subclass from the old superclass. if (superclass != nullptr) { - superclass->removeSubclass(this); + superclass->removeSubclass(this, logger); } // set the new superclass superclass = acquire(sup); invalidate(); // add this class as new subclass of the new superclass. if (sup != nullptr) { - sup->addSubclass(this); + sup->addSubclass(this, logger); + // set the attribute descriptor supertype + getAttributesDescriptor()->setParentStructure( + sup->getAttributesDescriptor(), logger); + } else { + getAttributesDescriptor()->setParentStructure(nullptr, logger); } } @@ -397,17 +400,20 @@ bool StructuredClass::isSubclassOf(Handle c) const return superclass->isSubclassOf(c); } -void StructuredClass::addSubclass(Handle sc) +void StructuredClass::addSubclass(Handle sc, Logger &logger) { + if (sc == nullptr) { + return; + } // check if we already have that class. if (subclasses.find(sc) == subclasses.end()) { invalidate(); subclasses.push_back(sc); } - sc->setSuperclass(this); + sc->setSuperclass(this, logger); } -void StructuredClass::removeSubclass(Handle sc) +void StructuredClass::removeSubclass(Handle sc, Logger &logger) { // if we don't have this subclass we can return directly. if (sc == nullptr) { @@ -420,7 +426,7 @@ void StructuredClass::removeSubclass(Handle sc) // otherwise we have to erase it. invalidate(); subclasses.erase(it); - sc->setSuperclass(nullptr); + sc->setSuperclass(nullptr, logger); } const void StructuredClass::gatherFieldDescriptors( @@ -450,13 +456,11 @@ NodeVector StructuredClass::getEffectiveFieldDescriptors() /* Class AnnotationClass */ -AnnotationClass::AnnotationClass( - Manager &mgr, std::string name, Handle domain, - // TODO: What would be a wise default value for attributes? - Handle attributesDescriptor) - : Descriptor(mgr, std::move(name), domain, attributesDescriptor) +AnnotationClass::AnnotationClass(Manager &mgr, std::string name, + Handle domain) + : Descriptor(mgr, std::move(name), domain) { - if (!domain.isNull()) { + if (domain != nullptr) { domain->addAnnotationClass(this); } } @@ -525,14 +529,12 @@ bool Domain::removeStructuredClass(Handle s) } Rooted Domain::createStructuredClass( - std::string name, Variant cardinality, - Handle attributesDescriptor, Handle superclass, + std::string name, Variant cardinality, Handle superclass, bool transparent, bool root) { return Rooted{new StructuredClass( - getManager(), std::move(name), this, std::move(cardinality), - attributesDescriptor, superclass, std::move(transparent), - std::move(root))}; + getManager(), std::move(name), this, std::move(cardinality), superclass, + std::move(transparent), std::move(root))}; } void Domain::addAnnotationClass(Handle a) @@ -564,11 +566,10 @@ bool Domain::removeAnnotationClass(Handle a) return false; } -Rooted Domain::createAnnotationClass( - std::string name, Handle attributesDescriptor) +Rooted Domain::createAnnotationClass(std::string name) { - return Rooted{new AnnotationClass( - getManager(), std::move(name), this, attributesDescriptor)}; + return Rooted{ + new AnnotationClass(getManager(), std::move(name), this)}; } /* Type registrations */ diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index dd0af4c..cd05441 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -217,7 +217,6 @@ class Descriptor; class StructuredClass; class Domain; - static const std::string DEFAULT_FIELD_NAME = "$default"; /** @@ -292,7 +291,8 @@ public: * Descriptor to be valid. */ FieldDescriptor(Manager &mgr, Handle parent, - Handle primitiveType, std::string name = DEFAULT_FIELD_NAME, + Handle primitiveType, + std::string name = DEFAULT_FIELD_NAME, bool optional = false); /** @@ -312,7 +312,8 @@ public: */ FieldDescriptor(Manager &mgr, Handle parent = nullptr, FieldType fieldType = FieldType::TREE, - std::string name = DEFAULT_FIELD_NAME, bool optional = false); + std::string name = DEFAULT_FIELD_NAME, + bool optional = false); /** * Returns a const reference to the NodeVector of StructuredClasses whose @@ -464,10 +465,9 @@ protected: bool doValidate(Logger &logger) const override; public: - Descriptor(Manager &mgr, std::string name, Handle domain, - Handle attributesDescriptor) + Descriptor(Manager &mgr, std::string name, Handle domain) : Node(mgr, std::move(name), domain), - attributesDescriptor(acquire(attributesDescriptor)), + attributesDescriptor(acquire(new StructType(mgr, "", nullptr))), fieldDescriptors(this) { } @@ -484,17 +484,6 @@ public: return attributesDescriptor; } - /** - * Sets the StructType that specifies the attributes of this Descriptor. - * - * @param t some StructType. - */ - void setAttributesDescriptor(Handle t) - { - invalidate(); - attributesDescriptor = acquire(t); - } - /** * Returns a const reference to the NodeVector of all FieldDescriptors of * this Descriptor. @@ -602,8 +591,7 @@ public: */ Rooted createFieldDescriptor( FieldDescriptor::FieldType fieldType = FieldDescriptor::FieldType::TREE, - std::string name = DEFAULT_FIELD_NAME, - bool optional = false); + std::string name = DEFAULT_FIELD_NAME, bool optional = false); /** * This tries to construct the shortest possible path of this Descriptor @@ -748,9 +736,6 @@ public: * have at least one author. This is set to * * per default, meaning that any number of * of instances is valid, including zero. - * @param attributesDescriptor is a StructType that specifies the attribute - * keys as well as value domains for this - * Descriptor. * @param superclass references a parent StructuredClass. Please * look for more information on inheritance in * the class documentation above. The default is @@ -767,7 +752,6 @@ public: StructuredClass(Manager &mgr, std::string name, Handle domain = nullptr, Variant cardinality = AnyCardinality, - Handle attributesDescriptor = nullptr, Handle superclass = nullptr, bool transparent = false, bool root = false); @@ -793,10 +777,15 @@ public: * This will also register this class as a subclass at the given superclass * and unregister it at the previous superclass. * - * @parem sup some StructuredClass that shall be the new superclass of this - * StructuredClass. + * It will also set the parent for this Descriptors AttributesDescriptor. + * + * @param sup some StructuredClass that shall be the new superclass of + * this StructuredClass. + * @param logger is some logger. Errors during setting the parent for this + * Descriptors AttributesDescriptor will be written into this + * logger. */ - void setSuperclass(Handle sup); + void setSuperclass(Handle sup, Logger &logger); /** * Returns true if this class is a subclass of the given class. It does not @@ -832,16 +821,22 @@ public: * on the given subclass. * * @param sc is some StructuredClass. + * @param logger is some logger. Errors during setting the parent for the + * new subclasses AttributesDescriptor will be written into + * this logger. */ - void addSubclass(Handle sc); + void addSubclass(Handle sc, Logger& logger); /** * Removes a subclass from this StructuredClass. This also calls * setSuperclass(nullptr) on the given subclass. * * @param sc is some StructuredClass. + * @param logger is some logger. Errors during setting the parent for the + * removed subclasses AttributesDescriptor will be written + * into this logger. */ - void removeSubclass(Handle sc); + void removeSubclass(Handle sc, Logger& logger); /** * Returns a const reference to the NodeVector of all FieldDescriptors of @@ -891,13 +886,8 @@ public: * AnnotationClass. * @param domain is the Domain this AnnotationClass belongs * to. - * @param attributesDescriptor is a StructType that specifies the attribute - * keys as well as value domains for this - * Descriptor. */ - AnnotationClass(Manager &mgr, std::string name, Handle domain, - // TODO: What would be a wise default value for attributes? - Handle attributesDescriptor = nullptr); + AnnotationClass(Manager &mgr, std::string name, Handle domain); }; /** @@ -1004,9 +994,6 @@ public: * have at least one author. This is set to * * per default, meaning that any number of * of instances is valid, including zero. - * @param attributesDescriptor is a StructType that specifies the attribute - * keys as well as value domains for this - * Descriptor. * @param superclass references a parent StructuredClass. Please * look for more information on inheritance in * the class documentation above. The default is @@ -1024,7 +1011,6 @@ public: */ Rooted createStructuredClass( std::string name, Variant cardinality = AnyCardinality, - Handle attributesDescriptor = nullptr, Handle superclass = nullptr, bool transparent = false, bool root = false); @@ -1064,12 +1050,8 @@ public: * @param name is a name for this AnnotationClass that will * be used for later references to this * AnnotationClass. - * @param attributesDescriptor is a StructType that specifies the attribute - * keys as well as value domains for this - * Descriptor. */ - Rooted createAnnotationClass( - std::string name, Handle attributesDescriptor = nullptr); + Rooted createAnnotationClass(std::string name); /** * Returns a const reference to the NodeVector of TypeSystems that are -- cgit v1.2.3