mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +00:00
LibCore: Call optional did_construct() method when constucting objects
Some objects need to perform tasks during construction that require the object to be fully constructed, which can't be done in the constructor. This allows postponing such tasks into a did_construct method that will be called right after the object was fully constructed.
This commit is contained in:
parent
ade85d980b
commit
20c066b8e0
1 changed files with 5 additions and 2 deletions
|
@ -59,10 +59,13 @@ enum class TimerShouldFireWhenNotVisible {
|
|||
#define C_OBJECT(klass) \
|
||||
public: \
|
||||
virtual const char* class_name() const override { return #klass; } \
|
||||
template<class... Args> \
|
||||
template<typename Klass = klass, class... Args> \
|
||||
static inline NonnullRefPtr<klass> construct(Args&&... args) \
|
||||
{ \
|
||||
return adopt_ref(*new klass(forward<Args>(args)...)); \
|
||||
auto obj = adopt_ref(*new Klass(forward<Args>(args)...)); \
|
||||
if constexpr (requires { declval<Klass>().did_construct(); }) \
|
||||
obj->did_construct(); \
|
||||
return obj; \
|
||||
}
|
||||
|
||||
#define C_OBJECT_ABSTRACT(klass) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue