mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 10:08:10 +00:00
LibCore: Add try_create(...) helper to all Core::Object derived classes
This is like construct(...) but returns ErrorOr<NonnullRefPtr<T>>.
This commit is contained in:
parent
16356ca478
commit
5a3f5582ba
1 changed files with 12 additions and 8 deletions
|
@ -63,14 +63,18 @@ enum class TimerShouldFireWhenNotVisible {
|
|||
Yes
|
||||
};
|
||||
|
||||
#define C_OBJECT(klass) \
|
||||
public: \
|
||||
virtual const char* class_name() const override { return #klass; } \
|
||||
template<typename Klass = klass, class... Args> \
|
||||
static inline NonnullRefPtr<klass> construct(Args&&... args) \
|
||||
{ \
|
||||
auto obj = adopt_ref(*new Klass(forward<Args>(args)...)); \
|
||||
return obj; \
|
||||
#define C_OBJECT(klass) \
|
||||
public: \
|
||||
virtual const char* class_name() const override { return #klass; } \
|
||||
template<typename Klass = klass, class... Args> \
|
||||
static NonnullRefPtr<klass> construct(Args&&... args) \
|
||||
{ \
|
||||
return adopt_ref(*new Klass(forward<Args>(args)...)); \
|
||||
} \
|
||||
template<typename Klass = klass, class... Args> \
|
||||
static ErrorOr<NonnullRefPtr<klass>> try_create(Args&&... args) \
|
||||
{ \
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) Klass(forward<Args>(args)...)); \
|
||||
}
|
||||
|
||||
#define C_OBJECT_ABSTRACT(klass) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue