From f1bb76dedf2d6b480b566540e811a7e0d3af9886 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Sun, 21 Dec 2014 15:13:37 +0100 Subject: First draft of book domain example and slight changes to the book domain: _all_ structuredclasses are listed in the domain now and StructuredClasses that are allowed at the root level have a root flag. --- CMakeLists.txt | 2 +- src/core/model/Domain.cpp | 2 +- src/core/model/Domain.hpp | 55 +++++++++++++++++++++++++++++++++--------- test/core/model/TestDomain.hpp | 8 +++--- 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 563977e..3575d7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,7 @@ PKG_CHECK_MODULES(EXPAT REQUIRED expat) FIND_PACKAGE(Boost COMPONENTS system filesystem REQUIRED) # Set utf8cpp include path -SET(UTF8CPP_INCLUDE_DIR "lib/utf8") +SET(UTF8CPP_INCLUDE_DIR "lib/utf8cpp") ################################################################################ # Inclusion of doxygen # diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index 77708e6..fafe090 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -68,7 +68,7 @@ void Domain::doResolve(std::vector> &res, const std::vector &path, Filter filter, void *filterData, unsigned idx, VisitorSet &visited) { - for (auto &s : rootStructures) { + for (auto &s : structureClasses) { s->resolve(res, path, filter, filterData, idx, visited, nullptr); } for (auto &a : annotationClasses) { diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index c0946bf..e257c0d 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -212,7 +212,6 @@ public: Rooted getPrimitiveType() const { return primitiveType; } }; - /** * This is a super class for StructuredClasses and AnnotationClasses and is, * in itself, not supposed to be instantiated. It defines that both, Annotations @@ -369,18 +368,46 @@ protected: public: const bool transparent; + const bool root; + /** + * The constructor for a StructuredClass. + * + * @param mgr is the current Manager. + * @param name is the name of the StructuredClass. + * @param domain is the Domain this StructuredClass belongs + * to. + * @param cardinality specifies how often an element of this type + * may occur at a specific point in the + * StructureTree. For example: A document should + * have at least one author. + * @param attributesDescriptor references a StructType that in turn + * specifies which key-value pairs are permitted + * as attributes for this StructuredClass. The + * default value is a null-reference, meaning + * that no attributes are permitted. + * @param isa references a parent StructuredClass. Please + * look for more information on inheritance in + * the class documentation above. The default is + * a null reference, meaning no parent class. + * @param transparent specifies whether this StructuredClass is + * transparent. For more information on + * transparency please refer to the class + * documentation above. The default is false. + */ StructuredClass(Manager &mgr, std::string name, Handle domain, const Cardinality &cardinality, Handle attributesDescriptor = {nullptr}, // TODO: What would be a wise default value for isa? Handle isa = {nullptr}, - bool transparent = false) + bool transparent = false, + bool root = false) : Descriptor(mgr, std::move(name), domain, attributesDescriptor), cardinality(cardinality), isa(acquire(isa)), parents(this), - transparent(transparent) + transparent(transparent), + root(root) { } @@ -404,15 +431,16 @@ class AnnotationClass : public Descriptor { }; /** - * A Domain node specifies which StructuredClasses are allowed at the root - * level (or which Nonterminals are axioms of the grammar) and which Annotations - * are allowed globally. TODO: Do we want to be able to restrict Annotations to - * certain Structures? + * A Domain node specifies which StructuredClasses and which AnnotationClasses + * are part of this domain. TODO: Do we want to be able to restrict Annotations + * to certain Structures? */ class Domain : public Node { private: - NodeVector rootStructures; + NodeVector structureClasses; NodeVector annotationClasses; + // TODO: Is it wise to attach the type systems here? If not: What would be + // a good alternative. NodeVector typesystems; protected: @@ -425,18 +453,21 @@ public: Domain(Manager &mgr, std::string name) // TODO: Can a domain have a parent? : Node(mgr, std::move(name), nullptr), - rootStructures(this), + structureClasses(this), annotationClasses(this), typesystems(this) { } // TODO: Is returning a NodeVector alright? - NodeVector &getRootStructures() { return rootStructures; } + NodeVector &getStructureClasses() + { + return structureClasses; + } - const NodeVector &getRootStructures() const + const NodeVector &getStructureClasses() const { - return rootStructures; + return structureClasses; } NodeVector &getAnnotationClasses() diff --git a/test/core/model/TestDomain.hpp b/test/core/model/TestDomain.hpp index 41fcdef..dd58524 100644 --- a/test/core/model/TestDomain.hpp +++ b/test/core/model/TestDomain.hpp @@ -59,9 +59,9 @@ static Rooted constructBookDomain(Manager &mgr) any.merge(Range::typeRangeFrom(0)); // Set up the "book" node. - Rooted book{ - new StructuredClass(mgr, "book", domain, single)}; - domain->getRootStructures().push_back(book); + Rooted book{new StructuredClass( + mgr, "book", domain, single, {nullptr}, {nullptr}, false, true)}; + domain->getStructureClasses().push_back(book); // The structure field of it. Rooted book_field{new FieldDescriptor(mgr, book)}; book->getFieldDescriptors().push_back(book_field); @@ -70,6 +70,7 @@ static Rooted constructBookDomain(Manager &mgr) Rooted section{ new StructuredClass(mgr, "section", domain, any)}; book_field->getChildren().push_back(section); + domain->getStructureClasses().push_back(section); // And the field of it. Rooted section_field{new FieldDescriptor(mgr, section)}; section->getFieldDescriptors().push_back(section_field); @@ -79,6 +80,7 @@ static Rooted constructBookDomain(Manager &mgr) mgr, "paragraph", domain, any, {nullptr}, {nullptr}, true)}; section_field->getChildren().push_back(paragraph); book_field->getChildren().push_back(paragraph); + domain->getStructureClasses().push_back(paragraph); // ... and has a primitive field. Rooted paragraph_field{new FieldDescriptor( mgr, paragraph, domain->getTypesystems()[0]->getTypes()[1], "text", -- cgit v1.2.3