OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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:
56  typedef util::TreeNode<value_type> node_type;
58  OSVR_CLIENT_EXPORT InterfaceTree();
59 
63  OSVR_CLIENT_EXPORT bool
65 
69  OSVR_CLIENT_EXPORT bool
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()) {
100  func(util::getTreeNodeFullPath(node,
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
shared_ptr< ClientInterface > ClientInterfacePtr
Pointer for holding ClientInterface objects safely.
RemoteHandlerPtr getHandlerForPath(std::string const &path)
Returns the handler for a given path.
RemoteHandlerPtr eraseHandlerForPath(std::string const &path)
Clears and returns the handler for a given path.
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.
bool addInterface(common::ClientInterfacePtr const &iface)
Add an interface to the tree.
RemoteHandlerPtr replaceHandlerForPath(std::string const &path, RemoteHandlerPtr const &handler)
Sets the handler for a given path, returning the old handler if any.
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...
void updateHandlers()
Call the update method on all handlers.
common::InterfaceList & getInterfacesForPath(std::string const &path)
Returns a reference to the list of interfaces registered for a given path.
bool removeInterface(common::ClientInterfacePtr const &iface)
Remove an interface from the tree.
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
void clearHandlers()
Removes all handlers.
Wrapper for a container of handlers.
const char * getPathSeparator()
Gets the path separator - a slash - as a null-terminated string.
Automatically-generated export header - do not edit!
Header.