From b60796c4b070ff49103be7dbdaa5c8ae4de73bc4 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Tue, 13 Aug 2024 01:18:13 +0300 Subject: [PATCH] add StructMapper draft --- src/data/StructMapper.hpp | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/data/StructMapper.hpp diff --git a/src/data/StructMapper.hpp b/src/data/StructMapper.hpp new file mode 100644 index 00000000..1c92f882 --- /dev/null +++ b/src/data/StructMapper.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include +#include +#include + +#include "typedefs.hpp" + +namespace data { + enum class FieldType { + I8, I16, I32, I64, F32, F64 + }; + + struct Field { + FieldType type; + std::string name; + int offset; + }; + + class StructMapping { + std::vector fields; + std::unordered_map indices; + public: + const Field* getField(const std::string& name) const { + auto found = indices.find(name); + if (found == indices.end()) { + return nullptr; + } + return &fields.at(found->second); + } + }; + + class StructAccess { + const StructMapping& mapping; + uint8_t* buffer; + public: + StructAccess(const StructMapping& mapping, uint8_t* buffer) + : mapping(mapping), buffer(buffer) { + } + }; +}