This repository was archived by the owner on Aug 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathmemorydatastore.cpp
57 lines (43 loc) · 1.78 KB
/
memorydatastore.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
Copyright 2015 Ilya Zhuravlev
This file is part of Acquisition.
Acquisition is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Acquisition is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Acquisition. If not, see <http://www.gnu.org/licenses/>.
*/
#include "memorydatastore.h"
#include "currencymanager.h"
std::string MemoryDataStore::Get(const std::string &key, const std::string &default_value) {
auto i = data_.find(key);
if (i == data_.end())
return default_value;
return i->second;
}
void MemoryDataStore::Set(const std::string &key, const std::string &value) {
data_[key] = value;
}
void MemoryDataStore::InsertCurrencyUpdate(const CurrencyUpdate &update) {
currency_updates_.push_back(update);
}
std::vector<CurrencyUpdate> MemoryDataStore::GetAllCurrency() {
return currency_updates_;
}
void MemoryDataStore::SetBool(const std::string &key, bool value) {
SetInt(key, static_cast<int>(value));
}
bool MemoryDataStore::GetBool(const std::string &key, bool default_value) {
return static_cast<bool>(GetInt(key, static_cast<int>(default_value)));
}
void MemoryDataStore::SetInt(const std::string &key, int value) {
Set(key, std::to_string(value));
}
int MemoryDataStore::GetInt(const std::string &key, int default_value) {
return std::stoi(Get(key, std::to_string(default_value)));
}