Merge pull request #453 from minggo/iss622

fixed #622: add comment of CCUserDefault
This commit is contained in:
minggo 2011-08-04 20:08:16 -07:00
commit 08b25229ac
2 changed files with 68 additions and 1 deletions

View File

@ -1,6 +1,5 @@
/**************************************************************************** /****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org Copyright (c) 2010-2011 cocos2d-x.org
Copyright (c) 2008-2010 Ricardo Quesada
http://www.cocos2d-x.org http://www.cocos2d-x.org
@ -32,23 +31,68 @@ THE SOFTWARE.
NS_CC_BEGIN; NS_CC_BEGIN;
/**
* 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
*/
class CC_DLL CCUserDefault class CC_DLL CCUserDefault
{ {
public: public:
~CCUserDefault(); ~CCUserDefault();
// get value methods // get value methods
/**
@brief 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 = false); bool getBoolForKey(const char* pKey, bool defaultValue = false);
/**
@brief 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 = 0); int getIntegerForKey(const char* pKey, int defaultValue = 0);
/**
@brief 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=0.0f); float getFloatForKey(const char* pKey, float defaultValue=0.0f);
/**
@brief 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=0.0); double getDoubleForKey(const char* pKey, double defaultValue=0.0);
/**
@brief 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 = ""); std::string getStringForKey(const char* pKey, const std::string & defaultValue = "");
// set value methods // set value methods
/**
@brief Set bool value by key.
*/
void setBoolForKey(const char* pKey, bool value); void setBoolForKey(const char* pKey, bool value);
/**
@brief Set integer value by key.
*/
void setIntegerForKey(const char* pKey, int value); void setIntegerForKey(const char* pKey, int value);
/**
@brief Set float value by key.
*/
void setFloatForKey(const char* pKey, float value); void setFloatForKey(const char* pKey, float value);
/**
@brief Set double value by key.
*/
void setDoubleForKey(const char* pKey, double value); void setDoubleForKey(const char* pKey, double value);
/**
@brief Set string value by key.
*/
void setStringForKey(const char* pKey, const std::string & value); void setStringForKey(const char* pKey, const std::string & value);
static CCUserDefault* sharedUserDefault(); static CCUserDefault* sharedUserDefault();

View File

@ -1,3 +1,26 @@
/****************************************************************************
Copyright (c) 2010-2011 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCUserDefault.h" #include "CCUserDefault.h"
#include "platform/CCFileUtils.h" #include "platform/CCFileUtils.h"