OpenWareLaboratory
Resource Class Reference

Public Member Functions

template<typename Array , typename Element >
Array asArray (size_t offset=0, size_t max_size=0xFFFFFFFF)
 Array conversion. More...
 
FloatArray asFloatArray (size_t offset=0, size_t max_size=0xFFFFFFFF)
 
bool exists () const
 
void * getData ()
 Get pointer to data. More...
 
const char * getName () const
 Get resource name. More...
 
size_t getSize () const
 Get buffer size in bytes. More...
 
bool hasData () const
 Check if data is available. More...
 
bool isMutable () const
 
size_t read (void *dest, size_t len, size_t offset=0)
 Read data from resource into memory. More...
 
 Resource ()
 
 ~Resource ()
 

Static Public Member Functions

static void destroy (Resource *resource)
 Clean up used memory resources. More...
 
static Resourceload (const char *name)
 Open resource and load data. More...
 
static Resourceopen (const char *name)
 Get resource from storage. More...
 

Protected Member Functions

 Resource (const char *name, size_t size, void *data)
 

Protected Attributes

bool allocated
 
uint8_t * data
 
const char * name
 
size_t size
 

Detailed Description

Definition at line 8 of file Resource.h.

Constructor & Destructor Documentation

Resource::Resource ( )
inline

Definition at line 92 of file Resource.h.

Referenced by open().

Resource::~Resource ( )
inline

Definition at line 93 of file Resource.h.

Resource::Resource ( const char *  name,
size_t  size,
void *  data 
)
inlineprotected

Definition at line 95 of file Resource.h.

Member Function Documentation

template<typename Array , typename Element >
template FloatArray Resource::asArray< FloatArray, float > ( size_t  offset = 0,
size_t  max_size = 0xFFFFFFFF 
)

Array conversion.

Parameters
offsetoffset in bytes
max_sizemaximum size, actual size can be smaller depending on object size

Definition at line 9 of file Resource.cpp.

References data, and size.

FloatArray Resource::asFloatArray ( size_t  offset = 0,
size_t  max_size = 0xFFFFFFFF 
)
inline

Definition at line 55 of file Resource.h.

void Resource::destroy ( Resource resource)
static

Clean up used memory resources.

Definition at line 18 of file Resource.cpp.

References allocated, and data.

bool Resource::exists ( ) const
inline

Definition at line 31 of file Resource.h.

References size.

void* Resource::getData ( )
inline

Get pointer to data.

This may be NULL if no buffer is assigned yet.

Definition at line 20 of file Resource.h.

References data.

const char* Resource::getName ( ) const
inline

Get resource name.

Definition at line 42 of file Resource.h.

References name.

size_t Resource::getSize ( ) const
inline

Get buffer size in bytes.

Definition at line 27 of file Resource.h.

References size.

bool Resource::hasData ( ) const
inline

Check if data is available.

Definition at line 13 of file Resource.h.

References data.

Referenced by load().

bool Resource::isMutable ( ) const
inline

Definition at line 35 of file Resource.h.

References allocated.

Resource * Resource::load ( const char *  name)
static

Open resource and load data.

Allocates extra memory to hold the resource if required. Returned object must be garbage collected with Resource::destroy()

Definition at line 36 of file Resource.cpp.

References allocated, data, hasData(), open(), and size.

Resource * Resource::open ( const char *  name)
static

Get resource from storage.

Returned object must be garbage collected with Resource::destroy()

Parameters
nameresource name
Returns
NULL if resource does not exist or can't be read.

Definition at line 24 of file Resource.cpp.

References data, Resource(), and size.

Referenced by load().

size_t Resource::read ( void *  dest,
size_t  len,
size_t  offset = 0 
)

Read data from resource into memory.

Parameters
lenmaximum number of bytes to read
offsetindex of first byte to read from
Returns
number of bytes actually read

Definition at line 57 of file Resource.cpp.

References data, min, name, and size.

Field Documentation

bool Resource::allocated
protected

Definition at line 100 of file Resource.h.

Referenced by destroy(), isMutable(), and load().

uint8_t* Resource::data
protected

Definition at line 99 of file Resource.h.

Referenced by asArray(), destroy(), getData(), hasData(), load(), open(), and read().

const char* Resource::name
protected

Definition at line 97 of file Resource.h.

Referenced by getName(), and read().

size_t Resource::size
protected

Definition at line 98 of file Resource.h.

Referenced by asArray(), exists(), getSize(), load(), open(), and read().


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