vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
behavior_field_visitor.h
1#pragma once
2
3#include <cstddef>
4#include <string>
5#include <type_traits>
6#include <utility>
7
8#include <glm/glm.hpp>
9#include <glm/gtc/quaternion.hpp>
10
11#include "resource/asset_type.h"
12
13namespace Vkm::Engine {
14
23class BehaviorFieldVisitor {
24 public:
25 BehaviorFieldVisitor() = default;
26 virtual ~BehaviorFieldVisitor() = default;
27
28 BehaviorFieldVisitor(const BehaviorFieldVisitor& other) = delete;
29 BehaviorFieldVisitor& operator=(const BehaviorFieldVisitor& other) = delete;
30
31 BehaviorFieldVisitor(BehaviorFieldVisitor && other) = delete;
32 BehaviorFieldVisitor& operator=(BehaviorFieldVisitor && other) = delete;
33
34 public:
35 virtual void field(const char* name, float& value) = 0;
36 virtual void field(const char* name, int& value) = 0;
37 virtual void field(const char* name, bool& value) = 0;
38 virtual void field(const char* name, glm::vec2& value) = 0;
39 virtual void field(const char* name, glm::vec3& value) = 0;
40 virtual void field(const char* name, glm::vec4& value) = 0;
41 virtual void field(const char* name, glm::quat& value) = 0;
42 virtual void field(const char* name, std::string& value) = 0;
43
55 virtual void enumField(const char* name, int& index, const char* const* names, std::size_t count) = 0;
56
68 virtual void assetField(const char* name, std::string& assetName, AssetType type) = 0;
69
79 virtual bool beginStruct(const char* name) = 0;
80
84 virtual void endStruct() = 0;
85};
86
94template<typename V, typename = void>
95inline constexpr bool VISITOR_SUPPORTS_FIELD = false;
96
97template<typename V>
98inline constexpr bool VISITOR_SUPPORTS_FIELD<
99 V,
100 std::void_t<decltype(
101 std::declval<BehaviorFieldVisitor&>().field(std::declval<const char*>(), std::declval<V&>())
102 )>
103> = true;
104
105} // namespace Vkm::Engine
virtual void assetField(const char *name, std::string &assetName, AssetType type)=0
Visit a field that names an asset, type-erased to (name, kind).
virtual bool beginStruct(const char *name)=0
Enter a nested reflected-struct field; return true to descend.
virtual void endStruct()=0
Leave the struct opened by a beginStruct() that returned true.
virtual void enumField(const char *name, int &index, const char *const *names, std::size_t count)=0
Visit an enum field, type-erased to (name index, name table).