Class AssetPack

Class Documentation

class AssetPack

Interface for lazy access to an asset pack file.

Public Functions

AssetPack()

Create an empty asset pack.

Resource GetResource(const std::string &address)

Access a resource.

Parameters:

address – The resource’s address

Throws:
  • std::runtime_error – If the resource address provided is invalid

  • std::runtime_error – If the resource does not exist in the pack

Returns:

The resource object

void DeleteResource(const std::string &address)

Remove a resource from the pack.

Parameters:

address – The resource’s address

Throws:
  • std::runtime_error – If the resource address provided is invalid

  • std::runtime_error – If the resource does not exist in the pack

std::vector<std::string> ListResources()

Get a list of resources in the pack.

Returns:

A list of all resource addresses

std::vector<std::string> ListResourcesOfType(Resource::Type type)

Get a list of resources of a certain type in the pack.

Throws:

std::runtime_error – If the provided type is a type of resource that cannot be embedded in a pack

Returns:

A list of all matchingresource addresses

bool HasResource(const std::string &address)

Check if the pack contains a specific resource.

Parameters:

address – The resource’s address

Returns:

If the pack contains the resource

void PutResource(const std::string &address, Resource &&resource)

Insert a resource into the pack, replacing any previous resources at its address.

Parameters:
  • address – The resource’s address

  • resource – The Resource object

Throws:

std::runtime_error – If the resource address provided is invalid

void Export(std::ostream *stream)

Write an asset pack to an output stream.

Parameters:

stream – The stream to write the pack to

Throws:
  • std::runtime_error – If the stream pointer is invalid

  • std::runtime_error – If encoding fails

Public Static Functions

static AssetPack OpenFromFile(const std::string &filePath)

Open an asset pack file from on disk.

Parameters:

filePath – The relative path (from the working directory) to the file to open

Throws:
  • std::runtime_error – If the file does not exist or is not an asset pack

  • std::runtime_error – If the pack is of an incompatible revision

  • std::runtime_error – If decoding fails

Returns:

The opened pack

static AssetPack OpenFromStream(std::istream *stream)

Open an asset pack file from an input stream.

Warning

The new asset pack will control the stream exclusively, and it is not recoverable from the object. Do not perform further operations on the stream after calling this!

Parameters:

stream – The stream from which to load the pack

Throws:
  • std::runtime_error – If the stream pointer is invalid

  • std::runtime_error – If the stream is not an asset pack

  • std::runtime_error – If decoding fails

Returns:

The opened pack