1.10
Public Types | Public Member Functions | Static Public Member Functions | List of all members
ResourceManager Class Reference

Manages EGT resource data blobs. More...

#include <resource.h>

Public Types

using ItemArray = std::vector< std::string >
 Item array type.
 

Public Member Functions

void add (const char *name, const std::vector< unsigned char > &data)
 Register a resource as raw data.
 
void add (const char *name, const unsigned char *data, size_t len)
 Register a resource as raw data.
 
void clear ()
 Clear all registered resources.
 
void clear (const char *name)
 Clear the specified resource by name.
 
const unsigned char * data (const char *name)
 Get a pointer to the in-memory resource data.
 
bool exists (const char *name) const
 
EGT_NODISCARD ItemArray list () const
 Get a list of registered resource names.
 
bool read (const char *name, unsigned char *data, size_t length, size_t offset=0)
 Read data from a resource.
 
void remove (const char *name)
 Unregister a resource.
 
size_t size (const char *name)
 Get the data length of a resource.
 
bool stream_read (const char *name, unsigned char *data, size_t length)
 Read starting from internal stream offset.
 
void stream_reset (const char *name)
 Reset internal read stream offset.
 

Static Public Member Functions

static ResourceManagerinstance ()
 Get a reference to the ResourceManager instance.
 

Detailed Description

Manages EGT resource data blobs.

Resources can be registered with this class and then read back later directly from this class. When using an EGT API, like Image() that takes a URI, prefix the name in the URI with scheme 'res' to make EGT read the resource from ResourceManager.

See also
Resources

Member Typedef Documentation

◆ ItemArray

using ItemArray = std::vector<std::string>

Item array type.

Member Function Documentation

◆ add() [1/2]

void add ( const char *  name,
const std::vector< unsigned char > &  data 
)

Register a resource as raw data.

◆ add() [2/2]

void add ( const char *  name,
const unsigned char *  data,
size_t  len 
)

Register a resource as raw data.

Warning
This does not copy the data, so it must remain available.

◆ clear() [1/2]

void clear ( )

Clear all registered resources.

◆ clear() [2/2]

void clear ( const char *  name)

Clear the specified resource by name.

◆ data()

const unsigned char * data ( const char *  name)

Get a pointer to the in-memory resource data.

◆ exists()

bool exists ( const char *  name) const
Returns
true if the resource with the given name is registered.

◆ instance()

static ResourceManager & instance ( )
static

Get a reference to the ResourceManager instance.

◆ list()

EGT_NODISCARD ItemArray list ( ) const

Get a list of registered resource names.

◆ read()

bool read ( const char *  name,
unsigned char *  data,
size_t  length,
size_t  offset = 0 
)

Read data from a resource.

◆ remove()

void remove ( const char *  name)

Unregister a resource.

◆ size()

size_t size ( const char *  name)

Get the data length of a resource.

◆ stream_read()

bool stream_read ( const char *  name,
unsigned char *  data,
size_t  length 
)

Read starting from internal stream offset.

◆ stream_reset()

void stream_reset ( const char *  name)

Reset internal read stream offset.

See also
read_stream()