FunctionalJointVisitor.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/PlayRho
3  *
4  * This software is provided 'as-is', without any express or implied
5  * warranty. In no event will the authors be held liable for any damages
6  * arising from the use of this software.
7  *
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  *
12  * 1. The origin of this software must not be misrepresented; you must not
13  * claim that you wrote the original software. If you use this software
14  * in a product, an acknowledgment in the product documentation would be
15  * appreciated but is not required.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  * misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  */
20 
21 #ifndef PLAYRHO_DYNAMICS_JOINTS_FUNCTIONALJOINTVISITOR_HPP
22 #define PLAYRHO_DYNAMICS_JOINTS_FUNCTIONALJOINTVISITOR_HPP
23 
25 #include <functional>
26 #include <tuple>
27 #include <utility>
28 
29 namespace playrho {
30 namespace d2 {
31 
36 {
37 public:
39  template <class T>
40  using Proc = std::function<void(T)>;
41 
42  //using Tuple = std::tuple<Proc<Types>...>;
43  //FunctionalJointVisitor(const Tuple& v): procs{v} {}
44 
46  using Tuple = std::tuple<
69  >;
70 
72 
75  template <class T>
76  FunctionalJointVisitor& Use(const Proc<T>& proc) noexcept
77  {
78  std::get<Proc<T>>(procs) = proc;
79  return *this;
80  }
81 
82  // Overrides of all the base class's Visit methods...
83  // Uses decltype to ensure the correctly typed invocation of the Handle method.
84  void Visit(const RevoluteJoint& arg) override { Handle<decltype(arg)>(arg); }
85  void Visit(RevoluteJoint& arg) override { Handle<decltype(arg)>(arg); }
86  void Visit(const PrismaticJoint& arg) override { Handle<decltype(arg)>(arg); }
87  void Visit(PrismaticJoint& arg) override { Handle<decltype(arg)>(arg); }
88  void Visit(const DistanceJoint& arg) override { Handle<decltype(arg)>(arg); }
89  void Visit(DistanceJoint& arg) override { Handle<decltype(arg)>(arg); }
90  void Visit(const PulleyJoint& arg) override { Handle<decltype(arg)>(arg); }
91  void Visit(PulleyJoint& arg) override { Handle<decltype(arg)>(arg); }
92  void Visit(const TargetJoint& arg) override { Handle<decltype(arg)>(arg); }
93  void Visit(TargetJoint& arg) override { Handle<decltype(arg)>(arg); }
94  void Visit(const GearJoint& arg) override { Handle<decltype(arg)>(arg); }
95  void Visit(GearJoint& arg) override { Handle<decltype(arg)>(arg); }
96  void Visit(const WheelJoint& arg) override { Handle<decltype(arg)>(arg); }
97  void Visit(WheelJoint& arg) override { Handle<decltype(arg)>(arg); }
98  void Visit(const WeldJoint& arg) override { Handle<decltype(arg)>(arg); }
99  void Visit(WeldJoint& arg) override { Handle<decltype(arg)>(arg); }
100  void Visit(const FrictionJoint& arg) override { Handle<decltype(arg)>(arg); }
101  void Visit(FrictionJoint& arg) override { Handle<decltype(arg)>(arg); }
102  void Visit(const RopeJoint& arg) override { Handle<decltype(arg)>(arg); }
103  void Visit(RopeJoint& arg) override { Handle<decltype(arg)>(arg); }
104  void Visit(const MotorJoint& arg) override { Handle<decltype(arg)>(arg); }
105  void Visit(MotorJoint& arg) override { Handle<decltype(arg)>(arg); }
106 
107 private:
108 
110  template <class T>
111  inline void Handle(T arg) const
112  {
113  const auto& proc = std::get<Proc<T>>(procs);
114  if (proc)
115  {
116  proc(arg);
117  }
118  }
119 };
120 
121 } // namespace d2
122 } // namespace playrho
123 
124 #endif // PLAYRHO_DYNAMICS_JOINTS_FUNCTIONALJOINTVISITOR_HPP
125