Added ResourceRef (Automatic resource reference)
Former-commit-id: 97a0b2732f4dc443b8e1676e68b33b1b53ddf4fb
This commit is contained in:
44
include/Nazara/Core/ResourceRef.hpp
Normal file
44
include/Nazara/Core/ResourceRef.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright (C) 2013 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_RESOURCEREF_HPP
|
||||
#define NAZARA_RESOURCEREF_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
template<typename T>
|
||||
class NzResourceRef
|
||||
{
|
||||
static_assert(std::is_base_of<NzResource, T>::value, "ResourceRef should only be used with resource type");
|
||||
|
||||
public:
|
||||
NzResourceRef() = default;
|
||||
NzResourceRef(T* resource);
|
||||
NzResourceRef(const NzResourceRef& ref);
|
||||
NzResourceRef(NzResourceRef&& ref);
|
||||
~NzResourceRef();
|
||||
|
||||
bool IsValid() const;
|
||||
T* Release();
|
||||
bool Reset(T* resource = nullptr);
|
||||
NzResourceRef& Swap(NzResourceRef& ref);
|
||||
|
||||
operator bool() const;
|
||||
operator T*() const;
|
||||
T* operator->() const;
|
||||
|
||||
NzResourceRef& operator=(const NzResourceRef& ref);
|
||||
NzResourceRef& operator=(NzResourceRef&& ref);
|
||||
|
||||
private:
|
||||
T* m_resource = nullptr;
|
||||
};
|
||||
|
||||
#include <Nazara/Core/ResourceRef.inl>
|
||||
|
||||
#endif // NAZARA_RESOURCEREF_HPP
|
||||
Reference in New Issue
Block a user