ladybird/AK/Forward.h

203 lines
4.3 KiB
C
Raw Normal View History

/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/DefaultDelete.h>
#include <AK/SinglyLinkedListSizePolicy.h>
#include <AK/StdLibExtras.h>
#include <AK/Types.h>
namespace AK {
namespace Detail {
template<size_t inline_capacity>
class ByteBuffer;
}
enum class TrailingCodePointTransformation : u8;
2023-01-25 19:06:16 +00:00
class BigEndianInputBitStream;
class BigEndianOutputBitStream;
class Bitmap;
using ByteBuffer = Detail::ByteBuffer<32>;
class CircularBuffer;
class ConstrainedStream;
class CountingStream;
class DeprecatedFlyString;
class ByteString;
class DeprecatedStringCodePointIterator;
class Duration;
class Error;
class FlyString;
class GenericLexer;
class IPv4Address;
class JsonArray;
class JsonObject;
class JsonValue;
class LexicalPath;
2023-01-25 19:06:16 +00:00
class LittleEndianInputBitStream;
class LittleEndianOutputBitStream;
class SearchableCircularBuffer;
class SeekableStream;
class StackInfo;
class Stream;
class String;
class StringBuilder;
class StringImpl;
class StringView;
class UnixDateTime;
class Utf16View;
class Utf32CodePointIterator;
class Utf32View;
class Utf8CodePointIterator;
2020-02-14 22:28:34 +00:00
class Utf8View;
2020-08-25 12:57:02 +00:00
template<typename T>
class Span;
2020-09-06 19:13:34 +00:00
template<typename T, size_t Size>
2020-09-11 22:43:11 +00:00
struct Array;
template<typename Container, typename ValueType>
class SimpleIterator;
template<typename T>
using ReadonlySpan = Span<T const>;
using ReadonlyBytes = ReadonlySpan<u8>;
using Bytes = Span<u8>;
template<typename T, AK::MemoryOrder DefaultMemoryOrder>
class Atomic;
template<typename T, typename TSizeCalculationPolicy = DefaultSizeCalculationPolicy>
class SinglyLinkedList;
template<typename T>
class DoublyLinkedList;
template<typename T, size_t capacity>
class CircularQueue;
template<typename T>
struct Traits;
template<typename T, typename TraitsForT = Traits<T>, bool IsOrdered = false>
class HashTable;
template<typename T, typename TraitsForT = Traits<T>>
using OrderedHashTable = HashTable<T, TraitsForT, true>;
template<typename K, typename V, typename KeyTraits = Traits<K>, typename ValueTraits = Traits<V>, bool IsOrdered = false>
class HashMap;
template<typename K, typename V, typename KeyTraits = Traits<K>, typename ValueTraits = Traits<V>>
using OrderedHashMap = HashMap<K, V, KeyTraits, ValueTraits, true>;
template<typename T>
class Badge;
template<typename T>
class FixedArray;
template<size_t precision, typename Underlying = i32>
class FixedPoint;
template<typename>
class Function;
template<typename Out, typename... In>
class Function<Out(In...)>;
template<typename T>
class NonnullRefPtr;
template<typename T>
class NonnullOwnPtr;
template<typename T>
class Optional;
template<typename T>
class RefPtr;
template<typename T, typename TDeleter = DefaultDelete<T>>
class OwnPtr;
template<typename T>
class WeakPtr;
template<typename T, size_t inline_capacity = 0>
requires(!IsRvalueReference<T>) class Vector;
template<typename T, typename ErrorType = Error>
class [[nodiscard]] ErrorOr;
}
#if USING_AK_GLOBALLY
using AK::Array;
using AK::Atomic;
using AK::Badge;
2023-01-25 19:06:16 +00:00
using AK::BigEndianInputBitStream;
using AK::BigEndianOutputBitStream;
using AK::Bitmap;
using AK::ByteBuffer;
using AK::Bytes;
using AK::ByteString;
using AK::CircularBuffer;
using AK::CircularQueue;
using AK::ConstrainedStream;
using AK::CountingStream;
using AK::DeprecatedFlyString;
using AK::DeprecatedStringCodePointIterator;
using AK::DoublyLinkedList;
using AK::Duration;
using AK::Error;
using AK::ErrorOr;
using AK::FixedArray;
using AK::FixedPoint;
using AK::FlyString;
using AK::Function;
using AK::GenericLexer;
using AK::HashMap;
using AK::HashTable;
using AK::IPv4Address;
using AK::JsonArray;
using AK::JsonObject;
using AK::JsonValue;
using AK::LexicalPath;
2023-01-25 19:06:16 +00:00
using AK::LittleEndianInputBitStream;
using AK::LittleEndianOutputBitStream;
using AK::NonnullOwnPtr;
using AK::NonnullRefPtr;
using AK::Optional;
using AK::OwnPtr;
using AK::ReadonlyBytes;
using AK::RefPtr;
using AK::SearchableCircularBuffer;
using AK::SeekableStream;
using AK::SinglyLinkedList;
using AK::Span;
using AK::StackInfo;
using AK::Stream;
AK: Introduce the new String, replacement for DeprecatedString DeprecatedString (formerly String) has been with us since the start, and it has served us well. However, it has a number of shortcomings that I'd like to address. Some of these issues are hard if not impossible to solve incrementally inside of DeprecatedString, so instead of doing that, let's build a new String class and then incrementally move over to it instead. Problems in DeprecatedString: - It assumes string allocation never fails. This makes it impossible to use in allocation-sensitive contexts, and is the reason we had to ban DeprecatedString from the kernel entirely. - The awkward null state. DeprecatedString can be null. It's different from the empty state, although null strings are considered empty. All code is immediately nicer when using Optional<DeprecatedString> but DeprecatedString came before Optional, which is how we ended up like this. - The encoding of the underlying data is ambiguous. For the most part, we use it as if it's always UTF-8, but there have been cases where we pass around strings in other encodings (e.g ISO8859-1) - operator[] and length() are used to iterate over DeprecatedString one byte at a time. This is done all over the codebase, and will *not* give the right results unless the string is all ASCII. How we solve these issues in the new String: - Functions that may allocate now return ErrorOr<String> so that ENOMEM errors can be passed to the caller. - String has no null state. Use Optional<String> when needed. - String is always UTF-8. This is validated when constructing a String. We may need to add a bypass for this in the future, for cases where you have a known-good string, but for now: validate all the things! - There is no operator[] or length(). You can get the underlying data with bytes(), but for iterating over code points, you should be using an UTF-8 iterator. Furthermore, it has two nifty new features: - String implements a small string optimization (SSO) for strings that can fit entirely within a pointer. This means up to 3 bytes on 32-bit platforms, and 7 bytes on 64-bit platforms. Such small strings will not be heap-allocated. - String can create substrings without making a deep copy of the substring. Instead, the superstring gets +1 refcount from the substring, and it acts like a view into the superstring. To make substrings like this, use the substring_with_shared_superstring() API. One caveat: - String does not guarantee that the underlying data is null-terminated like DeprecatedString does today. While this was nifty in a handful of places where we were calling C functions, it did stand in the way of shared-superstring substrings.
2022-12-01 12:27:43 +00:00
using AK::String;
using AK::StringBuilder;
using AK::StringImpl;
using AK::StringView;
using AK::TrailingCodePointTransformation;
using AK::Traits;
using AK::UnixDateTime;
using AK::Utf16View;
using AK::Utf32CodePointIterator;
using AK::Utf32View;
using AK::Utf8CodePointIterator;
2020-02-14 22:28:34 +00:00
using AK::Utf8View;
using AK::Vector;
#endif