本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
cocos2d-X 节点(CCUserDefault.h)API
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
///cocos2d-x-3.0alpha0/cocos2dx/support/user_default #ifndef __SUPPORT_CCUSERDEFAULT_H__ #define __SUPPORT_CCUSERDEFAULT_H__ #include "platform/CCPlatformMacros.h" #include <string> #include "cocoa/CCData.h" NS_CC_BEGIN /** * @addtogroup data_storage * @{ */ /** * UserDefault 作为一个小型数据库. 你可以使用他 保存/获取 基础的类型值. * 例如, setBoolForKey("played", true) 会往数据库里面添加一个 bool 值 true. * 他的 key 是 "played". 你可以使用 key 获得它的值例如: getBoolForKey("played"). * * 支持下列基本类型: * bool, int, float, double, string */ class CC_DLL UserDefault { public: /** * @js NA * @lua NA */ ~UserDefault(); // get value methods /** @brief 使用 key 获取值(bool), 如果 key 不存在,将返回一个默认值。 你可以设置默认值, 或者返回 false. * @js NA */ bool getBoolForKey(const char* pKey); /** * @js NA */ bool getBoolForKey(const char* pKey, bool defaultValue); /** @brief 使用 key 获取值(integer), 如果 key 不存在,将返回一个默认值。 你可以设置默认值, 或者返回 0. * @js NA */ int getIntegerForKey(const char* pKey); /** * @js NA */ int getIntegerForKey(const char* pKey, int defaultValue); /** @brief 使用 key 获取值(Float), 如果 key 不存在,将返回一个默认值。 你可以设置默认值, 或者返回 0.0f. * @js NA */ float getFloatForKey(const char* pKey); /** * @js NA */ float getFloatForKey(const char* pKey, float defaultValue); /** @brief 使用 key 获取值(double), 如果 key 不存在,将返回一个默认值。 你可以设置默认值, 或者返回 0.0. * @js NA */ double getDoubleForKey(const char* pKey); /** * @js NA */ double getDoubleForKey(const char* pKey, double defaultValue); /** @brief 使用 key 获取值(string), 如果 key 不存在,将返回一个默认值。 你可以设置默认值, 或者返回 "". * @js NA */ std::string getStringForKey(const char* pKey); /** * @js NA */ std::string getStringForKey(const char* pKey, const std::string & defaultValue); /** @brief 使用 key 获取值(binary data),如果 key 不存在,将返回一个默认值。 你可以设置默认值, 或者返回 null. * @js NA * @lua NA */ Data* getDataForKey(const char* pKey); /** * @js NA * @lua NA */ Data* getDataForKey(const char* pKey, Data* defaultValue); // set value methods /** @brief 使用 key 设置值(bool). * @js NA */ void setBoolForKey(const char* pKey, bool value); /** @brief 使用 key 设置值(Integer). * @js NA */ void setIntegerForKey(const char* pKey, int value); /** @brief 使用 key 设置值(float). * @js NA */ void setFloatForKey(const char* pKey, float value); /** @brief 使用 key 设置值(double). * @js NA */ void setDoubleForKey(const char* pKey, double value); /** @brief 使用 key 设置值(string). * @js NA */ void setStringForKey(const char* pKey, const std::string & value); /** @brief 使用 key 设置值(binary data) . * @js NA * @lua NA */ void setDataForKey(const char* pKey, const Data& value); /** @brief 将内容保存到XML文件 * @js NA */ void flush(); /** returns the singleton (单例) * @js NA * @lua NA */ static UserDefault* getInstance(); /** * @js NA */ static void destroyInstance(); /** 过时不再需要建议使用新的 API. 可以使用 getInstace() 代替 * @js NA * @lua NA */ CC_DEPRECATED_ATTRIBUTE static UserDefault* sharedUserDefault(); /** * @js NA */ CC_DEPRECATED_ATTRIBUTE static void purgeSharedUserDefault(); /** * @js NA */ const static std::string& getXMLFilePath(); /** * @js NA */ static bool isXMLFileExist(); private: UserDefault(); static bool createXMLFile(); static void initXMLFilePath(); static UserDefault* _userDefault; static std::string _filePath; static bool _isFilePathInitialized; }; // end of data_storage group /// @} NS_CC_END #endif // __SUPPORT_CCUSERDEFAULT_H__