OSVR-Core
InterfaceTree.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_InterfaceTree_h_GUID_7F88FD57_3657_4AA6_B725_A1C69AA21ED2
26 #define INCLUDED_InterfaceTree_h_GUID_7F88FD57_3657_4AA6_B725_A1C69AA21ED2
27 
28 // Internal Includes
29 #include <osvr/Client/Export.h>
31 #include <osvr/Util/TreeNode.h>
37 
38 // Library/third-party includes
39 // - none
40 
41 // Standard includes
42 #include <vector>
43 
44 namespace osvr {
45 namespace client {
46 
48  RemoteHandlerPtr handler;
49  common::InterfaceList interfaces;
50  };
53  class InterfaceTree {
54  public:
58  OSVR_CLIENT_EXPORT InterfaceTree();
59 
63  OSVR_CLIENT_EXPORT bool
64  addInterface(common::ClientInterfacePtr const &iface);
65 
69  OSVR_CLIENT_EXPORT bool
70  removeInterface(common::ClientInterfacePtr const &iface);
71 
74  OSVR_CLIENT_EXPORT common::InterfaceList &
75  getInterfacesForPath(std::string const &path);
76 
78  OSVR_CLIENT_EXPORT RemoteHandlerPtr
79  getHandlerForPath(std::string const &path);
80 
82  OSVR_CLIENT_EXPORT RemoteHandlerPtr
83  eraseHandlerForPath(std::string const &path);
84 
87  OSVR_CLIENT_EXPORT RemoteHandlerPtr replaceHandlerForPath(
88  std::string const &path, RemoteHandlerPtr const &handler);
89 
91  OSVR_CLIENT_EXPORT void updateHandlers();
92 
94  OSVR_CLIENT_EXPORT void clearHandlers();
95 
97  template <typename F> void visitPathsWithoutHandlers(F &&func) {
98  osvr::util::traverseWith(*m_root, [&](node_type &node) {
99  if (!node.value().handler && !node.value().interfaces.empty()) {
102  }
103  });
104  }
105 
106  private:
108  node_type &m_getNodeForPath(std::string const &path);
109 
111  RemoteHandlerPtr m_removeHandler(node_type &node);
112 
114  RemoteHandlerPtr m_setHandler(node_type &node,
115  RemoteHandlerPtr const &handler);
116  node_type::ptr_type m_root;
117  HandlerContainer m_handlers;
118  friend class HandlerClearVisitor;
119  };
120 
121 } // namespace client
122 } // namespace osvr
123 #endif // INCLUDED_InterfaceTree_h_GUID_7F88FD57_3657_4AA6_B725_A1C69AA21ED2
Definition: InterfaceTree.h:47
Definition: InterfaceTree.cpp:38
shared_ptr< ClientInterface > ClientInterfacePtr
Pointer for holding ClientInterface objects safely.
Definition: ClientInterfacePtr.h:43
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
value_type & value()
Reference accessor for contained value.
Definition: TreeNode.h:134
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
TreeNodePointer< ValueType >::type ptr_type
The pointer for holding this template instantiation - used primarily/only in holding the root node...
Definition: TreeNode.h:80
void traverseWith(T &node, F &&functor)
A method to handle visiting every node in a tree with a lambda or other by-value function object...
Definition: TreeTraversalVisitor.h:67
Holds on to lists of interfaces organized into the tree structure, as well as their associated handle...
Definition: InterfaceTree.h:53
void visitPathsWithoutHandlers(F &&func)
Visit all paths with interfaces in their list but no handler.
Definition: InterfaceTree.h:97
Definition: benchGeometry.cpp:23
Wrapper for a container of handlers.
Definition: HandlerContainer.h:41
OSVR_COMMON_EXPORT const char * getPathSeparator()
Gets the path separator - a slash - as a null-terminated string.
Definition: RoutingConstants.cpp:38
Header.