OSVR-Core
PathTree.h
Go to the documentation of this file.
1 
11 // Copyright 2014 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_PathTree_h_GUID_8C6C691A_AAB1_4586_64DD_BD3F870C9071
26 #define INCLUDED_PathTree_h_GUID_8C6C691A_AAB1_4586_64DD_BD3F870C9071
27 
28 // Internal Includes
29 #include <osvr/Common/Export.h>
31 #include <osvr/Common/PathTree_fwd.h> // IWYU pragma: export
32 
33 // Library/third-party includes
34 #include <boost/noncopyable.hpp>
35 
36 // Standard includes
37 #include <string>
38 
39 namespace osvr {
40 namespace common {
43  class PathTree : boost::noncopyable {
44  public:
46  OSVR_COMMON_EXPORT PathTree();
47 
51  template <typename F> void visitTree(F &functor) { functor(*m_root); }
52 
55  template <typename F> void visitConstTree(F &functor) const {
56  functor(const_cast<PathNode const &>(*m_root));
57  }
59 
65  OSVR_COMMON_EXPORT PathNode &getNodeByPath(std::string const &path);
66 
71  OSVR_COMMON_EXPORT PathNode const &
72  getNodeByPath(std::string const &path) const;
73 
78  OSVR_COMMON_EXPORT PathNode &
79  getNodeByPath(std::string const &path,
80  PathElement const &finalComponentDefault);
81 
83  OSVR_COMMON_EXPORT void reset();
84 
85  PathNode &getRoot() { return *m_root; }
86 
87  PathNode const &getRoot() const { return *m_root; }
88 
89  private:
91  PathNodePtr m_root;
92  };
93 
100  OSVR_COMMON_EXPORT bool
101  addAlias(PathNode &node, std::string const &source,
102  AliasPriority priority = ALIASPRIORITY_MANUAL);
103 
113  OSVR_COMMON_EXPORT bool
114  addAliasFromRoute(PathNode &node, std::string const &route,
115  AliasPriority priority = ALIASPRIORITY_MANUAL);
116 
118  PathNode &node, std::string const &source, std::string const &dest,
119  AliasPriority priority = ALIASPRIORITY_MANUAL);
120 
121  bool addArticulation(PathNode &node, std::string const &source,
122  std::string const &dest);
123 
124  bool isPathAbsolute(std::string const &source);
125 
129  OSVR_COMMON_EXPORT void clonePathTree(PathTree const &src, PathTree &dest);
130 
131 } // namespace common
132 } // namespace osvr
133 
134 #endif // INCLUDED_PathTree_h_GUID_8C6C691A_AAB1_4586_64DD_BD3F870C9071
bool addArticulation(PathNode &node, std::string const &source, std::string const &dest)
Definition: PathTree.cpp:165
void visitConstTree(F &functor) const
Visit the tree, with const nodes, starting at the root, with the given functor.
Definition: PathTree.h:55
Handles spatial transformations.
Definition: SerializationTraitExample_Complicated.h:40
A node in a generic tree, which can contain an object by value.
Definition: TreeNode.h:72
A tree representation, with path/url syntax, of the known OSVR system.
Definition: PathTree.h:43
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
OSVR_COMMON_EXPORT PathTree()
Constructor.
Definition: PathTree.cpp:47
OSVR_COMMON_EXPORT PathNode & getNodeByPath(std::string const &path)
Returns the node indicated by the path, which must be absolute (begin with a /).
Definition: PathTree.cpp:48
OSVR_COMMON_EXPORT void clonePathTree(PathTree const &src, PathTree &dest)
Clones a path tree.
Definition: PathTree.cpp:188
OSVR_COMMON_EXPORT void reset()
Reset the path tree to a new, empty root node.
Definition: PathTree.cpp:66
boost::variant< NullElement, AliasElement, ArticulationElement, SensorElement, InterfaceElement, DeviceElement, PluginElement, StringElement > PathElement
The variant type containing a particular kind of path element.
Definition: PathElementTypes_fwd.h:54
::osvr::util::TreeNodePointer< PathElement >::type PathNodePtr
The ownership pointer of the specific tree node.
Definition: PathNode_fwd.h:45
OSVR_COMMON_EXPORT bool addAlias(PathNode &node, std::string const &source, AliasPriority priority=ALIASPRIORITY_MANUAL)
Make node an alias pointing to source, with the given priority, if it needs updating.
void visitTree(F &functor)
Visitation.
Definition: PathTree.h:51
OSVR_COMMON_EXPORT bool addAliasFromRoute(PathNode &node, std::string const &route, AliasPriority priority=ALIASPRIORITY_MANUAL)
Parse an old-style route object (with source and destination), and use the given node as a entry poin...
bool addAliasFromSourceAndRelativeDest(PathNode &node, std::string const &source, std::string const &dest, AliasPriority priority=ALIASPRIORITY_MANUAL)
Definition: PathTree.cpp:149