mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-16 14:08:59 +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)...);
|
return module<BaseT>::template initialize<ImplT>(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename ImplT >
|
template < typename... ImplTs >
|
||||||
void shutdown() noexcept {
|
void shutdown() noexcept {
|
||||||
using BaseT = typename ImplT::base_type;
|
return (... , module<typename ImplTs::base_type>::shutdown());
|
||||||
module<BaseT>::shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename ImplT >
|
template < typename... ImplTs >
|
||||||
bool is_initialized() noexcept {
|
bool is_initialized() noexcept {
|
||||||
using BaseT = typename ImplT::base_type;
|
return (... && module<typename ImplTs::base_type>::is_initialized());
|
||||||
return module<BaseT>::is_initialized();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template < typename ImplT >
|
template < typename ImplT >
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ namespace
|
|||||||
using namespace e2d;
|
using namespace e2d;
|
||||||
|
|
||||||
template < typename Module, typename... Args >
|
template < typename Module, typename... Args >
|
||||||
void safe_module_initialize(Args&&... args) {
|
Module& safe_module_initialize(Args&&... args) {
|
||||||
if ( !modules::is_initialized<Module>() ) {
|
return modules::is_initialized<Module>()
|
||||||
modules::initialize<Module>(std::forward<Args>(args)...);
|
? modules::instance<Module>()
|
||||||
}
|
: modules::initialize<Module>(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
void safe_register_predef_path(
|
void safe_register_predef_path(
|
||||||
|
|||||||
@@ -86,11 +86,7 @@ namespace e2d::dbgui_widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool hierarchy_widget::show() {
|
bool hierarchy_widget::show() {
|
||||||
if ( !modules::is_initialized<editor>() ) {
|
if ( !modules::is_initialized<editor, world>() ) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !modules::is_initialized<world>() ) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,11 +18,7 @@ namespace e2d::dbgui_widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool inspector_widget::show() {
|
bool inspector_widget::show() {
|
||||||
if ( !modules::is_initialized<editor>() ) {
|
if ( !modules::is_initialized<editor, inspector>() ) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !modules::is_initialized<inspector>() ) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,12 @@ namespace
|
|||||||
private:
|
private:
|
||||||
u32 m_;
|
u32 m_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class empty_module : public module<empty_module> {
|
||||||
|
};
|
||||||
|
|
||||||
|
class empty_module_impl : public empty_module {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("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>(), module_not_initialized);
|
||||||
REQUIRE_THROWS_AS(modules::instance<mul_module_impl>(), 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