MLIB
Loading...
Searching...
No Matches
mlib::asset Class Reference

Class for storing asset files in Windows resource data. More...

#include <asset.h>

Public Member Functions

 asset (int id_, const std::string &name_=std::string(), bool persist=false)
 Constructor for an asset object.
 
 ~asset ()
 Destructor. Delete asset file if it exists.
 
const void * data ()
 Load asset data.
 
size_t size ()
 Return size of asset (in bytes)
 
bool write (const std::string &path)
 Write the asset to a folder.
 
bool remove ()
 

Data Fields

const std::string name
 

Detailed Description

Class for storing asset files in Windows resource data.

This class provides a mechanism for 'hiding' the different assets needed by a HTTP server (pages, CSS files, images, etc.) inside the EXE file.

Each asset is stored as a user-defined resource of type RESFILE (defined as 256) and is identified by its ID. An asset can be written to a file. When the asset object goes out of scope the file is deleted.

The resource file (.rc) should contain some lines like these: IDR_INDEX_HTML RESFILE "index.html" IDR_MAIN_CSS RESFILE "main.css"

Constructor & Destructor Documentation

◆ asset()

mlib::asset::asset ( int id_,
const std::string & name_ = std::string (),
bool persist = false )
inline

Constructor for an asset object.

Parameters
name_asset file name
id_resource ID
persistif true do not delete disk file when asset object is destructed

Member Function Documentation

◆ data()

const void * mlib::asset::data ( )

Load asset data.

Returns
pointer to asset data or 0 if an error occurs.

◆ write()

bool mlib::asset::write ( const std::string & path)

Write the asset to a folder.

Parameters
pathroot path for asset file (with or without terminating backslash)
Returns
true if successful, false otherwise

Asset filename is obtained by appending the asset name to the root path. For persistent assets, if file already exists, it is not overwritten.


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