fixed_typemap: implement need<> method
It may be used in constructors of other objects to assert a dependency. It also helps to ensure reverse destruction order of that dependency.
This commit is contained in:
+2
-5
@@ -29,11 +29,8 @@ struct vfs_manager
|
|||||||
|
|
||||||
bool vfs::mount(std::string_view vpath, std::string_view path)
|
bool vfs::mount(std::string_view vpath, std::string_view path)
|
||||||
{
|
{
|
||||||
if (!g_fxo->get<vfs_manager>())
|
// Workaround
|
||||||
{
|
g_fxo->need<vfs_manager>();
|
||||||
// Init (TODO)
|
|
||||||
g_fxo->init<vfs_manager>();
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto table = g_fxo->get<vfs_manager>();
|
const auto table = g_fxo->get<vfs_manager>();
|
||||||
|
|
||||||
|
|||||||
@@ -148,6 +148,16 @@ namespace stx
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if object is not initialized but shall be initialized first (to use in initializing other objects)
|
||||||
|
template <typename T>
|
||||||
|
void need() noexcept
|
||||||
|
{
|
||||||
|
if (!get<T>())
|
||||||
|
{
|
||||||
|
init<T>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Explicitly (re)initialize object of type T possibly with dynamic type As and arguments
|
// Explicitly (re)initialize object of type T possibly with dynamic type As and arguments
|
||||||
template <typename T, typename As = T, typename... Args>
|
template <typename T, typename As = T, typename... Args>
|
||||||
As* init(Args&&... args) noexcept
|
As* init(Args&&... args) noexcept
|
||||||
|
|||||||
Reference in New Issue
Block a user