diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/model/Document.cpp | 32 | ||||
-rw-r--r-- | src/core/model/Document.hpp | 33 |
2 files changed, 53 insertions, 12 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 411a755..3a076c4 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -598,7 +598,7 @@ bool StructureNode::doValidate(Logger &logger) const StructureNode::StructureNode(Manager &mgr, std::string name, Handle<Node> parent, const std::string &fieldName) - : Node(mgr, std::move(name), parent) + : DocumentNode(mgr, std::move(name), parent) { if (parent->isa(&RttiTypes::StructuredEntity)) { parent.cast<StructuredEntity>()->addStructureNode(this, fieldName); @@ -611,7 +611,7 @@ StructureNode::StructureNode(Manager &mgr, std::string name, StructureNode::StructureNode(Manager &mgr, std::string name, Handle<Node> parent, size_t fieldIdx) - : Node(mgr, std::move(name), parent) + : DocumentNode(mgr, std::move(name), parent) { if (parent->isa(&RttiTypes::StructuredEntity)) { parent.cast<StructuredEntity>()->addStructureNode(this, fieldIdx); @@ -622,6 +622,12 @@ StructureNode::StructureNode(Manager &mgr, std::string name, } } +StructureNode::StructureNode(Manager &mgr, std::string name, + Handle<Node> parent) + : DocumentNode(mgr, std::move(name), parent) +{ +} + /* Class StructuredEntity */ StructuredEntity::StructuredEntity(Manager &mgr, Handle<Document> doc, @@ -641,6 +647,13 @@ StructuredEntity::StructuredEntity(Manager &mgr, Handle<Node> parent, { } +void StructuredEntity::doResolve(ResolutionState &state) +{ + for (const auto &field : getFields()) { + continueResolveComposita(field, field.getIndex(), state); + } +} + bool StructuredEntity::doValidate(Logger &logger) const { bool valid = true; @@ -732,7 +745,7 @@ AnnotationEntity::AnnotationEntity(Manager &mgr, Handle<Document> parent, Handle<AnnotationClass> descriptor, Handle<Anchor> start, Handle<Anchor> end, Variant attributes, std::string name) - : Node(mgr, std::move(name), parent), + : DocumentNode(mgr, std::move(name), parent), DocumentEntity(this, descriptor, attributes) { if (parent != nullptr) { @@ -742,6 +755,13 @@ AnnotationEntity::AnnotationEntity(Manager &mgr, Handle<Document> parent, setEnd(end); } +void AnnotationEntity::doResolve(ResolutionState &state) +{ + for (const auto &field : getFields()) { + continueResolveComposita(field, field.getIndex(), state); + } +} + bool AnnotationEntity::doValidate(Logger &logger) const { bool valid = true; @@ -986,8 +1006,10 @@ namespace RttiTypes { const Rtti Document = RttiBuilder<ousia::Document>("Document") .parent(&RootNode) .composedOf({&AnnotationEntity, &StructuredEntity}); +const Rtti DocumentNode = + RttiBuilder<ousia::DocumentNode>("DocumentNode").parent(&Node); const Rtti StructureNode = - RttiBuilder<ousia::StructureNode>("StructureNode").parent(&Node); + RttiBuilder<ousia::StructureNode>("StructureNode").parent(&DocumentNode); const Rtti StructuredEntity = RttiBuilder<ousia::StructuredEntity>("StructuredEntity") .parent(&StructureNode) @@ -997,7 +1019,7 @@ const Rtti DocumentPrimitive = RttiBuilder<ousia::DocumentPrimitive>( const Rtti Anchor = RttiBuilder<ousia::Anchor>("Anchor").parent(&StructureNode); const Rtti AnnotationEntity = RttiBuilder<ousia::AnnotationEntity>("AnnotationEntity") - .parent(&Node) + .parent(&DocumentNode) .composedOf({&StructuredEntity, &DocumentPrimitive, &Anchor}); } } diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index 1ac913d..b2691c0 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -172,6 +172,8 @@ private: protected: bool doValidate(Logger &logger) const; + std::vector<NodeVector<StructureNode>> &getFields() { return fields; } + public: /** * The constructor for a DocumentEntity. Node that this does not inherit @@ -498,10 +500,19 @@ public: }; /** + * The DocumentNode class is a dummy class for being capable of selecting + * all nodes in the document graph e.g. when resolving element names. + */ +class DocumentNode : public Node { +public: + using Node::Node; +}; + +/** * A StructureNode is a Node of the StructureTree of the document. This is a * common superclass for StructuredEntity, Anchor and DocumentPrimitive. */ -class StructureNode : public Node { +class StructureNode : public DocumentNode { friend DocumentEntity; protected: @@ -524,10 +535,7 @@ public: * Constructor for an empty StructureNode. */ StructureNode(Manager &mgr, std::string name = "", - Handle<Node> parent = nullptr) - : Node(mgr, std::move(name), parent) - { - } + Handle<Node> parent = nullptr); }; /** @@ -541,6 +549,7 @@ private: bool transparent = false; protected: + void doResolve(ResolutionState &state) override; bool doValidate(Logger &logger) const override; public: @@ -675,6 +684,7 @@ public: : StructureNode(mgr, "", parent, fieldName), content(content) { } + /** * Constructor for a DocumentPrimitive. * @@ -697,11 +707,18 @@ public: } /** + * Returns the content of this DocumentPrimitive as a const reference. + * + * @return the content of this DocumentPrimitive. + */ + const Variant &getContent() const { return content; } + + /** * Returns the content of this DocumentPrimitive. * * @return the content of this DocumentPrimitive. */ - Variant getContent() const { return content; } + Variant &getContent() { return content; } /** * Sets the content of this DocumentPrimitive to the given Variant. @@ -828,7 +845,7 @@ public: * the two text exerpts "emphasized" and "and" separately. * */ -class AnnotationEntity : public Node, public DocumentEntity { +class AnnotationEntity : public DocumentNode, public DocumentEntity { friend DocumentEntity; friend Document; @@ -837,6 +854,7 @@ private: Owned<Anchor> end; protected: + void doResolve(ResolutionState &state) override; bool doValidate(Logger &logger) const override; public: @@ -1081,6 +1099,7 @@ public: namespace RttiTypes { extern const Rtti Document; +extern const Rtti DocumentNode; extern const Rtti DocumentEntity; extern const Rtti AnnotationEntity; extern const Rtti StructureNode; |