LibCore: Add a forward declaration header

This patch adds <LibCore/Forward.h> and uses it in various places to
shrink the header dependency graph.
This commit is contained in:
Andreas Kling 2020-02-14 22:29:06 +01:00
parent 3bbf4610d2
commit 8f7333f080
Notes: sideshowbarker 2024-07-19 09:20:22 +09:00
35 changed files with 143 additions and 38 deletions

View File

@ -70,6 +70,9 @@ class NonnullRefPtr;
template<typename T>
class NonnullOwnPtr;
template<typename T>
class Optional;
template<typename T>
class RefPtr;
@ -98,6 +101,7 @@ using AK::JsonObject;
using AK::JsonValue;
using AK::NonnullOwnPtr;
using AK::NonnullRefPtr;
using AK::Optional;
using AK::OwnPtr;
using AK::RefPtr;
using AK::SinglyLinkedList;

View File

@ -26,6 +26,8 @@
#pragma once
#include <AK/Assertions.h>
namespace AK {
class IntrusiveListNode;

View File

@ -30,6 +30,8 @@
#include <AK/Platform.h>
#include <AK/StdLibExtras.h>
namespace AK {
template<typename T>
class CONSUMABLE(unknown) alignas(T) Optional {
public:
@ -161,3 +163,7 @@ private:
char m_storage[sizeof(T)];
bool m_has_value { false };
};
}
using AK::Optional;

View File

@ -26,6 +26,7 @@
#include "History.h"
#include "ManualModel.h"
#include <AK/ByteBuffer.h>
#include <LibCore/File.h>
#include <LibGUI/AboutDialog.h>
#include <LibGUI/Action.h>

View File

@ -25,6 +25,7 @@
*/
#include "ProcessStacksWidget.h"
#include <AK/ByteBuffer.h>
#include <LibCore/File.h>
#include <LibCore/Timer.h>
#include <LibGUI/BoxLayout.h>

View File

@ -26,6 +26,7 @@
#include "Editor.h"
#include "EditorWrapper.h"
#include <AK/ByteBuffer.h>
#include <AK/FileSystemPath.h>
#include <LibCore/DirIterator.h>
#include <LibCore/File.h>

View File

@ -25,6 +25,7 @@
*/
#include <AK/BufferStream.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/StringBuilder.h>
#include <LibCore/File.h>

View File

@ -25,6 +25,7 @@
*/
#include <AK/BufferStream.h>
#include <AK/OwnPtr.h>
#include <LibAudio/WavLoader.h>
#include <LibCore/File.h>
#include <LibCore/IODeviceStreamReader.h>

View File

@ -30,11 +30,10 @@
#include <AK/String.h>
#include <AK/Types.h>
#include <AK/WeakPtr.h>
#include <LibCore/Forward.h>
namespace Core {
class Object;
class Event {
public:
enum Type {

View File

@ -24,12 +24,14 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Badge.h>
#include <AK/IDAllocator.h>
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <AK/Time.h>
#include <LibCore/Event.h>
#include <LibCore/EventLoop.h>
#include <LibCore/LocalServer.h>
#include <LibCore/LocalSocket.h>
#include <LibCore/Notifier.h>
#include <LibCore/Object.h>
@ -328,7 +330,7 @@ void EventLoop::post_event(Object& receiver, NonnullOwnPtr<Event>&& event)
#ifdef CEVENTLOOP_DEBUG
dbg() << "Core::EventLoop::post_event: {" << m_queued_events.size() << "} << receiver=" << receiver << ", event=" << event;
#endif
m_queued_events.append({ receiver.make_weak_ptr(), move(event) });
m_queued_events.empend(receiver, move(event));
}
void EventLoop::wait_for_event(WaitMode mode)
@ -509,4 +511,20 @@ void EventLoop::wake()
}
}
EventLoop::QueuedEvent::QueuedEvent(Object& receiver, NonnullOwnPtr<Event> event)
: receiver(receiver.make_weak_ptr())
, event(move(event))
{
}
EventLoop::QueuedEvent::QueuedEvent(QueuedEvent&& other)
: receiver(other.receiver)
, event(move(other.event))
{
}
EventLoop::QueuedEvent::~QueuedEvent()
{
}
}

View File

@ -26,23 +26,18 @@
#pragma once
#include <AK/Badge.h>
#include <AK/Forward.h>
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <AK/Vector.h>
#include <AK/WeakPtr.h>
#include <LibCore/Event.h>
#include <LibCore/LocalServer.h>
#include <LibCore/Forward.h>
#include <LibCore/Object.h>
#include <LibThread/Lock.h>
#include <sys/select.h>
#include <sys/time.h>
#include <time.h>
namespace Core {
class Object;
class Notifier;
class EventLoop {
public:
EventLoop();
@ -87,6 +82,12 @@ private:
void get_next_timer_expiration(timeval&);
struct QueuedEvent {
AK_MAKE_NONCOPYABLE(QueuedEvent);
public:
QueuedEvent(Object& receiver, NonnullOwnPtr<Event>);
QueuedEvent(QueuedEvent&&);
~QueuedEvent();
WeakPtr<Object> receiver;
NonnullOwnPtr<Event> event;
};

View File

@ -0,0 +1,61 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
namespace Core {
class ArgsParser;
class ChildEvent;
class ConfigFile;
class CustomEvent;
class DateTime;
class DirIterator;
class ElapsedTime;
class Event;
class EventLoop;
class File;
class HttpJob;
class HttpRequest;
class HttpResponse;
class IODevice;
class LocalServer;
class LocalSocket;
class MimeData;
class NetworkJob;
class NetworkResponse;
class Notifier;
class Object;
class ProcessStatisticsReader;
class Socket;
class SocketAddress;
class TCPServer;
class TCPSocket;
class TimerEvent;
class UdpServer;
class UdpSocket;
enum class TimerShouldFireWhenNotVisible;
}

View File

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/ByteBuffer.h>
#include <AK/PrintfImplementation.h>
#include <LibCore/IODevice.h>
#include <LibCore/SyscallUtils.h>
@ -296,4 +297,10 @@ void IODevice::set_fd(int fd)
m_fd = fd;
did_update_fd(fd);
}
bool IODevice::write(const StringView& v)
{
return write((const u8*)v.characters_without_null_termination(), v.length());
}
}

View File

@ -26,8 +26,7 @@
#pragma once
#include <AK/ByteBuffer.h>
#include <AK/StringView.h>
#include <AK/Forward.h>
#include <LibCore/Object.h>
namespace Core {
@ -64,7 +63,7 @@ public:
ByteBuffer read_all();
bool write(const u8*, int size);
bool write(const StringView& v) { return write((const u8*)v.characters_without_null_termination(), v.length()); }
bool write(const StringView&);
// FIXME: I would like this to be const but currently it needs to call populate_read_buffer().
bool can_read_line();

View File

@ -26,7 +26,6 @@
#pragma once
#include <AK/Badge.h>
#include <LibCore/Socket.h>
namespace Core {

View File

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Badge.h>
#include <LibCore/Event.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Notifier.h>

View File

@ -26,19 +26,13 @@
#pragma once
#include <AK/Badge.h>
#include <AK/Function.h>
#include <AK/Forward.h>
#include <AK/IntrusiveList.h>
#include <AK/Noncopyable.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/StdLibExtras.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <AK/Weakable.h>
namespace AK {
class JsonObject;
}
#include <LibCore/Forward.h>
namespace Core {
@ -47,12 +41,6 @@ enum class TimerShouldFireWhenNotVisible {
Yes
};
class ChildEvent;
class CustomEvent;
class Event;
class EventLoop;
class TimerEvent;
#define C_OBJECT(klass) \
public: \
virtual const char* class_name() const override { return #klass; } \

View File

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/ByteBuffer.h>
#include <LibCore/Notifier.h>
#include <LibCore/Socket.h>
#include <arpa/inet.h>

View File

@ -26,6 +26,7 @@
#pragma once
#include <AK/Function.h>
#include <LibCore/IODevice.h>
#include <LibCore/SocketAddress.h>

View File

@ -26,14 +26,13 @@
#pragma once
#include <AK/IPv4Address.h>
#include <LibCore/Notifier.h>
#include <AK/Forward.h>
#include <AK/Function.h>
#include <LibCore/Forward.h>
#include <LibCore/Object.h>
namespace Core {
class UdpSocket;
class UdpServer : public Object {
C_OBJECT(UdpServer)
public:

View File

@ -26,7 +26,6 @@
#pragma once
#include <AK/Badge.h>
#include <LibCore/Socket.h>
namespace Core {

View File

@ -24,9 +24,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <LibGfx/Bitmap.h>
#include <AK/Badge.h>
#include <LibGUI/DragOperation.h>
#include <LibGUI/WindowServerConnection.h>
#include <LibGfx/Bitmap.h>
namespace GUI {

View File

@ -26,14 +26,14 @@
#pragma once
#include <AK/Badge.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/String.h>
#include <AK/WeakPtr.h>
#include <LibCore/Object.h>
#include <LibGUI/WindowType.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Rect.h>
#include <LibGUI/WindowType.h>
namespace GUI {

View File

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/ByteBuffer.h>
#include <AK/URL.h>
#include <LibCore/File.h>
#include <LibHTML/DOM/Document.h>

View File

@ -26,6 +26,7 @@
#pragma once
#include <AK/ByteBuffer.h>
#include <LibCore/Event.h>
#include <LibCore/EventLoop.h>
#include <LibCore/IODevice.h>

View File

@ -26,6 +26,7 @@
#pragma once
#include <AK/ByteBuffer.h>
#include <AK/NonnullOwnPtrVector.h>
#include <LibCore/Event.h>
#include <LibCore/EventLoop.h>

View File

@ -30,6 +30,7 @@
#include <AK/NonnullRefPtr.h>
#include <AK/Optional.h>
#include <AK/Queue.h>
#include <LibCore/Event.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Object.h>
#include <LibThread/Lock.h>

View File

@ -27,6 +27,7 @@
#pragma once
#include "ASClientConnection.h"
#include <AK/Badge.h>
#include <AK/ByteBuffer.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/Queue.h>

View File

@ -26,6 +26,7 @@
#include "LookupServer.h"
#include <LibCore/EventLoop.h>
#include <LibCore/LocalServer.h>
#include <stdio.h>
int main(int argc, char** argv)

View File

@ -26,7 +26,9 @@
#include "Service.h"
#include <AK/Assertions.h>
#include <AK/ByteBuffer.h>
#include <LibCore/ConfigFile.h>
#include <LibCore/Event.h>
#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
#include <errno.h>

View File

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/ByteBuffer.h>
#include <LibCore/File.h>
#include <assert.h>
#include <fcntl.h>

View File

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/ByteBuffer.h>
#include <LibCore/File.h>
#include <LibGUI/AboutDialog.h>
#include <LibGUI/Action.h>

View File

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/ByteBuffer.h>
#include <AK/String.h>
#include <LibCore/File.h>
#include <LibMarkdown/MDDocument.h>

View File

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/ByteBuffer.h>
#include <AK/String.h>
#include <LibCore/File.h>
#include <LibMarkdown/MDDocument.h>
@ -45,7 +46,8 @@ int main(int argc, char* argv[])
else
file_name = argv[i];
auto file = Core::File::construct();;
auto file = Core::File::construct();
;
bool success;
if (file_name == nullptr) {
success = file->open(STDIN_FILENO, Core::IODevice::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescription::No);

View File

@ -25,6 +25,7 @@
*/
#include <AK/Assertions.h>
#include <AK/ByteBuffer.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
#include <errno.h>