1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:57:43 +00:00

LibCore: Convert CTCPSocket to ObjectPtr, add construct() helper

The C_OBJECT macro now also inserts a static construct(...) helper into
the class. Now we can make the constructor(s) private and instead call:

    auto socket = CTCPSocket::construct(arguments);

construct() returns an ObjectPtr<T>, which we'll later switch to being
a NonnullRefPtr<T>, once everything else in in place for ref-counting.
This commit is contained in:
Andreas Kling 2019-09-21 10:13:34 +02:00
parent 1f5a9762a2
commit 4298ba25c3
15 changed files with 30 additions and 25 deletions

View file

@ -1,11 +1,12 @@
#pragma once
#include <AK/String.h>
#include <AK/Function.h>
#include <AK/IntrusiveList.h>
#include <AK/StdLibExtras.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <AK/Weakable.h>
#include <LibCore/ObjectPtr.h>
namespace AK {
class JsonObject;
@ -16,9 +17,14 @@ class CChildEvent;
class CCustomEvent;
class CTimerEvent;
#define C_OBJECT(klass) \
public: \
virtual const char* class_name() const override { return #klass; }
#define C_OBJECT(klass) \
public: \
virtual const char* class_name() const override { return #klass; } \
template<class... Args> \
static inline ObjectPtr<klass> construct(Args&&... args) \
{ \
return ObjectPtr<klass>(new klass(forward<Args>(args)...)); \
}
class CObject : public Weakable<CObject> {
// NOTE: No C_OBJECT macro for CObject itself.