-
Notifications
You must be signed in to change notification settings - Fork 0
/
DB.cpp
34 lines (27 loc) · 1017 Bytes
/
DB.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "DB.h"
namespace dxco {
std::map<std::string, int> DB::icache;
std::map<std::string, std::string> DB::scache;
void DB::putString(const std::string& key, const std::string& value) {
cocos2d::CCUserDefault::sharedUserDefault()->setStringForKey(key.c_str(), value);
cocos2d::CCUserDefault::sharedUserDefault()->flush();
DB::scache[key] = value;
}
void DB::putInteger(const std::string& key, const int& value) {
cocos2d::CCUserDefault::sharedUserDefault()->setIntegerForKey(key.c_str(), value);
cocos2d::CCUserDefault::sharedUserDefault()->flush();
DB::icache[key] = value;
}
std::string DB::getString(const std::string& key) {
if (DB::scache.count(key)) {
return DB::scache[key];
}
return cocos2d::CCUserDefault::sharedUserDefault()->getStringForKey(key.c_str());
}
int DB::getInteger(const std::string& key, int def) {
if (DB::icache.count(key)) {
return DB::icache[key];
}
return cocos2d::CCUserDefault::sharedUserDefault()->getIntegerForKey(key.c_str(), def);
}
} /* namespace dxco */