mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Move some of LogStream out of line & add overloads for smart pointers.
This commit is contained in:
parent
07d11a9b6b
commit
1b013ba699
Notes:
sideshowbarker
2024-07-19 13:23:39 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/1b013ba6995
9 changed files with 87 additions and 31 deletions
|
@ -2,8 +2,9 @@
|
|||
|
||||
#include "StdLibExtras.h"
|
||||
#include "Types.h"
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/kmalloc.h>
|
||||
|
||||
namespace AK {
|
||||
|
|
34
AK/LogStream.cpp
Normal file
34
AK/LogStream.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include <AK/AKString.h>
|
||||
#include <AK/LogStream.h>
|
||||
#include <AK/StringView.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
inline const LogStream& operator<<(const LogStream& stream, const String& value)
|
||||
{
|
||||
stream.write(value.characters(), value.length());
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline const LogStream& operator<<(const LogStream& stream, const StringView& value)
|
||||
{
|
||||
stream.write(value.characters(), value.length());
|
||||
return stream;
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, int value)
|
||||
{
|
||||
return stream << String::number(value);
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, unsigned value)
|
||||
{
|
||||
return stream << String::number(value);
|
||||
}
|
||||
|
||||
const LogStream& operator<<(const LogStream& stream, const void* value)
|
||||
{
|
||||
return stream << String::format("%p", value);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/AKString.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/kstdio.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
class String;
|
||||
class StringView;
|
||||
|
||||
class LogStream {
|
||||
public:
|
||||
LogStream() {}
|
||||
|
@ -35,21 +38,19 @@ inline DebugLogStream dbg()
|
|||
|
||||
inline const LogStream& operator<<(const LogStream& stream, const char* value)
|
||||
{
|
||||
stream.write(value, strlen(value));
|
||||
int length = 0;
|
||||
const char* p = value;
|
||||
while (*(p++))
|
||||
++length;
|
||||
stream.write(value, length);
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline const LogStream& operator<<(const LogStream& stream, const String& value)
|
||||
{
|
||||
stream.write(value.characters(), value.length());
|
||||
return stream;
|
||||
}
|
||||
|
||||
inline const LogStream& operator<<(const LogStream& stream, const StringView& value)
|
||||
{
|
||||
stream.write(value.characters(), value.length());
|
||||
return stream;
|
||||
}
|
||||
const LogStream& operator<<(const LogStream&, const String&);
|
||||
const LogStream& operator<<(const LogStream&, const StringView&);
|
||||
const LogStream& operator<<(const LogStream&, int);
|
||||
const LogStream& operator<<(const LogStream&, unsigned);
|
||||
const LogStream& operator<<(const LogStream&, const void*);
|
||||
|
||||
inline const LogStream& operator<<(const LogStream& stream, char value)
|
||||
{
|
||||
|
@ -62,17 +63,7 @@ inline const LogStream& operator<<(const LogStream& stream, bool value)
|
|||
return stream << (value ? "true" : "false");
|
||||
}
|
||||
|
||||
inline const LogStream& operator<<(const LogStream& stream, int value)
|
||||
{
|
||||
return stream << String::number(value);
|
||||
}
|
||||
|
||||
inline const LogStream& operator<<(const LogStream& stream, unsigned value)
|
||||
{
|
||||
return stream << String::number(value);
|
||||
}
|
||||
|
||||
inline const LogStream& operator<<(const LogStream& stream, const void* value)
|
||||
{
|
||||
return stream << String::format("%p", value);
|
||||
}
|
||||
using AK::LogStream;
|
||||
using AK::dbg;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/LogStream.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
#ifdef __clang__
|
||||
|
@ -239,6 +240,12 @@ inline NonnullRefPtr<T> adopt(T& object)
|
|||
return NonnullRefPtr<T>(NonnullRefPtr<T>::Adopt, object);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline const LogStream& operator<<(const LogStream& stream, const NonnullRefPtr<T>& value)
|
||||
{
|
||||
return stream << value.ptr();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::adopt;
|
||||
|
|
13
AK/OwnPtr.h
13
AK/OwnPtr.h
|
@ -1,8 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "StdLibExtras.h"
|
||||
#include "Traits.h"
|
||||
#include "Types.h"
|
||||
#include <AK/LogStream.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/Traits.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
@ -115,6 +116,12 @@ struct Traits<OwnPtr<T>> : public GenericTraits<OwnPtr<T>> {
|
|||
static bool equals(const OwnPtr<T>& a, const OwnPtr<T>& b) { return a.ptr() == b.ptr(); }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline const LogStream& operator<<(const LogStream& stream, const OwnPtr<T>& value)
|
||||
{
|
||||
return stream << value.ptr();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::make;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/LogStream.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
|
@ -203,6 +204,12 @@ private:
|
|||
T* m_ptr = nullptr;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
inline const LogStream& operator<<(const LogStream& stream, const RefPtr<T>& value)
|
||||
{
|
||||
return stream << value.ptr();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::RefPtr;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "Weakable.h"
|
||||
#include <AK/LogStream.h>
|
||||
#include <AK/Weakable.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
|
@ -66,6 +67,12 @@ inline WeakPtr<T> Weakable<T>::make_weak_ptr()
|
|||
return WeakPtr<T>(m_link.copy_ref());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline const LogStream& operator<<(const LogStream& stream, const WeakPtr<T>& value)
|
||||
{
|
||||
return stream << value.ptr();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using AK::WeakPtr;
|
||||
|
|
|
@ -88,6 +88,7 @@ AK_OBJS = \
|
|||
../AK/JsonValue.o \
|
||||
../AK/JsonArray.o \
|
||||
../AK/JsonParser.o \
|
||||
../AK/LogStream.o \
|
||||
../AK/ELF/ELFImage.o \
|
||||
../AK/ELF/ELFLoader.o
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ AK_OBJS = \
|
|||
../AK/JsonArray.o \
|
||||
../AK/JsonObject.o \
|
||||
../AK/JsonParser.o \
|
||||
../AK/LogStream.o \
|
||||
../AK/MappedFile.o
|
||||
|
||||
LIBC_OBJS = \
|
||||
|
|
Loading…
Reference in a new issue