mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
utils: variadic module::is_initialized and module::shutdown
This commit is contained in:
@@ -80,16 +80,14 @@ namespace e2d::modules
|
||||
return module<BaseT>::template initialize<ImplT>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template < typename ImplT >
|
||||
template < typename... ImplTs >
|
||||
void shutdown() noexcept {
|
||||
using BaseT = typename ImplT::base_type;
|
||||
module<BaseT>::shutdown();
|
||||
return (... , module<typename ImplTs::base_type>::shutdown());
|
||||
}
|
||||
|
||||
template < typename ImplT >
|
||||
template < typename... ImplTs >
|
||||
bool is_initialized() noexcept {
|
||||
using BaseT = typename ImplT::base_type;
|
||||
return module<BaseT>::is_initialized();
|
||||
return (... && module<typename ImplTs::base_type>::is_initialized());
|
||||
}
|
||||
|
||||
template < typename ImplT >
|
||||
|
||||
@@ -23,10 +23,10 @@ namespace
|
||||
using namespace e2d;
|
||||
|
||||
template < typename Module, typename... Args >
|
||||
void safe_module_initialize(Args&&... args) {
|
||||
if ( !modules::is_initialized<Module>() ) {
|
||||
modules::initialize<Module>(std::forward<Args>(args)...);
|
||||
}
|
||||
Module& safe_module_initialize(Args&&... args) {
|
||||
return modules::is_initialized<Module>()
|
||||
? modules::instance<Module>()
|
||||
: modules::initialize<Module>(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void safe_register_predef_path(
|
||||
|
||||
@@ -86,11 +86,7 @@ namespace e2d::dbgui_widgets
|
||||
}
|
||||
|
||||
bool hierarchy_widget::show() {
|
||||
if ( !modules::is_initialized<editor>() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !modules::is_initialized<world>() ) {
|
||||
if ( !modules::is_initialized<editor, world>() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,7 @@ namespace e2d::dbgui_widgets
|
||||
}
|
||||
|
||||
bool inspector_widget::show() {
|
||||
if ( !modules::is_initialized<editor>() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !modules::is_initialized<inspector>() ) {
|
||||
if ( !modules::is_initialized<editor, inspector>() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,12 @@ namespace
|
||||
private:
|
||||
u32 m_;
|
||||
};
|
||||
|
||||
class empty_module : public module<empty_module> {
|
||||
};
|
||||
|
||||
class empty_module_impl : public empty_module {
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("module") {
|
||||
@@ -92,4 +98,27 @@ TEST_CASE("module") {
|
||||
REQUIRE_THROWS_AS(modules::instance<mul_module>(), module_not_initialized);
|
||||
REQUIRE_THROWS_AS(modules::instance<mul_module_impl>(), module_not_initialized);
|
||||
}
|
||||
{
|
||||
REQUIRE_FALSE(modules::is_initialized<mul_module>());
|
||||
REQUIRE_FALSE(modules::is_initialized<empty_module>());
|
||||
REQUIRE_FALSE(modules::is_initialized<mul_module, empty_module>());
|
||||
|
||||
REQUIRE_NOTHROW(modules::initialize<mul_module_impl>(3));
|
||||
|
||||
REQUIRE(modules::is_initialized<mul_module>());
|
||||
REQUIRE_FALSE(modules::is_initialized<empty_module>());
|
||||
REQUIRE_FALSE(modules::is_initialized<mul_module, empty_module>());
|
||||
|
||||
REQUIRE_NOTHROW(modules::initialize<empty_module_impl>());
|
||||
|
||||
REQUIRE(modules::is_initialized<mul_module>());
|
||||
REQUIRE(modules::is_initialized<empty_module>());
|
||||
REQUIRE(modules::is_initialized<mul_module, empty_module>());
|
||||
|
||||
REQUIRE_NOTHROW(modules::shutdown<empty_module, mul_module_impl>());
|
||||
|
||||
REQUIRE_FALSE(modules::is_initialized<mul_module>());
|
||||
REQUIRE_FALSE(modules::is_initialized<empty_module>());
|
||||
REQUIRE_FALSE(modules::is_initialized<mul_module, empty_module>());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user