Unravel Engine C++ Reference
Loading...
Searching...
No Matches
unravel::asset_database Class Reference

Manages asset metadata and provides functionality for adding, removing, and querying assets. More...

#include <asset_storage.h>

Classes

struct  meta
 Metadata information for an asset including its location. More...
 

Public Types

using database_t = std::map<hpp::uuid, meta>
 Type definition for the asset database.
 

Public Member Functions

auto get_database () const -> const database_t &
 Gets the entire asset database.
 
void set_database (const database_t &rhs)
 Sets the asset database.
 
void remove_all ()
 Removes all assets from the database.
 
auto add_asset (const std::string &location, const asset_meta &meta, bool override) -> hpp::uuid
 Adds an asset to the database.
 
auto get_uuid (const std::string &location) const -> const hpp::uuid &
 Gets the UUID of an asset based on its location.
 
auto get_metadata (const std::string &location) const -> const meta &
 
auto get_metadata (const hpp::uuid &id) const -> const meta &
 Gets the metadata of an asset based on its UUID.
 
void rename_asset (const std::string &key, const std::string &new_key)
 Renames an asset.
 
void remove_asset (const std::string &key)
 Removes an asset from the database.
 

Detailed Description

Manages asset metadata and provides functionality for adding, removing, and querying assets.

Definition at line 193 of file asset_storage.h.

Member Typedef Documentation

◆ database_t

using unravel::asset_database::database_t = std::map<hpp::uuid, meta>

Type definition for the asset database.

Definition at line 209 of file asset_storage.h.

Member Function Documentation

◆ add_asset()

auto unravel::asset_database::add_asset ( const std::string & location,
const asset_meta & meta,
bool override ) -> hpp::uuid
inline

Adds an asset to the database.

If an entry already exists for location:

  • override == false: returns the existing UUID and does nothing else.
  • override == true: updates the entry's metadata in place, keeping the original UUID so that any link referencing it stays valid.

Otherwise inserts a new entry keyed by meta.uid.

The entire operation runs under a single lock: looking up the existing entry, deciding whether to insert vs. update, and mutating the map all happen atomically. The previous implementation released the lock between the lookup and the insert, which opened a TOC-TOU window where another thread could remove the entry and we'd end up inserting under a fresh random UUID instead of preserving the existing one (or, with override, creating a duplicate entry that aliased the same location under two different UUIDs).

Parameters
locationThe location of the asset.
metaThe metadata of the asset.
overrideWhether to overwrite an existing entry's metadata.
Returns
The UUID of the added (or pre-existing) asset.

Definition at line 263 of file asset_storage.h.

◆ get_database()

auto unravel::asset_database::get_database ( ) const -> const database_t&
inline

Gets the entire asset database.

Returns
A constant reference to the asset database.

Definition at line 215 of file asset_storage.h.

◆ get_metadata() [1/2]

auto unravel::asset_database::get_metadata ( const hpp::uuid & id) const -> const meta&
inline

Gets the metadata of an asset based on its UUID.

Parameters
idThe UUID of the asset.
Returns
The metadata of the asset.

Definition at line 329 of file asset_storage.h.

◆ get_metadata() [2/2]

auto unravel::asset_database::get_metadata ( const std::string & location) const -> const meta&
inline

Definition at line 310 of file asset_storage.h.

◆ get_uuid()

auto unravel::asset_database::get_uuid ( const std::string & location) const -> const hpp::uuid&
inline

Gets the UUID of an asset based on its location.

Parameters
locationThe location of the asset.
Returns
The UUID of the asset, or a nil UUID if not found.

Definition at line 296 of file asset_storage.h.

◆ remove_all()

void unravel::asset_database::remove_all ( )
inline

Removes all assets from the database.

Definition at line 233 of file asset_storage.h.

◆ remove_asset()

void unravel::asset_database::remove_asset ( const std::string & key)
inline

Removes an asset from the database.

Parameters
keyThe key of the asset to remove.

Definition at line 368 of file asset_storage.h.

◆ rename_asset()

void unravel::asset_database::rename_asset ( const std::string & key,
const std::string & new_key )
inline

Renames an asset.

Parameters
keyThe current key of the asset.
new_keyThe new key for the asset.

Definition at line 348 of file asset_storage.h.

◆ set_database()

void unravel::asset_database::set_database ( const database_t & rhs)
inline

Sets the asset database.

Parameters
rhsThe asset database to set.

Definition at line 224 of file asset_storage.h.


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