IceShard
1
A personal game engine project, with development focused on 2D/2.5D games.
Toggle main menu visibility
Loading...
Searching...
No Matches
modules
public
ice
module.hxx
Go to the documentation of this file.
1
3
4
#pragma once
5
#include <
ice/mem_allocator.hxx
>
6
#include <
ice/module_negotiator.hxx
>
7
#include <
ice/module_concepts.hxx
>
8
9
namespace
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(
26
ice::Allocator
*
alloc
,
27
ice::ModuleNegotiatorAPIContext* context,
28
ice::ModuleNegotiatorAPI
* negotiator
29
)
noexcept
30
{
31
static_assert
(
32
ice::concepts::ModuleLoadable<Type>
,
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
ice::Module
Base class for modules that will automatically register them to be loaded by the module manager.
Definition
module.hxx:17
ice::Module::~Module
virtual ~Module() noexcept=default
ice::Module::module_info
static auto module_info() noexcept -> ice::ModuleInfo const &
Definition
module.hxx:22
ice::ModuleNegotiatorTagged
Definition
module_negotiator.hxx:82
ice::concepts::ModuleLoadable
Definition
module_concepts.hxx:41
mem_allocator.hxx
module_concepts.hxx
module_negotiator.hxx
ice
SPDX-License-Identifier: MIT.
Definition
array.hxx:12
ice::alloc
auto alloc(ice::usize size) noexcept -> ice::AllocResult
ice::Allocator
ice::AllocatorBase< ice::build::is_debug||ice::build::is_develop > Allocator
Definition
mem_types.hxx:25
ice::ModuleInfo
Stores information of module load and unload functions.
Definition
module_info.hxx:12
ice::ModuleNegotiatorAPI
Negotiation API used to register and query modules for their APIs.
Definition
module_negotiator.hxx:17
Generated by
1.18.0