cocos2d-x  3.0alpha1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
UserDefault Class Reference

UserDefault acts as a tiny database. More...

#include <CCUserDefault.h>

Public Member Functions

 ~UserDefault ()
bool getBoolForKey (const char *pKey)
 Get bool value by key, if the key doesn't exist, a default value will return. More...
 
bool getBoolForKey (const char *pKey, bool defaultValue)
int getIntegerForKey (const char *pKey)
 Get integer value by key, if the key doesn't exist, a default value will return. More...
 
local getIntegerForKey ( local pKey)
 Get integer value by key, if the key doesn't exist, a default value will return. More...
 
int getIntegerForKey (const char *pKey, int defaultValue)
float getFloatForKey (const char *pKey)
 Get float value by key, if the key doesn't exist, a default value will return. More...
 
float getFloatForKey (const char *pKey, float defaultValue)
double getDoubleForKey (const char *pKey)
 Get double value by key, if the key doesn't exist, a default value will return. More...
 
local getDoubleForKey ( local pKey)
 Get double value by key, if the key doesn't exist, a default value will return. More...
 
double getDoubleForKey (const char *pKey, double defaultValue)
std::string getStringForKey (const char *pKey)
 Get string value by key, if the key doesn't exist, a default value will return. More...
 
std::string getStringForKey (const char *pKey, const std::string &defaultValue)
local getStringForKey ( local pKey, local defaultValue)
DatagetDataForKey (const char *pKey)
 Get binary data value by key, if the key doesn't exist, a default value will return. More...
 
DatagetDataForKey (const char *pKey, Data *defaultValue)
void setBoolForKey (const char *pKey, bool value)
 Set bool value by key. More...
 
void setIntegerForKey (const char *pKey, int value)
 Set integer value by key. More...
 
local setIntegerForKey ( local pKey, local value)
 Set integer value by key. More...
 
void setFloatForKey (const char *pKey, float value)
 Set float value by key. More...
 
void setDoubleForKey (const char *pKey, double value)
 Set double value by key. More...
 
void setStringForKey (const char *pKey, const std::string &value)
 Set string value by key. More...
 
void setDataForKey (const char *pKey, const Data &value)
 Set binary data value by key. More...
 
void flush ()
 Save content to xml file. More...
 

Static Public Member Functions

static UserDefaultgetInstance ()
 returns the singleton More...
 
static void destroyInstance ()
local destroyInstance ()
static CC_DEPRECATED_ATTRIBUTE
UserDefault
sharedUserDefault ()
 deprecated. More...
 
static CC_DEPRECATED_ATTRIBUTE void purgeSharedUserDefault ()
local purgeSharedUserDefault ()
static const std::string & getXMLFilePath ()
local getXMLFilePath ()
static bool isXMLFileExist ()
local isXMLFileExist ()

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

Constructor & Destructor Documentation

Member Function Documentation

static void destroyInstance ( )
static
local destroyInstance ( )
static
void flush ( )

Save content to xml file.

local flush ( )

Save content to xml file.

bool getBoolForKey ( const char *  pKey)

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

You can set the default value, or it is false.

local getBoolForKey ( local  pKey)

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

You can set the default value, or it is false.

bool getBoolForKey ( const char *  pKey,
bool  defaultValue 
)
local getBoolForKey ( local  pKey,
local  defaultValue 
)
Data* getDataForKey ( const char *  pKey)

Get binary data value by key, if the key doesn't exist, a default value will return.

You can set the default value, or it is null.

Data* getDataForKey ( const char *  pKey,
Data defaultValue 
)
double getDoubleForKey ( const char *  pKey)

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

You can set the default value, or it is 0.0.

local getDoubleForKey ( local  pKey)

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

You can set the default value, or it is 0.0.

double getDoubleForKey ( const char *  pKey,
double  defaultValue 
)
local getDoubleForKey ( local  pKey,
local  defaultValue 
)
float getFloatForKey ( const char *  pKey)

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

You can set the default value, or it is 0.0f.

local getFloatForKey ( local  pKey)

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

You can set the default value, or it is 0.0f.

float getFloatForKey ( const char *  pKey,
float  defaultValue 
)
local getFloatForKey ( local  pKey,
local  defaultValue 
)
static UserDefault* getInstance ( )
static

returns the singleton

int getIntegerForKey ( const char *  pKey)

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

You can set the default value, or it is 0.

local getIntegerForKey ( local  pKey)

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

You can set the default value, or it is 0.

int getIntegerForKey ( const char *  pKey,
int  defaultValue 
)
local getIntegerForKey ( local  pKey,
local  defaultValue 
)
std::string getStringForKey ( const char *  pKey)

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

You can set the default value, or it is "".

local getStringForKey ( local  pKey)

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

You can set the default value, or it is "".

std::string getStringForKey ( const char *  pKey,
const std::string &  defaultValue 
)
local getStringForKey ( local  pKey,
local  defaultValue 
)
static const std::string&
getXMLFilePath
( )
static
local getXMLFilePath ( )
static
static bool isXMLFileExist ( )
static
local isXMLFileExist ( )
static
static CC_DEPRECATED_ATTRIBUTE
void purgeSharedUserDefault
( )
static
local purgeSharedUserDefault ( )
static
void setBoolForKey ( const char *  pKey,
bool  value 
)

Set bool value by key.

local setBoolForKey ( local  pKey,
local  value 
)

Set bool value by key.

void setDataForKey ( const char *  pKey,
const Data value 
)

Set binary data value by key.

void setDoubleForKey ( const char *  pKey,
double  value 
)

Set double value by key.

local setDoubleForKey ( local  pKey,
local  value 
)

Set double value by key.

void setFloatForKey ( const char *  pKey,
float  value 
)

Set float value by key.

local setFloatForKey ( local  pKey,
local  value 
)

Set float value by key.

void setIntegerForKey ( const char *  pKey,
int  value 
)

Set integer value by key.

local setIntegerForKey ( local  pKey,
local  value 
)

Set integer value by key.

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

Set string value by key.

local setStringForKey ( local  pKey,
local  value 
)

Set string value by key.

static CC_DEPRECATED_ATTRIBUTE
UserDefault* sharedUserDefault
( )
static

deprecated.

Use getInstace() instead


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