Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
RefCounted.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_REFCOUNTED_HPP
8 #define NAZARA_REFCOUNTED_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <atomic>
12 
13 #if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_REFCOUNTED
14  #include <Nazara/Core/ThreadSafety.hpp>
15 #else
16  #include <Nazara/Core/ThreadSafetyOff.hpp>
17 #endif
18 
19 namespace Nz
20 {
21  class NAZARA_CORE_API RefCounted
22  {
23  public:
24  RefCounted(bool persistent = true);
25  RefCounted(const RefCounted&) = delete;
26  RefCounted(RefCounted&&) = default;
27  virtual ~RefCounted();
28 
29  void AddReference() const;
30 
31  unsigned int GetReferenceCount() const;
32 
33  bool IsPersistent() const;
34 
35  bool RemoveReference() const;
36 
37  bool SetPersistent(bool persistent = true, bool checkReferenceCount = false);
38 
39  RefCounted& operator=(const RefCounted&) = delete;
40  RefCounted& operator=(RefCounted&&) = default;
41 
42  private:
43  std::atomic_bool m_persistent;
44  mutable std::atomic_uint m_referenceCount;
45  };
46 }
47 
48 #endif // NAZARA_RESOURCE_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Core class that represents a reference with a counter.
Definition: RefCounted.hpp:21