Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
TypeDescriptorVector.hpp
1#pragma once
2
3#include <vector>
4#include "TypeDescriptor.hpp"
5#include "TypeResolver.hpp"
6
7namespace Grindstone::Reflection {
9 std::string name;
10 TypeDescriptor* itemType;
11 size_t (*getSize)(const void*);
12 void* (*getItem)(const void*, size_t);
13 void (*erase)(void*, size_t indexs);
14 void (*emplaceBack)(void*);
15
16 template <typename ItemType>
18 : TypeDescriptor{ "std::vector<>", sizeof(std::vector<ItemType>), ReflectionTypeData::Vector },
19 itemType{ TypeResolver<ItemType>::Get()},
20 name{ (std::string("std::vector<") + TypeResolver<ItemType>::Get()->GetFullName() + ">").c_str() }
21 {
22 getSize = [](const void* vecPtr) -> size_t {
23 const auto& vec = *(const std::vector<ItemType>*) vecPtr;
24 return vec.size();
25 };
26
27 getItem = [](const void* vecPtr, size_t index) -> void* {
28 auto& vec = *(std::vector<ItemType>*) vecPtr;
29 return (void*)&vec[index];
30 };
31
32 erase = [](void* vecPtr, size_t index) -> void {
33 auto& vec = *(std::vector<ItemType>*) vecPtr;
34 vec.erase(vec.begin() + index);
35 };
36
37 emplaceBack = [](void* vecPtr) -> void {
38 auto& vec = *(std::vector<ItemType>*) vecPtr;
39 vec.emplace_back();
40 };
41 }
42
43 virtual const char* GetFullName() const override {
44 return name.c_str();
45 }
46 };
47
48 template <typename T>
49 class TypeResolver<std::vector<T>> {
50 public:
51 static TypeDescriptor* Get() {
52 static TypeDescriptor_StdVector typeDesc{ (T*) nullptr };
53 return &typeDesc;
54 }
55 };
56}
Definition TypeDescriptorVector.hpp:8
Definition TypeDescriptor.hpp:6
Definition TypeResolver.hpp:8