Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Functor.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Core module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_FUNCTOR_HPP
8 #define NAZARA_FUNCTOR_HPP
9 
10 #include <Nazara/Core/Algorithm.hpp>
11 
12 // Inspired from the of code of the SFML by Laurent Gomila
13 
14 namespace Nz
15 {
16  struct Functor
17  {
18  virtual ~Functor() {}
19 
20  virtual void Run() = 0;
21  };
22 
23  template<typename F>
24  struct FunctorWithoutArgs : Functor
25  {
26  FunctorWithoutArgs(F func);
27 
28  void Run() override;
29 
30  private:
31  F m_func;
32  };
33 
34  template<typename F, typename... Args>
35  struct FunctorWithArgs : Functor
36  {
37  FunctorWithArgs(F func, Args&&... args);
38 
39  void Run() override;
40 
41  private:
42  F m_func;
43  std::tuple<Args...> m_args;
44  };
45 
46  template<typename C>
47  struct MemberWithoutArgs : Functor
48  {
49  MemberWithoutArgs(void (C::*func)(), C* object);
50 
51  void Run() override;
52 
53  private:
54  void (C::*m_func)();
55  C* m_object;
56  };
57 }
58 
59 #include <Nazara/Core/Functor.inl>
60 
61 #endif // NAZARA_FUNCTOR_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Core class that represents a functor using a function with arguments.
Definition: Functor.hpp:35
Core class that represents a functor using a function without argument.
Definition: Functor.hpp:24
Core class that represents a functor using a member function.
Definition: Functor.hpp:47