From 5712ae821cee989943625629e8fe59ea7bb8eb1c Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Mon, 15 Dec 2014 13:40:36 +0100 Subject: first draft for StructuredClass --- src/core/model/Domain.hpp | 120 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 114 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index 13c65e5..9bd2982 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -191,11 +191,11 @@ public: // TODO: Is returning a ManagedVector alright? ManagedVector &getChildren() { return children; } - FieldType getFieldType() { return type; } + FieldType getFieldType() const { return type; } - bool isPrimitive() { return type == FieldType::PRIMITIVE; } + bool isPrimitive() const { return type == FieldType::PRIMITIVE; } - Rooted getPrimitiveType() { return primitiveType; } + Rooted getPrimitiveType() const { return primitiveType; } }; /** @@ -236,22 +236,130 @@ public: Handle attributesDescriptor, ManagedVector fieldDescriptors) : Node(mgr, std::move(name), parent), - attributesDescriptor(attributesDescriptor), + attributesDescriptor(acquire(attributesDescriptor)), fieldDescriptors(fieldDescriptors) { } - Rooted getAttributesDescriptor() + Rooted getAttributesDescriptor() const { return attributesDescriptor; } // TODO: Is returning a ManagedVector alright? - ManagedVector getFieldDescriptors() + ManagedVector getFieldDescriptors() const { return fieldDescriptors; } }; + +// TODO: Implement +class Cardinality { +} + +/** + * A StructuredClass specifies nodes in the StructureTree of a document that + * implements this domain. For more information on the StructureTree please + * consult the Header documentation above. + * + * Note that a StructuredClass may "invade" an existing Domain description by + * defining itself as a viable child in one existing field. Consider a "section" + * StructuredClass (continuing the example in the header documentation): + * + * + * + * + * paragraph + * + * + * + * + * Of course in most cases we do not only want to allow paragraphs inside + * sections, but also (for example) lists. How would one add that + * without manipulating the existing domain or having to define an entirely + * new domain in which section allows for lists? + * + * Our solution to this problem is the parent mechanism. The simplified XML + * (TODO: Use non-simplified version as soon as possible) for the "list" + * StructuredClass would look like this: + * + * + * + * + * item + * + * + * + * section.structure + * + * + * + * This does indeed interfere with an existing domain and one must carefully + * craft such parent references to not create undesired side effects. However + * they provide the most convenient mechanism to extend existing domains + * without having to rewrite them. + * + * Another important factor is the 'transparent' flag. Transparent + * StructureClasses may be implicitly constructed in the document graph. + * If we go back to our example a user would (without transparency) have to + * explicitly declare: + * + * + *
+ * Text. + *
+ *
+ * + * But in our mind the document + + * + *
+ * Text. + *
+ *
+ * + * Is already sufficiently specific. We can infer that a paragraph should be + * wrapped around "Text.". Therefore we set the 'transparent' flag of the + * "paragraph" StructuredClass to true. Please note that such inferences + * become increasingly complicated when children of transparent + * StructuredClasses are allowed to be transparent as well. So use with care. + * + * Finally we allow StructuredClasses to inherit attributes of other + * StructuredClasses. Inheritance also implies that instance of the inheriting + * class can be used wherever an instance of the inherited class is allowed. + * Inheritance therefore also goes for fields. TODO: What is the specification + * for field inheritance? Is the child allowed to specify children at all? + * Is that interpreted as overriding the parent fields or constructing a union? + * What about the cardinality? + */ +class StructuredClass : public Descriptor { +private: + const Cardinality cardinality; + Owned isa; + ManagedVector parents; + +public: + const bool transparent; + + StructuredClass(Manager &mgr, std::string name, Handle parent, + const Cardinality cardinality &, + // TODO: Wha would be a wise default value for isa? + Handle isa, + ManagedVector parents) + : Node(mgr, std::move(name), parent), + cardinality(cardinality), + isa(acquire(isa)), + parents(parents) + { + } + + const Cardinality &getCardinality() const { return cardinality; } + + Rooted getIsA() const {return isa}; + + // TODO: Is returning a ManagedVector alright? + ManagedVector getParents() { return parents; } +}; } } -- cgit v1.2.3