CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
MetaItem.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 "Forward.hpp"
11#include "Type.hpp"
12#include "Box.hpp"
13
17
18#include <functional>
19
20namespace CeresEngine {
21
23 enum class MetaCategory : unsigned int {
25 Class,
26
29
31 Method,
32
35
37 Enum,
38
41 };
42
44 private:
47
48 public:
50 using EnumerateFunction = FunctionView<bool(const Box&) const>;
51
55 template<typename T> [[nodiscard]] bool has() const { return has(getType<T>()); }
56
60 [[nodiscard]] bool has(const Type& type) const;
61
65 template<typename T> [[nodiscard]] const T& get() const { return get(getType<T>()).template cref<T>(); }
66
70 [[nodiscard]] const Box& get(const Type& type) const;
71
75 template<typename T> [[nodiscard]] const T* getIf() const { return has<T>() ? &get<T>() : nullptr; }
76
78 void set(const Type& type, Box&& value);
79
81 void set(Box&& value);
82
86 void forEach(const EnumerateFunction& func) const;
87 };
88
90 class MetaItem {
91 public:
93
94 public:
97 };
98
99} //namespace CeresEngine
A value type that can hold any alongside it's type information.
Definition Box.hpp:40
Definition Class.hpp:46
Represents a reflected enum from C++.
Definition Enum.hpp:26
Represents an enum value.
Definition Enum.hpp:75
A generic item that can be added as a member of a namespace.
Definition MetaItem.hpp:90
virtual MetaCategory getCategory() const =0
Gets the category of the item.
virtual ~MetaItem() noexcept=default
void set(const Type &type, Box &&value)
Sets the attribute for the given type.
bool has(const Type &type) const
Checks if the item has the given attribute type.
void set(Box &&value)
Sets the attribute for the given type.
HashMap< TypeID, Box > mAttributes
The underlying storage of the attributes.
Definition MetaItem.hpp:46
const T & get() const
Gets an item attribute by type.
Definition MetaItem.hpp:65
const Box & get(const Type &type) const
Gets an item attribute by type.
const T * getIf() const
Gets an item attribute if it exists.
Definition MetaItem.hpp:75
void forEach(const EnumerateFunction &func) const
Calls the func function for each attribute present on the item.
FunctionView< bool(const Box &) const > EnumerateFunction
A function that enumerates attributes of an item.
Definition MetaItem.hpp:50
bool has() const
Checks if the item has the given attribute type.
Definition MetaItem.hpp:55
Represents a reflected C++ type. Can be used to get metadata from a C++ type.
Definition Type.hpp:32
Definition Application.hpp:19
MetaCategory
The category of a MetaItem.
Definition MetaItem.hpp:23
@ Method
Indicates that the item is a method.
@ Property
Indicates that the item is a property.
@ Constructor
Indicates that the item is a constructor.
std::unordered_map< Key, T, Hash, KeyEqual, ScopedAllocatorAdaptor< StdAllocator< Pair< const Key, T >, RawAllocator > > > HashMap
HashMap is an associative container that contains key-value pairs with unique keys.
Definition Map.hpp:33
FunctionBase< false, true, fu2::capacity_default, true, false, Signatures... > FunctionView
A non owning copyable function wrapper for arbitrary callable types.
Definition Function.hpp:64
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25