From 60d9d3f9f54fab975c39d4c341f118df90628375 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Mon, 12 Jan 2015 13:42:10 +0100 Subject: normalized NodeVector access in model classes and added some more documentation to model classes. --- test/core/model/TestAdvanced.hpp | 22 +++++++++++----------- test/core/model/TestDocumentBuilder.hpp | 13 +++++-------- test/core/model/TestDomain.hpp | 32 ++++++++++++++++---------------- 3 files changed, 32 insertions(+), 35 deletions(-) (limited to 'test/core') diff --git a/test/core/model/TestAdvanced.hpp b/test/core/model/TestAdvanced.hpp index 769a0df..696fbed 100644 --- a/test/core/model/TestAdvanced.hpp +++ b/test/core/model/TestAdvanced.hpp @@ -60,9 +60,9 @@ static Rooted constructHeadingDomain(Manager &mgr, mgr, "heading", domain, card, {nullptr}, {nullptr}, true)}; // as field we actually want to refer to the field of paragraph. Rooted p = resolveDescriptor(bookDomain, "paragraph"); - heading->getFieldDescriptors().push_back(p->getFieldDescriptors()[0]); + heading->addFieldDescriptor(p->getFieldDescriptors()[0]); // add the class to the domain. - domain->getStructureClasses().push_back(heading); + domain->addStructuredClass(heading); // create a new field for headings in each section type. std::vector secclasses{"book", "section", "subsection", "paragraph"}; @@ -70,8 +70,8 @@ static Rooted constructHeadingDomain(Manager &mgr, Rooted desc = resolveDescriptor(bookDomain, s); Rooted heading_field{new FieldDescriptor( mgr, desc, FieldDescriptor::FieldType::SUBTREE, "heading")}; - heading_field->getChildren().push_back(heading); - desc->getFieldDescriptors().push_back(heading_field); + heading_field->addChild(heading); + desc->addFieldDescriptor(heading_field); } return domain; } @@ -94,18 +94,18 @@ static Rooted constructListDomain(Manager &mgr, // set up item StructuredClass; Rooted item{new StructuredClass( mgr, "item", domain, any, {nullptr}, {nullptr}, false)}; - domain->getStructureClasses().push_back(item); + domain->addStructuredClass(item); // as field we actually want to refer to the field of paragraph. - item->getFieldDescriptors().push_back(p->getFieldDescriptors()[0]); + item->addFieldDescriptor(p->getFieldDescriptors()[0]); // set up list StructuredClasses. std::vector listTypes{"ol", "ul"}; for (auto &listType : listTypes) { Rooted list{new StructuredClass( mgr, listType, domain, any, {nullptr}, p, false)}; Rooted list_field{new FieldDescriptor(mgr, list)}; - list_field->getChildren().push_back(item); - list->getFieldDescriptors().push_back(list_field); - domain->getStructureClasses().push_back(list); + list_field->addChild(item); + list->addFieldDescriptor(list_field); + domain->addStructuredClass(list); } return domain; } @@ -122,10 +122,10 @@ static Rooted constructEmphasisDomain(Manager &mgr, // create AnnotationClasses Rooted em{ new AnnotationClass(mgr, "emphasized", domain, {nullptr})}; - domain->getAnnotationClasses().push_back(em); + domain->addAnnotationClass(em); Rooted strong{ new AnnotationClass(mgr, "strong", domain, {nullptr})}; - domain->getAnnotationClasses().push_back(strong); + domain->addAnnotationClass(strong); return domain; } diff --git a/test/core/model/TestDocumentBuilder.hpp b/test/core/model/TestDocumentBuilder.hpp index ed7a0ee..4662a28 100644 --- a/test/core/model/TestDocumentBuilder.hpp +++ b/test/core/model/TestDocumentBuilder.hpp @@ -165,8 +165,7 @@ Rooted buildStructuredEntity( fieldName + "!"); return {nullptr}; } - NodeVector &field = parent->getField(fieldName); - field.push_back(entity); + parent->addStructuredEntity(entity, fieldName); // and return it. return entity; @@ -205,8 +204,7 @@ Rooted buildPrimitiveEntity( fieldName + "!"); return {nullptr}; } - NodeVector &field = parent->getField(fieldName); - field.push_back(entity); + parent->addStructuredEntity(entity, fieldName); // and return it. return entity; } @@ -244,8 +242,7 @@ Rooted buildAnchor(Logger &logger, fieldName + "!"); return {nullptr}; } - NodeVector &field = parent->getField(fieldName); - field.push_back(anchor); + parent->addStructuredEntity(anchor, fieldName); // and return it. return anchor; } @@ -289,9 +286,9 @@ Rooted buildAnnotationEntity( // Then construct the AnnotationEntity itself Rooted anno{new AnnotationEntity( document->getManager(), document, descriptor.cast(), - attributes, start, end, name)}; + start, end, attributes, name)}; // append the new entity to the document - document->getAnnotations().push_back(anno); + document->addAnnotation(anno); // and return it. return anno; } diff --git a/test/core/model/TestDomain.hpp b/test/core/model/TestDomain.hpp index aa3096d..48db57a 100644 --- a/test/core/model/TestDomain.hpp +++ b/test/core/model/TestDomain.hpp @@ -44,53 +44,53 @@ static Rooted constructBookDomain(Manager &mgr, // Set up the "book" node. Rooted book{new StructuredClass( mgr, "book", domain, single, {nullptr}, {nullptr}, false, true)}; - domain->getStructureClasses().push_back(book); + domain->addStructuredClass(book); // The structure field of it. Rooted book_field{new FieldDescriptor(mgr, book)}; - book->getFieldDescriptors().push_back(book_field); + book->addFieldDescriptor(book_field); // From there on the "section". Rooted section{ new StructuredClass(mgr, "section", domain, any)}; - book_field->getChildren().push_back(section); - domain->getStructureClasses().push_back(section); + book_field->addChild(section); + domain->addStructuredClass(section); // And the field of it. Rooted section_field{new FieldDescriptor(mgr, section)}; - section->getFieldDescriptors().push_back(section_field); + section->addFieldDescriptor(section_field); // We also add the "paragraph", which is transparent. Rooted paragraph{new StructuredClass( mgr, "paragraph", domain, any, {nullptr}, {nullptr}, true)}; - section_field->getChildren().push_back(paragraph); - book_field->getChildren().push_back(paragraph); - domain->getStructureClasses().push_back(paragraph); + section_field->addChild(paragraph); + book_field->addChild(paragraph); + domain->addStructuredClass(paragraph); // And the field of it. Rooted paragraph_field{ new FieldDescriptor(mgr, paragraph)}; - paragraph->getFieldDescriptors().push_back(paragraph_field); + paragraph->addFieldDescriptor(paragraph_field); // We append "subsection" to section. Rooted subsection{ new StructuredClass(mgr, "subsection", domain, any)}; - section_field->getChildren().push_back(subsection); - domain->getStructureClasses().push_back(subsection); + section_field->addChild(subsection); + domain->addStructuredClass(subsection); // And the field of it. Rooted subsection_field{ new FieldDescriptor(mgr, subsection)}; - subsection->getFieldDescriptors().push_back(subsection_field); + subsection->addFieldDescriptor(subsection_field); // and we add the paragraph to subsections fields - subsection_field->getChildren().push_back(paragraph); + subsection_field->addChild(paragraph); // Finally we add the "text" node, which is transparent as well. Rooted text{new StructuredClass( mgr, "text", domain, any, {nullptr}, {nullptr}, true)}; - paragraph_field->getChildren().push_back(text); - domain->getStructureClasses().push_back(text); + paragraph_field->addChild(text); + domain->addStructuredClass(text); // ... and has a primitive field. Rooted text_field{new FieldDescriptor( mgr, text, domain->getTypesystems()[0]->getTypes()[0], "content", false)}; - text->getFieldDescriptors().push_back(text_field); + text->addFieldDescriptor(text_field); return domain; } -- cgit v1.2.3