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
Notes: sideshowbarker 2024-07-17 17:34:04 +09:00
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) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -38,7 +39,7 @@ public:
static ErrorOr<AnonymousBuffer> create_with_size(size_t);
static ErrorOr<AnonymousBuffer> create_from_anon_fd(int fd, size_t);
AnonymousBuffer() { }
AnonymousBuffer() = default;
bool is_valid() const { return m_impl; }

View file

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

View file

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

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
*
* 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()
{
if (auto ref = m_child.strong_ref())

View file

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

View file

@ -1,6 +1,6 @@
/*
* 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
*/
@ -36,7 +36,7 @@ AK_ENUM_BITWISE_OPERATORS(FileWatcherEvent::Type);
class FileWatcherBase {
public:
virtual ~FileWatcherBase() { }
virtual ~FileWatcherBase() = default;
ErrorOr<bool> add_watch(String path, FileWatcherEvent::Type event_mask);
ErrorOr<bool> remove_watch(String path);

View file

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

View file

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

View file

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

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
*
* 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&)
{
}

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -24,7 +25,7 @@ public:
ProtocolFailed,
Cancelled,
};
virtual ~NetworkJob() override;
virtual ~NetworkJob() override = default;
// Could fire twice, after Headers and after Trailers!
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) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -13,12 +14,12 @@ namespace Core {
class NetworkResponse : public RefCounted<NetworkResponse> {
public:
virtual ~NetworkResponse();
virtual ~NetworkResponse() = default;
bool is_error() const { return m_error; }
protected:
explicit NetworkResponse();
explicit NetworkResponse() = default;
bool m_error { false };
};

View file

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

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -40,7 +41,7 @@ class ObjectClassRegistration {
public:
ObjectClassRegistration(StringView class_name, Function<RefPtr<Object>()> factory, ObjectClassRegistration* parent_class = nullptr);
~ObjectClassRegistration();
~ObjectClassRegistration() = default;
String class_name() const { return m_class_name; }
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) 2022, the SerenityOS developers.
*
* 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) 2022, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -16,7 +17,7 @@ class Property {
public:
Property(String name, Function<JsonValue()> getter, Function<bool(const JsonValue&)> setter = nullptr);
~Property();
~Property() = default;
bool set(const JsonValue& value)
{

View file

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

View file

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

View file

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

View file

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