summaryrefslogtreecommitdiffstats
path: root/core/io
diff options
context:
space:
mode:
Diffstat (limited to 'core/io')
-rw-r--r--core/io/CMakeLists.txt7
-rw-r--r--core/io/buffer.cc208
-rw-r--r--core/io/buffer.hh260
-rw-r--r--core/io/cmdline.cc83
-rw-r--r--core/io/cmdline.hh13
-rw-r--r--core/io/config_map.cc131
-rw-r--r--core/io/config_map.hh33
7 files changed, 735 insertions, 0 deletions
diff --git a/core/io/CMakeLists.txt b/core/io/CMakeLists.txt
new file mode 100644
index 0000000..0639d2c
--- /dev/null
+++ b/core/io/CMakeLists.txt
@@ -0,0 +1,7 @@
+target_sources(core PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/buffer.cc"
+ "${CMAKE_CURRENT_LIST_DIR}/buffer.hh"
+ "${CMAKE_CURRENT_LIST_DIR}/cmdline.cc"
+ "${CMAKE_CURRENT_LIST_DIR}/cmdline.hh"
+ "${CMAKE_CURRENT_LIST_DIR}/config_map.cc"
+ "${CMAKE_CURRENT_LIST_DIR}/config_map.hh")
diff --git a/core/io/buffer.cc b/core/io/buffer.cc
new file mode 100644
index 0000000..62f981c
--- /dev/null
+++ b/core/io/buffer.cc
@@ -0,0 +1,208 @@
+#include "core/pch.hh"
+
+#include "core/io/buffer.hh"
+
+#include "core/math/constexpr.hh"
+
+io::ReadBuffer::ReadBuffer(const void* data, std::size_t size)
+{
+ reset(data, size);
+}
+
+io::ReadBuffer::ReadBuffer(const ENetPacket* packet)
+{
+ reset(packet);
+}
+
+io::ReadBuffer::ReadBuffer(PHYSFS_File* file)
+{
+ reset(file);
+}
+
+std::size_t io::ReadBuffer::size(void) const
+{
+ return m_vector.size();
+}
+
+const std::byte* io::ReadBuffer::data(void) const
+{
+ return m_vector.data();
+}
+
+void io::ReadBuffer::reset(const void* data, std::size_t size)
+{
+ auto bytes = reinterpret_cast<const std::byte*>(data);
+ m_vector.assign(bytes, bytes + size);
+ m_position = 0U;
+}
+
+void io::ReadBuffer::reset(const ENetPacket* packet)
+{
+ auto bytes_ptr = reinterpret_cast<const std::byte*>(packet->data);
+ m_vector.assign(bytes_ptr, bytes_ptr + packet->dataLength);
+ m_position = 0;
+}
+
+void io::ReadBuffer::reset(PHYSFS_File* file)
+{
+ m_vector.resize(PHYSFS_fileLength(file));
+ m_position = 0;
+
+ PHYSFS_seek(file, 0);
+ PHYSFS_readBytes(file, m_vector.data(), m_vector.size());
+}
+
+float io::ReadBuffer::read_FP32(void)
+{
+ return math::uint32_to_float(read_UI32());
+}
+
+std::uint8_t io::ReadBuffer::read_UI8(void)
+{
+ if((m_position + 1U) <= m_vector.size()) {
+ auto result = static_cast<std::uint8_t>(m_vector[m_position]);
+ m_position += 1U;
+ return result;
+ }
+
+ m_position += 1U;
+ return 0;
+}
+
+std::uint16_t io::ReadBuffer::read_UI16(void)
+{
+ if((m_position + 2U) <= m_vector.size()) {
+ auto result = UINT16_C(0x0000);
+ result |= static_cast<std::uint16_t>(m_vector[m_position + 0U]) << 8U;
+ result |= static_cast<std::uint16_t>(m_vector[m_position + 1U]) << 0U;
+ m_position += 2U;
+ return result;
+ }
+
+ m_position += 2U;
+ return 0;
+}
+
+std::uint32_t io::ReadBuffer::read_UI32(void)
+{
+ if((m_position + 4U) <= m_vector.size()) {
+ auto result = UINT32_C(0x00000000);
+ result |= static_cast<std::uint32_t>(m_vector[m_position + 0U]) << 24U;
+ result |= static_cast<std::uint32_t>(m_vector[m_position + 1U]) << 16U;
+ result |= static_cast<std::uint32_t>(m_vector[m_position + 2U]) << 8U;
+ result |= static_cast<std::uint32_t>(m_vector[m_position + 3U]) << 0U;
+ m_position += 4U;
+ return result;
+ }
+
+ m_position += 4U;
+ return 0;
+}
+
+std::uint64_t io::ReadBuffer::read_UI64(void)
+{
+ if((m_position + 8U) <= m_vector.size()) {
+ auto result = UINT64_C(0x0000000000000000);
+ result |= (0x00000000000000FF & static_cast<std::uint64_t>(m_vector[m_position + 0U])) << 56U;
+ result |= (0x00000000000000FF & static_cast<std::uint64_t>(m_vector[m_position + 1U])) << 48U;
+ result |= (0x00000000000000FF & static_cast<std::uint64_t>(m_vector[m_position + 2U])) << 40U;
+ result |= (0x00000000000000FF & static_cast<std::uint64_t>(m_vector[m_position + 3U])) << 32U;
+ result |= (0x00000000000000FF & static_cast<std::uint64_t>(m_vector[m_position + 4U])) << 24U;
+ result |= (0x00000000000000FF & static_cast<std::uint64_t>(m_vector[m_position + 5U])) << 16U;
+ result |= (0x00000000000000FF & static_cast<std::uint64_t>(m_vector[m_position + 6U])) << 8U;
+ result |= (0x00000000000000FF & static_cast<std::uint64_t>(m_vector[m_position + 7U])) << 0U;
+ m_position += 8U;
+ return result;
+ }
+
+ m_position += 8U;
+ return 0;
+}
+
+std::string io::ReadBuffer::read_string(void)
+{
+ auto size = static_cast<std::size_t>(read_UI16());
+ auto result = std::string();
+
+ for(std::size_t i = 0; i < size; ++i) {
+ if(m_position < m_vector.size()) {
+ result.push_back(static_cast<char>(m_vector[m_position]));
+ }
+
+ m_position += 1U;
+ }
+
+ return result;
+}
+
+std::size_t io::WriteBuffer::size(void) const
+{
+ return m_vector.size();
+}
+
+const std::byte* io::WriteBuffer::data(void) const
+{
+ return m_vector.data();
+}
+
+void io::WriteBuffer::reset(void)
+{
+ m_vector.clear();
+}
+
+void io::WriteBuffer::write_UI8(std::uint8_t value)
+{
+ m_vector.push_back(static_cast<std::byte>(value));
+}
+
+void io::WriteBuffer::write_UI16(std::uint16_t value)
+{
+ m_vector.push_back(static_cast<std::byte>(UINT16_C(0xFF) & ((value & UINT16_C(0xFF00)) >> 8U)));
+ m_vector.push_back(static_cast<std::byte>(UINT16_C(0xFF) & ((value & UINT16_C(0x00FF)) >> 0U)));
+}
+
+void io::WriteBuffer::write_UI32(std::uint32_t value)
+{
+ m_vector.push_back(static_cast<std::byte>(UINT32_C(0xFF) & ((value & UINT32_C(0xFF000000)) >> 24U)));
+ m_vector.push_back(static_cast<std::byte>(UINT32_C(0xFF) & ((value & UINT32_C(0x00FF0000)) >> 16U)));
+ m_vector.push_back(static_cast<std::byte>(UINT32_C(0xFF) & ((value & UINT32_C(0x0000FF00)) >> 8U)));
+ m_vector.push_back(static_cast<std::byte>(UINT32_C(0xFF) & ((value & UINT32_C(0x000000FF)) >> 0U)));
+}
+
+void io::WriteBuffer::write_UI64(std::uint64_t value)
+{
+ m_vector.push_back(static_cast<std::byte>(UINT64_C(0xFF) & ((value & UINT64_C(0xFF00000000000000)) >> 56U)));
+ m_vector.push_back(static_cast<std::byte>(UINT64_C(0xFF) & ((value & UINT64_C(0x00FF000000000000)) >> 48U)));
+ m_vector.push_back(static_cast<std::byte>(UINT64_C(0xFF) & ((value & UINT64_C(0x0000FF0000000000)) >> 40U)));
+ m_vector.push_back(static_cast<std::byte>(UINT64_C(0xFF) & ((value & UINT64_C(0x000000FF00000000)) >> 32U)));
+ m_vector.push_back(static_cast<std::byte>(UINT64_C(0xFF) & ((value & UINT64_C(0x00000000FF000000)) >> 24U)));
+ m_vector.push_back(static_cast<std::byte>(UINT64_C(0xFF) & ((value & UINT64_C(0x0000000000FF0000)) >> 16U)));
+ m_vector.push_back(static_cast<std::byte>(UINT64_C(0xFF) & ((value & UINT64_C(0x000000000000FF00)) >> 8U)));
+ m_vector.push_back(static_cast<std::byte>(UINT64_C(0xFF) & ((value & UINT64_C(0x00000000000000FF)) >> 0U)));
+}
+
+void io::WriteBuffer::write_string(const std::string& value)
+{
+ const std::size_t size = math::min<std::size_t>(UINT16_MAX, value.size());
+
+ write_UI16(static_cast<std::uint16_t>(size));
+
+ for(std::size_t i = 0; i < size; m_vector.push_back(static_cast<std::byte>(value[i++]))) {
+ // empty
+ }
+}
+
+PHYSFS_File* io::WriteBuffer::to_file(const char* path, bool append) const
+{
+ if(auto file = (append ? PHYSFS_openAppend(path) : PHYSFS_openWrite(path))) {
+ PHYSFS_writeBytes(file, m_vector.data(), m_vector.size());
+ return file;
+ }
+
+ return nullptr;
+}
+
+ENetPacket* io::WriteBuffer::to_packet(enet_uint32 flags) const
+{
+ return enet_packet_create(m_vector.data(), m_vector.size(), flags);
+}
diff --git a/core/io/buffer.hh b/core/io/buffer.hh
new file mode 100644
index 0000000..205381f
--- /dev/null
+++ b/core/io/buffer.hh
@@ -0,0 +1,260 @@
+#ifndef CORE_IO_BUFFER_HH
+#define CORE_IO_BUFFER_HH 1
+
+#include "core/math/floathacks.hh"
+
+namespace io
+{
+class ReadBuffer final {
+public:
+ ReadBuffer(void) = default;
+ explicit ReadBuffer(const void* data, std::size_t size);
+ explicit ReadBuffer(const ENetPacket* packet);
+ explicit ReadBuffer(PHYSFS_File* file);
+ virtual ~ReadBuffer(void) = default;
+
+ std::size_t size(void) const;
+ const std::byte* data(void) const;
+
+ void reset(const void* data, std::size_t size);
+ void reset(const ENetPacket* packet);
+ void reset(PHYSFS_File* file);
+
+ float read_FP32(void);
+ std::uint8_t read_UI8(void);
+ std::uint16_t read_UI16(void);
+ std::uint32_t read_UI32(void);
+ std::uint64_t read_UI64(void);
+ std::string read_string(void);
+
+ inline std::int8_t read_I8(void);
+ inline std::int16_t read_I16(void);
+ inline std::int32_t read_I32(void);
+ inline std::int64_t read_I64(void);
+
+ inline ReadBuffer& operator>>(float& value);
+ inline ReadBuffer& operator>>(std::int8_t& value);
+ inline ReadBuffer& operator>>(std::int16_t& value);
+ inline ReadBuffer& operator>>(std::int32_t& value);
+ inline ReadBuffer& operator>>(std::int64_t& value);
+ inline ReadBuffer& operator>>(std::uint8_t& value);
+ inline ReadBuffer& operator>>(std::uint16_t& value);
+ inline ReadBuffer& operator>>(std::uint32_t& value);
+ inline ReadBuffer& operator>>(std::uint64_t& value);
+ inline ReadBuffer& operator>>(std::string& value);
+
+private:
+ std::vector<std::byte> m_vector;
+ std::size_t m_position;
+};
+} // namespace io
+
+namespace io
+{
+class WriteBuffer final {
+public:
+ WriteBuffer(void) = default;
+ virtual ~WriteBuffer(void) = default;
+
+ std::size_t size(void) const;
+ const std::byte* data(void) const;
+
+ void reset(void);
+
+ void write_FP32(float value);
+ void write_UI8(std::uint8_t value);
+ void write_UI16(std::uint16_t value);
+ void write_UI32(std::uint32_t value);
+ void write_UI64(std::uint64_t value);
+ void write_string(const std::string& value);
+
+ inline void write_I8(std::int8_t value);
+ inline void write_I16(std::int16_t value);
+ inline void write_I32(std::int32_t value);
+ inline void write_I64(std::int64_t value);
+
+ inline WriteBuffer& operator<<(float value);
+ inline WriteBuffer& operator<<(std::int8_t value);
+ inline WriteBuffer& operator<<(std::int16_t value);
+ inline WriteBuffer& operator<<(std::int32_t value);
+ inline WriteBuffer& operator<<(std::int64_t value);
+ inline WriteBuffer& operator<<(std::uint8_t value);
+ inline WriteBuffer& operator<<(std::uint16_t value);
+ inline WriteBuffer& operator<<(std::uint32_t value);
+ inline WriteBuffer& operator<<(std::uint64_t value);
+ inline WriteBuffer& operator<<(const std::string& value);
+
+ PHYSFS_File* to_file(const char* path, bool append = false) const;
+ ENetPacket* to_packet(enet_uint32 flags = ENET_PACKET_FLAG_RELIABLE) const;
+
+private:
+ std::vector<std::byte> m_vector;
+};
+} // namespace io
+
+inline std::int8_t io::ReadBuffer::read_I8(void)
+{
+ return static_cast<std::int8_t>(read_UI8());
+}
+
+inline std::int16_t io::ReadBuffer::read_I16(void)
+{
+ return static_cast<std::int16_t>(read_UI16());
+}
+
+inline std::int32_t io::ReadBuffer::read_I32(void)
+{
+ return static_cast<std::int32_t>(read_UI32());
+}
+
+inline std::int64_t io::ReadBuffer::read_I64(void)
+{
+ return static_cast<std::int64_t>(read_UI64());
+}
+
+inline io::ReadBuffer& io::ReadBuffer::operator>>(float& value)
+{
+ value = read_FP32();
+ return *this;
+}
+
+inline io::ReadBuffer& io::ReadBuffer::operator>>(std::int8_t& value)
+{
+ value = read_I8();
+ return *this;
+}
+
+inline io::ReadBuffer& io::ReadBuffer::operator>>(std::int16_t& value)
+{
+ value = read_I16();
+ return *this;
+}
+
+inline io::ReadBuffer& io::ReadBuffer::operator>>(std::int32_t& value)
+{
+ value = read_I32();
+ return *this;
+}
+
+inline io::ReadBuffer& io::ReadBuffer::operator>>(std::int64_t& value)
+{
+ value = read_I64();
+ return *this;
+}
+
+inline io::ReadBuffer& io::ReadBuffer::operator>>(std::uint8_t& value)
+{
+ value = read_UI8();
+ return *this;
+}
+
+inline io::ReadBuffer& io::ReadBuffer::operator>>(std::uint16_t& value)
+{
+ value = read_UI16();
+ return *this;
+}
+
+inline io::ReadBuffer& io::ReadBuffer::operator>>(std::uint32_t& value)
+{
+ value = read_UI32();
+ return *this;
+}
+
+inline io::ReadBuffer& io::ReadBuffer::operator>>(std::uint64_t& value)
+{
+ value = read_UI64();
+ return *this;
+}
+
+inline io::ReadBuffer& io::ReadBuffer::operator>>(std::string& value)
+{
+ value = read_string();
+ return *this;
+}
+
+inline void io::WriteBuffer::write_FP32(float value)
+{
+ write_UI32(math::float_to_uint32(value));
+}
+
+inline void io::WriteBuffer::write_I8(std::int8_t value)
+{
+ write_UI8(static_cast<std::uint8_t>(value));
+}
+
+inline void io::WriteBuffer::write_I16(std::int16_t value)
+{
+ write_UI16(static_cast<std::uint16_t>(value));
+}
+
+inline void io::WriteBuffer::write_I32(std::int32_t value)
+{
+ write_UI32(static_cast<std::uint32_t>(value));
+}
+
+inline void io::WriteBuffer::write_I64(std::int64_t value)
+{
+ write_UI64(static_cast<std::uint64_t>(value));
+}
+
+inline io::WriteBuffer& io::WriteBuffer::operator<<(float value)
+{
+ write_FP32(value);
+ return *this;
+}
+
+inline io::WriteBuffer& io::WriteBuffer::operator<<(std::int8_t value)
+{
+ write_I8(value);
+ return *this;
+}
+
+inline io::WriteBuffer& io::WriteBuffer::operator<<(std::int16_t value)
+{
+ write_I16(value);
+ return *this;
+}
+
+inline io::WriteBuffer& io::WriteBuffer::operator<<(std::int32_t value)
+{
+ write_I32(value);
+ return *this;
+}
+
+inline io::WriteBuffer& io::WriteBuffer::operator<<(std::int64_t value)
+{
+ write_I64(value);
+ return *this;
+}
+
+inline io::WriteBuffer& io::WriteBuffer::operator<<(std::uint8_t value)
+{
+ write_UI8(value);
+ return *this;
+}
+
+inline io::WriteBuffer& io::WriteBuffer::operator<<(std::uint16_t value)
+{
+ write_UI16(value);
+ return *this;
+}
+
+inline io::WriteBuffer& io::WriteBuffer::operator<<(std::uint32_t value)
+{
+ write_UI32(value);
+ return *this;
+}
+
+inline io::WriteBuffer& io::WriteBuffer::operator<<(std::uint64_t value)
+{
+ write_UI64(value);
+ return *this;
+}
+
+inline io::WriteBuffer& io::WriteBuffer::operator<<(const std::string& value)
+{
+ write_string(value);
+ return *this;
+}
+
+#endif // CORE_BUFFER_HH
diff --git a/core/io/cmdline.cc b/core/io/cmdline.cc
new file mode 100644
index 0000000..c43727d
--- /dev/null
+++ b/core/io/cmdline.cc
@@ -0,0 +1,83 @@
+#include "core/pch.hh"
+
+#include "core/io/cmdline.hh"
+
+// Valid options always start with OPTION_PREFIX, can contain
+// a bunch of OPTION_PREFIX'es inside and never end with one
+constexpr static char OPTION_PREFIX = '-';
+
+static std::unordered_map<std::string, std::string> options;
+
+static inline bool is_option_string(const std::string& string)
+{
+ if(string.find_last_of(OPTION_PREFIX) >= (string.size() - 1)) {
+ return false;
+ }
+
+ return string[0] == OPTION_PREFIX;
+}
+
+static inline std::string get_option(const std::string& string)
+{
+ std::size_t i;
+ for(i = 0; string[i] == OPTION_PREFIX; ++i) {
+ // empty
+ }
+
+ return std::string(string.cbegin() + i, string.cend());
+}
+
+void io::cmdline::create(int argc, char** argv)
+{
+ for(int idx = 1; idx < argc; ++idx) {
+ std::string string = argv[idx];
+
+ if(!is_option_string(string)) {
+ spdlog::warn("cmdline: non-argument at {}: {}", idx, string);
+ continue;
+ }
+
+ auto option_string = get_option(string);
+ auto next_idx = idx + 1;
+
+ if(next_idx < argc) {
+ std::string argument = argv[next_idx];
+
+ if(!is_option_string(argument)) {
+ options.insert_or_assign(option_string, argument);
+ idx = next_idx;
+ continue;
+ }
+ }
+
+ // The option is either last or has no
+ // argument (happens when there is a valid
+ // option right next to the one we're parsing)
+ options.insert_or_assign(option_string, std::string());
+ }
+}
+
+void io::cmdline::insert(const char* option, const char* argument)
+{
+ if(argument == nullptr) {
+ options.insert_or_assign(option, std::string());
+ } else {
+ options.insert_or_assign(option, argument);
+ }
+}
+
+const char* io::cmdline::get(const char* option, const char* fallback)
+{
+ auto it = options.find(option);
+
+ if(it == options.cend()) {
+ return fallback;
+ }
+
+ return it->second.c_str();
+}
+
+bool io::cmdline::contains(const char* option)
+{
+ return options.count(option);
+}
diff --git a/core/io/cmdline.hh b/core/io/cmdline.hh
new file mode 100644
index 0000000..d68d9ef
--- /dev/null
+++ b/core/io/cmdline.hh
@@ -0,0 +1,13 @@
+#ifndef CORE_IO_CMDLINE_HH
+#define CORE_IO_CMDLINE_HH 1
+#pragma once
+
+namespace io::cmdline
+{
+void create(int argc, char** argv);
+void insert(const char* option, const char* argument = nullptr);
+const char* get(const char* option, const char* fallback = nullptr);
+bool contains(const char* option);
+} // namespace io::cmdline
+
+#endif // CORE_IO_CMDLINE_HH
diff --git a/core/io/config_map.cc b/core/io/config_map.cc
new file mode 100644
index 0000000..7bce1a6
--- /dev/null
+++ b/core/io/config_map.cc
@@ -0,0 +1,131 @@
+#include "core/pch.hh"
+
+#include "core/io/config_map.hh"
+
+#include "core/config/ivalue.hh"
+#include "core/io/cmdline.hh"
+#include "core/utils/string.hh"
+#include "core/version.hh"
+
+void io::ConfigMap::load_cmdline(void)
+{
+ for(auto it : m_values) {
+ if(auto value = io::cmdline::get(it.first.c_str())) {
+ it.second->set(value);
+ }
+ }
+}
+
+bool io::ConfigMap::load_file(const char* path)
+{
+ if(auto file = PHYSFS_openRead(path)) {
+ auto source = std::string(PHYSFS_fileLength(file), char(0x00));
+ PHYSFS_readBytes(file, source.data(), source.size());
+ PHYSFS_close(file);
+
+ std::string line;
+ std::string kv_string;
+ std::istringstream stream(source);
+
+ while(std::getline(stream, line)) {
+ auto comment = line.find_first_of('#');
+
+ if(comment == std::string::npos) {
+ kv_string = utils::trim_whitespace(line);
+ } else {
+ kv_string = utils::trim_whitespace(line.substr(0, comment));
+ }
+
+ if(utils::is_whitespace(kv_string)) {
+ // Ignore empty or commented out lines
+ continue;
+ }
+
+ auto separator = kv_string.find('=');
+
+ if(separator == std::string::npos) {
+ spdlog::warn("config: {}: invalid line: {}", path, line);
+ continue;
+ }
+
+ auto kv_name = utils::trim_whitespace(kv_string.substr(0, separator));
+ auto kv_value = utils::trim_whitespace(kv_string.substr(separator + 1));
+
+ auto kv_pair = m_values.find(kv_name);
+
+ if(kv_pair == m_values.cend()) {
+ spdlog::warn("config: {}: unknown key: {}", path, kv_name);
+ continue;
+ }
+
+ kv_pair->second->set(kv_value.c_str());
+ }
+
+ return true;
+ }
+
+ return false;
+}
+
+bool io::ConfigMap::save_file(const char* path) const
+{
+ std::ostringstream stream;
+
+ auto curtime = std::time(nullptr);
+
+ stream << "# Voxelius " << project_version_string << " configuration file" << std::endl;
+ stream << "# Generated at: " << std::put_time(std::gmtime(&curtime), "%Y-%m-%d %H:%M:%S %z") << std::endl << std::endl;
+
+ for(const auto& it : m_values) {
+ stream << it.first << "=";
+ stream << it.second->get();
+ stream << std::endl;
+ }
+
+ if(auto file = PHYSFS_openWrite(path)) {
+ auto source = stream.str();
+ PHYSFS_writeBytes(file, source.data(), source.size());
+ PHYSFS_close(file);
+ return true;
+ }
+
+ return false;
+}
+
+bool io::ConfigMap::set_value(const char* name, const char* value)
+{
+ auto kv_pair = m_values.find(name);
+
+ if(kv_pair != m_values.cend()) {
+ kv_pair->second->set(value);
+ return true;
+ }
+
+ return false;
+}
+
+const char* io::ConfigMap::get_value(const char* name) const
+{
+ auto kv_pair = m_values.find(name);
+ if(kv_pair != m_values.cend()) {
+ return kv_pair->second->get();
+ } else {
+ return nullptr;
+ }
+}
+
+void io::ConfigMap::add_value(const char* name, config::IValue& vref)
+{
+ m_values.insert_or_assign(name, &vref);
+}
+
+const config::IValue* io::ConfigMap::find(const char* name) const
+{
+ auto kv_pair = m_values.find(name);
+
+ if(kv_pair != m_values.cend()) {
+ return kv_pair->second;
+ } else {
+ return nullptr;
+ }
+}
diff --git a/core/io/config_map.hh b/core/io/config_map.hh
new file mode 100644
index 0000000..8ff92e1
--- /dev/null
+++ b/core/io/config_map.hh
@@ -0,0 +1,33 @@
+#ifndef CORE_CONFIG_MAP_HH
+#define CORE_CONFIG_MAP_HH 1
+#pragma once
+
+namespace config
+{
+class IValue;
+} // namespace config
+
+namespace io
+{
+class ConfigMap final {
+public:
+ ConfigMap(void) = default;
+ virtual ~ConfigMap(void) = default;
+
+ void load_cmdline(void);
+ bool load_file(const char* path);
+ bool save_file(const char* path) const;
+
+ bool set_value(const char* name, const char* value);
+ const char* get_value(const char* name) const;
+
+ void add_value(const char* name, config::IValue& vref);
+
+ const config::IValue* find(const char* name) const;
+
+private:
+ std::unordered_map<std::string, config::IValue*> m_values;
+};
+} // namespace io
+
+#endif // CORE_CONFIG_MAP_HH