Corrade::Utility::Resource class

Data resource management.

This class provides support for compiled-in data resources - both compiling and reading. Resources can be differentiated into more groups, every resource in given group has unique filename.

See Resource management for brief introduction and example usage. Standalone resource compiler executable is implemented in corrade-rc.

Resource configuration file

Function compileFrom() takes a configuration file as parameter. The file allows you to specify filenames and filename aliases of resource files instead of passing the data manually to compile(). The file is used when compiling resources using corrade_add_resource() via CMake. The file can be also used when overriding compiled-in resources with live data using overrideGroup(). All filenames are expected to be in UTF-8. Example file:

group=myGroup

[file]
filename=../resources/intro-new-final.ogg
alias=intro.ogg

[file]
filename=license.txt

[file]
filename=levels-insane.conf
alias=levels-easy.conf

Public static functions

static auto compile(const std::string& name, const std::string& group, const std::vector<std::pair<std::string, std::string>>& files) -> std::string
Compile data resource file.
static auto compileFrom(const std::string& name, const std::string& configurationFile) -> std::string
Compile data resource file using configuration file.
static void overrideGroup(const std::string& group, const std::string& configurationFile)
Override group.
static auto hasGroup(const std::string& group) -> bool
Whether given group exists.

Constructors, destructors, conversion operators

Resource(const std::string& group) explicit
Constructor.

Public functions

auto list() const -> std::vector<std::string>
List of all resources in the group.
auto getRaw(const std::string& filename) const -> Containers::ArrayView<const char>
Get pointer to raw resource data.
auto get(const std::string& filename) const -> std::string
Get data resource.

Function documentation

static std::string Corrade::Utility::Resource::compile(const std::string& name, const std::string& group, const std::vector<std::pair<std::string, std::string>>& files)

Compile data resource file.

Parameters
name Resource name (see CORRADE_RESOURCE_INITIALIZE())
group Group name
files Files (pairs of filename, file data)

Produces C++ file with hexadecimal data representation.

static std::string Corrade::Utility::Resource::compileFrom(const std::string& name, const std::string& configurationFile)

Compile data resource file using configuration file.

Parameters
name Resource name (see CORRADE_RESOURCE_INITIALIZE())
configurationFile Filename of configuration file

Produces C++ file with hexadecimal data representation. See class documentation for configuration file syntax overview. The filenames are taken relative to configuration file path.

static void Corrade::Utility::Resource::overrideGroup(const std::string& group, const std::string& configurationFile)

Override group.

Parameters
group Group name
configurationFile Filename of configuration file. Empty string will discard the override.

Overrides compiled-in resources of given group with live data specified in given configuration file, useful during development and debugging. Subsequently created Resource instances with the same group will take data from live filesystem instead and fallback to compiled-in resources only for not found files.

Corrade::Utility::Resource::Resource(const std::string& group) explicit

Constructor.

Parameters
group Group name

The group must exist.

std::vector<std::string> Corrade::Utility::Resource::list() const

List of all resources in the group.

Note that the list contains only list of compiled-in files, no additional filenames from overriden group are incluuded.

Containers::ArrayView<const char> Corrade::Utility::Resource::getRaw(const std::string& filename) const

Get pointer to raw resource data.

Parameters
filename Filename in UTF-8

Returns reference to data of given file in the group. The file must exist. If the file is empty, returns nullptr.

std::string Corrade::Utility::Resource::get(const std::string& filename) const

Get data resource.

Parameters
filename Filename in UTF-8

Returns data of given file in the group. The file must exist.