diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-01-25 15:50:52 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-01-25 15:50:52 +0100 |
commit | eab6577b066319aab7ebaf514e6bb7aab9590624 (patch) | |
tree | b93f21d4eb207b539e341aee6bba500b9aea8783 | |
parent | 37a002577e7f4949e0634dca7e828b5333d2ccc5 (diff) |
removed cardinality type definition from Domain.hpp and made everything compatible with the Variant cardinality.
-rw-r--r-- | src/core/model/Document.cpp | 8 | ||||
-rw-r--r-- | src/core/model/Domain.cpp | 17 | ||||
-rw-r--r-- | src/core/model/Domain.hpp | 15 | ||||
-rw-r--r-- | test/core/model/DocumentTest.cpp | 2 | ||||
-rw-r--r-- | test/core/model/DomainTest.cpp | 8 | ||||
-rw-r--r-- | test/core/model/TestAdvanced.hpp | 6 | ||||
-rw-r--r-- | test/core/model/TestDomain.hpp | 6 |
7 files changed, 35 insertions, 27 deletions
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<FieldDescriptor> Descriptor::createFieldDescriptor( /* Class StructuredClass */ StructuredClass::StructuredClass(Manager &mgr, std::string name, - Handle<Domain> domain, - const Cardinality &cardinality, + Handle<Domain> domain, Variant cardinality, Handle<StructType> attributesDescriptor, Handle<StructuredClass> 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<StructuredClass> s) } Rooted<StructuredClass> Domain::createStructuredClass( - std::string name, const Cardinality &cardinality, + std::string name, Variant cardinality, Handle<StructType> attributesDescriptor, Handle<StructuredClass> superclass, bool transparent, bool root) { return Rooted<StructuredClass>{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<AnnotationClass> 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<size_t> Cardinality; /** * This is the default cardinality. */ -static Cardinality createAny() +static Variant::cardinalityType createAny() { - Cardinality any; + Variant::cardinalityType any; any.merge(Range<size_t>::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<StructuredClass> superclass; NodeVector<StructuredClass> subclasses; bool transparent; @@ -758,7 +757,7 @@ public: */ StructuredClass(Manager &mgr, std::string name = "", Handle<Domain> domain = nullptr, - const Cardinality &cardinality = AnyCardinality, + Variant cardinality = AnyCardinality, Handle<StructType> attributesDescriptor = nullptr, Handle<StructuredClass> 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<StructuredClass> createStructuredClass( - std::string name, const Cardinality &cardinality = AnyCardinality, + std::string name, Variant cardinality = AnyCardinality, Handle<StructType> attributesDescriptor = nullptr, Handle<StructuredClass> superclass = nullptr, bool transparent = false, bool root = false); diff --git a/test/core/model/DocumentTest.cpp b/test/core/model/DocumentTest.cpp index e07deb8..1d8457c 100644 --- a/test/core/model/DocumentTest.cpp +++ b/test/core/model/DocumentTest.cpp @@ -117,7 +117,7 @@ TEST(Document, validate) Manager mgr{1}; Rooted<SystemTypesystem> sys{new SystemTypesystem(mgr)}; Rooted<Domain> domain{new Domain(mgr, sys, "trivial")}; - Cardinality single; + Variant::cardinalityType single; single.merge({1}); // Set up the "root" StructuredClass. Rooted<StructuredClass> rootClass{new StructuredClass( diff --git a/test/core/model/DomainTest.cpp b/test/core/model/DomainTest.cpp index c00b122..54fd86a 100644 --- a/test/core/model/DomainTest.cpp +++ b/test/core/model/DomainTest.cpp @@ -152,8 +152,8 @@ TEST(Descriptor, pathToAdvanced) Rooted<SystemTypesystem> sys{new SystemTypesystem(mgr)}; // Construct the domain Rooted<Domain> domain{new Domain(mgr, sys, "nasty")}; - Cardinality any; - any.merge(Range<size_t>::typeRangeFrom(0)); + Variant::cardinalityType any; + any.merge(Range<size_t>::typeRange()); // Let's create the classes that we need first Rooted<StructuredClass> A{new StructuredClass( @@ -225,8 +225,8 @@ TEST(StructuredClass, isSubclassOf) Manager mgr{1}; Rooted<SystemTypesystem> sys{new SystemTypesystem(mgr)}; Rooted<Domain> domain{new Domain(mgr, sys, "inheritance")}; - Cardinality any; - any.merge(Range<size_t>::typeRangeFrom(0)); + Variant::cardinalityType any; + any.merge(Range<size_t>::typeRange()); Rooted<StructuredClass> A{new StructuredClass( mgr, "A", domain, any, {nullptr}, {nullptr}, false, true)}; // first branch diff --git a/test/core/model/TestAdvanced.hpp b/test/core/model/TestAdvanced.hpp index f8585d1..6f8ca33 100644 --- a/test/core/model/TestAdvanced.hpp +++ b/test/core/model/TestAdvanced.hpp @@ -53,7 +53,7 @@ static Rooted<Domain> constructHeadingDomain(Manager &mgr, // set up domain node. Rooted<Domain> domain{new Domain(mgr, sys, "headings")}; // set up cardinality (every section may have at most one heading). - Cardinality card; + Variant::cardinalityType card; card.merge({0, 1}); // set up heading StructuredClass. Rooted<StructuredClass> heading{new StructuredClass( @@ -84,8 +84,8 @@ static Rooted<Domain> constructListDomain(Manager &mgr, // set up domain node. Rooted<Domain> domain{new Domain(mgr, sys, "list")}; // set up cardinality - Cardinality any; - any.merge(Range<size_t>::typeRangeFrom(0)); + Variant::cardinalityType any; + any.merge(Range<size_t>::typeRange()); // get book.paragraph Rooted<StructuredClass> p = resolveDescriptor(bookDomain, "paragraph"); // set up item StructuredClass; diff --git a/test/core/model/TestDomain.hpp b/test/core/model/TestDomain.hpp index f6b8805..ec63216 100644 --- a/test/core/model/TestDomain.hpp +++ b/test/core/model/TestDomain.hpp @@ -36,10 +36,10 @@ static Rooted<Domain> constructBookDomain(Manager &mgr, // Start with the Domain itself. Rooted<Domain> domain{new Domain(mgr, sys, "book")}; // Set up the cardinalities we'll need. - Cardinality single; + Variant::cardinalityType single; single.merge({1}); - Cardinality any; - any.merge(Range<size_t>::typeRangeFrom(0)); + Variant::cardinalityType any; + any.merge(Range<size_t>::typeRange()); // Set up the "book" node. Rooted<StructuredClass> book{new StructuredClass( |