summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-03-03 15:54:14 +0100
committerAndreas Stöckel <andreas@somweyr.de>2015-03-03 15:54:14 +0100
commitf6b22312127f29f71aa26ca28142ad3e5f193445 (patch)
treef499d0d5414bcec2d03904ff078a7acbefcedf42
parente1f71b37d632418390b2aac2f89c9d05297a413c (diff)
Do not allow structs to be transparent and root at the same time
-rw-r--r--src/core/model/Ontology.cpp14
-rw-r--r--test/core/model/OntologyTest.cpp14
2 files changed, 19 insertions, 9 deletions
diff --git a/src/core/model/Ontology.cpp b/src/core/model/Ontology.cpp
index f52f8ca..e7bc7c4 100644
--- a/src/core/model/Ontology.cpp
+++ b/src/core/model/Ontology.cpp
@@ -800,6 +800,7 @@ bool StructuredClass::doValidate(Logger &logger) const
valid = false;
}
}
+
// check the cardinality.
if (!cardinality.isCardinality()) {
logger.error(cardinality.toString() + " is not a cardinality!", *this);
@@ -819,6 +820,15 @@ bool StructuredClass::doValidate(Logger &logger) const
if (superclass != nullptr) {
valid = valid & superclass->validate(logger);
}
+
+ // Make sure root classes are not transparent
+ if (root && transparent) {
+ logger.error(
+ std::string("Descriptor \"") + getName() +
+ std::string("\" cannot be transparent and root at the same time."));
+ valid = false;
+ }
+
// check the validity as a Descriptor.
/*
* Note that we do not check the validity of all subclasses. This is because
@@ -1126,7 +1136,7 @@ const Rtti StructuredClass =
const Rtti AnnotationClass =
RttiBuilder<ousia::AnnotationClass>("AnnotationClass").parent(&Descriptor);
const Rtti Ontology = RttiBuilder<ousia::Ontology>("Ontology")
- .parent(&RootNode)
- .composedOf({&StructuredClass, &AnnotationClass});
+ .parent(&RootNode)
+ .composedOf({&StructuredClass, &AnnotationClass});
}
}
diff --git a/test/core/model/OntologyTest.cpp b/test/core/model/OntologyTest.cpp
index 265e9e2..c6e0596 100644
--- a/test/core/model/OntologyTest.cpp
+++ b/test/core/model/OntologyTest.cpp
@@ -336,11 +336,11 @@ TEST(Descriptor, pathToCycles)
// Construct the ontology
Rooted<Ontology> ontology{new Ontology(mgr, sys, "cycles")};
Rooted<StructuredClass> A{new StructuredClass(
- mgr, "A", ontology, Cardinality::any(), {nullptr}, true, true)};
+ mgr, "A", ontology, Cardinality::any(), {nullptr}, true, false)};
A->addSubclass(A, logger);
ASSERT_FALSE(ontology->validate(logger));
Rooted<StructuredClass> B{new StructuredClass(
- mgr, "B", ontology, Cardinality::any(), {nullptr}, false, true)};
+ mgr, "B", ontology, Cardinality::any(), {nullptr}, true, false)};
Rooted<FieldDescriptor> A_field = A->createFieldDescriptor(logger).first;
A_field->addChild(B);
/*
@@ -444,7 +444,7 @@ TEST(Descriptor, getDefaultFieldsCycles)
// Construct the ontology
Rooted<Ontology> ontology{new Ontology(mgr, sys, "cycles")};
Rooted<StructuredClass> A{new StructuredClass(
- mgr, "A", ontology, Cardinality::any(), {nullptr}, true, true)};
+ mgr, "A", ontology, Cardinality::any(), {nullptr}, true, false)};
A->addSubclass(A, logger);
ASSERT_FALSE(ontology->validate(logger));
Rooted<FieldDescriptor> A_field =
@@ -504,7 +504,7 @@ TEST(Descriptor, getPermittedChildrenCycles)
// Construct the ontology
Rooted<Ontology> ontology{new Ontology(mgr, sys, "cycles")};
Rooted<StructuredClass> A{new StructuredClass(
- mgr, "A", ontology, Cardinality::any(), {nullptr}, true, true)};
+ mgr, "A", ontology, Cardinality::any(), {nullptr}, true, false)};
A->addSubclass(A, logger);
ASSERT_FALSE(ontology->validate(logger));
Rooted<FieldDescriptor> A_field = A->createFieldDescriptor(logger).first;
@@ -529,7 +529,7 @@ TEST(Descriptor, getSyntaxDescriptor)
// Construct the ontology
Rooted<Ontology> ontology{new Ontology(mgr, sys, "ontology")};
Rooted<StructuredClass> A{new StructuredClass(
- mgr, "A", ontology, Cardinality::any(), {nullptr}, true, true)};
+ mgr, "A", ontology, Cardinality::any(), {nullptr}, false, false)};
A->setStartToken(TokenDescriptor(Tokens::Indent));
A->setEndToken(TokenDescriptor(Tokens::Dedent));
{
@@ -558,7 +558,7 @@ TEST(Descriptor, getPermittedTokens)
Rooted<Ontology> ontology{new Ontology(mgr, sys, "ontology")};
// add one StructuredClass with all tokens set.
Rooted<StructuredClass> A{new StructuredClass(
- mgr, "A", ontology, Cardinality::any(), {nullptr}, true, true)};
+ mgr, "A", ontology, Cardinality::any(), {nullptr}, false, false)};
A->setStartToken(TokenDescriptor(Tokens::Indent));
A->setEndToken(TokenDescriptor(Tokens::Dedent));
{
@@ -795,7 +795,7 @@ TEST(Ontology, getAllTokenDescriptors)
Rooted<Ontology> ontology{new Ontology(mgr, sys, "ontology")};
// add one StructuredClass with all tokens set.
Rooted<StructuredClass> A{new StructuredClass(
- mgr, "A", ontology, Cardinality::any(), {nullptr}, true, true)};
+ mgr, "A", ontology, Cardinality::any(), {nullptr}, false, false)};
A->setStartToken(TokenDescriptor(Tokens::Indent));
A->setEndToken(TokenDescriptor(Tokens::Dedent));
{