OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ApplyPathNodeVisitor.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_ApplyPathNodeVisitor_h_GUID_5F05BD33_812E_4A98_354F_1481FC8AB5BE
26 #define INCLUDED_ApplyPathNodeVisitor_h_GUID_5F05BD33_812E_4A98_354F_1481FC8AB5BE
27 
28 // Internal Includes
29 #include <osvr/Common/Export.h>
31 #include <osvr/Util/TreeNode_fwd.h>
32 #include <osvr/Common/PathNode.h>
33 
34 // Library/third-party includes
35 #include <boost/variant/static_visitor.hpp>
36 #include <boost/variant/apply_visitor.hpp>
37 #include <boost/noncopyable.hpp>
38 
39 // Standard includes
40 // - none
41 
42 namespace osvr {
43 namespace common {
44  namespace detail {
45  template <typename Visitor, typename NodeType,
46  typename ResultType = typename Visitor::result_type>
47  class PathNodeVisitorImpl : public boost::static_visitor<ResultType> {
48  public:
49  PathNodeVisitorImpl(NodeType &node, Visitor &v)
50  : m_node(node), m_v(v) {}
51 
55  operator=(PathNodeVisitorImpl const &) = delete;
56 
58  template <typename T> ResultType operator()(T &val) {
59  return m_v(m_node, val);
60  }
61 
63  template <typename T> ResultType operator()(T const &val) {
64  return m_v(m_node, val);
65  }
66 
67  private:
68  NodeType &m_node;
69  Visitor &m_v;
70  };
71 
73  template <typename Visitor, typename NodeType>
74  class PathNodeVisitorImpl<Visitor, NodeType, void>
75  : public boost::static_visitor<void>, boost::noncopyable {
76  public:
77  PathNodeVisitorImpl(NodeType &node, Visitor &v)
78  : m_node(node), m_v(v) {}
79 
83  operator=(PathNodeVisitorImpl const &) = delete;
84 
86  template <typename T> void operator()(T &val) { m_v(m_node, val); }
87 
89  template <typename T> void operator()(T const &val) {
90  m_v(m_node, val);
91  }
92 
93  private:
94  NodeType &m_node;
95  Visitor &m_v;
96  };
97 
98  } // namespace detail
99 
103  template <typename Visitor>
104  inline typename Visitor::result_type applyPathNodeVisitor(Visitor &v,
105  PathNode &node) {
107  return boost::apply_visitor(visitor, node.value());
108  }
109 
112  template <typename Visitor>
113  inline typename Visitor::result_type
114  applyPathNodeVisitor(Visitor &v, PathNode const &node) {
116  return boost::apply_visitor(visitor, node.value());
117  }
118 
120 } // namespace common
121 } // namespace osvr
122 
123 #endif // INCLUDED_ApplyPathNodeVisitor_h_GUID_5F05BD33_812E_4A98_354F_1481FC8AB5BE
::osvr::util::TreeNode< PathElement > PathNode
The specific tree node type that contains a path element.
Definition: PathNode_fwd.h:42
void operator()(T &val)
Function call method for a non-const visitor.
PathNodeVisitorImpl & operator=(PathNodeVisitorImpl const &)=delete
Disable assignment operator, since we have reference members.
void operator()(T const &val)
Function call method for a const visitor.
ResultType operator()(T &val)
Function call method for a non-const visitor.
Visitor::result_type applyPathNodeVisitor(Visitor &v, PathNode &node)
Visit a node's element's contained type, similar to boost::apply_visitor, but passing both the PathNo...
Automatically-generated export header - do not edit!
ResultType operator()(T const &val)
Function call method for a const visitor.
Header forward-declaring the types in PathElementTypes.h and including the PathElement typedef...
Header.