diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-05-04 08:48:24 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-05-04 08:48:24 -0400 |
commit | 095293277dbca80e91c4f25b05923b7cb3a79396 (patch) | |
tree | c87a293a74769bd9b28595ba7bd83d714e70dc56 /include | |
parent | d2b7f062a0240bfdc8b84593834fc711c7a53dca (diff) |
fade fixes
Diffstat (limited to 'include')
-rw-r--r-- | include/brice.hpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/include/brice.hpp b/include/brice.hpp new file mode 100644 index 0000000..60fcec8 --- /dev/null +++ b/include/brice.hpp @@ -0,0 +1,48 @@ +#ifndef BRICE_H_ +#define BRICE_H_ + +#include <unordered_map> +#include <string> +#include <istream> +#include <fstream> + +#include <common.hpp> + +class Brice { +private: + std::unordered_map<std::string, std::string> ice; +public: + Brice(void){} + ~Brice(void){} + + std::string getValue(const std::string& id) const { + auto item = ice.find(id); + return (item == std::end(ice)) ? "" : item->second; + } + + void addValue(const std::string &id, const std::string& value) { + ice.emplace(std::make_pair(id, value)); + } + + void save(void) const { + std::ofstream out ("brice.dat", std::ios::out | std::ios::binary); + std::string data = std::to_string(ice.size()) + '\n'; + + if (!out.is_open()) + UserError("Cannot open brice data file"); + + for (const auto& i : ice) { + data.append(i.first + ',' ); + data.append(i.second + '\n'); + } + + out.write(data.data(), data.size()); + out.close(); + } + + void load(void) { + const std::string data = readFile("brice.dat"); + } +}; + +#endif // BRICE_H_ |