summaryrefslogtreecommitdiff
path: root/src/core/model
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-09 17:09:17 +0100
committerAndreas Stöckel <andreas@somweyr.de>2015-01-09 17:09:17 +0100
commit7d10e59d822f1e405f1f5ac252db11790a1e9b43 (patch)
tree04bdb94fb36e9485b236ef171d0f723a01378e0d /src/core/model
parentf37d3cd42eb18433445c2e259cd71a1b2bd67be0 (diff)
added path function ResolutionResult
Diffstat (limited to 'src/core/model')
-rw-r--r--src/core/model/Node.cpp19
-rw-r--r--src/core/model/Node.hpp14
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