IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
module.hxx
Go to the documentation of this file.
1
3
4#pragma once
8
9namespace ice
10{
11
15 template <typename Type>
16 class Module
17 {
18 public:
19 virtual ~Module() noexcept = default;
20
22 static inline auto module_info() noexcept -> ice::ModuleInfo const& { return _module_info; }
23
24 private:
25 static inline void internal_load(
27 ice::ModuleNegotiatorAPIContext* context,
28 ice::ModuleNegotiatorAPI* negotiator
29 ) noexcept
30 {
31 static_assert(
33 "Module types need to provide a static 'on_load' function!"
34 );
35
36 // We use a tagged negotiator so we can register the same API type from multiple modules in the same local execution unit.
37 ice::ModuleNegotiatorTagged<Type> const negotiator_instance{ negotiator, context };
38 if (Type::on_load(*alloc, negotiator_instance) == false)
39 {
40 return;
41 }
42 }
43
44 static inline void internal_unload(ice::Allocator* alloc) noexcept
45 {
46 // Not all modules need to be explicitly unloaded.
47 if constexpr (ice::concepts::ModuleUnloadable<Type>)
48 {
49 Type::on_unload(*alloc);
50 }
51 }
52
56 static inline ModulesEntry const _module_info{ &internal_load, &internal_unload };
57 };
58
59#if ISP_COMPILER_CLANG || ISP_COMPILER_GCC \
60 // We access 'module_info' here to force Clang and Gcc to initialize the 'static inline' variable.
61# define IS_WORKAROUND_MODULE_INITIALIZATION(type) \
62 private: static inline ice::ModuleInfo const& _workaround_info_instance = type::module_info()
63#else
64# define IS_WORKAROUND_MODULE_INITIALIZATION(type)
65#endif
66#define ICE_WORKAROUND_MODULE_INITIALIZATION(type) IS_WORKAROUND_MODULE_INITIALIZATION(type)
67
68} // namespace ice
Base class for modules that will automatically register them to be loaded by the module manager.
Definition module.hxx:17
virtual ~Module() noexcept=default
static auto module_info() noexcept -> ice::ModuleInfo const &
Definition module.hxx:22
Definition module_negotiator.hxx:82
Definition module_concepts.hxx:41
SPDX-License-Identifier: MIT.
Definition array.hxx:12
auto alloc(ice::usize size) noexcept -> ice::AllocResult
ice::AllocatorBase< ice::build::is_debug||ice::build::is_develop > Allocator
Definition mem_types.hxx:25
Stores information of module load and unload functions.
Definition module_info.hxx:12
Negotiation API used to register and query modules for their APIs.
Definition module_negotiator.hxx:17