UserDefault acts as a tiny database. More...
Public Member Functions | |
bool | getBoolForKey (const char *key) |
Get bool value by key, if the key doesn't exist, will return false. More... | |
local | getBoolForKey ( local key) |
Get bool value by key, if the key doesn't exist, will return false. More... | |
virtual bool | getBoolForKey (const char *key, bool defaultValue) |
Get bool value by key, if the key doesn't exist, will return passed default value. More... | |
int | getIntegerForKey (const char *key) |
Get integer value by key, if the key doesn't exist, will return 0. More... | |
virtual int | getIntegerForKey (const char *key, int defaultValue) |
Get bool value by key, if the key doesn't exist, will return passed default value. More... | |
local | getIntegerForKey ( local key, local defaultValue) |
Get bool value by key, if the key doesn't exist, will return passed default value. More... | |
float | getFloatForKey (const char *key) |
Get float value by key, if the key doesn't exist, will return 0.0. More... | |
virtual float | getFloatForKey (const char *key, float defaultValue) |
Get float value by key, if the key doesn't exist, will return passed default value. More... | |
local | getFloatForKey ( local key, local defaultValue) |
Get float value by key, if the key doesn't exist, will return passed default value. More... | |
double | getDoubleForKey (const char *key) |
Get double value by key, if the key doesn't exist, will return 0.0. More... | |
virtual double | getDoubleForKey (const char *key, double defaultValue) |
Get double value by key, if the key doesn't exist, will return passed default value. More... | |
local | getDoubleForKey ( local key, local defaultValue) |
Get double value by key, if the key doesn't exist, will return passed default value. More... | |
std::string | getStringForKey (const char *key) |
Get string value by key, if the key doesn't exist, will return an empty string. More... | |
virtual std::string | getStringForKey (const char *key, const std::string &defaultValue) |
Get string value by key, if the key doesn't exist, will return passed default value. More... | |
Data | getDataForKey (const char *key) |
Get Data value by key, if the key doesn't exist, will return an empty Data. More... | |
virtual Data | getDataForKey (const char *key, const Data &defaultValue) |
Get Data value by key, if the key doesn't exist, will return an empty Data. More... | |
local | getDataForKey ( local key, local defaultValue) |
Get Data value by key, if the key doesn't exist, will return an empty Data. More... | |
virtual void | setBoolForKey (const char *key, bool value) |
Set bool value by key. More... | |
virtual void | setIntegerForKey (const char *key, int value) |
Set integer value by key. More... | |
local | setIntegerForKey ( local key, local value) |
Set integer value by key. More... | |
virtual void | setFloatForKey (const char *key, float value) |
Set float value by key. More... | |
virtual void | setDoubleForKey (const char *key, double value) |
Set double value by key. More... | |
virtual void | setStringForKey (const char *key, const std::string &value) |
Set string value by key. More... | |
local | setStringForKey ( local key, local value) |
Set string value by key. More... | |
virtual void | setDataForKey (const char *key, const Data &value) |
Set Data value by key. More... | |
virtual void | flush () |
You should invoke this function to save values set by setXXXForKey(). | |
virtual void | deleteValueForKey (const char *key) |
delete any value by key, More... | |
Static Public Member Functions | |
static UserDefault * | getInstance () |
Returns the singleton. | |
static void | setDelegate (UserDefault *delegate) |
You can inherit from platform dependent implementation of UserDefault, such as UserDefaultAndroid, and use this function to set delegate, then UserDefault will invoke delegate's implementation. More... | |
local | setDelegate ( local delegate) |
You can inherit from platform dependent implementation of UserDefault, such as UserDefaultAndroid, and use this function to set delegate, then UserDefault will invoke delegate's implementation. More... | |
static UserDefault * | sharedUserDefault () |
static void | purgeSharedUserDefault () |
static const std::string & | getXMLFilePath () |
All supported platforms other iOS & Android use xml file to save values. More... | |
local | getXMLFilePath () |
All supported platforms other iOS & Android use xml file to save values. More... | |
static bool | isXMLFileExist () |
All supported platforms other iOS & Android and CC_PLATFORM_WINRT use xml file to save values. More... | |
UserDefault acts as a tiny database.
You can save and get base type values by it. For example, setBoolForKey("played", true) will add a bool value true into the database. Its key is "played". You can get the value of the key by getBoolForKey("played").
It supports the following base types: bool, int, float, double, string
/
is not valid. bool getBoolForKey | ( | const char * | key | ) |
Get bool value by key, if the key doesn't exist, will return false.
You can set the default value, or it is false.
key | The key to get value. |
key
. local getBoolForKey | ( | local | key | ) |
Get bool value by key, if the key doesn't exist, will return false.
You can set the default value, or it is false.
key | The key to get value. |
key
.
|
virtual |
Get bool value by key, if the key doesn't exist, will return passed default value.
key | The key to get value. |
defaultValue | The default value to return if the key doesn't exist. |
|
virtual |
Get bool value by key, if the key doesn't exist, will return passed default value.
key | The key to get value. |
defaultValue | The default value to return if the key doesn't exist. |
int getIntegerForKey | ( | const char * | key | ) |
Get integer value by key, if the key doesn't exist, will return 0.
You can set the default value, or it is 0.
key | The key to get value. |
local getIntegerForKey | ( | local | key | ) |
Get integer value by key, if the key doesn't exist, will return 0.
You can set the default value, or it is 0.
key | The key to get value. |
|
virtual |
Get bool value by key, if the key doesn't exist, will return passed default value.
key | The key to get value. |
defaultValue | The default value to return if the key doesn't exist. |
|
virtual |
Get bool value by key, if the key doesn't exist, will return passed default value.
key | The key to get value. |
defaultValue | The default value to return if the key doesn't exist. |
float getFloatForKey | ( | const char * | key | ) |
Get float value by key, if the key doesn't exist, will return 0.0.
key | The key to get value. |
local getFloatForKey | ( | local | key | ) |
Get float value by key, if the key doesn't exist, will return 0.0.
key | The key to get value. |
|
virtual |
Get float value by key, if the key doesn't exist, will return passed default value.
key | The key to get value. |
defaultValue | The default value to return if the key doesn't exist. |
|
virtual |
Get float value by key, if the key doesn't exist, will return passed default value.
key | The key to get value. |
defaultValue | The default value to return if the key doesn't exist. |
double getDoubleForKey | ( | const char * | key | ) |
Get double value by key, if the key doesn't exist, will return 0.0.
key | The key to get value. |
local getDoubleForKey | ( | local | key | ) |
Get double value by key, if the key doesn't exist, will return 0.0.
key | The key to get value. |
|
virtual |
Get double value by key, if the key doesn't exist, will return passed default value.
key | The key to get value. |
defaultValue | The default value to return if the key doesn't exist. |
|
virtual |
Get double value by key, if the key doesn't exist, will return passed default value.
key | The key to get value. |
defaultValue | The default value to return if the key doesn't exist. |
std::string getStringForKey | ( | const char * | key | ) |
Get string value by key, if the key doesn't exist, will return an empty string.
key | The key to get value. |
local getStringForKey | ( | local | key | ) |
Get string value by key, if the key doesn't exist, will return an empty string.
key | The key to get value. |
|
virtual |
Get string value by key, if the key doesn't exist, will return passed default value.
key | The key to get value. |
defaultValue | The default value to return if the key doesn't exist. |
|
virtual |
Get string value by key, if the key doesn't exist, will return passed default value.
key | The key to get value. |
defaultValue | The default value to return if the key doesn't exist. |
Data getDataForKey | ( | const char * | key | ) |
Get Data value by key, if the key doesn't exist, will return an empty Data.
key | The key to get value. |
local getDataForKey | ( | local | key | ) |
Get Data value by key, if the key doesn't exist, will return an empty Data.
key | The key to get value. |
|
virtual |
Get Data value by key, if the key doesn't exist, will return an empty Data.
key | The key to get value. |
defaultValue | The default value to return if the key doesn't exist. |
|
virtual |
Get Data value by key, if the key doesn't exist, will return an empty Data.
key | The key to get value. |
defaultValue | The default value to return if the key doesn't exist. |
|
virtual |
Set bool value by key.
key | The key to set. |
value | A bool value to set to the key. |
|
virtual |
Set bool value by key.
key | The key to set. |
value | A bool value to set to the key. |
|
virtual |
Set integer value by key.
key | The key to set. |
value | A integer value to set to the key. |
|
virtual |
Set integer value by key.
key | The key to set. |
value | A integer value to set to the key. |
|
virtual |
Set float value by key.
key | The key to set. |
value | A float value to set to the key. |
|
virtual |
Set float value by key.
key | The key to set. |
value | A float value to set to the key. |
|
virtual |
Set double value by key.
key | The key to set. |
value | A double value to set to the key. |
|
virtual |
Set double value by key.
key | The key to set. |
value | A double value to set to the key. |
|
virtual |
Set string value by key.
key | The key to set. |
value | A string value to set to the key. |
|
virtual |
Set string value by key.
key | The key to set. |
value | A string value to set to the key. |
|
virtual |
Set Data value by key.
key | The key to set. |
value | A Data value to set to the key. |
|
virtual |
Set Data value by key.
key | The key to set. |
value | A Data value to set to the key. |
|
virtual |
delete any value by key,
key | The key to delete value. |
|
virtual |
delete any value by key,
key | The key to delete value. |
|
static |
You can inherit from platform dependent implementation of UserDefault, such as UserDefaultAndroid, and use this function to set delegate, then UserDefault will invoke delegate's implementation.
For example, your store native data base or other format store.
If you don't want to system default implementation after setting delegate, you can just pass nullptr to this function.
|
static |
You can inherit from platform dependent implementation of UserDefault, such as UserDefaultAndroid, and use this function to set delegate, then UserDefault will invoke delegate's implementation.
For example, your store native data base or other format store.
If you don't want to system default implementation after setting delegate, you can just pass nullptr to this function.
|
static |
You can inherit from platform dependent implementation of UserDefault, such as UserDefaultAndroid, and use this function to set delegate, then UserDefault will invoke delegate's implementation.
For example, your store native data base or other format store.
If you don't want to system default implementation after setting delegate, you can just pass nullptr to this function.
|
static |
|
static |
|
static |
|
static |
All supported platforms other iOS & Android use xml file to save values.
This function is return the file path of the xml path.
|
static |
All supported platforms other iOS & Android use xml file to save values.
This function is return the file path of the xml path.
|
static |
All supported platforms other iOS & Android and CC_PLATFORM_WINRT use xml file to save values.
This function checks whether the xml file exists or not.
|
static |
All supported platforms other iOS & Android and CC_PLATFORM_WINRT use xml file to save values.
This function checks whether the xml file exists or not.