CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Enum.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 "Box.hpp"
11#include "MetaContainer.hpp"
12#include "MetaItem.hpp"
13#include "Type.hpp"
14
17
18#include <functional>
19
20namespace CeresEngine {
21
22 class EnumValue;
23
26 class Enum : public MetaContainer {
27 public:
29
30 public:
32
33 public:
35
36 public:
40
41 public:
46
51
56
60 [[nodiscard]] Optional<StringView> getName(const Box& value) const;
61
64 void forEachValue(const EnumerateElementFunction& func) const;
65
69
70 protected:
72 };
73
75 class EnumValue : public MetaItem {
76 public:
79
80 public:
82
83 private:
86
88 mutable Box mValue;
89
93
94 public:
96
97 public:
100
102 [[nodiscard]] MetaCategory getCategory() const override { return kCategory; }
103
104 public:
107 if(!mValue) {
108 CE_ASSERT(mValueGetter != nullptr);
111 }
112 return mValueReference;
113 }
114 };
115
116} // namespace CeresEngine
#define CE_ASSERT(...)
Definition Macros.hpp:323
A value type that can hold any alongside it's type information.
Definition Box.hpp:40
Box cref() const &
Gets a reference to the meta value.
Represents a reflected enum from C++.
Definition Enum.hpp:26
void addElement(StringView name, ValueGetter &&value)
String name
Definition Enum.hpp:31
Optional< StringView > getName(const Box &value) const
Gets the name of an enum by value.
Generator< const EnumValue > forEachValue() const
Iterates over all enum values on the enum.
const EnumValue * getEnumValueWithValue(const Box &name) const
Gets the MetaEnumValue for the entry with the given value.
Optional< const Box & > getValue(StringView name) const
Gets the value of an enum by name.
FunctionView< bool(const EnumValue &) const > EnumerateElementFunction
Defines a type that represents the function to be called when iterating over all MetaEnumValue.
Definition Enum.hpp:39
UniqueFunction< Box() const > ValueGetter
Definition Enum.hpp:28
void forEachValue(const EnumerateElementFunction &func) const
Calls func for each value in the enum.
const EnumValue * getEnumValueWithName(StringView name) const
Gets the MetaEnumValue for the entry named name.
Represents an enum value.
Definition Enum.hpp:75
typename Enum::ValueGetter ValueGetter
Definition Enum.hpp:78
MetaCategory getCategory() const override
Gets the category of the item.
Definition Enum.hpp:102
StringView name
Definition Enum.hpp:81
static constexpr MetaCategory kCategory
Gets the category of the item.
Definition Enum.hpp:99
EnumValue(Enum &owner, StringView name, ValueGetter &&getter)
const Box & getValue() const noexcept
The enum value, as returned from the getter.
Definition Enum.hpp:106
Box mValue
The enum value, as returned from the getter.
Definition Enum.hpp:88
Box mValueReference
A const reference to the enum value.
Definition Enum.hpp:92
ValueGetter mValueGetter
The enum value getter function.
Definition Enum.hpp:85
A generator represents a coroutine type that produces a sequence of values of type T,...
Definition Generator.hpp:50
A base class for a container of MetaItems.
Definition MetaContainer.hpp:35
A generic item that can be added as a member of a namespace.
Definition MetaItem.hpp:90
Definition Optional.hpp:17
Definition Application.hpp:19
MetaCategory
The category of a MetaItem.
Definition MetaItem.hpp:23
@ EnumValue
Indicates that the item is an enum value.
FunctionBase< false, true, fu2::capacity_default, true, false, Signatures... > FunctionView
A non owning copyable function wrapper for arbitrary callable types.
Definition Function.hpp:64
FunctionBase< true, false, fu2::capacity_default, true, false, Signatures... > UniqueFunction
An owning non copyable function wrapper for arbitrary callable types.
Definition Function.hpp:59
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25