30 class MemoryDataStream;
81 if constexpr(std::is_constructible_v<
T,
ResourceData&, Args...>) {
210 [[nodiscard]]
ResourceManager* getResourceManager() const noexcept {
return mData !=
nullptr ? &mData->manager :
nullptr; }
226 static const PackagePtr nullPackagePtr =
nullptr;
227 return mData !=
nullptr ? mData->package : nullPackagePtr;
231 template<
typename T = Resource> [[nodiscard]]
SPtr<T> getShared() noexcept {
return static_pointer_cast<T>(shared_from_this()); }
234 template<
typename T = Resource> [[nodiscard]]
SPtr<const T> getShared() const noexcept {
return static_pointer_cast<const T>(shared_from_this()); }
272 template<
typename T,
typename Base = Resource>
class TResource :
public Base {
284 [[nodiscard]]
SPtr<T> getShared() noexcept {
return std::static_pointer_cast<T>(Resource::getShared()); }
287 [[nodiscard]]
SPtr<const T> getShared() const noexcept {
return std::static_pointer_cast<const T>(Resource::getShared()); }
317 template<
typename... Args>
319 :
T(
std::forward<Args>(args)...) {}
323 template<
typename... Args>
325 :
T(
std::forward<Args>(args)...) {}
330 template<
typename... Args>
345 template<
typename... Args>
347 : mValue(
std::forward<Args>(args)...) {}
351 template<
typename... Args>
353 : mValue(
std::forward<Args>(args)...) {}
358 template<
typename... Args>
366 const T&
get()
const {
return mValue; }
374template<>
struct std::hash<
CeresEngine::ResourceID> : std::hash<CeresEngine::UUID> {};
#define CE_REFLECTABLE_CLASS
Definition IReflectable.hpp:38
#define CE_REFL_DATA_GET(N, G)
Definition Macros.hpp:548
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
A stream associated to a resource.
Definition ResourceStream.hpp:430
An interface that must be implemented by types that wish to expose richer reflection data.
Definition IReflectable.hpp:29
A helper class that wraps and protects a value from non-synchronized access.
Definition Threading.hpp:516
Definition Resource.hpp:155
LockedObject< StreamMap, SharedMutex > mStreams
The known resource streams.
Definition Resource.hpp:160
~MemoryResourceData() noexcept final=default
MemoryResourceData virtual destructor.
HashMap< ResourceStreamID, ResourceStreamDataPtr > StreamMap
Definition Resource.hpp:157
MemoryResourceData(ResourceManager &resourceManager) noexcept
Creates a new MemoryResourceData instance.
Definition Resource.hpp:166
A stream that provides write-only stream functionality.
Definition Stream.hpp:307
A simple reference counter base class.
Definition SmartPtr.hpp:438
An object, provided by the resource manager, to view and alter data from the resource itself.
Definition Resource.hpp:89
virtual ~ResourceData() noexcept=default
ResourceData virtual destructor.
ResourceManager & manager
The resource manager that owns the resource.
Definition Resource.hpp:92
Vector< HResource > mUnsavedResources
A list of sub-resources that are pending a save.
Definition Resource.hpp:122
Map< ResourceID, WeakResourceHandle< Resource > > mSubResources
A map that enumerates the sub-resurces attached to this resource.
Definition Resource.hpp:119
ResourceData(ResourceManager &resourceManager) noexcept
Creates a new ResourceData instance.
Definition Resource.hpp:128
Definition ResourceHandle.hpp:166
A base class that all resources must extend from.
Definition Resource.hpp:186
virtual ~Resource() noexcept=default
Resource virtual destructor.
virtual const ResourceTypeInfo & getResourceType() const noexcept=0
Returns the resource type information descriptor.
SPtr< ResourceMetadata > getResourceMetadata() const noexcept
A pointer to the user-defined resource metadata.
Definition Resource.hpp:222
Resource()
Default constructor for the Resource class.
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition Resource.hpp:267
HResourceStream createStream(const ResourceStreamFlags &flags=ResourceStreamFlag::Default)
Creates a new resource stream.
HResource getParentResource() const noexcept
A parent resource to which this resource is attached to.
Definition Resource.hpp:219
SPtr< T > getShared() noexcept
Gets a shared pointer to the resource.
Definition Resource.hpp:231
virtual void serialize(OutputStream &dataStream) const =0
Serializes a resource by writing data to dataStream.
HResource getResourceHandle() const noexcept
Definition Resource.hpp:213
SPtr< const T > getShared() const noexcept
Gets a shared pointer to the resource.
Definition Resource.hpp:234
Resource(ResourceData &data)
Creates a new Resource instance by passing a ResourceData instance.
Definition Resource.hpp:203
void destroyStream(HResourceStream &stream)
Destroys a stream.
UUID getResourceID() const noexcept
Definition Resource.hpp:216
const PackagePtr & getPackage() const noexcept
The package from which the resource was loaded from.
Definition Resource.hpp:225
The ResourceManager is the main class responsible for managing and handling all resources in the engi...
Definition ResourceManager.hpp:47
ResourceObject(Args &&... args)
Creates a new instance of the T resource.
Definition Resource.hpp:324
ResourceObject(ResourceData &data, Args &&... args)
Creates a new instance of the T resource.
Definition Resource.hpp:331
ResourceObject(Args &&... args)
Creates a new instance of the T resource.
Definition Resource.hpp:318
ResourceObject(Args &&... args)
Creates a new instance of the T resource.
Definition Resource.hpp:352
const T & get() const
The object value.
Definition Resource.hpp:366
T & get()
The object value.
Definition Resource.hpp:363
T mValue
The object value.
Definition Resource.hpp:340
ResourceObject(Args &&... args)
Creates a new instance of the T resource.
Definition Resource.hpp:346
ResourceObject(ResourceData &data, Args &&... args)
Creates a new instance of the T resource.
Definition Resource.hpp:359
A wrapper type that wraps a generic object into a resource.
Definition Resource.hpp:308
An object that allows storing side-band data for a resource.
Definition ResourceStream.hpp:129
Utility template class that can be extended by Resources to automatically implement methods that are ...
Definition Resource.hpp:272
::CeresEngine::ClassInfo getClassInfo() const noexcept override
Definition Resource.hpp:274
SPtr< T > getShared() noexcept
Gets a shared pointer to the resource.
Definition Resource.hpp:284
void serialize(OutputStream &dataStream) const override
Serializes a resource by writing data to dataStream.
Definition Resource.hpp:300
ResourceHandle< T > getResourceHandle() const noexcept
Definition Resource.hpp:281
const ResourceTypeInfo & getResourceType() const noexcept override
Returns the resource type information descriptor.
Definition Resource.hpp:291
SPtr< const T > getShared() const noexcept
Gets a shared pointer to the resource.
Definition Resource.hpp:287
TResource(ResourceData &data, InputStream &dataStream)
Definition Resource.hpp:295
::CeresEngine::ClassInfo getClassInfo() noexcept override
Definition Resource.hpp:273
Represents a reflected C++ type. Can be used to get metadata from a C++ type.
Definition Type.hpp:32
StringView getTypeName() const noexcept
Definition ResourceHandle.hpp:339
Definition Application.hpp:19
constexpr bool is_implicitly_constructible
A type trait type that checks if Type is implicitly constructible from Arguments.
Definition TypeTraits.hpp:41
SPtr< T > constructResource(ResourceData &resourceData, Args &&... args)
Constructs a new resource instance.
Definition Resource.hpp:80
std::shared_ptr< T > SPtr
SPtr is a smart pointer that retains shared ownership of an object through a pointer.
Definition SmartPtr.hpp:37
constexpr bool is_explicitly_constructible
A type trait type that checks if Type is explicitly constructible from Arguments.
Definition TypeTraits.hpp:27
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
ResourceStreamFlag
A set of flags that can be given when creating a new resource stream.
Definition ResourceStream.hpp:38
std::unordered_map< Key, T, Hash, KeyEqual, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > HashMap
HashMap is an associative container that contains key-value pairs with unique keys.
Definition Map.hpp:33
auto parent(const Entity &parent)
Sets the entity parent.
Definition Helpers.hpp:52
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
std::map< Key, T, Compare, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > Map
Map is a sorted associative container that contains key-value pairs with unique keys.
Definition Map.hpp:24
A structure that contains type information for a class.
Definition IReflectable.hpp:15
Wrapper around an enum that allows simple use of bitwise logic operations.
Definition Flags.hpp:19
Type that uniquely represents a resource in the resource system.
Definition Resource.hpp:37
ResourceID(const UUID &uuid)
Converts a raw UUID into a ResouceID.
Definition Resource.hpp:41
static const ResourceID null
A null (or empty) resource ID.
Definition Resource.hpp:44
Type that uniquely represents a stream in the resource system.
Definition ResourceStream.hpp:24
A structure that describes type information for a resource.
Definition Resource.hpp:63
StringView getName() const noexcept
Definition Resource.hpp:69
const std::type_info & typeInfo
Definition Resource.hpp:64
ResourceTypeInfo(const std::type_info &typeInfo, const Type type)
Definition Resource.hpp:67
static const ResourceTypeInfo & get()
Definition Resource.hpp:71
const Type type
Definition Resource.hpp:65
Represents a universally unique identifier (UUID).
Definition UUID.hpp:27
constexpr UUID()=default
Initializes an empty UUID.