stellarlib 0.1.0
Loading...
Searching...
No Matches
lifecycle.hpp
1/* clang-format off */
2
3/*
4 stellarlib
5 Copyright (C) 2025-2026 Domán Zana
6
7 This software is provided 'as-is', without any express or implied
8 warranty. In no event will the authors be held liable for any damages
9 arising from the use of this software.
10
11 Permission is granted to anyone to use this software for any purpose,
12 including commercial applications, and to alter it and redistribute it
13 freely, subject to the following restrictions:
14
15 1. The origin of this software must not be misrepresented; you must not
16 claim that you wrote the original software. If you use this software
17 in a product, an acknowledgment in the product documentation would be
18 appreciated but is not required.
19 2. Altered source versions must be plainly marked as such, and must not be
20 misrepresented as being the original software.
21 3. This notice may not be removed or altered from any source distribution.
22*/
23
24#ifndef STELLARLIB_APP_LIFECYCLE_HPP
25#define STELLARLIB_APP_LIFECYCLE_HPP
26
27#include <SDL3/SDL_events.h>
28
29#include <utility>
30
31namespace stellarlib::app::internal
32{
33template <typename System>
34class lifecycle final
35{
36friend System;
37
38public:
39 [[nodiscard]]
40 constexpr lifecycle() noexcept = delete;
41
42 [[nodiscard]]
43 constexpr lifecycle(const lifecycle &) noexcept = delete;
44
45 [[nodiscard]]
46 constexpr lifecycle(lifecycle &&) noexcept = delete;
47
48 constexpr auto operator=(const lifecycle &) noexcept
49 -> lifecycle & = delete;
50
51 constexpr auto operator=(lifecycle &&) noexcept
52 -> lifecycle & = delete;
53
54 constexpr ~lifecycle() noexcept = delete;
55
56private:
57 template <typename Subsystem, typename Info>
58 [[nodiscard]]
59 static constexpr auto init(Info &&info)
60 {
61 return Subsystem{std::forward<Info>(info)};
62 }
63
64 template <typename Subsystem>
65 [[nodiscard]]
66 static constexpr auto iterate(Subsystem &subsystem)
67 {
68 return subsystem.iterate();
69 }
70
71 template <typename Subsystem>
72 [[nodiscard]]
73 static constexpr auto event(const Subsystem &subsystem, const SDL_Event &event)
74 {
75 return subsystem.event(event);
76 }
77};
78}
79
80#endif
context::info info
Main initialization descriptor.
Definition init.hpp:41