mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 20:42:56 +01:00
base: add Reconstructible::conditional method
The new 'conditional' method simplifies the typical use case for 'Constructible' objects where the constructed/destructed state depends on a configuration parameter. The method alleviates the need to re-implement the logic again and again. The patch also removes the 'Reconstructible' constructor arguments because they are unused. Fixes #3006
This commit is contained in:
committed by
Christian Helmuth
parent
fe303f0e46
commit
7d641d5f1f
@@ -136,6 +136,19 @@ class Genode::Reconstructible : Noncopyable
|
||||
*/
|
||||
bool is_constructed() const { return constructed(); }
|
||||
|
||||
/**
|
||||
* Construct or destruct volatile object according to 'condition'
|
||||
*/
|
||||
template <typename... ARGS>
|
||||
void conditional(bool condition, ARGS &&... args)
|
||||
{
|
||||
if (condition && !constructed())
|
||||
construct(args...);
|
||||
|
||||
if (!condition && constructed())
|
||||
destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Access contained object
|
||||
*/
|
||||
@@ -161,11 +174,8 @@ class Genode::Reconstructible : Noncopyable
|
||||
template <typename MT>
|
||||
struct Genode::Constructible : Reconstructible<MT>
|
||||
{
|
||||
template <typename... ARGS>
|
||||
Constructible(ARGS &&...)
|
||||
:
|
||||
Reconstructible<MT>((typename Reconstructible<MT>::Lazy *)nullptr)
|
||||
{ }
|
||||
Constructible()
|
||||
: Reconstructible<MT>((typename Reconstructible<MT>::Lazy *)nullptr) { }
|
||||
};
|
||||
|
||||
#endif /* _INCLUDE__UTIL__RECONSTRUCTIBLE_H_ */
|
||||
|
||||
Reference in New Issue
Block a user