From eab6577b066319aab7ebaf514e6bb7aab9590624 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Sun, 25 Jan 2015 15:50:52 +0100 Subject: removed cardinality type definition from Domain.hpp and made everything compatible with the Variant cardinality. --- src/core/model/Document.cpp | 8 ++++++-- src/core/model/Domain.cpp | 17 +++++++++++------ src/core/model/Domain.hpp | 15 +++++++-------- 3 files changed, 24 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 61c384d..42192a2 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -147,6 +147,10 @@ bool DocumentEntity::doValidate(Logger &logger) const // a constructor we can not check anything else. return false; } + // if we have an invalid descriptor we can not proceed either. + if(!descriptor->validate(logger)){ + return false; + } // check the attribute primitive content. bool valid; if (descriptor->getAttributesDescriptor() == nullptr) { @@ -218,7 +222,7 @@ bool DocumentEntity::doValidate(Logger &logger) const * cardinality. */ for (auto &ac : fieldDescs[f]->getChildren()) { - const size_t min = ac->getCardinality().min(); + const size_t min = ac->getCardinality().asCardinality().min(); if (min > 0) { logger.error( std::string("Field \"") + fieldDescs[f]->getName() + @@ -305,7 +309,7 @@ bool DocumentEntity::doValidate(Logger &logger) const if (n != nums.end()) { num = n->second; } - if (!ac->getCardinality().contains(num)) { + if (!ac->getCardinality().asCardinality().contains(num)) { logger.error( std::string("Field \"") + fieldDescs[f]->getName() + "\" had " + std::to_string(num) + " elements of class \"" + diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index c7afd22..635fc50 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -306,13 +306,12 @@ Rooted Descriptor::createFieldDescriptor( /* Class StructuredClass */ StructuredClass::StructuredClass(Manager &mgr, std::string name, - Handle domain, - const Cardinality &cardinality, + Handle domain, Variant cardinality, Handle attributesDescriptor, Handle superclass, bool transparent, bool root) : Descriptor(mgr, std::move(name), domain, attributesDescriptor), - cardinality(cardinality), + cardinality(std::move(cardinality)), superclass(acquire(superclass)), subclasses(this), transparent(transparent), @@ -338,6 +337,11 @@ bool StructuredClass::doValidate(Logger &logger) const valid = false; } } + // check the cardinality. + if(!cardinality.isCardinality()){ + logger.error(cardinality.toString() + " is not a cardinality!"); + valid = false; + } // check the validity of this superclass. if (superclass != nullptr) { valid = valid & superclass->validate(logger); @@ -496,13 +500,14 @@ bool Domain::removeStructuredClass(Handle s) } Rooted Domain::createStructuredClass( - std::string name, const Cardinality &cardinality, + std::string name, Variant cardinality, Handle attributesDescriptor, Handle superclass, bool transparent, bool root) { return Rooted{new StructuredClass( - getManager(), std::move(name), this, cardinality, attributesDescriptor, - superclass, std::move(transparent), std::move(root))}; + getManager(), std::move(name), this, std::move(cardinality), + attributesDescriptor, superclass, std::move(transparent), + std::move(root))}; } void Domain::addAnnotationClass(Handle a) diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index e40a9f3..ef228b1 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -618,20 +618,19 @@ public: * cardinalities independent of context? Should we not have at least have the * possibility to define it context-dependently? */ -typedef RangeSet Cardinality; /** * This is the default cardinality. */ -static Cardinality createAny() +static Variant::cardinalityType createAny() { - Cardinality any; + Variant::cardinalityType any; any.merge(Range::typeRangeFrom(0)); return std::move(any); } -static const Cardinality AnyCardinality = createAny(); +static const Variant AnyCardinality = createAny(); /** * A StructuredClass specifies nodes in the StructureTree of a document that @@ -710,7 +709,7 @@ class StructuredClass : public Descriptor { friend Domain; private: - const Cardinality cardinality; + const Variant cardinality; Owned superclass; NodeVector subclasses; bool transparent; @@ -758,7 +757,7 @@ public: */ StructuredClass(Manager &mgr, std::string name = "", Handle domain = nullptr, - const Cardinality &cardinality = AnyCardinality, + Variant cardinality = AnyCardinality, Handle attributesDescriptor = nullptr, Handle superclass = nullptr, bool transparent = false, bool root = false); @@ -768,7 +767,7 @@ public: * * @return the Cardinality of this StructuredClass (as a RangeSet). */ - const Cardinality &getCardinality() const { return cardinality; } + const Variant &getCardinality() const { return cardinality; } /** * Returns the superclass of this StructuredClass. This is not the same as @@ -1016,7 +1015,7 @@ public: * @return the newly created StructuredClass. */ Rooted createStructuredClass( - std::string name, const Cardinality &cardinality = AnyCardinality, + std::string name, Variant cardinality = AnyCardinality, Handle attributesDescriptor = nullptr, Handle superclass = nullptr, bool transparent = false, bool root = false); -- cgit v1.2.3