Functions

Resource APIs
[Wavepacket Common Headers]

These APIs support the ability to build resources (strings, binary objects, etc. More...

Collaboration diagram for Resource APIs:

Functions

int getResourceNamespaceCount (void) throw ()
 retrieve the number of namespaces
const char * getResourceNamespaceName (int index) throw ()
 retrieve the indexed namespace name. Returns NULL on invalid input
int getStringResourceCount (const char *nameSpace) throw ()
 retrieve the number of string resources in the specified namespace
const char * getStringResourceName (const char *nameSpace, int index) throw ()
 retrieve the name of a given string resource
const char * getStringResource (const char *nameSpace, const char *name) throw ()
 retrieve a string resource by name (returns NULL if not found)
void registerStringResource (const char *nameSpace, const char *name, const char *value)
 register a new string resource in the given namespace

Detailed Description

These APIs support the ability to build resources (strings, binary objects, etc.

) directly into the binary for later reference.

At the moment support is somewhat hacky, but can be improved over time.

Some limitations (aka design features) of the current API:


To use resources in your binary, add resource definitions to the config file. As an example:

        resource {
                namespace       foo             # must specify namespace
                type            string          # this is the only type supported
                name            my-resource     # any text will do
                file            foobar.txt      # local file
        }

That will create a resource named "my-resource" whose value is the contents of the file "foobar.txt".

A namespace is just a string identifier, which should be reasonably unique so you won't have collisions with other libraries that are declaring their own resources.

NOTE: this is the same config file that is used by the Wavepacket Build System. See that documentation for more information.

Once a resource has been declared and named in the config file, and the application is rebuilt, the resource can be retrieved within the application code by calling getStringResource().

Notes on the resource entry:

For example, this resource entry:

        resource {
                namespace       foo
                file            license.txt
        }

is equivalent to:

        resource {
                namespace       foo
                type            string          # type 'string' is assumed as default
                name            license.txt     # name is assumed to be filename
                file            license.txt
        }


That is, within the application code you can now call getStringResource("foo", "license.txt") to retrieve a string containing the full contents of license.txt.


TODO: support other resource types.


Function Documentation

int getResourceNamespaceCount ( void   )  throw ()

retrieve the number of namespaces

Definition at line 149 of file resources.cpp.

const char* getResourceNamespaceName ( int  index  )  throw ()

retrieve the indexed namespace name. Returns NULL on invalid input

Definition at line 164 of file resources.cpp.

int getStringResourceCount ( const char *  nameSpace  )  throw ()

retrieve the number of string resources in the specified namespace

Definition at line 186 of file resources.cpp.

const char* getStringResourceName ( const char *  nameSpace,
int  index 
) throw ()

retrieve the name of a given string resource

Definition at line 201 of file resources.cpp.

const char* getStringResource ( const char *  nameSpace,
const char *  name 
) throw ()

retrieve a string resource by name (returns NULL if not found)

Definition at line 227 of file resources.cpp.

void registerStringResource ( const char *  nameSpace,
const char *  name,
const char *  value 
)

register a new string resource in the given namespace

Definition at line 253 of file resources.cpp.