OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
GenerateVrpnDynamicServer.cpp
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 // Internal Includes
27 #include "VrpnBaseFlexServer.h"
28 #include "VrpnAnalogServer.h"
29 #include "VrpnButtonServer.h"
30 #include "VrpnTrackerServer.h"
31 #include "GenerateCompoundServer.h"
32 
33 // Library/third-party includes
34 #include <boost/mpl/vector.hpp>
35 #include <boost/mpl/begin_end.hpp>
36 #include <boost/mpl/next.hpp>
37 #include <boost/mpl/deref.hpp>
38 #include <boost/mpl/push_back.hpp>
39 #include <boost/mpl/empty.hpp>
40 #include <boost/utility.hpp>
41 
42 // Standard includes
43 // - none
44 
45 namespace osvr {
46 namespace connection {
47 
48  namespace server_generation {
49  typedef boost::mpl::vector<vrpn_BaseFlexServer, VrpnAnalogServer,
50  VrpnButtonServer,
51  VrpnTrackerServer> ServerTypes;
52  template <typename T> struct ShouldInclude {
53  static bool predicate(DeviceConstructionData &);
54  };
55 
56  template <>
59  return true;
60  }
61 
62  template <>
63  bool ShouldInclude<VrpnAnalogServer>::predicate(
64  DeviceConstructionData &init) {
65  return init.obj.getAnalogs().is_initialized();
66  }
67 
68  template <>
69  bool ShouldInclude<VrpnButtonServer>::predicate(
70  DeviceConstructionData &init) {
71  return init.obj.getButtons().is_initialized();
72  }
73 
74  template <>
75  bool ShouldInclude<VrpnTrackerServer>::predicate(
76  DeviceConstructionData &init) {
77  return init.obj.getTracker();
78  }
79  typedef boost::mpl::begin<ServerTypes>::type Begin;
80  typedef boost::mpl::end<ServerTypes>::type End;
81 
84  template <typename Result, typename Enable = void>
86 
88  template <typename Result>
90  Result, typename boost::enable_if<
91  typename boost::mpl::empty<Result>::type>::type> {
92  static vrpn_MainloopObject *make(DeviceConstructionData &) {
93  return nullptr;
94  }
95  };
97  template <typename Result>
99  Result, typename boost::disable_if<
100  typename boost::mpl::empty<Result>::type>::type> {
101  static vrpn_MainloopObject *make(DeviceConstructionData &init) {
102  return vrpn_MainloopObject::wrap(
104  }
105  };
106 
108  template <typename Iter = Begin,
109  typename Result = boost::mpl::vector0<>,
110  typename Enable = void>
112 
114  template <typename Iter, typename Result>
116  Iter, Result,
117  typename boost::disable_if<boost::is_same<Iter, End> >::type> {
118  static vrpn_MainloopObject *run(DeviceConstructionData &init) {
119  typedef typename boost::mpl::deref<Iter>::type CurrentType;
120  typedef typename boost::mpl::next<Iter>::type NextIter;
121 
122  typedef
123  typename boost::mpl::push_back<Result, CurrentType>::type
124  ExtendedResult;
126  typedef FilterAndGenerate<NextIter, Result> NextWithout;
128  return NextWith::run(init);
129  }
130  return NextWithout::run(init);
131  }
132  };
133 
135  template <typename Iter, typename Result>
137  Iter, Result,
138  typename boost::enable_if<boost::is_same<Iter, End> >::type> {
139  static vrpn_MainloopObject *run(DeviceConstructionData &init) {
141  }
142  };
143 
144  } // namespace server_generation
145 
146  vrpn_MainloopObject *
147  generateVrpnDynamicServer(server_generation::ConstructorArgument &init) {
149  }
150 } // namespace connection
151 } // namespace osvr
Template to invoke construction once sequence filtering is complete.
Metaprogramming to generate a VRPN server object out of an MPL sequence of types. ...