Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
HandledObject.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Development Kit"
3 // For conditions of distribution and use, see copyright notice in Prerequesites.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_OBJECTHANDLER_HPP
8 #define NAZARA_OBJECTHANDLER_HPP
9 
10 #include <Nazara/Core/Bitset.hpp>
11 #include <memory>
12 #include <vector>
13 
14 namespace Nz
15 {
16  template<typename T> class ObjectHandle;
17 
18  template<typename T>
19  class HandledObject
20  {
21  friend ObjectHandle<T>;
22 
23  public:
24  HandledObject() = default;
25  HandledObject(const HandledObject& object);
26  HandledObject(HandledObject&& object);
27  ~HandledObject();
28 
29  ObjectHandle<T> CreateHandle();
30 
31  HandledObject& operator=(const HandledObject& object);
32  HandledObject& operator=(HandledObject&& object);
33 
34  protected:
35  void UnregisterAllHandles();
36 
37  private:
38  void RegisterHandle(ObjectHandle<T>* handle);
39  void UnregisterHandle(ObjectHandle<T>* handle) noexcept;
40  void UpdateHandle(ObjectHandle<T>* oldHandle, ObjectHandle<T>* newHandle) noexcept;
41 
42  std::vector<ObjectHandle<T>*> m_handles;
43  };
44 }
45 
46 #include <Nazara/Core/HandledObject.inl>
47 
48 #endif // NAZARA_OBJECTHANDLER_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Core class that represents a object handle.
Definition: HandledObject.hpp:16