cocos2d-x  2.2.3-gd2.113-rev1ec524e
Loading...
Searching...
No Matches
CCUserDefault Class Reference

CCUserDefault acts as a tiny database. More...

#include <CCUserDefault.h>

Public Member Functions

 ~CCUserDefault ()
 
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...
 
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...
 
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)
 
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...
 
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 flush ()
 Save content to xml file. More...
 

Static Public Member Functions

static CCUserDefaultsharedUserDefault ()
 
static void purgeSharedUserDefault ()
 
static const std::string & getXMLFilePath ()
 
static bool isXMLFileExist ()
 

Detailed Description

CCUserDefault 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

◆ ~CCUserDefault()

Member Function Documentation

◆ flush()

void flush ( )

Save content to xml file.

◆ getBoolForKey() [1/2]

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.

◆ getBoolForKey() [2/2]

bool getBoolForKey ( const char *  pKey,
bool  defaultValue 
)

◆ getDoubleForKey() [1/2]

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.

◆ getDoubleForKey() [2/2]

double getDoubleForKey ( const char *  pKey,
double  defaultValue 
)

◆ getFloatForKey() [1/2]

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.

◆ getFloatForKey() [2/2]

float getFloatForKey ( const char *  pKey,
float  defaultValue 
)

◆ getIntegerForKey() [1/2]

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.

◆ getIntegerForKey() [2/2]

int getIntegerForKey ( const char *  pKey,
int  defaultValue 
)

◆ getStringForKey() [1/2]

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 "".

◆ getStringForKey() [2/2]

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

◆ getXMLFilePath()

static const std::string & getXMLFilePath ( )
static

◆ isXMLFileExist()

static bool isXMLFileExist ( )
static

◆ purgeSharedUserDefault()

static void purgeSharedUserDefault ( )
static

◆ setBoolForKey()

void setBoolForKey ( const char *  pKey,
bool  value 
)

Set bool value by key.

◆ setDoubleForKey()

void setDoubleForKey ( const char *  pKey,
double  value 
)

Set double value by key.

◆ setFloatForKey()

void setFloatForKey ( const char *  pKey,
float  value 
)

Set float value by key.

◆ setIntegerForKey()

void setIntegerForKey ( const char *  pKey,
int  value 
)

Set integer value by key.

◆ setStringForKey()

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

Set string value by key.

◆ sharedUserDefault()

static CCUserDefault * sharedUserDefault ( )
static

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