Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
CallOnExit.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_CALLONEXIT_HPP
8 #define NAZARA_CALLONEXIT_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <functional>
12 
13 namespace Nz
14 {
15  class CallOnExit
16  {
17  using Func = std::function<void()>;
18 
19  public:
20  CallOnExit(Func func = nullptr);
21  CallOnExit(const CallOnExit&) = delete;
22  CallOnExit(CallOnExit&&) = delete;
23  ~CallOnExit();
24 
25  void CallAndReset(Func func = nullptr);
26  void Reset(Func func = nullptr);
27 
28  CallOnExit& operator=(const CallOnExit&) = delete;
29  CallOnExit& operator=(CallOnExit&&) = default;
30 
31  private:
32  Func m_func;
33  };
34 }
35 
36 #include <Nazara/Core/CallOnExit.inl>
37 
38 #endif // NAZARA_CALLONEXIT_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
CallOnExit(Func func=nullptr)
Constructs a CallOnExit object with a function.
Definition: CallOnExit.inl:22
~CallOnExit()
Destructs the object and calls the function.
Definition: CallOnExit.inl:31
Core class that represents a function to call at the end of the scope.
Definition: CallOnExit.hpp:15
void CallAndReset(Func func=nullptr)
Calls the function and sets the new callback.
Definition: CallOnExit.inl:43
void Reset(Func func=nullptr)
Resets the function.
Definition: CallOnExit.inl:57