这是一个以XML文件格式来存放简单数据的,可存储数据类型为bool, int, float, double, string。
他的部分源文件为:
std::string getStringForKey(const char* key);
/**
* Get string value by key, if the key doesn't exist, will return passed default value.
* @param key The key to get value.
* @param defaultValue The default value to return if the key doesn't exist.
* @return String value of the key.
* @js NA
*/
virtual std::string getStringForKey(const char* key, const std::string & defaultValue);
/**
* Get Data value by key, if the key doesn't exist, will return an empty Data.
* @param key The key to get value.
* @return Data value of the key.
* @js NA
*/
Data getDataForKey(const char* key);
/**
* Get Data value by key, if the key doesn't exist, will return an empty Data.
* @param key The key to get value.
* @param defaultValue The default value to return if the key doesn't exist.
* @return Data value of the key.
* @js NA
*/
virtual Data getDataForKey(const char* key, const Data& defaultValue);
把数据存入里面,只需相应的api即可设置,取出等:
auto userdefault = UserDefault::getInstance();
//查看路径,测试用
log(userdefault->getXMLFilePath().c_str());
//存储本次游戏分数
char score_str[100] = {0};
sprintf(score_str, "%d", m_score);
userdefault->setStringForKey("LastScore", score_str);
//存储最佳游戏分数
auto bestscore = userdefault->getStringForKey("BestScore");
if (m_score > atoi(bestscore.c_str()))
userdefault->setStringForKey("BestScore", score_str);