Cocos2d-x  v3.12
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups
UserDefault Class Reference

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...
 
local getIntegerForKey ( local 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 integer 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...
 
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...
 
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 for key. More...
 
local setBoolForKey ( local key, local value)
 Set bool value for key. More...
 
virtual void setIntegerForKey (const char *key, int value)
 Set integer value for key. More...
 
local setIntegerForKey ( local key, local value)
 Set integer value for key. More...
 
virtual void setFloatForKey (const char *key, float value)
 Set float value for key. More...
 
local setFloatForKey ( local key, local value)
 Set float value for key. More...
 
virtual void setDoubleForKey (const char *key, double value)
 Set double value for key. More...
 
local setDoubleForKey ( local key, local value)
 Set double value for key. More...
 
virtual void setStringForKey (const char *key, const std::string &value)
 Set string value for key. More...
 
local setStringForKey ( local key, local value)
 Set string value for key. More...
 
virtual void setDataForKey (const char *key, const Data &value)
 Set Data value for key. More...
 
local setDataForKey ( local key, local value)
 Set Data value for 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 The key to delete value.
 
local deleteValueForKey ( local key)
 delete any value by key The key to delete value.
 

Static Public Member Functions

static UserDefaultgetInstance ()
 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 UserDefaultsharedUserDefault ()
static void purgeSharedUserDefault ()
local purgeSharedUserDefault ()
static const std::string & getXMLFilePath ()
 All supported platforms except iOS, Android & CC_PLATFORM_WINRT use xml file to save values. More...
 
local getXMLFilePath ()
 All supported platforms except iOS, Android & CC_PLATFORM_WINRT use xml file to save values. More...
 
static bool isXMLFileExist ()
 All supported platforms except iOS, Android & CC_PLATFORM_WINRT use xml file to save values. More...
 

Detailed Description

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

Member Function Documentation

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. The key to get value. Bool value by 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. The key to get value. Bool value by key.

virtual bool getBoolForKey ( const char *  key,
bool  defaultValue 
)
virtual

Get bool value by key, if the key doesn't exist, will return passed default value.

The key to get value. The default value to return if the key doesn't exist. Bool value by key.

local getBoolForKey ( local  key,
local  defaultValue 
)
virtual

Get bool value by key, if the key doesn't exist, will return passed default value.

The key to get value. The default value to return if the key doesn't exist. Bool value by key.

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. The key to get value. Integer value of the key.

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. The key to get value. Integer value of the key.

virtual int getIntegerForKey ( const char *  key,
int  defaultValue 
)
virtual

Get integer value by key, if the key doesn't exist, will return passed default value.

The key to get value. The default value to return if the key doesn't exist. Integer value of the key.

local getIntegerForKey ( local  key,
local  defaultValue 
)
virtual

Get integer value by key, if the key doesn't exist, will return passed default value.

The key to get value. The default value to return if the key doesn't exist. Integer value of the key.

float getFloatForKey ( const char *  key)

Get float value by key, if the key doesn't exist, will return 0.0.

The key to get value. Float value of the key.

local getFloatForKey ( local  key)

Get float value by key, if the key doesn't exist, will return 0.0.

The key to get value. Float value of the key.

virtual float getFloatForKey ( const char *  key,
float  defaultValue 
)
virtual

Get float value by key, if the key doesn't exist, will return passed default value.

The key to get value. The default value to return if the key doesn't exist. Float value of the key.

local getFloatForKey ( local  key,
local  defaultValue 
)
virtual

Get float value by key, if the key doesn't exist, will return passed default value.

The key to get value. The default value to return if the key doesn't exist. Float value of the key.

double getDoubleForKey ( const char *  key)

Get double value by key, if the key doesn't exist, will return 0.0.

The key to get value. Double value of the key.

local getDoubleForKey ( local  key)

Get double value by key, if the key doesn't exist, will return 0.0.

The key to get value. Double value of the key.

virtual double getDoubleForKey ( const char *  key,
double  defaultValue 
)
virtual

Get double value by key, if the key doesn't exist, will return passed default value.

The key to get value. The default value to return if the key doesn't exist. Double value of the key.

local getDoubleForKey ( local  key,
local  defaultValue 
)
virtual

Get double value by key, if the key doesn't exist, will return passed default value.

The key to get value. The default value to return if the key doesn't exist. Double value of the key.

std::string getStringForKey ( const char *  key)

Get string value by key, if the key doesn't exist, will return an empty string.

The key to get value. String value of the key.

local getStringForKey ( local  key)

Get string value by key, if the key doesn't exist, will return an empty string.

The key to get value. String value of the key.

virtual std::string getStringForKey ( const char *  key,
const std::string &  defaultValue 
)
virtual

Get string value by key, if the key doesn't exist, will return passed default value.

The key to get value. The default value to return if the key doesn't exist. String value of the key.

local getStringForKey ( local  key,
local  defaultValue 
)
virtual

Get string value by key, if the key doesn't exist, will return passed default value.

The key to get value. The default value to return if the key doesn't exist. String value of the key.

Data getDataForKey ( const char *  key)

Get Data value by key, if the key doesn't exist, will return an empty Data.

The key to get value. Data value of the key.

local getDataForKey ( local  key)

Get Data value by key, if the key doesn't exist, will return an empty Data.

The key to get value. Data value of the key.

virtual Data getDataForKey ( const char *  key,
const Data &  defaultValue 
)
virtual

Get Data value by key, if the key doesn't exist, will return an empty Data.

The key to get value. The default value to return if the key doesn't exist. Data value of the key.

local getDataForKey ( local  key,
local  defaultValue 
)
virtual

Get Data value by key, if the key doesn't exist, will return an empty Data.

The key to get value. The default value to return if the key doesn't exist. Data value of the key.

virtual void setBoolForKey ( const char *  key,
bool  value 
)
virtual

Set bool value for key.

The key to set. A bool value to set to the key.

local setBoolForKey ( local  key,
local  value 
)
virtual

Set bool value for key.

The key to set. A bool value to set to the key.

virtual void setIntegerForKey ( const char *  key,
int  value 
)
virtual

Set integer value for key.

The key to set. A integer value to set to the key.

local setIntegerForKey ( local  key,
local  value 
)
virtual

Set integer value for key.

The key to set. A integer value to set to the key.

virtual void setFloatForKey ( const char *  key,
float  value 
)
virtual

Set float value for key.

The key to set. A float value to set to the key.

local setFloatForKey ( local  key,
local  value 
)
virtual

Set float value for key.

The key to set. A float value to set to the key.

virtual void setDoubleForKey ( const char *  key,
double  value 
)
virtual

Set double value for key.

The key to set. A double value to set to the key.

local setDoubleForKey ( local  key,
local  value 
)
virtual

Set double value for key.

The key to set. A double value to set to the key.

virtual void setStringForKey ( const char *  key,
const std::string &  value 
)
virtual

Set string value for key.

The key to set. A string value to set to the key.

local setStringForKey ( local  key,
local  value 
)
virtual

Set string value for key.

The key to set. A string value to set to the key.

virtual void setDataForKey ( const char *  key,
const Data &  value 
)
virtual

Set Data value for key.

The key to set. A Data value to set to the key.

local setDataForKey ( local  key,
local  value 
)
virtual

Set Data value for key.

The key to set. A Data value to set to the key.

static void setDelegate ( UserDefault delegate)
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.

After setting delegate, If you don't want to using it anymore, you can just pass nullptr to this function.

It will delete previous delegate

var setDelegate ( var  delegate)
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.

After setting delegate, If you don't want to using it anymore, you can just pass nullptr to this function.

It will delete previous delegate

local setDelegate ( local  delegate)
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.

After setting delegate, If you don't want to using it anymore, you can just pass nullptr to this function.

It will delete previous delegate

static UserDefault*
sharedUserDefault
( )
static
static void purgeSharedUserDefault ( )
static
local purgeSharedUserDefault ( )
static
static const std::string&
getXMLFilePath
( )
static

All supported platforms except iOS, Android & CC_PLATFORM_WINRT use xml file to save values.

This function is return the file path of the xml path.

local getXMLFilePath ( )
static

All supported platforms except iOS, Android & CC_PLATFORM_WINRT use xml file to save values.

This function is return the file path of the xml path.

static bool isXMLFileExist ( )
static

All supported platforms except iOS, Android & CC_PLATFORM_WINRT use xml file to save values.

This function checks whether the xml file exists or not. True if the xml file exists, flase if not.

local isXMLFileExist ( )
static

All supported platforms except iOS, Android & CC_PLATFORM_WINRT use xml file to save values.

This function checks whether the xml file exists or not. True if the xml file exists, flase if not.


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