CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Package.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Forward.hpp"
11
12#include "Resource.hpp"
13
15
21
22namespace CeresEngine {
23
24 class PackagedResourceData;
25
33
40 using UUID::UUID;
41
43 explicit PackageID(const UUID& uuid) : UUID(uuid) {}
44
46 static const PackageID null;
47 };
48
54 class Package final : public RefCounted<Package> {
56
68
69 private:
72
76
77 private:
80
83
85 struct PrivateData;
86
89
99
102
103 public:
107 explicit Package(PackageManager& manager, const PackageURL& packageURL);
108
109 ~Package() noexcept;
110
111 public:
113 [[nodiscard]] const PackageID& getPackageID() const noexcept { return mPackageID; }
114
116 [[nodiscard]] const SPtr<PackageMetadata>& getMetadata() const noexcept { return mMetadata; }
117
119 void setMetadata(const SPtr<PackageMetadata>& metadata) noexcept { mMetadata = metadata; }
120
125 [[nodiscard]] bool isEmpty() const noexcept;
126
127 public: // Resource Management
134 Async<> addResource(const FilePath& path, const HResource& resource, bool allowReplacing = false);
135
138 Async<> removeResource(const FilePath& path);
139
142 Async<> removeResource(const ResourceID& resourceID);
143
146 Async<HResource> loadResource(const FilePath& path);
147
150 Async<HResource> loadResource(const ResourceID& resourceID);
151
152 public: // Package management
153 Async<> save();
154 Async<> save(const PackageURL& url);
155
156 private:
159 Optional<FilePath> resolveUUIDToPath(const ResourceID& uuid);
160
163 Optional<ResourceID> resolvePathToUUID(const FilePath& path);
164 };
165
167 using PackagePtr = RC<Package>;
168
171 public:
174 explicit PackagedResourceData(Package& package) noexcept;
175
179 explicit PackagedResourceData(Package& package, ResourceData&& existingData) noexcept;
180 };
181
182} // namespace CeresEngine
#define CE_REFLECTABLE_CLASS
Definition IReflectable.hpp:38
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Path to file or directory.
Definition FilePath.hpp:37
A helper class that wraps and protects a value from non-synchronized access.
Definition Threading.hpp:516
Definition Optional.hpp:17
A package is a collection of resources that are stored in a single data blob.
Definition Package.hpp:54
LockedObject< PackageIndex, SharedMutex > mIndex
The package index. Contains information about the contents of the package.
Definition Package.hpp:101
Package(PackageManager &manager, const PackageURL &packageURL)
Creates a new package.
const SPtr< PackageMetadata > & getMetadata() const noexcept
Definition Package.hpp:116
PackageURL mPackageURL
An absolute URL to the package.
Definition Package.hpp:75
void setMetadata(const SPtr< PackageMetadata > &metadata) noexcept
Definition Package.hpp:119
PackageManager & mManager
The package manager from which this package was loaded from.
Definition Package.hpp:71
PackageID mPackageID
A UUID that uniquely identifies the package.
Definition Package.hpp:79
bool isEmpty() const noexcept
Checks if the package is currently empty and contains no resources.
SPtr< PackageMetadata > mMetadata
A pointer to the package metadata object.
Definition Package.hpp:82
UPtr< PrivateData > mData
The package data.
Definition Package.hpp:88
A manager that handles packages, their loading, saving and other runtime related tasks.
Definition PackageManager.hpp:18
A ResourceData sub-class that represents a resource owned and contained within a package.
Definition Package.hpp:170
PackagedResourceData(Package &package, ResourceData &&existingData) noexcept
Creates a new PackagedResourceData instance from an existing ResourceData.
PackagedResourceData(Package &package) noexcept
Creates a new PackagedResourceData instance.
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
Definition ResourceHandle.hpp:166
A Uniform Resource Identifier (URI) is a unique sequence of characters that identifies a logical or p...
Definition URI.hpp:54
Definition ResourceHandle.hpp:339
Definition Application.hpp:19
std::unique_ptr< T, Deleter > UPtr
UPtr is a smart pointer that owns and manages another object through a pointer and disposes of that o...
Definition SmartPtr.hpp:28
std::shared_ptr< T > SPtr
SPtr is a smart pointer that retains shared ownership of an object through a pointer.
Definition SmartPtr.hpp:37
cti::continuable< Args... > Async
Defines a non-copyable continuation type which uses the function2 backend for type erasure.
Definition Async.hpp:22
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
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
A structure that describes a single entry in the package.
Definition Package.hpp:58
FilePath path
The path of the package entry.
Definition Package.hpp:63
ResourceID resourceID
The resource ID for the entry.
Definition Package.hpp:60
WeakResourceHandle< Resource > handle
A weak handle to the resource. Can be locked to return a strong handle to resource.
Definition Package.hpp:66
A structure that wraps the index of a package.
Definition Package.hpp:92
HashMap< String, Entry > byPath
Index of package resources by their paths.
Definition Package.hpp:97
HashMap< ResourceID, Entry > byUUID
Index of package resources by their UUID.
Definition Package.hpp:94
Type that uniquely represents a package in the resource system.
Definition Package.hpp:39
static const PackageID null
A null (or empty) resource ID.
Definition Package.hpp:46
PackageID(const UUID &uuid)
Converts a raw UUID into a PackageID.
Definition Package.hpp:43
A class that contains metadata for a package.
Definition Package.hpp:27
virtual ~PackageMetadata() noexcept=default
Type that uniquely represents a resource in the resource system.
Definition Resource.hpp:37
Represents a universally unique identifier (UUID).
Definition UUID.hpp:27
constexpr UUID()=default
Initializes an empty UUID.