|
MostlyHarmless 0.0.1
|
Contains classes and functions related to data management. More...
Classes | |
| class | DatabasePropertyWatcher |
| A convenience class for responding to changes in a databaseState, potentially fired from other processes. Watches a given property's field corresponding to type T for changes, and fires a callback on change. Note that callback will run on a background timer thread, so if you need thread safety, be sure to utilise ISharedState::callOnMessageThread from your callback lambda. More... | |
Typedefs | |
| using | DatabaseValueVariant = std::variant<std::string, bool, int, float, double> |
| A std::variant containing all types satisfying the DatabaseStorageType concept. | |
Functions | |
| DatabaseState (const DatabaseState &)=delete | |
| DatabaseState (DatabaseState &&other) noexcept | |
| DatabaseState & | operator= (const DatabaseState &)=delete |
| DatabaseState & | operator= (DatabaseState &&other) noexcept |
| static auto | tryCreate (const std::filesystem::path &location, const std::vector< std::pair< std::string, DatabaseValueVariant > > &initialValues) -> std::optional< DatabaseState > |
| ~DatabaseState () noexcept | |
| template<DatabaseStorageType T> | |
| auto | set (std::string_view name, const T &toSet) -> void |
| template<DatabaseStorageType T> | |
| auto | get (std::string_view name) -> std::optional< T > |
| auto | duplicate () const -> std::optional< DatabaseState > |
Contains classes and functions related to data management.
| using mostly_harmless::data::DatabaseValueVariant = std::variant<std::string, bool, int, float, double> |
A std::variant containing all types satisfying the DatabaseStorageType concept.
|
delete |
Non Copyable, as the database connection pointer will be closed on destruction...
|
noexcept |
Moveable, nulls other's connection pointer
| other | The moved-from DatabaseState instance |
|
nodiscard |
Tries to create a copy of the current database connection. This is useful as database connections are only safe to use on a single thread - so for polling for changes on a background thread for example, a new connection must be used.
Will not work with an in-memory database created with filename = ":memory:".
|
nodiscard |
Attempts to retrieve the value of a named field in the database.
| T | A std::string, bool, any int, float, or double. |
| name | The name of the database field to retrieve |
|
delete |
Non Copyable, as the database connection pointer will be closed on destruction...
|
noexcept |
Moveable, nulls other's connection pointer
| other | The moved-from DatabaseState instance |
| auto mostly_harmless::data::set | ( | std::string_view | name, |
| const T & | toSet ) -> void |
Sets the value of a database entry with a matching name. If not found, will first create the entry.
| T | A std::string, bool, any int, float, or double |
| name | The name of the field to set. |
| toSet | The value to set. |
|
staticnodiscard |
Attempts to create a new DatabaseState instance. On construction, will attempt to open the database passed to location, and establish a connection to it if it exists. If it doesn't exist, creates the database, and a table to store user data in.
| location | A path to the database to create or open. |
| initialValues | A vector containing the initial values to add to the database if it didn't exist. If the database DID exist, but any of the keys in the vector aren't present, they'll be added with the values specified and existing items will be skipped. |
|
noexcept |
The internal database handle is closed if not null.