From 7d10e59d822f1e405f1f5ac252db11790a1e9b43 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 9 Jan 2015 17:09:17 +0100 Subject: added path function ResolutionResult --- src/core/model/Node.cpp | 19 ++++++++++++++----- src/core/model/Node.hpp | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/model/Node.cpp b/src/core/model/Node.cpp index d1aee53..5d8bbeb 100644 --- a/src/core/model/Node.cpp +++ b/src/core/model/Node.cpp @@ -213,6 +213,13 @@ public: size_t resultCount() { return shared.result.size(); } }; +/* Class ResolutionResult */ + +std::vector ResolutionResult::path() const +{ + return node->path(resolutionRoot); +} + /* Class Node */ void Node::setName(std::string name) @@ -223,18 +230,20 @@ void Node::setName(std::string name) this->name = std::move(name); } -void Node::path(std::vector &p) const +void Node::path(std::vector &p, Handle root) const { if (!isRoot()) { - parent->path(p); + parent->path(p, root); + } + if (this != root) { + p.push_back(name); } - p.push_back(name); } -std::vector Node::path() const +std::vector Node::path(Handle root) const { std::vector res; - path(res); + path(res, root); return res; } diff --git a/src/core/model/Node.hpp b/src/core/model/Node.hpp index c9c2808..6001dc2 100644 --- a/src/core/model/Node.hpp +++ b/src/core/model/Node.hpp @@ -67,6 +67,14 @@ struct ResolutionResult { : node(node), resolutionRoot(resolutionRoot) { } + + /** + * Returns a canonical path leading to the node. The path is relative to the + * resolutionRoot (the root node of the subgraph the node was defined in). + * + * @return a canonical path leading to the node. + */ + std::vector path() const; }; // Forward declaration @@ -99,7 +107,7 @@ private: * * @param p is the list the path should be constructed in. */ - void path(std::vector &p) const; + void path(std::vector &p, Handle root) const; /** * Returns true if the resolution process is just at the beginning (no part @@ -325,10 +333,12 @@ public: * Returns the vector containing the complete path to this node (including * the name of the parent nodes). * + * @param root is the node up to which the path should be returned. Ignored + * if set to nullptr. * @return a vector containing the path (starting with the root node) to * this node as a list of names. */ - std::vector path() const; + std::vector path(Handle root = nullptr) const; /** * Function which resolves a name path to a list of possible nodes starting -- cgit v1.2.3