From adf031f1ce3891635d7c3af2bb2f3e90de52c6ca Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Wed, 1 Apr 2015 00:03:05 +0200 Subject: Some small formatting and comment changes, introduce more anonymous namespaces in cpp --- src/core/model/Ontology.cpp | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'src/core/model/Ontology.cpp') diff --git a/src/core/model/Ontology.cpp b/src/core/model/Ontology.cpp index 0341df8..d63c5e7 100644 --- a/src/core/model/Ontology.cpp +++ b/src/core/model/Ontology.cpp @@ -30,6 +30,7 @@ namespace ousia { /* Helper Functions */ +namespace { struct PathState { std::shared_ptr pred; Node *node; @@ -177,21 +178,25 @@ struct CollectState { CollectState(Node *n, size_t depth) : n(n), depth(depth) {} }; +/** + * TODO: @Benjmin Documentation! + */ template static NodeVector collect(const Node *start, F match) { - // result NodeVector res; - // queue for breadth-first search of graph. + + // Queue and set for breadth-first search of the document graph std::queue q; - // put the initial node on the stack. - q.push(CollectState(const_cast(start), 0)); - // set of visited nodes. std::unordered_set visited; + + // Put the start node onto the stack. + q.push(CollectState(const_cast(start), 0)); while (!q.empty()) { CollectState state = q.front(); q.pop(); - // do not proceed if this node was already visited. + + // Do not proceed if this node was already visited. if (!visited.insert(state.n).second) { continue; } @@ -202,11 +207,12 @@ static NodeVector collect(const Node *start, F match) // look through all fields. NodeVector fields = strct->getFieldDescriptors(); for (auto fd : fields) { - // note matches. + // Store all matching items if (match(fd, state.depth)) { res.push_back(fd); } - // only continue in the TREE field. + + // Only continue in the TREE field. if (fd->getFieldType() == FieldDescriptor::FieldType::TREE) { q.push(CollectState(fd.get(), state.depth)); } @@ -221,6 +227,7 @@ static NodeVector collect(const Node *start, F match) if (match(c, state.depth)) { res.push_back(c); } + // We only continue our search via transparent children. if (c->isTransparent()) { q.push(CollectState(c.get(), state.depth + 1)); @@ -234,7 +241,7 @@ static NodeVector collect(const Node *start, F match) static std::vector collectPermittedTokens( const Node *start, Handle ontology) { - // gather SyntaxDescriptors for structure children first. + // Gather SyntaxDescriptors for structure children first std::vector res; collect(start, [&res](Handle n, size_t depth) { SyntaxDescriptor stx; @@ -243,21 +250,24 @@ static std::vector collectPermittedTokens( } else { stx = n.cast()->getSyntaxDescriptor(depth); } - // do not add trivial SyntaxDescriptors. + + // Do not add trivial SyntaxDescriptors if (!stx.isEmpty()) { - res.push_back(stx); + res.emplace_back(stx); } return false; }); - // gather SyntaxDescriptors for AnnotationClasses. + + // Gather SyntaxDescriptors for AnnotationClasses. for (auto a : ontology->getAnnotationClasses()) { SyntaxDescriptor stx = a->getSyntaxDescriptor(); if (!stx.isEmpty()) { - res.push_back(stx); + res.emplace_back(stx); } } return res; } +} /* Class FieldDescriptor */ -- cgit v1.2.3