The CYIPersistentStore class manages storing and retrieving application state data.
This class supports the use of custom types if they overide the << and >> operators.
Custom Type Example:
#include <utility/YiPersistentStore.h>
Public Types | |
enum | StoreError { StoreError::OK = 0, StoreError::Corrupted, StoreError::NotEnoughSpace, StoreError::BadParameters, StoreError::Unknown } |
Public Member Functions | |
CYIPersistentStore (uint64_t maxSizeInBytes=0) | |
CYIPersistentStore (const CYIPersistentStore &rRHS) | |
virtual | ~CYIPersistentStore () |
CYIPersistentStore & | operator= (const CYIPersistentStore &rRHS) |
template<typename T > | |
void | Add (const CYIString &Key, const T &value) |
template<typename T > | |
bool | Find (const CYIString &Key, T *value) const |
void | Remove (const CYIString &key) |
std::vector< CYIString > | GetKeys () const |
void | Clear () |
bool | Save (const CYIString &file) |
bool | Load (const CYIString &file) |
void | RequestSave (const CYIString &file) |
void | RequestLoad (const CYIString &file) |
bool | Clear (const CYIString &file) |
StoreError | GetLastErrorCode () const |
Public Attributes | |
CYISignal< bool > | SaveCompleted |
CYISignal< bool > | LoadCompleted |
Friends | |
class | IYIPersistentStorePriv |
|
strong |
CYIPersistentStore::CYIPersistentStore | ( | uint64_t | maxSizeInBytes = 0 | ) |
CYIPersistentStore::CYIPersistentStore | ( | const CYIPersistentStore & | rRHS | ) |
|
virtual |
|
inline |
Add a key-value pair to be saved as application state data. If the provided key already exists in the state data, it is updated with the provided value.
Example: int32_t num = 19; PersistentStore.Add("key", num);
void CYIPersistentStore::Clear | ( | ) |
Clear the in-memory state.
bool CYIPersistentStore::Clear | ( | const CYIString & | file | ) |
Synchronous - Clear the file contents.
|
inline |
Retrieve the value for the specified key from the loaded application state. If the key is found, returns true and value is set to the key's corresponding value. Returns false if the key is not found.
Example: int32_t num = 19; if(PersistentStore.Find("key", &num)) {
num will now be set to the key's corresponding value }
std::vector<CYIString> CYIPersistentStore::GetKeys | ( | ) | const |
Returns the all of the keys that exist in the state data.
StoreError CYIPersistentStore::GetLastErrorCode | ( | ) | const |
bool CYIPersistentStore::Load | ( | const CYIString & | file | ) |
Synchronous - Load the state data from the specified file.
CYIPersistentStore& CYIPersistentStore::operator= | ( | const CYIPersistentStore & | rRHS | ) |
void CYIPersistentStore::Remove | ( | const CYIString & | key | ) |
Removes the key-value pair entry associated with the key key.
Example: PersistentStore.Remove("key");
void CYIPersistentStore::RequestLoad | ( | const CYIString & | file | ) |
Asynchronous - Load the state data from the specified file.
void CYIPersistentStore::RequestSave | ( | const CYIString & | file | ) |
Asynchronous - Save the current state data to the specified file.
bool CYIPersistentStore::Save | ( | const CYIString & | file | ) |
Synchronous - Save the current state data to the specified file.
|
friend |
CYISignal<bool> CYIPersistentStore::LoadCompleted |
Callback for when the Asynchronous RequestLoad completes.
CYISignal<bool> CYIPersistentStore::SaveCompleted |
Callback for when the Asynchronous RequestSave completes.