diff options
-rw-r--r-- | src/core/model/Node.cpp | 19 | ||||
-rw-r--r-- | src/core/model/Node.hpp | 14 |
2 files changed, 26 insertions, 7 deletions
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<std::string> 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<std::string> &p) const +void Node::path(std::vector<std::string> &p, Handle<Node> root) const { if (!isRoot()) { - parent->path(p); + parent->path(p, root); + } + if (this != root) { + p.push_back(name); } - p.push_back(name); } -std::vector<std::string> Node::path() const +std::vector<std::string> Node::path(Handle<Node> root) const { std::vector<std::string> 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<std::string> path() const; }; // Forward declaration @@ -99,7 +107,7 @@ private: * * @param p is the list the path should be constructed in. */ - void path(std::vector<std::string> &p) const; + void path(std::vector<std::string> &p, Handle<Node> 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<std::string> path() const; + std::vector<std::string> path(Handle<Node> root = nullptr) const; /** * Function which resolves a name path to a list of possible nodes starting |