CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::Package Class Referencefinal

A package is a collection of resources that are stored in a single data blob. More...

#include <CeresEngine/Resource/Package.hpp>

Inheritance diagram for CeresEngine::Package:
CeresEngine::RefCounted< Package >

Classes

struct  Entry
 A structure that describes a single entry in the package. More...
 
struct  PackageIndex
 A structure that wraps the index of a package. More...
 

Public Member Functions

 Package (PackageManager &manager, const PackageURL &packageURL)
 Creates a new package.
 
 ~Package () noexcept
 
const PackageIDgetPackageID () const noexcept
 A UUID that uniquely identifies the package.
 
const SPtr< PackageMetadata > & getMetadata () const noexcept
 Generates a hash for the provided type.
 
void setMetadata (const SPtr< PackageMetadata > &metadata) noexcept
 Generates a hash for the provided type.
 
bool isEmpty () const noexcept
 Checks if the package is currently empty and contains no resources.
 
Async addResource (const FilePath &path, const HResource &resource, bool allowReplacing=false)
 Adds a new resource to the package.
 
Async removeResource (const FilePath &path)
 Removes the resource at the given path from the package.
 
Async removeResource (const ResourceID &resourceID)
 Removes the resource with the given ID from the package.
 
Async< HResourceloadResource (const FilePath &path)
 Loads a resource from the package.
 
Async< HResourceloadResource (const ResourceID &resourceID)
 Loads a resource from the package.
 
Async save ()
 
Async save (const PackageURL &url)
 
- Public Member Functions inherited from CeresEngine::RefCounted< Package >
 RefCounted (Args &&... args)
 Creates a new RefCounted object and constructs a new Deleter by forwarding Args to it.
 
void retain () noexcept
 Retains the object by increment it's reference count by one.
 
bool release () noexcept
 Relases the object by decrementing it's reference count by one.
 

Private Member Functions

Optional< FilePathresolveUUIDToPath (const ResourceID &uuid)
 Resolves a resource UUID to it's package-relative path.
 
Optional< ResourceIDresolvePathToUUID (const FilePath &path)
 Resolves a package-relative resource path to it's UUID.
 

Private Attributes

PackageManagermManager
 The package manager from which this package was loaded from.
 
PackageURL mPackageURL
 An absolute URL to the package.
 
PackageID mPackageID
 A UUID that uniquely identifies the package.
 
SPtr< PackageMetadatamMetadata
 A pointer to the package metadata object.
 
UPtr< PrivateDatamData
 The package data.
 
LockedObject< PackageIndex, SharedMutexmIndex
 The package index. Contains information about the contents of the package.
 

Friends

class PackagedResourceData
 

Detailed Description

A package is a collection of resources that are stored in a single data blob.

Loading a package will not load the resources, but will instead load a small header that contains information about the resources contained in the package. However, loading a package will make all it's resources available on the resource system.

Constructor & Destructor Documentation

◆ Package()

CeresEngine::Package::Package ( PackageManager manager,
const PackageURL packageURL 
)
explicit

Creates a new package.

Parameters
managerThe manager that will own the package.
packageURLThe URL to which the package will be stored at.

◆ ~Package()

CeresEngine::Package::~Package ( )
noexcept

Member Function Documentation

◆ addResource()

Async CeresEngine::Package::addResource ( const FilePath path,
const HResource resource,
bool  allowReplacing = false 
)

Adds a new resource to the package.

Parameters
pathThe path to add the resource inside the package.
resourceThe resource to be added to the package.
allowReplacingIf true, will replace the resource inside the package if a resource already exists on the given path.

◆ getMetadata()

const SPtr< PackageMetadata > & CeresEngine::Package::getMetadata ( ) const
inlinenoexcept

Generates a hash for the provided type.

Type must have a std::hash specialization.

Template Parameters
Tthe type to be hashed
Parameters
vThe value to be hashed
Returns
The hashed value

◆ getPackageID()

const PackageID & CeresEngine::Package::getPackageID ( ) const
inlinenoexcept

A UUID that uniquely identifies the package.

◆ isEmpty()

bool CeresEngine::Package::isEmpty ( ) const
noexcept

Checks if the package is currently empty and contains no resources.

Note
This can be used when removing resources to check if the package is empty and can be removed.

◆ loadResource() [1/2]

Async< HResource > CeresEngine::Package::loadResource ( const FilePath path)

Loads a resource from the package.

If the resource is already loaded, the loaded instance is returned.

◆ loadResource() [2/2]

Async< HResource > CeresEngine::Package::loadResource ( const ResourceID resourceID)

Loads a resource from the package.

If the resource is already loaded, the loaded instance is returned.

◆ removeResource() [1/2]

Async CeresEngine::Package::removeResource ( const FilePath path)

Removes the resource at the given path from the package.

Parameters
pathThe path to remove the resource at.

◆ removeResource() [2/2]

Async CeresEngine::Package::removeResource ( const ResourceID resourceID)

Removes the resource with the given ID from the package.

Parameters
pathThe resource ID of the resource to be removed.

◆ resolvePathToUUID()

Optional< ResourceID > CeresEngine::Package::resolvePathToUUID ( const FilePath path)
private

Resolves a package-relative resource path to it's UUID.

If no such resource exists on the package, an empty optional is returned.

◆ resolveUUIDToPath()

Optional< FilePath > CeresEngine::Package::resolveUUIDToPath ( const ResourceID uuid)
private

Resolves a resource UUID to it's package-relative path.

If no such resource exists on the package, an empty optional is returned.

◆ save() [1/2]

Async CeresEngine::Package::save ( )

◆ save() [2/2]

Async CeresEngine::Package::save ( const PackageURL url)

◆ setMetadata()

void CeresEngine::Package::setMetadata ( const SPtr< PackageMetadata > &  metadata)
inlinenoexcept

Generates a hash for the provided type.

Type must have a std::hash specialization.

Template Parameters
Tthe type to be hashed
Parameters
vThe value to be hashed
Returns
The hashed value

Friends And Related Symbol Documentation

◆ PackagedResourceData

Member Data Documentation

◆ mData

UPtr<PrivateData> CeresEngine::Package::mData
private

The package data.

◆ mIndex

LockedObject<PackageIndex, SharedMutex> CeresEngine::Package::mIndex
private

The package index. Contains information about the contents of the package.

◆ mManager

PackageManager& CeresEngine::Package::mManager
private

The package manager from which this package was loaded from.

◆ mMetadata

SPtr<PackageMetadata> CeresEngine::Package::mMetadata
private

A pointer to the package metadata object.

◆ mPackageID

PackageID CeresEngine::Package::mPackageID
private

A UUID that uniquely identifies the package.

◆ mPackageURL

PackageURL CeresEngine::Package::mPackageURL
private

An absolute URL to the package.

All contained resources use this as their base URL.


The documentation for this class was generated from the following file: