5#include "Foundation/HashFunctions.h"
50 other.resource =
nullptr;
102 operator bool()
const {
return this->resource !=
nullptr; }
106 const ResourceBase * operator->()
const {
return this->resource; }
108 ResourceBase * get() {
return this->resource; }
110 const ResourceBase * get()
const {
return this->resource; }
120 void reset(ResourceBase * otherResource);
126 ResourceId getId()
const;
128 size_t hash(
size_t hashValue =
Cogs::hash())
const {
129 return Cogs::hash(
reinterpret_cast<intptr_t
>(resource), hashValue);
153 template<
typename ResourceType>
230 struct hash<
Cogs::Core::ResourceHandleBase>
234 return std::hash<const void *>()(handle.get());
bool HandleIsValid(const ResourceHandle_t< T > &handle)
Check if the given resource is valid, that is not equal to NoHandle or InvalidHandle.
Contains all Cogs related functionality.
constexpr size_t hash() noexcept
Simple getter function that returns the initial value for fnv1a hashing.
Base class for engine resources.
Resource handle base class handling reference counting of resources derived from ResourceBase.
static const ResourceHandleBase NoHandle
Provided as shorthand for empty resource handles.
void reset(ResourceBase *otherResource)
Reset the contents of this instance to the given handle and resource.
ResourceHandleBase & operator=(const ResourceHandleBase &other)
Assign the handle from the given other handle.
ResourceHandleBase()=default
Constructs an empty handle, holding no resource.
ResourceHandleBase(ResourceHandleBase &&other) noexcept
Move constructs a handle from the given other handle.
bool operator==(const ResourceHandleBase &other) const
Compares this instance against the contents of other.
bool operator!=(const ResourceHandleBase &other) const
Compares this instance against other for inequality.
ResourceHandleBase(const ResourceHandleBase &other)
Copy constructs a handle from the given other handle.
ResourceHandleBase(ResourceBase *resource)
Constructs a handle with the given integer handle and resource pointer pair.
ResourceBase * resource
Pointer to held resource.
Opaque resource handle for holding references to resources.
ResourceHandle_t()=default
Default construct a resource handle.
ResourceType * operator->() const
Pointer operator, returns the held resource.
ResourceHandle_t & operator=(const ResourceHandle_t &other)
Copy assign the handle from the given other handle.
ResourceHandle_t(const ResourceHandle_t &other)
Copy construct a handle.
ResourceHandle_t(ResourceBase *resource)
Constructs a handle from the given resource pointer.
static const ResourceHandle_t NoHandle
Handle representing a default (or none if default not present) resource.
ResourceHandle_t(ResourceHandle_t &&other) noexcept
Move construct a handle from the given r-value.
ResourceType * resolve() const
Resolve the handle, returning a pointer to the actual resource.