mirror of https://github.com/axmolengine/axmol.git
added support for optional default values in CCUserDefault getters
This commit is contained in:
parent
9c5fa51e6b
commit
af61a7c650
|
@ -38,18 +38,18 @@ public:
|
|||
~CCUserDefault();
|
||||
|
||||
// get value methods
|
||||
bool getBoolForKey(const char* pKey);
|
||||
int getIntegerForKey(const char* pKey);
|
||||
float getFloatForKey(const char* pKey);
|
||||
double getDoubleForKey(const char* pKey);
|
||||
std::string getStringForKey(const char* pKey);
|
||||
bool getBoolForKey(const char* pKey, bool defaultValue = false);
|
||||
int getIntegerForKey(const char* pKey, int defaultValue = 0);
|
||||
float getFloatForKey(const char* pKey, float defaultValue=0.0f);
|
||||
double getDoubleForKey(const char* pKey, double defaultValue=0.0);
|
||||
std::string getStringForKey(const char* pKey, const std::string & defaultValue = "");
|
||||
|
||||
// set value methods
|
||||
void setBoolForKey(const char* pKey, bool value);
|
||||
void setIntegerForKey(const char* pKey, int value);
|
||||
void setFloatForKey(const char* pKey, float value);
|
||||
void setDoubleForKey(const char* pKey, double value);
|
||||
void setStringForKey(const char* pKey, std::string value);
|
||||
void setStringForKey(const char* pKey, const std::string & value);
|
||||
|
||||
static CCUserDefault* sharedUserDefault();
|
||||
static void purgeSharedUserDefault();
|
||||
|
|
|
@ -148,10 +148,10 @@ void CCUserDefault::purgeSharedUserDefault()
|
|||
m_spUserDefault = NULL;
|
||||
}
|
||||
|
||||
bool CCUserDefault::getBoolForKey(const char* pKey)
|
||||
bool CCUserDefault::getBoolForKey(const char* pKey, bool defaultValue)
|
||||
{
|
||||
const char* value = getValueForKey(pKey);
|
||||
bool ret = false;
|
||||
bool ret = defaultValue;
|
||||
|
||||
if (value)
|
||||
{
|
||||
|
@ -164,10 +164,10 @@ bool CCUserDefault::getBoolForKey(const char* pKey)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int CCUserDefault::getIntegerForKey(const char* pKey)
|
||||
int CCUserDefault::getIntegerForKey(const char* pKey, int defaultValue)
|
||||
{
|
||||
const char* value = getValueForKey(pKey);
|
||||
int ret = 0;
|
||||
int ret = defaultValue;
|
||||
|
||||
if (value)
|
||||
{
|
||||
|
@ -178,17 +178,17 @@ int CCUserDefault::getIntegerForKey(const char* pKey)
|
|||
return ret;
|
||||
}
|
||||
|
||||
float CCUserDefault::getFloatForKey(const char* pKey)
|
||||
float CCUserDefault::getFloatForKey(const char* pKey, float defaultValue)
|
||||
{
|
||||
float ret = (float)getDoubleForKey(pKey);
|
||||
float ret = (float)getDoubleForKey(pKey, (double)defaultValue);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
double CCUserDefault::getDoubleForKey(const char* pKey)
|
||||
double CCUserDefault::getDoubleForKey(const char* pKey, double defaultValue)
|
||||
{
|
||||
const char* value = getValueForKey(pKey);
|
||||
double ret = 0.0;
|
||||
double ret = defaultValue;
|
||||
|
||||
if (value)
|
||||
{
|
||||
|
@ -199,10 +199,10 @@ double CCUserDefault::getDoubleForKey(const char* pKey)
|
|||
return ret;
|
||||
}
|
||||
|
||||
string CCUserDefault::getStringForKey(const char* pKey)
|
||||
string CCUserDefault::getStringForKey(const char* pKey, const std::string & defaultValue)
|
||||
{
|
||||
const char* value = getValueForKey(pKey);
|
||||
string ret("");
|
||||
string ret = defaultValue;
|
||||
|
||||
if (value)
|
||||
{
|
||||
|
@ -264,7 +264,7 @@ void CCUserDefault::setDoubleForKey(const char* pKey, double value)
|
|||
setValueForKey(pKey, tmp);
|
||||
}
|
||||
|
||||
void CCUserDefault::setStringForKey(const char* pKey, std::string value)
|
||||
void CCUserDefault::setStringForKey(const char* pKey, const std::string & value)
|
||||
{
|
||||
// check key
|
||||
if (! pKey)
|
||||
|
|
Loading…
Reference in New Issue