UserDefault acts as a tiny database. More...
#include <CCUserDefault.h>
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... | |
bool | getBoolForKey (const char *key, bool defaultValue) |
Get bool value by key, if the key doesn't exist, will return passed default value. More... | |
local | getBoolForKey ( local key, local 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... | |
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... | |
float | getFloatForKey (const char *key, float 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... | |
double | getDoubleForKey (const char *key, double 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... | |
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... | |
local | getStringForKey ( local key, local 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... | |
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... | |
void | setBoolForKey (const char *key, bool value) |
Set bool value by key. More... | |
void | setIntegerForKey (const char *key, int value) |
Set integer value by key. More... | |
void | setFloatForKey (const char *key, float value) |
Set float value by key. More... | |
void | setDoubleForKey (const char *key, double value) |
Set double value by key. More... | |
void | setStringForKey (const char *key, const std::string &value) |
Set string value by key. More... | |
void | setDataForKey (const char *key, const Data &value) |
Set Data value by key. More... | |
void | flush () |
You should invoke this function to save values set by setXXXForKey(). More... | |
Static Public Member Functions | |
static UserDefault * | getInstance () |
Returns the singleton. More... | |
static void | destroyInstance () |
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 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
|
static |
|
static |
void flush | ( | ) |
You should invoke this function to save values set by setXXXForKey().
local flush | ( | ) |
You should invoke this function to save values set by setXXXForKey().
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
. bool getBoolForKey | ( | const char * | key, |
bool | defaultValue | ||
) |
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. |
local getBoolForKey | ( | local | key, |
local | defaultValue | ||
) |
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. |
Data getDataForKey | ( | const char * | key | ) |
local getDataForKey | ( | local | key | ) |
local getDataForKey | ( | local | key, |
local | defaultValue | ||
) |
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. |
double getDoubleForKey | ( | const char * | key, |
double | defaultValue | ||
) |
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. |
local getDoubleForKey | ( | local | key, |
local | defaultValue | ||
) |
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. |
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. |
float getFloatForKey | ( | const char * | key, |
float | defaultValue | ||
) |
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. |
local getFloatForKey | ( | local | key, |
local | defaultValue | ||
) |
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. |
|
static |
Returns the singleton.
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. |
int getIntegerForKey | ( | const char * | key, |
int | defaultValue | ||
) |
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. |
local getIntegerForKey | ( | local | key, |
local | defaultValue | ||
) |
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. |
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. |
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.
key | The key to get value. |
defaultValue | The default value to return if the key doesn't exist. |
local getStringForKey | ( | local | key, |
local | defaultValue | ||
) |
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. |
|
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 use xml file to save values.
This function checks whether the xml file exists or not.
|
static |
All supported platforms other iOS & Android use xml file to save values.
This function checks whether the xml file exists or not.
|
static |
|
static |
void setBoolForKey | ( | const char * | key, |
bool | value | ||
) |
Set bool value by key.
key | The key to set. |
value | A bool value to set to the key. |
local setBoolForKey | ( | local | key, |
local | value | ||
) |
Set bool value by key.
key | The key to set. |
value | A bool value to set to the key. |
void setDataForKey | ( | const char * | key, |
const Data & | value | ||
) |
local setDataForKey | ( | local | key, |
local | value | ||
) |
void setDoubleForKey | ( | const char * | key, |
double | value | ||
) |
Set double value by key.
key | The key to set. |
value | A double value to set to the key. |
local setDoubleForKey | ( | local | key, |
local | value | ||
) |
Set double value by key.
key | The key to set. |
value | A double value to set to the key. |
void setFloatForKey | ( | const char * | key, |
float | value | ||
) |
Set float value by key.
key | The key to set. |
value | A float value to set to the key. |
local setFloatForKey | ( | local | key, |
local | value | ||
) |
Set float value by key.
key | The key to set. |
value | A float value to set to the key. |
void setIntegerForKey | ( | const char * | key, |
int | value | ||
) |
Set integer value by key.
key | The key to set. |
value | A integer value to set to the key. |
local setIntegerForKey | ( | local | key, |
local | value | ||
) |
Set integer value by key.
key | The key to set. |
value | A integer value to set to the key. |
void setStringForKey | ( | const char * | key, |
const std::string & | value | ||
) |
Set string value by key.
key | The key to set. |
value | A string value to set to the key. |
local setStringForKey | ( | local | key, |
local | value | ||
) |
Set string value by key.
key | The key to set. |
value | A string value to set to the key. |
|
static |