λ61
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Tetex7
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18//
19// Created by tete on 07/23/2025.
20//
21#pragma once
22
23#ifndef L61_EVENT_SYSTEM_TYPES_HPP
24#define L61_EVENT_SYSTEM_TYPES_HPP
25#include <cstdint>
26#include <type_traits>
27#include <string>
28#include <variant>
29
30namespace l61::EventSystem
31{
33 {
34 constexpr inline std::int32_t PRE_LOAD = -40;
35 constexpr inline std::int32_t EXT_LOADED = -11;
36 constexpr inline const char* T61_TIMER = "com.trs.l61.eventbus.t60";
37 constexpr inline const char* SCRIPT_ENGINE_DEBUGGER_EVENT = "com.trs.l61.scriptengine.debugger.gevent";
38 };
39 using bus_frequency_t = std::variant<std::int32_t, std::string>;
40}
41
42namespace l61::meta
43{
47 template<typename T>
49 std::is_same_v<T, std::int32_t> ||
50 std::is_same_v<T, std::string> ||
51 std::is_convertible_v<T, std::string>; // To appease the compiler for string literals
52
53 template<typename T>
55 {
56 constexpr static bool value = eventBusFrequencyCompatible<T>;
57 };
58 template<typename T>
60}
61
62template <>
63struct std::formatter<l61::EventSystem::bus_frequency_t> : std::formatter<std::string> {
64 auto format(const l61::EventSystem::bus_frequency_t& freq, format_context& ctx) const {
65 const std::string result = std::visit([]<typename Tp>(const Tp& val) {
66 using T = std::decay_t<Tp>;
67 if constexpr (std::is_same_v<T, std::string>)
68 return std::format("\"{}\"", val);
69 else if constexpr (std::is_same_v<T, std::int32_t>)
70 return std::format("{}", val);
71 else
72 return std::format("'{}'", val);
73 }, freq);
74 return std::formatter<std::string>::format(result, ctx);
75 }
76};
77
78#endif //L61_EVENT_SYSTEM_TYPES_HPP
Definition types.hpp:33
constexpr const char * SCRIPT_ENGINE_DEBUGGER_EVENT
Definition types.hpp:37
constexpr const char * T61_TIMER
Definition types.hpp:36
constexpr std::int32_t PRE_LOAD
Definition types.hpp:34
constexpr std::int32_t EXT_LOADED
Definition types.hpp:35
Definition Event.hpp:27
std::variant< std::int32_t, std::string > bus_frequency_t
Definition types.hpp:39
Definition Object.hpp:38
constexpr bool is_eventBus_freq_compatible_v
Definition types.hpp:59
Definition Object.hpp:34
static constexpr bool value
Definition types.hpp:56
auto format(const l61::EventSystem::bus_frequency_t &freq, format_context &ctx) const
Definition types.hpp:64