1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:27:35 +00:00

Libraries: Use default constructors/destructors in LibCore

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
This commit is contained in:
Lenny Maiorani 2022-02-26 09:09:45 -07:00 committed by Brian Gianforcaro
parent c6dcb12b00
commit ea58b8d927
23 changed files with 46 additions and 74 deletions

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -38,7 +39,7 @@ public:
static ErrorOr<AnonymousBuffer> create_with_size(size_t); static ErrorOr<AnonymousBuffer> create_with_size(size_t);
static ErrorOr<AnonymousBuffer> create_from_anon_fd(int fd, size_t); static ErrorOr<AnonymousBuffer> create_from_anon_fd(int fd, size_t);
AnonymousBuffer() { } AnonymousBuffer() = default;
bool is_valid() const { return m_impl; } bool is_valid() const { return m_impl; }

View file

@ -20,7 +20,6 @@ set(SOURCES
MappedFile.cpp MappedFile.cpp
MimeData.cpp MimeData.cpp
NetworkJob.cpp NetworkJob.cpp
NetworkResponse.cpp
Notifier.cpp Notifier.cpp
Object.cpp Object.cpp
Process.cpp Process.cpp

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, sin-ack <sin-ack@protonmail.com> * Copyright (c) 2018-2020, sin-ack <sin-ack@protonmail.com>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -13,7 +14,7 @@ namespace Core {
class DeferredInvocationContext final : public Core::Object { class DeferredInvocationContext final : public Core::Object {
C_OBJECT(DeferredInvocationContext) C_OBJECT(DeferredInvocationContext)
private: private:
DeferredInvocationContext() { } DeferredInvocationContext() = default;
}; };
} }

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -17,10 +18,6 @@ ChildEvent::ChildEvent(Type type, Object& child, Object* insertion_before_child)
{ {
} }
ChildEvent::~ChildEvent()
{
}
Object* ChildEvent::child() Object* ChildEvent::child()
{ {
if (auto ref = m_child.strong_ref()) if (auto ref = m_child.strong_ref())

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -29,12 +30,12 @@ public:
Custom, Custom,
}; };
Event() { } Event() = default;
explicit Event(unsigned type) explicit Event(unsigned type)
: m_type(type) : m_type(type)
{ {
} }
virtual ~Event() { } virtual ~Event() = default;
unsigned type() const { return m_type; } unsigned type() const { return m_type; }
@ -70,7 +71,7 @@ public:
, m_timer_id(timer_id) , m_timer_id(timer_id)
{ {
} }
~TimerEvent() { } ~TimerEvent() = default;
int timer_id() const { return m_timer_id; } int timer_id() const { return m_timer_id; }
@ -85,7 +86,7 @@ public:
, m_fd(fd) , m_fd(fd)
{ {
} }
~NotifierReadEvent() { } ~NotifierReadEvent() = default;
int fd() const { return m_fd; } int fd() const { return m_fd; }
@ -100,7 +101,7 @@ public:
, m_fd(fd) , m_fd(fd)
{ {
} }
~NotifierWriteEvent() { } ~NotifierWriteEvent() = default;
int fd() const { return m_fd; } int fd() const { return m_fd; }
@ -111,7 +112,7 @@ private:
class ChildEvent final : public Event { class ChildEvent final : public Event {
public: public:
ChildEvent(Type, Object& child, Object* insertion_before_child = nullptr); ChildEvent(Type, Object& child, Object* insertion_before_child = nullptr);
~ChildEvent(); ~ChildEvent() = default;
Object* child(); Object* child();
const Object* child() const; const Object* child() const;
@ -131,7 +132,7 @@ public:
, m_custom_type(custom_type) , m_custom_type(custom_type)
{ {
} }
~CustomEvent() { } ~CustomEvent() = default;
int custom_type() const { return m_custom_type; } int custom_type() const { return m_custom_type; }

View file

@ -1,6 +1,7 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, kleines Filmröllchen <malu.bertsch@gmail.com> * Copyright (c) 2022, kleines Filmröllchen <malu.bertsch@gmail.com>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -875,8 +876,4 @@ EventLoop::QueuedEvent::QueuedEvent(QueuedEvent&& other)
{ {
} }
EventLoop::QueuedEvent::~QueuedEvent()
{
}
} }

View file

@ -1,6 +1,7 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, kleines Filmröllchen <malu.bertsch@gmail.com> * Copyright (c) 2022, kleines Filmröllchen <malu.bertsch@gmail.com>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -117,7 +118,7 @@ private:
public: public:
QueuedEvent(Object& receiver, NonnullOwnPtr<Event>); QueuedEvent(Object& receiver, NonnullOwnPtr<Event>);
QueuedEvent(QueuedEvent&&); QueuedEvent(QueuedEvent&&);
~QueuedEvent(); ~QueuedEvent() = default;
WeakPtr<Object> receiver; WeakPtr<Object> receiver;
NonnullOwnPtr<Event> event; NonnullOwnPtr<Event> event;

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com> * Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
* Copyright (c) 2021, the SerenityOS developers. * Copyright (c) 2021-2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -36,7 +36,7 @@ AK_ENUM_BITWISE_OPERATORS(FileWatcherEvent::Type);
class FileWatcherBase { class FileWatcherBase {
public: public:
virtual ~FileWatcherBase() { } virtual ~FileWatcherBase() = default;
ErrorOr<bool> add_watch(String path, FileWatcherEvent::Type event_mask); ErrorOr<bool> add_watch(String path, FileWatcherEvent::Type event_mask);
ErrorOr<bool> remove_watch(String path); ErrorOr<bool> remove_watch(String path);

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -21,10 +22,6 @@ IODevice::IODevice(Object* parent)
{ {
} }
IODevice::~IODevice()
{
}
const char* IODevice::error_string() const const char* IODevice::error_string() const
{ {
return strerror(m_error); return strerror(m_error);

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -72,7 +73,7 @@ AK_ENUM_BITWISE_OPERATORS(OpenMode)
class IODevice : public Object { class IODevice : public Object {
C_OBJECT_ABSTRACT(IODevice) C_OBJECT_ABSTRACT(IODevice)
public: public:
virtual ~IODevice() override; virtual ~IODevice() override = default;
int fd() const { return m_fd; } int fd() const { return m_fd; }
OpenMode mode() const { return m_mode; } OpenMode mode() const { return m_mode; }

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -17,7 +18,7 @@ class MimeData : public Object {
C_OBJECT(MimeData); C_OBJECT(MimeData);
public: public:
virtual ~MimeData() { } virtual ~MimeData() = default;
ByteBuffer data(const String& mime_type) const { return m_data.get(mime_type).value_or({}); } ByteBuffer data(const String& mime_type) const { return m_data.get(mime_type).value_or({}); }
void set_data(const String& mime_type, ByteBuffer&& data) { m_data.set(mime_type, move(data)); } void set_data(const String& mime_type, ByteBuffer&& data) { m_data.set(mime_type, move(data)); }
@ -38,7 +39,7 @@ public:
const HashMap<String, ByteBuffer>& all_data() const { return m_data; } const HashMap<String, ByteBuffer>& all_data() const { return m_data; }
private: private:
MimeData() { } MimeData() = default;
explicit MimeData(const HashMap<String, ByteBuffer>& data) explicit MimeData(const HashMap<String, ByteBuffer>& data)
: m_data(data) : m_data(data)
{ {

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -15,10 +16,6 @@ NetworkJob::NetworkJob(Core::Stream::Stream& output_stream)
{ {
} }
NetworkJob::~NetworkJob()
{
}
void NetworkJob::start(Core::Stream::Socket&) void NetworkJob::start(Core::Stream::Socket&)
{ {
} }

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -24,7 +25,7 @@ public:
ProtocolFailed, ProtocolFailed,
Cancelled, Cancelled,
}; };
virtual ~NetworkJob() override; virtual ~NetworkJob() override = default;
// Could fire twice, after Headers and after Trailers! // Could fire twice, after Headers and after Trailers!
Function<void(const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> response_code)> on_headers_received; Function<void(const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> response_code)> on_headers_received;

View file

@ -1,19 +0,0 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/NetworkResponse.h>
namespace Core {
NetworkResponse::NetworkResponse()
{
}
NetworkResponse::~NetworkResponse()
{
}
}

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -13,12 +14,12 @@ namespace Core {
class NetworkResponse : public RefCounted<NetworkResponse> { class NetworkResponse : public RefCounted<NetworkResponse> {
public: public:
virtual ~NetworkResponse(); virtual ~NetworkResponse() = default;
bool is_error() const { return m_error; } bool is_error() const { return m_error; }
protected: protected:
explicit NetworkResponse(); explicit NetworkResponse() = default;
bool m_error { false }; bool m_error { false };
}; };

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -270,10 +271,6 @@ ObjectClassRegistration::ObjectClassRegistration(StringView class_name, Function
object_classes().set(class_name, this); object_classes().set(class_name, this);
} }
ObjectClassRegistration::~ObjectClassRegistration()
{
}
bool ObjectClassRegistration::is_derived_from(const ObjectClassRegistration& base_class) const bool ObjectClassRegistration::is_derived_from(const ObjectClassRegistration& base_class) const
{ {
if (&base_class == this) if (&base_class == this)

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -40,7 +41,7 @@ class ObjectClassRegistration {
public: public:
ObjectClassRegistration(StringView class_name, Function<RefPtr<Object>()> factory, ObjectClassRegistration* parent_class = nullptr); ObjectClassRegistration(StringView class_name, Function<RefPtr<Object>()> factory, ObjectClassRegistration* parent_class = nullptr);
~ObjectClassRegistration(); ~ObjectClassRegistration() = default;
String class_name() const { return m_class_name; } String class_name() const { return m_class_name; }
const ObjectClassRegistration* parent_class() const { return m_parent_class; } const ObjectClassRegistration* parent_class() const { return m_parent_class; }

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -15,8 +16,4 @@ Property::Property(String name, Function<JsonValue()> getter, Function<bool(cons
{ {
} }
Property::~Property()
{
}
} }

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -16,7 +17,7 @@ class Property {
public: public:
Property(String name, Function<JsonValue()> getter, Function<bool(const JsonValue&)> setter = nullptr); Property(String name, Function<JsonValue()> getter, Function<bool(const JsonValue&)> setter = nullptr);
~Property(); ~Property() = default;
bool set(const JsonValue& value) bool set(const JsonValue& value)
{ {

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -23,7 +24,7 @@ public:
Local Local
}; };
SocketAddress() { } SocketAddress() = default;
SocketAddress(const IPv4Address& address) SocketAddress(const IPv4Address& address)
: m_type(Type::IPv4) : m_type(Type::IPv4)
, m_ipv4_address(address) , m_ipv4_address(address)

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com> * Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -382,7 +383,7 @@ public:
virtual ~UDPSocket() override { close(); } virtual ~UDPSocket() override { close(); }
private: private:
UDPSocket() { } UDPSocket() = default;
void setup_notifier() void setup_notifier()
{ {
@ -452,7 +453,7 @@ public:
virtual ~LocalSocket() { close(); } virtual ~LocalSocket() { close(); }
private: private:
LocalSocket() { } LocalSocket() = default;
void setup_notifier() void setup_notifier()
{ {
@ -774,7 +775,7 @@ public:
size_t buffer_size() const { return m_helper.buffer_size(); } size_t buffer_size() const { return m_helper.buffer_size(); }
virtual ~BufferedSeekable() override { } virtual ~BufferedSeekable() override = default;
private: private:
BufferedSeekable(NonnullOwnPtr<T> stream, ByteBuffer buffer) BufferedSeekable(NonnullOwnPtr<T> stream, ByteBuffer buffer)
@ -843,7 +844,7 @@ public:
virtual size_t buffer_size() const override { return m_helper.buffer_size(); } virtual size_t buffer_size() const override { return m_helper.buffer_size(); }
virtual ~BufferedSocket() override { } virtual ~BufferedSocket() override = default;
private: private:
BufferedSocket(NonnullOwnPtr<T> stream, ByteBuffer buffer) BufferedSocket(NonnullOwnPtr<T> stream, ByteBuffer buffer)

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -20,10 +21,6 @@ Timer::Timer(int interval_ms, Function<void()>&& timeout_handler, Object* parent
start(interval_ms); start(interval_ms);
} }
Timer::~Timer()
{
}
void Timer::start() void Timer::start()
{ {
start(m_interval_ms); start(m_interval_ms);

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -29,7 +30,7 @@ public:
return timer; return timer;
} }
virtual ~Timer() override; virtual ~Timer() override = default;
void start(); void start();
void start(int interval_ms); void start(int interval_ms);