Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
system_set.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <helios/core_pch.hpp>
4
5#include <ctti/name.hpp>
6#include <ctti/type_id.hpp>
7
8#include <concepts>
9#include <cstddef>
10#include <string_view>
11#include <type_traits>
12
13namespace helios::app {
14
15/**
16 * @brief Type alias for system set type IDs.
17 * @details Used to uniquely identify system set types at runtime.
18 */
19using SystemSetId = size_t;
20
21/**
22 * @brief Trait to identify valid system set types.
23 * @details A valid system set type must be an empty struct or class.
24 * This ensures system sets are zero-cost type markers with no runtime overhead.
25 * @tparam T Type to check
26 */
27template <typename T>
28concept SystemSetTrait = std::is_empty_v<std::remove_cvref_t<T>>;
29
30/**
31 * @brief Trait to identify system sets with custom names.
32 * @details A system set with name trait must satisfy SystemSetTrait and provide:
33 * - `static constexpr std::string_view GetName() noexcept`
34 * @tparam T Type to check
35 */
36template <typename T>
38 { T::GetName() } -> std::same_as<std::string_view>;
39};
40
41/**
42 * @brief Gets unique type ID for a system set type.
43 * @details Uses CTTI to generate a unique hash for the system set type.
44 * The ID is consistent across compilation units.
45 * @tparam T System set type
46 * @return Unique type ID for the system set
47 */
48template <SystemSetTrait T>
49constexpr SystemSetId SystemSetIdOf() noexcept {
50 return ctti::type_index_of<T>().hash();
51}
52
53/**
54 * @brief Gets the name of a system set type.
55 * @details Returns the custom name if GetName() is provided,
56 * otherwise returns the CTTI-generated type name.
57 * @tparam T System set type
58 * @return Name of the system set
59 */
60template <SystemSetTrait T>
61constexpr std::string_view SystemSetNameOf() noexcept {
62 if constexpr (SystemSetWithNameTrait<T>) {
63 return T::GetName();
64 } else {
65 return ctti::name_of<T>();
66 }
67}
68
69} // namespace helios::app
Trait to identify valid system set types.
Trait to identify system sets with custom names.
constexpr SystemSetId SystemSetIdOf() noexcept
Gets unique type ID for a system set type.
constexpr std::string_view SystemSetNameOf() noexcept
Gets the name of a system set type.
size_t SystemSetId
Type alias for system set type IDs.