From 51de9238ddbd6b7f4cdaa5e9a5918cae952891b2 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Mon, 12 Jan 2015 15:50:10 +0100 Subject: Tried to introduce another StructureNode class as common superclass for StructuredEntity, Anchor and DocumentPrimitive. Nearly seems to work, but not entirely so. There are still issues with the Manager it seems. --- src/core/model/Document.cpp | 8 +++-- src/core/model/Document.hpp | 73 ++++++++++++++++++++++++++++++--------------- 2 files changed, 54 insertions(+), 27 deletions(-) (limited to 'src/core/model') diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index f591095..723aafd 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -111,13 +111,15 @@ const Rtti Document = const Rtti AnnotationEntity = RttiBuilder("AnnotationEntity").parent(&DocumentEntity).composedOf( &StructuredEntity); +const Rtti StructureNode = + RttiBuilder("StructureNode").parent(&Node); const Rtti StructuredEntity = - RttiBuilder("StructuredEntity").parent(&DocumentEntity).composedOf( + RttiBuilder("StructuredEntity").parent(&DocumentEntity).parent(&StructureNode).composedOf( {&StructuredEntity, &Anchor, &DocumentPrimitive}); const Rtti DocumentPrimitive = - RttiBuilder("DocumentPrimitive").parent(&StructuredEntity); + RttiBuilder("DocumentPrimitive").parent(&StructureNode); const Rtti Anchor = - RttiBuilder("Anchor").parent(&StructuredEntity); + RttiBuilder("Anchor").parent(&StructureNode); } } diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index 6e3b320..9bf8f07 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -124,9 +124,8 @@ class Rtti; namespace model { -class StructuredEntity; -class AnnotationEntity; class Document; +class StructureNode; /** * A DocumentEntity is the common superclass for StructuredEntities and @@ -139,11 +138,11 @@ class Document; * name. * */ -class DocumentEntity : public Node { +class DocumentEntity : public virtual Node { private: Owned descriptor; const Variant attributes; - std::vector> fields; + std::vector> fields; int getFieldDescriptorIndex(const std::string &fieldName, bool enforce) const; @@ -164,10 +163,12 @@ public: if (!descriptor.isNull()) { for (size_t f = 0; f < descriptor->getFieldDescriptors().size(); f++) { - fields.push_back(NodeVector(this)); + fields.push_back(NodeVector(this)); } } } + //TODO: Is this necessary? + virtual ~DocumentEntity() {}; Rooted getDescriptor() const { return descriptor; } @@ -203,7 +204,7 @@ public: * FieldDescriptor in the Domain description. * @return a NodeVector of all StructuredEntities in that field. */ - const NodeVector &getField( + const NodeVector &getField( const std::string &fieldName = "") const { return fields[getFieldDescriptorIndex(fieldName, true)]; @@ -220,7 +221,7 @@ public: * this DocumentEntity. * @return a NodeVector of all StructuredEntities in that field. */ - const NodeVector &getField( + const NodeVector &getField( Handle fieldDescriptor) const { return fields[getFieldDescriptorIndex(fieldDescriptor, true)]; @@ -238,7 +239,7 @@ public: * @param fieldName is the name of a field as specified in the * FieldDescriptor in the Domain description. */ - void addStructuredEntity(Handle s, + void addStructuredEntity(Handle s, const std::string &fieldName = "") { fields[getFieldDescriptorIndex(fieldName, true)].push_back(s); @@ -256,10 +257,10 @@ public: * @param fieldName is the name of a field as specified in the * FieldDescriptor in the Domain description. */ - void addStructuredEntities(const std::vector> &ss, + void addStructuredEntities(const std::vector> &ss, const std::string &fieldName = "") { - NodeVector &field = + NodeVector &field = fields[getFieldDescriptorIndex(fieldName, true)]; field.insert(field.end(), ss.begin(), ss.end()); } @@ -274,7 +275,7 @@ public: * @param fieldDescriptor is a FieldDescriptor defined in the Descriptor for * this DocumentEntity. */ - void addStructuredEntity(Handle s, + void addStructuredEntity(Handle s, Handle fieldDescriptor) { fields[getFieldDescriptorIndex(fieldDescriptor, true)].push_back(s); @@ -291,26 +292,42 @@ public: * @param fieldDescriptor is a FieldDescriptor defined in the Descriptor for * this DocumentEntity. */ - void addStructuredEntities(const std::vector> &ss, + void addStructuredEntities(const std::vector> &ss, Handle fieldDescriptor) { - NodeVector &field = + NodeVector &field = fields[getFieldDescriptorIndex(fieldDescriptor, true)]; field.insert(field.end(), ss.begin(), ss.end()); } }; /** - * A StructuredEntity is a node in the Structure Tree of a document. For more + * A StructureNode is a Node of the StructureTree of the document. This is a + * common superclass for StructuredEntity, Anchor and DocumentPrimitive. + */ +class StructureNode : public virtual Node { +public: + StructureNode(Manager &mgr, std::string name, Handle parent) + : Node(mgr, std::move(name), parent) + { + } + //TODO: Is this necessary? + virtual ~StructureNode(){}; +}; + +/** + * A StructuredEntity is an instance of a StructuredClass. For more * information please refer to the header documentation above. */ -class StructuredEntity : public DocumentEntity { +class StructuredEntity : public DocumentEntity, public StructureNode { public: StructuredEntity(Manager &mgr, Handle parent, Handle descriptor, Variant attributes, std::string name = "") - : DocumentEntity(mgr, parent, descriptor, std::move(attributes), - std::move(name)) + : Node(mgr, std::move(name), parent), + DocumentEntity(mgr, parent, descriptor, std::move(attributes), + std::move(name)), + StructureNode(mgr, std::move(name), parent) { } }; @@ -320,15 +337,20 @@ public: * The most straightforward example for this is the actual document text, e.g. * inside a paragraph. In that case this would represent a mere string. */ -class DocumentPrimitive : public StructuredEntity { +class DocumentPrimitive : public StructureNode { +private: + Variant content; + public: DocumentPrimitive(Manager &mgr, Handle parent, Variant content = {}) - : StructuredEntity(mgr, parent, nullptr, std::move(content)) + : Node(mgr, parent), + StructureNode(mgr, "", parent), + content(content) { } - Variant getContent() const { return getAttributes(); } + Variant getContent() const { return content; } // TODO: Override such methods like "getField" to disable them? }; @@ -361,7 +383,7 @@ public: * referenced by an AnnotationEntity as it start and end point. * Please refer to the AnnotationEntity documentation for more information. */ - class Anchor : public StructuredEntity { + class Anchor : public StructureNode { public: /** * @param mgr is the Manager instance. @@ -369,8 +391,9 @@ public: * not the AnnotationEntity that references this Anchor. * @param name is the Anchor id. */ - Anchor(Manager &mgr, Handle parent, std::string name) - : StructuredEntity(mgr, parent, nullptr, Variant(), std::move(name)) + Anchor(Manager &mgr, std::string name, Handle parent) + : Node(mgr, std::move(name), parent), + StructureNode(mgr, std::move(name), parent) { } }; @@ -399,7 +422,8 @@ public: Handle descriptor, Handle start, Handle end, Variant attributes = {}, std::string name = "") - : DocumentEntity(mgr, parent, descriptor, attributes, std::move(name)), + : Node(mgr, std::move(name), parent), + DocumentEntity(mgr, parent, descriptor, attributes, std::move(name)), start(acquire(start)), end(acquire(end)) { @@ -509,6 +533,7 @@ namespace RttiTypes { extern const Rtti Document; extern const Rtti DocumentEntity; extern const Rtti AnnotationEntity; +extern const Rtti StructureNode; extern const Rtti StructuredEntity; extern const Rtti DocumentPrimitive; extern const Rtti Anchor; -- cgit v1.2.3