StevEngine
StevEngine is a customizable C++ game engine.
Loading...
Searching...
No Matches
KeyValueStore.hpp
1#pragma once
2#include "Stream.hpp"
3#include <map>
4
5namespace StevEngine::Utilities {
6 class KeyValueStore {
7 public:
8 KeyValueStore() {};
9
16 template <typename T> T Read(const std::string& key) const {
17 Stream stream(Text);
18 stream.GetStream() << data.at(key).GetStream().str();
19 return stream.Read<T>();
20 }
21
28 template <typename T> void Write(const std::string& key, const T& input) {
29 if(data.contains(key)) {
30 data.erase(key);
31 }
32 Stream stream(Text);
33 stream << input;
34 data.emplace(key, stream);
35 }
36
41 void Erase(std::string key);
42
48 bool Contains(std::string key) const;
49
56 void WriteToFile(const char* path) const;
57
62 void ReadFromFile(const Resources::Resource& file);
63
68 void ReadFromFile(std::ifstream& file);
69 private:
71 std::map<std::string, Stream> data;
73 void ReadFromStream(Stream& stream);
74 };
75}
Container for loaded resource data.
Definition ResourceManager.hpp:11
void WriteToFile(const char *path) const
Write full content to a file.
Definition KeyValueStore.cpp:15
void ReadFromFile(const Resources::Resource &file)
Read content from a file.
Definition KeyValueStore.cpp:24
void Write(const std::string &key, const T &input)
Write data of specified type.
Definition KeyValueStore.hpp:28
bool Contains(std::string key) const
Erase key from store.
Definition KeyValueStore.cpp:10
T Read(const std::string &key) const
Read data of specified type.
Definition KeyValueStore.hpp:16
void Erase(std::string key)
Erase key from store.
Definition KeyValueStore.cpp:6
Stream for serialization of data.
Definition Stream.hpp:22
T Read()
Read data of specified type from stream.
std::stringstream & GetStream()
Get underlying std::stringstream object.
Definition Stream.hpp:100