You.i Engine
CYIPersistentStore Class Reference

Detailed Description

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:

class CustomClass
{
public:
CYIString contents;
CustomClass(const CYIString &contents)
: contents(contents)
{
}
};
std::ostream &operator<<(::std::ostream &os, const CustomClass &data)
{
return os << data.contents;
}
std::istream &operator>>(::std::istream &is, CustomClass &data)
{
return is >> data.contents;
}
CustomClass storedValue = CustomClass("value");
PersistentStore.Add("key", storedValue);
CustomClass retrievedValue;
if (PersistentStore.Find("key", &retrievedValue))
{
// retrievedValue will be set to the key's corresponding value
}
Note
Platform Notes:
  • tvOS: The maximum data which can be stored per application is 500KB.
  • WebOS: The maximum data which can be stored is 10MB shared between all applications on the device. There are 3 reserved keys for the WebOS platform which are _id, _kind and _rev.
  • All Other Platforms: Persistent store data is written directly onto the device file system. The only limitation is the total available storage on the device.

#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 ()
 
CYIPersistentStoreoperator= (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< CYIStringGetKeys () 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
 

Member Enumeration Documentation

◆ StoreError

Enumerator
OK 
Corrupted 
NotEnoughSpace 
BadParameters 
Unknown 

Constructor & Destructor Documentation

◆ CYIPersistentStore() [1/2]

CYIPersistentStore::CYIPersistentStore ( uint64_t  maxSizeInBytes = 0)

◆ CYIPersistentStore() [2/2]

CYIPersistentStore::CYIPersistentStore ( const CYIPersistentStore rRHS)

◆ ~CYIPersistentStore()

virtual CYIPersistentStore::~CYIPersistentStore ( )
virtual

Member Function Documentation

◆ Add()

template<typename T >
void CYIPersistentStore::Add ( const CYIString Key,
const T &  value 
)
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);

◆ Clear() [1/2]

void CYIPersistentStore::Clear ( )

Clear the in-memory state.

◆ Clear() [2/2]

bool CYIPersistentStore::Clear ( const CYIString file)

Synchronous - Clear the file contents.

◆ Find()

template<typename T >
bool CYIPersistentStore::Find ( const CYIString Key,
T *  value 
) const
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 }

◆ GetKeys()

std::vector<CYIString> CYIPersistentStore::GetKeys ( ) const

Returns the all of the keys that exist in the state data.

◆ GetLastErrorCode()

StoreError CYIPersistentStore::GetLastErrorCode ( ) const

◆ Load()

bool CYIPersistentStore::Load ( const CYIString file)

Synchronous - Load the state data from the specified file.

Note
This method will replace any existing state data with the state data from the file, including any keys in the state data that do not exist in the file.

◆ operator=()

CYIPersistentStore& CYIPersistentStore::operator= ( const CYIPersistentStore rRHS)

◆ Remove()

void CYIPersistentStore::Remove ( const CYIString key)

Removes the key-value pair entry associated with the key key.

Example: PersistentStore.Remove("key");

◆ RequestLoad()

void CYIPersistentStore::RequestLoad ( const CYIString file)

Asynchronous - Load the state data from the specified file.

Note
This method will replace any existing state data with the state data from the file, including any keys in the state data that do not exist in the file.
See also
LoadCompleted Signal

◆ RequestSave()

void CYIPersistentStore::RequestSave ( const CYIString file)

Asynchronous - Save the current state data to the specified file.

See also
SaveCompleted Signal

◆ Save()

bool CYIPersistentStore::Save ( const CYIString file)

Synchronous - Save the current state data to the specified file.

Friends And Related Function Documentation

◆ IYIPersistentStorePriv

friend class IYIPersistentStorePriv
friend

Member Data Documentation

◆ LoadCompleted

CYISignal<bool> CYIPersistentStore::LoadCompleted

Callback for when the Asynchronous RequestLoad completes.

◆ SaveCompleted

CYISignal<bool> CYIPersistentStore::SaveCompleted

Callback for when the Asynchronous RequestSave completes.


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