Toast Engine
Loading...
Searching...
No Matches
asset_field_access.hpp
Go to the documentation of this file.
1
13
14#pragma once
15
16#include <any>
18#include <toast/reflect/reflect.hpp>
19#include <toast/uid.hpp>
20#include <vector>
21
22namespace toast {
23
24template<class Class, typename Handle, typename Tag>
26 static auto get(void* obj) -> std::any {
27 return std::any {(static_cast<Class*>(obj)->*_detail::template Accessor<Tag>::member).uid()};
28 }
29
30 static void set(void* obj, std::any value) {
31 if (auto* uid = std::any_cast<toast::UID>(&value)) {
32 static_cast<Class*>(obj)->*_detail::template Accessor<Tag>::member = assets::load<typename Handle::asset_type>(*uid);
33 }
34 }
35};
36
44template<class Class, typename Vector, typename Tag>
46 using Handle = typename Vector::value_type;
47 using AssetType = typename Handle::asset_type;
48
49 static auto get(void* obj) -> std::any {
50 const Vector& handles = static_cast<Class*>(obj)->*_detail::template Accessor<Tag>::member;
51 std::vector<toast::UID> uids;
52 uids.reserve(handles.size());
53 for (const auto& handle : handles) {
54 uids.push_back(handle.uid());
55 }
56 return std::any {std::move(uids)};
57 }
58
59 static void set(void* obj, std::any value) {
60 if (auto* uids = std::any_cast<std::vector<toast::UID>>(&value)) {
61 Vector handles;
62 handles.reserve(uids->size());
63 for (toast::UID uid : *uids) {
64 handles.push_back(assets::load<AssetType>(uid));
65 }
66 static_cast<Class*>(obj)->*_detail::template Accessor<Tag>::member = std::move(handles);
67 }
68 }
69};
70
71}
Public API for the asset management system.
Reflection accessor for a std::vector of assets::Handle<T> members.
Definition asset_field_access.hpp:45
Definition asset_field_access.hpp:25
Definition uid.hpp:20
Unique identifier for everything that exists in our engine.