OSVR-Core
TreeNodeFullPath.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_TreeNodeFullPath_h_GUID_46FC8EF9_1977_4086_CC13_D85136A55414
26 #define INCLUDED_TreeNodeFullPath_h_GUID_46FC8EF9_1977_4086_CC13_D85136A55414
27 
28 // Internal Includes
29 #include <osvr/Util/TreeNode.h>
30 
31 // Library/third-party includes
32 // - none
33 
34 // Standard includes
35 #include <sstream>
36 
37 namespace osvr {
38 namespace util {
39  namespace tree {
40  template <typename T>
41  inline void buildPathRecursively(util::TreeNode<T> const &node,
42  const char pathSeparator[],
43  std::ostream &os) {
44  auto parent = node.getParent();
45  if (parent) {
46  buildPathRecursively(*parent, pathSeparator, os);
47  }
48  if (!node.isRoot()) {
49  os << pathSeparator << node.getName();
50  }
51  }
52 
55  template <typename T>
56  inline std::string getTreeNodeFullPath(util::TreeNode<T> const &node,
57  const char pathSeparator[]) {
59  if (node.isRoot()) {
60  return std::string(pathSeparator);
61  }
62  std::ostringstream os;
63  buildPathRecursively(node, pathSeparator, os);
64  return os.str();
65  }
66  } // namespace tree
68 } // namespace util
69 } // namespace osvr
70 
71 #endif // INCLUDED_TreeNodeFullPath_h_GUID_46FC8EF9_1977_4086_CC13_D85136A55414
Definition: RunLoopManager.h:42
A node in a generic tree, which can contain an object by value.
Definition: TreeNode.h:72
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
std::string getTreeNodeFullPath(util::TreeNode< T > const &node, const char pathSeparator[])
Given a tree node and a path separator, get the full path identifying that tree node.
Definition: TreeNodeFullPath.h:56
bool isRoot() const
Is the current node a root node?
Definition: TreeNode.h:276
Header.