From a1245cf2ad80cba0a71ffb184966ee77a7e166cc Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 15 Jan 2015 14:18:07 +0100 Subject: Further simplified document buildup by doing the addition to parents of StructureNodes in the constructor and refactored Anchor as standalone class instead of AnnotationEntity child. This made some changes in the test bench necessary as well. --- src/core/model/Document.cpp | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'src/core/model/Document.cpp') diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index eca24e7..299b427 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -89,11 +89,38 @@ int DocumentEntity::getFieldDescriptorIndex( } } +/* Class StructureNode */ + +StructureNode::StructureNode(Manager &mgr, std::string name, + Handle parent, const std::string &fieldName) + : Node(mgr, std::move(name), parent) +{ + if(parent->isa(RttiTypes::StructuredEntity)){ + parent.cast()->addStructureNode(this, fieldName); + } else if(parent->isa(RttiTypes::AnnotationEntity)){ + parent.cast()->addStructureNode(this, fieldName); + } else{ + throw OusiaException("The proposed parent was no DocumentEntity!"); + } +} + +/* Class StructuredEntity */ + +StructuredEntity::StructuredEntity(Manager &mgr, Handle doc, + Handle descriptor, + Variant attributes, std::string name) + : StructureNode(mgr, std::move(name), doc), + DocumentEntity(this, descriptor, std::move(attributes)) +{ + doc->setRoot(this); +} + /* Class AnnotationEntity */ AnnotationEntity::AnnotationEntity(Manager &mgr, Handle parent, - Handle descriptor, Handle start, - Handle end, Variant attributes, std::string name) + Handle descriptor, + Handle start, Handle end, + Variant attributes, std::string name) : Node(mgr, std::move(name), parent), DocumentEntity(this, descriptor, attributes), start(acquire(start)), @@ -121,15 +148,15 @@ const Rtti Document = {&AnnotationEntity, &StructuredEntity}); const Rtti StructureNode = RttiBuilder("StructureNode").parent(&Node); -const Rtti AnnotationEntity = - RttiBuilder("AnnotationEntity").parent(&Node).composedOf(&StructureNode); const Rtti StructuredEntity = RttiBuilder("StructuredEntity").parent(&StructureNode).composedOf( - {&StructureNode}); + {&StructuredEntity, &DocumentPrimitive, &Anchor}); const Rtti DocumentPrimitive = RttiBuilder("DocumentPrimitive").parent(&StructureNode); -const Rtti Anchor = - RttiBuilder("Anchor").parent(&StructureNode); +const Rtti Anchor = RttiBuilder("Anchor").parent(&StructureNode); +const Rtti AnnotationEntity = + RttiBuilder("AnnotationEntity").parent(&Node).composedOf( + {&StructuredEntity, &DocumentPrimitive, &Anchor}); } } -- cgit v1.2.3