diff options
Diffstat (limited to 'src/core/model/Document.cpp')
-rw-r--r-- | src/core/model/Document.cpp | 157 |
1 files changed, 0 insertions, 157 deletions
diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 5386525..912a04e 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -89,163 +89,6 @@ NodeVector<StructuredEntity> &DocumentEntity::getField( "node."); } -/* Class StructuredEntity */ - -static Rooted<Descriptor> resolveDescriptor(std::vector<Handle<Domain>> domains, - const std::string &className, - const RttiBase &type) -{ - // iterate over all domains. - for (auto &d : domains) { - // use the actual resolve method. - std::vector<ResolutionResult> 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<Descriptor>(); - } - } - return {nullptr}; -} - -Rooted<StructuredEntity> StructuredEntity::buildRootEntity( - Handle<Document> document, std::vector<Handle<Domain>> domains, - const std::string &className, Variant attributes, std::string name) -{ - // If the parent is not set, we can not build the entity. - if (document == nullptr) { - return {nullptr}; - } - // If we can not find the correct descriptor, we can not build the entity - // either. - Rooted<Descriptor> descriptor = - resolveDescriptor(domains, className, RttiTypes::StructuredClass); - if (descriptor == nullptr) { - return {nullptr}; - } - // Then construct the StructuredEntity itself. - Rooted<StructuredEntity> root{new StructuredEntity( - document->getManager(), document, descriptor.cast<StructuredClass>(), - attributes, std::move(name))}; - // append it to the document. - document->setRoot(root); - // and return it. - return root; -} - -Rooted<StructuredEntity> StructuredEntity::buildEntity( - Handle<DocumentEntity> parent, std::vector<Handle<Domain>> domains, - const std::string &className, const std::string &fieldName, - Variant attributes, std::string name) -{ - // If the parent is not set, we can not build the entity. - if (parent == nullptr) { - return {nullptr}; - } - // If we can not find the correct descriptor, we can not build the entity - // either. - Rooted<Descriptor> descriptor = - resolveDescriptor(domains, className, RttiTypes::StructuredClass); - if (descriptor == nullptr) { - return {nullptr}; - } - // Then construct the StructuredEntity itself. - Rooted<StructuredEntity> entity{new StructuredEntity( - parent->getManager(), parent, descriptor.cast<StructuredClass>(), - attributes, std::move(name))}; - // if the field does not exist, return null handle as well. - if (!parent->hasField(fieldName)) { - return {nullptr}; - } - // append the new entity to the right field. - if (!parent->hasField(fieldName)) { - return {nullptr}; - } - NodeVector<StructuredEntity> &field = parent->getField(fieldName); - field.push_back(entity); - - // and return it. - return entity; -} - -/* Class DocumentPrimitive */ - -Rooted<DocumentPrimitive> DocumentPrimitive::buildEntity( - Handle<DocumentEntity> parent, Variant content, - const std::string &fieldName) -{ - // If the parent is not set, we can not build the entity. - if (parent == nullptr) { - return {nullptr}; - } - // Then construct the StructuredEntity itself. - Rooted<DocumentPrimitive> entity{ - new DocumentPrimitive(parent->getManager(), parent, content)}; - // if the field does not exist, return null handle as well. - if (!parent->hasField(fieldName)) { - return {nullptr}; - } - // append the new entity to the right field. - if (!parent->hasField(fieldName)) { - return {nullptr}; - } - NodeVector<StructuredEntity> &field = parent->getField(fieldName); - field.push_back(entity); - // and return it. - return entity; -} - -/* Class AnnotationEntity */ - -Rooted<AnnotationEntity::Anchor> AnnotationEntity::buildAnchor( - Handle<DocumentEntity> parent, std::string id, const std::string &fieldName) -{ - // If the parent is not set, we can not build the anchor. - if (parent == nullptr) { - return {nullptr}; - } - // Then construct the Anchor itself - Rooted<Anchor> anchor{ - new AnnotationEntity::Anchor(parent->getManager(), parent, id)}; - // append the new entity to the right field. - if (!parent->hasField(fieldName)) { - return {nullptr}; - } - NodeVector<StructuredEntity> &field = parent->getField(fieldName); - field.push_back(anchor); - // and return it. - return anchor; -} - -Rooted<AnnotationEntity> AnnotationEntity::buildEntity( - Handle<Document> parent, std::vector<Handle<Domain>> domains, - const std::string &className, Handle<AnnotationEntity::Anchor> start, - Handle<AnnotationEntity::Anchor> end, Variant attributes, std::string name) -{ - // If the parent is not set, we can not build the AnnotationEntity. - if (parent == nullptr) { - return {nullptr}; - } - // If we can not find the correct descriptor, we can not build the entity - // either. - Rooted<Descriptor> descriptor = - resolveDescriptor(domains, className, RttiTypes::AnnotationClass); - if (descriptor == nullptr) { - return {nullptr}; - } - // Then construct the AnnotationEntity itself - Rooted<AnnotationEntity> anno{new AnnotationEntity( - parent->getManager(), parent, descriptor.cast<AnnotationClass>(), - attributes, start, end, name)}; - // append the new entity to the document - parent->getAnnotations().push_back(anno); - // and return it. - return anno; -} - /* Class Document */ void Document::continueResolve(ResolutionState &state) |