From 57cbdaa164d1b7ff4987b86fe3cc2c8ba14b0b23 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 9 Jan 2015 13:33:44 +0100 Subject: Improvements to Document classes in accordance with Benjamin --- src/core/model/Document.cpp | 60 +++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 15 deletions(-) (limited to 'src/core/model/Document.cpp') diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 945fb3e..5386525 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -24,6 +24,8 @@ namespace ousia { namespace model { +/* Class DocumentEntity */ + int DocumentEntity::getFieldDescriptorIndex(const std::string &fieldName) { const NodeVector &fds = descriptor->getFieldDescriptors(); @@ -87,20 +89,23 @@ NodeVector &DocumentEntity::getField( "node."); } -static Rooted resolveDescriptor( - std::vector> domains, const std::string &className) +/* Class StructuredEntity */ + +static Rooted resolveDescriptor(std::vector> domains, + const std::string &className, + const RttiBase &type) { // iterate over all domains. for (auto &d : domains) { // use the actual resolve method. - std::vector resolved = d->resolve(className, typeOf()); + std::vector resolved = d->resolve(className, type); // if we don't find anything, continue. if (resolved.size() == 0) { continue; } // Otherwise take the first valid result. for (auto &r : resolved) { - return r.node.cast(); + return r.node.cast(); } } return {nullptr}; @@ -116,14 +121,15 @@ Rooted StructuredEntity::buildRootEntity( } // If we can not find the correct descriptor, we can not build the entity // either. - Rooted descriptor = resolveDescriptor(domains, className); + Rooted descriptor = + resolveDescriptor(domains, className, RttiTypes::StructuredClass); if (descriptor == nullptr) { return {nullptr}; } // Then construct the StructuredEntity itself. - Rooted root{ - new StructuredEntity(document->getManager(), document, descriptor, - attributes, std::move(name))}; + Rooted root{new StructuredEntity( + document->getManager(), document, descriptor.cast(), + attributes, std::move(name))}; // append it to the document. document->setRoot(root); // and return it. @@ -141,13 +147,15 @@ Rooted StructuredEntity::buildEntity( } // If we can not find the correct descriptor, we can not build the entity // either. - Rooted descriptor = resolveDescriptor(domains, className); + Rooted descriptor = + resolveDescriptor(domains, className, RttiTypes::StructuredClass); if (descriptor == nullptr) { return {nullptr}; } // Then construct the StructuredEntity itself. Rooted entity{new StructuredEntity( - parent->getManager(), parent, descriptor, attributes, std::move(name))}; + parent->getManager(), parent, descriptor.cast(), + attributes, std::move(name))}; // if the field does not exist, return null handle as well. if (!parent->hasField(fieldName)) { return {nullptr}; @@ -163,6 +171,8 @@ Rooted StructuredEntity::buildEntity( return entity; } +/* Class DocumentPrimitive */ + Rooted DocumentPrimitive::buildEntity( Handle parent, Variant content, const std::string &fieldName) @@ -188,6 +198,8 @@ Rooted DocumentPrimitive::buildEntity( return entity; } +/* Class AnnotationEntity */ + Rooted AnnotationEntity::buildAnchor( Handle parent, std::string id, const std::string &fieldName) { @@ -219,23 +231,41 @@ Rooted AnnotationEntity::buildEntity( } // If we can not find the correct descriptor, we can not build the entity // either. - Rooted descriptor = resolveDescriptor(domains, className); + Rooted descriptor = + resolveDescriptor(domains, className, RttiTypes::AnnotationClass); if (descriptor == nullptr) { return {nullptr}; } // Then construct the AnnotationEntity itself - Rooted anno{ - new AnnotationEntity(parent->getManager(), parent, descriptor, - attributes, start, end, name)}; + Rooted anno{new AnnotationEntity( + parent->getManager(), parent, descriptor.cast(), + attributes, start, end, name)}; // append the new entity to the document parent->getAnnotations().push_back(anno); // and return it. return anno; } -/* Type registrations */ +/* Class Document */ + +void Document::continueResolve(ResolutionState &state) +{ + // Try to resolve annotations and other document nodes first + bool hasResult = + continueResolveComposita(annotations, annotations.getIndex(), state); + if (root != nullptr) { + hasResult = hasResult | continueResolveCompositum(root, state); + } + + // If no direct child has been found, continue resolving the referenced + // domains + if (!hasResult) { + continueResolveReferences(domains, state); + } +} } +/* Type registrations */ namespace RttiTypes { const Rtti DocumentEntity = RttiBuilder("DocumentEntity").parent(&Node); -- cgit v1.2.3