OSVR-Core
GenerateCompoundServer.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_GenerateCompoundServer_h_GUID_55F870FA_C398_49B8_9907_A007B3C6F8CA
26 #define INCLUDED_GenerateCompoundServer_h_GUID_55F870FA_C398_49B8_9907_A007B3C6F8CA
27 
28 // Internal Includes
30 
31 // Library/third-party includes
32 #include <boost/mpl/begin_end.hpp>
33 #include <boost/mpl/deref.hpp>
34 #include <boost/mpl/next.hpp>
35 #include <boost/type_traits/is_same.hpp>
36 
37 // Standard includes
38 // - none
39 
40 namespace osvr {
41 namespace connection {
42  namespace server_generation {
43 
47  template <typename Types> struct GenerateServer {
48 
49  template <typename Iter>
50  struct IsLast
51  : boost::is_same<typename boost::mpl::next<Iter>::type,
52  typename boost::mpl::end<Types>::type> {};
53 
55  template <typename Iter = typename boost::mpl::begin<Types>::type,
56  bool Last = IsLast<Iter>::value>
57  class ServerElement {};
58 
60  template <typename Iter> struct LeafBase {
61  typedef typename boost::mpl::deref<Iter>::type type;
62  };
63 
66  template <typename Iter> struct ChainBase {
68  type;
69  };
70 
73  template <typename Iter>
74  class ServerElement<Iter, true> : public LeafBase<Iter>::type {
75  public:
76  typedef typename LeafBase<Iter>::type MyLeafBase;
78  ServerElement(ConstructorArgument &init) : MyLeafBase(init) {}
79  void mainloop() { MyLeafBase::server_mainloop(); }
80  vrpn_Connection *connectionPtr() {
81  return MyLeafBase::connectionPtr();
82  }
83  };
84 
87  template <typename Iter>
88  class ServerElement<Iter, false> : public LeafBase<Iter>::type,
89  public ChainBase<Iter>::type {
90  public:
91  typedef typename LeafBase<Iter>::type MyLeafBase;
92  typedef typename ChainBase<Iter>::type MyChainBase;
93 
96  : MyLeafBase(init), MyChainBase(init) {}
97 
99  void mainloop() { MyLeafBase::server_mainloop(); }
100 
101  vrpn_Connection *connectionPtr() {
102  return MyLeafBase::connectionPtr();
103  }
104  };
105 
108 
110  static type *make(ConstructorArgument &init) {
111  return new type(init);
112  }
113  };
114  } // namespace server_generation
115 } // namespace connection
116 } // namespace osvr
117 
118 #endif // INCLUDED_GenerateCompoundServer_h_GUID_55F870FA_C398_49B8_9907_A007B3C6F8CA
void mainloop()
Mainloop calls server_mainloop in the leaf.
Definition: GenerateCompoundServer.h:99
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Compute base class: the recursive step to the next element in the sequence.
Definition: GenerateCompoundServer.h:66
static type * make(ConstructorArgument &init)
Create a server.
Definition: GenerateCompoundServer.h:110
Compute base class: the current class from the sequence.
Definition: GenerateCompoundServer.h:60
ServerElement(ConstructorArgument &init)
Constructor passing along.
Definition: GenerateCompoundServer.h:78
ServerElement(ConstructorArgument &init)
Constructor passing along to both base classes.
Definition: GenerateCompoundServer.h:95
Definition: DeviceConstructionData.h:41
Forward declare the main class.
Definition: GenerateCompoundServer.h:57
Metaprogramming to generate a VRPN server object out of an MPL sequence of types. ...
Definition: GenerateCompoundServer.h:47
ServerElement type
Computed server type.
Definition: GenerateCompoundServer.h:107