Files
NazaraEngine/include/Nazara/Core/RefCounted.hpp
Lynix 6f265a1cb3 Revert "Core/RefCounted: Remove persistent boolean"
This reverts commit db2ef3e90c3871290d114a9e6437b412e96c65aa [formerly a3f6ff88a25e63374eb6ce5b18269da2ba743b06] [formerly cfa12604fbb0da76fc27288b210ee1254a8b3a38 [formerly dee6ce858398e2de38ef1af00c1c630fd0126e09]] [formerly 1a23f0fddcd80ac33030061b7a00a3cfd43cb7fe [formerly d3cb17069c71449ae3f1cba6de55ea70f509e7a4] [formerly b2f8f82e9f3427310204f2e8a61d7bdfd96202d2 [formerly 5d117720d08d6d6243b3428d4b3f8aea1abef845]]].


Former-commit-id: a7af09faec974d268de6680f2c0c16d531048935 [formerly 37761044d13cf2e2041c9eed9ff113a41efd87f8] [formerly ae05b7afb5f43daf90cd8182bf24c98067be4d16 [formerly 6633982a51ba117a749f08efda338455eabe59b3]]
Former-commit-id: a4c99f7c8c26a0c1276eb5262871a1964d470bfb [formerly 741d46a0838a64e92aaa46fe563493da10d62c98]
Former-commit-id: fe30e63aeb19e56fa64447bdd884766f84f305dd
2016-08-02 13:20:34 +02:00

50 lines
1.1 KiB
C++

// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_REFCOUNTED_HPP
#define NAZARA_REFCOUNTED_HPP
#include <Nazara/Prerequesites.hpp>
#include <atomic>
#include <unordered_map>
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_REFCOUNTED
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
#endif
namespace Nz
{
class NAZARA_CORE_API RefCounted
{
public:
RefCounted(bool persistent = true);
RefCounted(const RefCounted&) = delete;
RefCounted(RefCounted&&) = default;
virtual ~RefCounted();
void AddReference() const;
unsigned int GetReferenceCount() const;
bool IsPersistent() const;
bool RemoveReference() const;
bool SetPersistent(bool persistent = true, bool checkReferenceCount = false);
RefCounted& operator=(const RefCounted&) = delete;
RefCounted& operator=(RefCounted&&) = default;
private:
std::atomic_bool m_persistent;
mutable std::atomic_uint m_referenceCount;
};
}
#endif // NAZARA_RESOURCE_HPP