Rapicorn - Experimental UI Toolkit - Source Code
13.07.0
|
Binary data access for builtin resources and files. More...
Public Member Functions | |
Blob () | |
Default construct a NULL blob. | |
String | name () const |
Provide the name of this resource Blob. | |
size_t | size () const |
Retrieve the size of a Blob in bytes, this may be 0. | |
const char * | data () const |
Access the data of a Blob. | |
const uint8 * | bytes () const |
Access the data of a Blob. | |
String | string () const |
Access data as string, strips trailing 0s. | |
operator _UBool () const | |
Checks if the blob contains accessible data. | |
Static Public Member Functions | |
static Blob | load (const String &res_path) |
Load Blob at res_path, sets errno on error. | |
static Blob | from (const String &blob_string) |
Create a Blob containing blob_string. |
Binary data access for builtin resources and files.
A Blob provides access to binary data (BLOB = Binary Large OBject) which can be preassembled and compiled into a program or located in a resource path directory. Locators for resources should generally adhere to the form:
res: [relative_path/] resource_name
See also: RAPICORN_STATIC_RESOURCE_DATA(), RAPICORN_STATIC_RESOURCE_ENTRY().
Example:
// Declare text resources for later use in a program. RAPICORN_STATIC_RESOURCE_DATA (text_resource) = "Alpha Beta Gamma"; // Compiler adds trailing 0 RAPICORN_STATIC_RESOURCE_ENTRY (text_resource, "tests/text_resource.txt"); // If a resource data length is given, it must match the initializer size (it may omit the trailing zero). RAPICORN_STATIC_RESOURCE_DATA (digit_resource) = "0123456789"; // Provide exactly 10 characters. RAPICORN_STATIC_RESOURCE_ENTRY (digit_resource, "tests/digit_resource.txt", 10); static void // Access a previously declared resource from anywhere within a program. access_text_resources () { // Load a Blob from "tests/text_resource.txt" Blob blob = Blob::load ("res:tests/text_resource.txt"); assert (blob.size() > 0); // Verify lookup success. // Access the Blob as string (automatically strips trailing 0s). std::string text = blob.string(); assert (text == "Alpha Beta Gamma"); // Verify its contents. // Load the other defined "tests/digit_resource.txt" blob. blob = Blob::load ("res:tests/digit_resource.txt"); // Access Blob size and data, assert (10 == blob.size() && 0 == strcmp (blob.data(), "0123456789")); }