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