issue #2397: UserDefault::sharedUserDefault() --> UserDefault::getInstance(), UserDefault::purgeSharedUserDefault() --> UserDefault::destroyInstance();

This commit is contained in:
James Chen 2013-07-12 14:34:57 +08:00
parent f8cd252c5c
commit 4a7e884de8
4 changed files with 44 additions and 28 deletions

View File

@ -444,7 +444,7 @@ UserDefault* UserDefault::sharedUserDefault()
// XXX: deprecated
void UserDefault::purgeSharedUserDefault()
{
return destroyInstance();
return UserDefault::destroyInstance();
}
bool UserDefault::isXMLFileExist()

View File

@ -150,15 +150,21 @@ UserDefault::UserDefault()
_spUserDefault = NULL;
}
// XXX: deprecated
void UserDefault::purgeSharedUserDefault()
{
UserDefault::destroyInstance();
}
void UserDefault::destroyInstance()
{
_spUserDefault = NULL;
}
bool UserDefault::getBoolForKey(const char* pKey)
{
return getBoolForKey(pKey, false);
}
bool UserDefault::getBoolForKey(const char* pKey)
{
return getBoolForKey(pKey, false);
}
bool UserDefault::getBoolForKey(const char* pKey, bool defaultValue)
{
@ -474,8 +480,13 @@ void UserDefault::setDataForKey(const char* pKey, const Data& value)
}
}
// XXX: deprecated
UserDefault* UserDefault::sharedUserDefault()
{
return UserDefault::getInstance();
}
UserDefault* UserDefault::getInstance()
{
#ifdef KEEP_COMPATABILITY
initXMLFilePath();

View File

@ -6,62 +6,62 @@ local function doTest()
-- set default value
CCUserDefault:sharedUserDefault():setStringForKey("string", "value1")
CCUserDefault:sharedUserDefault():setIntegerForKey("integer", 10)
CCUserDefault:sharedUserDefault():setFloatForKey("float", 2.3)
CCUserDefault:sharedUserDefault():setDoubleForKey("double", 2.4)
CCUserDefault:sharedUserDefault():setBoolForKey("bool", true)
CCUserDefault:getInstance():setStringForKey("string", "value1")
CCUserDefault:getInstance():setIntegerForKey("integer", 10)
CCUserDefault:getInstance():setFloatForKey("float", 2.3)
CCUserDefault:getInstance():setDoubleForKey("double", 2.4)
CCUserDefault:getInstance():setBoolForKey("bool", true)
-- print value
local ret = CCUserDefault:sharedUserDefault():getStringForKey("string")
local ret = CCUserDefault:getInstance():getStringForKey("string")
cclog("string is %s", ret)
local d = CCUserDefault:sharedUserDefault():getDoubleForKey("double")
local d = CCUserDefault:getInstance():getDoubleForKey("double")
cclog("double is %f", d)
local i = CCUserDefault:sharedUserDefault():getIntegerForKey("integer")
local i = CCUserDefault:getInstance():getIntegerForKey("integer")
cclog("integer is %d", i)
local f = CCUserDefault:sharedUserDefault():getFloatForKey("float")
local f = CCUserDefault:getInstance():getFloatForKey("float")
cclog("float is %f", f)
local b = CCUserDefault:sharedUserDefault():getBoolForKey("bool")
local b = CCUserDefault:getInstance():getBoolForKey("bool")
if b == true then
cclog("bool is true")
else
cclog("bool is false")
end
--CCUserDefault:sharedUserDefault():flush()
--CCUserDefault:getInstance():flush()
cclog("********************** after change value ***********************")
-- change the value
CCUserDefault:sharedUserDefault():setStringForKey("string", "value2")
CCUserDefault:sharedUserDefault():setIntegerForKey("integer", 11)
CCUserDefault:sharedUserDefault():setFloatForKey("float", 2.5)
CCUserDefault:sharedUserDefault():setDoubleForKey("double", 2.6)
CCUserDefault:sharedUserDefault():setBoolForKey("bool", false)
CCUserDefault:getInstance():setStringForKey("string", "value2")
CCUserDefault:getInstance():setIntegerForKey("integer", 11)
CCUserDefault:getInstance():setFloatForKey("float", 2.5)
CCUserDefault:getInstance():setDoubleForKey("double", 2.6)
CCUserDefault:getInstance():setBoolForKey("bool", false)
CCUserDefault:sharedUserDefault():flush()
CCUserDefault:getInstance():flush()
-- print value
ret = CCUserDefault:sharedUserDefault():getStringForKey("string")
ret = CCUserDefault:getInstance():getStringForKey("string")
cclog("string is %s", ret)
d = CCUserDefault:sharedUserDefault():getDoubleForKey("double")
d = CCUserDefault:getInstance():getDoubleForKey("double")
cclog("double is %f", d)
i = CCUserDefault:sharedUserDefault():getIntegerForKey("integer")
i = CCUserDefault:getInstance():getIntegerForKey("integer")
cclog("integer is %d", i)
f = CCUserDefault:sharedUserDefault():getFloatForKey("float")
f = CCUserDefault:getInstance():getFloatForKey("float")
cclog("float is %f", f)
b = CCUserDefault:sharedUserDefault():getBoolForKey("bool")
b = CCUserDefault:getInstance():getBoolForKey("bool")
if b == true then
cclog("bool is true")
else

View File

@ -17,7 +17,12 @@ class CCUserDefault
void flush();
// XXX: deprecated
static CCUserDefault* sharedUserDefault();
static void purgeSharedUserDefault();
static CCUserDefault* getInstance();
static void destroyInstance();
const static std::string& getXMLFilePath();
};