CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Enum.define.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Enum.hpp"
11#include "Type.define.hpp"
12
13namespace CeresEngine {
14 template<typename T> class TEnum : public TTypeInfo<T>, public Enum {
15 public:
16 explicit TEnum() : Enum(getTypeName<T>()) {}
17
18 public:
21
22 public:
23 inline void value(StringView name, const T& value) {
24 addElement(name, [value]() -> Box { return value; });
25 }
26 };
27
28 // ---------------------------------------------------------------------------------------------
29
30#define CE_META_ENUM_DEFINE_BASE(...) \
31 class ::CeresEngine::TUserTypeInfo<__VA_ARGS__> final : public TEnum<__VA_ARGS__> { \
32 using EnumType = __VA_ARGS__; \
33 \
34 public: \
35 explicit TUserTypeInfo() : TEnum<__VA_ARGS__>() { define(*this); } \
36 \
37 private: \
38 inline void define(TUserTypeInfo& define); \
39 }
40
41#define CE_META_ENUM_DEFINE(...) \
42 template<> CE_META_ENUM_DEFINE_BASE(__VA_ARGS__); \
43 template<> const ::CeresEngine::TypeInfo& ::CeresEngine::GetTypeInfo<__VA_ARGS__>::get() { \
44 static const TUserTypeInfo<__VA_ARGS__> kType; \
45 return kType; \
46 } \
47 void ::CeresEngine::TUserTypeInfo<__VA_ARGS__>::define(TUserTypeInfo& define)
48} // namespace CeresEngine
A value type that can hold any alongside it's type information.
Definition Box.hpp:40
Represents a reflected enum from C++.
Definition Enum.hpp:26
void addElement(StringView name, ValueGetter &&value)
String name
Definition Enum.hpp:31
Definition Enum.define.hpp:14
TEnum()
Definition Enum.define.hpp:16
void value(StringView name, const T &value)
Definition Enum.define.hpp:23
StringView getName() const noexcept final
Definition Enum.define.hpp:20
Definition TypeInfo.core.hpp:843
Definition Application.hpp:19
constexpr StringView getTypeName()
Definition TypeName.hpp:72
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25