A database that maps keys to struct entries, initialized from an initializer list. More...
#include <structdatabase.h>
Public Types | |
| using | Database = promeki::Map< KeyType, StructType > |
| using | NameDatabase = promeki::Map< String, KeyType > |
Public Member Functions | |
| StructDatabase ()=default | |
| Constructs an empty database. | |
| StructDatabase (const std::initializer_list< StructType > &&list) | |
| Constructs a database and populates it from an initializer list. | |
| void | add (const StructType &&val) |
| Adds a single entry to the database. | |
| const StructType & | get (const KeyType &id) const |
| Retrieves an entry by its key, falling back to key 0 if not found. | |
| KeyType | lookupKeyByName (const String &name) const |
| Looks up a key by the entry's name. | |
| void | load (const std::initializer_list< StructType > &&list) |
| Loads all entries from an initializer list. | |
| const Database & | database () const |
| Returns a const reference to the underlying database map. | |
| Database & | database () |
| Returns a mutable reference to the underlying database map. | |
A database that maps keys to struct entries, initialized from an initializer list.
Provides a structure database that can be initialized from an initializer list, allowing you to initialize a structure database on startup. The struct must contain members named id and name. The id is used as the key in the map. The ID 0 must exist as it will be returned as the fallback when an id is not found. The name must be a unique name for each struct entry.
| KeyType | The type used as the lookup key (must be convertible from 0 for the fallback). |
| StructType | The struct type stored in the database; must have id and name members. |
|
inline |
Constructs a database and populates it from an initializer list.
| list | Initializer list of StructType entries to load. |
|
inline |
Adds a single entry to the database.
| val | The struct entry to add (keyed by val.id). |
|
inline |
Retrieves an entry by its key, falling back to key 0 if not found.
| id | The key to look up. |
|
inline |
Loads all entries from an initializer list.
| list | The initializer list of entries to add. |
|
inline |
Looks up a key by the entry's name.
| name | The unique name to search for. |