diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-01-09 15:28:13 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-01-09 15:28:13 +0100 |
commit | 1eece2559a6cf16f5732d128c1cb6e43c5f60fbc (patch) | |
tree | 5086721fbe58ad9a5f34174890232cdb13d382c7 /src/core | |
parent | 2fd367790fd61f427263bdcfda0acba848d73bd8 (diff) |
Refactored building convenience methods to TestDocumentBuilder, added error logging and changed TestDocument and TestAdvanced as well as all users of those files accordingly.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/model/Document.cpp | 157 | ||||
-rw-r--r-- | src/core/model/Document.hpp | 109 |
2 files changed, 0 insertions, 266 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) diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index 466185b..c367e50 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -215,57 +215,6 @@ public: std::move(name)) { } - - /** - * This builds the root StructuredEntity for the given document. It - * automatically appends the newly build entity to the given document. - * - * @param document is the document this entity shall be build for. The - * resulting entity will automatically be appended to that - * document. Also the manager of that document will be - * used to register the new node. - * @param domains are the domains that are used to find the - * StructuredClass for the new node. The domains will be - * searched in the given order. - * @param className is the name of the StructuredClass. - * @param attributes are the attributes of the new node in terms of a Struct - * variant (empty per default). - * @param name is the name of this StructuredEntity (empty per - * default). - * @return the newly created StructuredEntity or a nullptr if some - * input handle was empty or the given domains did not - * contain a StructuredClass with the given name. - */ - static Rooted<StructuredEntity> buildRootEntity( - Handle<Document> document, std::vector<Handle<Domain>> domains, - const std::string &className, Variant attributes = Variant(), - std::string name = ""); - - /** - * This builds a StructuredEntity as child of the given DocumentEntity. It - * automatically appends the newly build entity to its parent. - * - * @param parent is the parent DocumentEntity. The newly constructed - * StructuredEntity will automatically be appended to it. - * @param domains are the domains that are used to find the - * StructuredClass for the new node. The domains will be - * searched in the given order. - * @param className is the name of the StructuredClass. - * @param fieldName is the name of the field where the newly constructed - * StructuredEntity shall be appended. - * @param attributes are the attributes of the new node in terms of a Struct - * variant (empty per default). - * @param name is the name of this StructuredEntity (empty per - * default). - * - * @return the newly created StructuredEntity or a nullptr if some - * input handle was empty or the given domains did not - * contain a StructuredClass with the given name. - */ - static Rooted<StructuredEntity> buildEntity( - Handle<DocumentEntity> parent, std::vector<Handle<Domain>> domains, - const std::string &className, const std::string &fieldName = "", - Variant attributes = Variant(), std::string name = ""); }; /** @@ -284,25 +233,6 @@ public: Variant getContent() const { return getAttributes(); } // TODO: Override such methods like "getField" to disable them? - - /** - * This builds a DocumentPrimitive as child of the given DocumentEntity. It - * automatically appends the newly build entity to its parent. - * - * @param parent is the parent DocumentEntity. The newly constructed - * DocumentPrimitive will automatically be appended to it. - * @param content is the primitive content of the new node in terms of a - * Struct variant. - * @param fieldName is the name of the field where the newly constructed - * StructuredEntity shall be appended. - * - * @return the newly created StructuredEntity or a nullptr if some - * input handle was empty or the given domains did not - * contain a StructuredClass with the given name. - */ - static Rooted<DocumentPrimitive> buildEntity( - Handle<DocumentEntity> parent, Variant content, - const std::string &fieldName = ""); }; /** @@ -365,45 +295,6 @@ public: Rooted<Anchor> getStart() { return start; } Rooted<Anchor> getEnd() { return end; } - - /** - * This builds an Anchor as child of the given DocumentEntity. It - * automatically appends the newly build Anchor to its parent. - * - * @param parent is the parent DocumentEntity. The newly constructed - * Anchor will automatically be appended to it. - * @param id is the id of this Anchor. - * @param fieldName is the name of the field where the newly constructed - * Anchor shall be appended. - * - * @return the newly created Anchor or a nullptr if some - * input handle was empty. - */ - static Rooted<Anchor> buildAnchor(Handle<DocumentEntity> parent, - std::string id, - const std::string &fieldName = ""); - /** - * This builds an AnnotationEntity as child of the given DocumentEntity. It - * automatically appends the newly build entity to its parent. - * - * @param parent is the document the newly constructed AnnotationEntity - * will be appended to. - * @param domains are the domains that are used to find the - * AnnotationClass for the new node. The domains will be - * searched in the given order. - * @param className is the name of the AnnotationClass. - * @param attributes are the attributes of the new node in terms of a Struct - * variant (empty per default). - * @param name is the name of this AnnotationEntity (empty per - * default). - * @return the newly created AnnotationEntity or a nullptr if some - * input handle was empty or the given domains did not - * contain a AnnotationClass with the given name. - */ - static Rooted<AnnotationEntity> buildEntity(Handle<Document> parent, std::vector<Handle<Domain>> domains, - const std::string &className, - Handle<Anchor> start, Handle<Anchor> end, - Variant attributes = Variant(), std::string name = ""); }; /** |