mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:07:46 +00:00
AK: Remove the deprecated Stream implementation :^)
This commit is contained in:
parent
63b11030f0
commit
e8d5e938de
11 changed files with 1 additions and 708 deletions
|
@ -1,139 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/DeprecatedStream.h>
|
||||
#include <AK/MemMem.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
class DeprecatedInputMemoryStream final : public DeprecatedInputStream {
|
||||
public:
|
||||
explicit DeprecatedInputMemoryStream(ReadonlyBytes bytes)
|
||||
: m_bytes(bytes)
|
||||
{
|
||||
}
|
||||
|
||||
bool unreliable_eof() const override { return eof(); }
|
||||
bool eof() const { return m_offset >= m_bytes.size(); }
|
||||
|
||||
size_t read(Bytes bytes) override
|
||||
{
|
||||
if (has_any_error())
|
||||
return 0;
|
||||
|
||||
auto const count = min(bytes.size(), remaining());
|
||||
__builtin_memcpy(bytes.data(), m_bytes.data() + m_offset, count);
|
||||
m_offset += count;
|
||||
return count;
|
||||
}
|
||||
|
||||
bool read_or_error(Bytes bytes) override
|
||||
{
|
||||
if (remaining() < bytes.size()) {
|
||||
set_recoverable_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
__builtin_memcpy(bytes.data(), m_bytes.data() + m_offset, bytes.size());
|
||||
m_offset += bytes.size();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool discard_or_error(size_t count) override
|
||||
{
|
||||
if (remaining() < count) {
|
||||
set_recoverable_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_offset += count;
|
||||
return true;
|
||||
}
|
||||
|
||||
void seek(size_t offset)
|
||||
{
|
||||
VERIFY(offset < m_bytes.size());
|
||||
m_offset = offset;
|
||||
}
|
||||
|
||||
u8 peek_or_error() const
|
||||
{
|
||||
if (remaining() == 0) {
|
||||
set_recoverable_error();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_bytes[m_offset];
|
||||
}
|
||||
|
||||
ReadonlyBytes bytes() const { return m_bytes; }
|
||||
size_t offset() const { return m_offset; }
|
||||
size_t remaining() const { return m_bytes.size() - m_offset; }
|
||||
|
||||
private:
|
||||
ReadonlyBytes m_bytes;
|
||||
size_t m_offset { 0 };
|
||||
};
|
||||
|
||||
class DeprecatedOutputMemoryStream final : public DeprecatedOutputStream {
|
||||
public:
|
||||
explicit DeprecatedOutputMemoryStream(Bytes bytes)
|
||||
: m_bytes(bytes)
|
||||
{
|
||||
}
|
||||
|
||||
size_t write(ReadonlyBytes bytes) override
|
||||
{
|
||||
auto const nwritten = bytes.copy_trimmed_to(m_bytes.slice(m_offset));
|
||||
m_offset += nwritten;
|
||||
return nwritten;
|
||||
}
|
||||
|
||||
bool write_or_error(ReadonlyBytes bytes) override
|
||||
{
|
||||
if (remaining() < bytes.size()) {
|
||||
set_recoverable_error();
|
||||
return false;
|
||||
}
|
||||
|
||||
write(bytes);
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t fill_to_end(u8 value)
|
||||
{
|
||||
auto const nwritten = m_bytes.slice(m_offset).fill(value);
|
||||
m_offset += nwritten;
|
||||
return nwritten;
|
||||
}
|
||||
|
||||
bool is_end() const { return remaining() == 0; }
|
||||
|
||||
ReadonlyBytes bytes() const { return { data(), size() }; }
|
||||
Bytes bytes() { return { data(), size() }; }
|
||||
|
||||
u8 const* data() const { return m_bytes.data(); }
|
||||
u8* data() { return m_bytes.data(); }
|
||||
|
||||
size_t size() const { return m_offset; }
|
||||
size_t remaining() const { return m_bytes.size() - m_offset; }
|
||||
void reset() { m_offset = 0; }
|
||||
|
||||
private:
|
||||
size_t m_offset { 0 };
|
||||
Bytes m_bytes;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if USING_AK_GLOBALLY
|
||||
using AK::DeprecatedInputMemoryStream;
|
||||
using AK::DeprecatedOutputMemoryStream;
|
||||
#endif
|
|
@ -1,167 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Concepts.h>
|
||||
#include <AK/Endian.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/Span.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
|
||||
namespace AK::Detail {
|
||||
|
||||
class DeprecatedStream {
|
||||
public:
|
||||
virtual ~DeprecatedStream() { VERIFY(!has_any_error()); }
|
||||
|
||||
virtual bool has_recoverable_error() const { return m_recoverable_error; }
|
||||
virtual bool has_fatal_error() const { return m_fatal_error; }
|
||||
virtual bool has_any_error() const { return has_recoverable_error() || has_fatal_error(); }
|
||||
|
||||
virtual bool handle_recoverable_error()
|
||||
{
|
||||
VERIFY(!has_fatal_error());
|
||||
return exchange(m_recoverable_error, false);
|
||||
}
|
||||
virtual bool handle_fatal_error() { return exchange(m_fatal_error, false); }
|
||||
virtual bool handle_any_error()
|
||||
{
|
||||
if (has_any_error()) {
|
||||
m_recoverable_error = false;
|
||||
m_fatal_error = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ErrorOr<void> try_handle_any_error()
|
||||
{
|
||||
if (!handle_any_error())
|
||||
return {};
|
||||
return Error::from_string_literal("Stream error");
|
||||
}
|
||||
|
||||
virtual void set_recoverable_error() const { m_recoverable_error = true; }
|
||||
virtual void set_fatal_error() const { m_fatal_error = true; }
|
||||
|
||||
private:
|
||||
mutable bool m_recoverable_error { false };
|
||||
mutable bool m_fatal_error { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
||||
class DeprecatedInputStream : public virtual Detail::DeprecatedStream {
|
||||
public:
|
||||
// Reads at least one byte unless none are requested or none are available. Does nothing
|
||||
// and returns zero if there is already an error.
|
||||
virtual size_t read(Bytes) = 0;
|
||||
|
||||
// If this function returns true, then no more data can be read. If read(Bytes) previously
|
||||
// returned zero even though bytes were requested, then the inverse is true as well.
|
||||
virtual bool unreliable_eof() const = 0;
|
||||
|
||||
// Some streams additionally define a method with the signature:
|
||||
//
|
||||
// bool eof() const;
|
||||
//
|
||||
// This method has the same semantics as unreliable_eof() but returns true if and only if no
|
||||
// more data can be read. (A failed read is not necessary.)
|
||||
|
||||
virtual bool read_or_error(Bytes) = 0;
|
||||
virtual bool discard_or_error(size_t count) = 0;
|
||||
};
|
||||
|
||||
class DeprecatedOutputStream : public virtual Detail::DeprecatedStream {
|
||||
public:
|
||||
virtual size_t write(ReadonlyBytes) = 0;
|
||||
virtual bool write_or_error(ReadonlyBytes) = 0;
|
||||
};
|
||||
|
||||
class DeprecatedDuplexStream
|
||||
: public DeprecatedInputStream
|
||||
, public DeprecatedOutputStream {
|
||||
};
|
||||
|
||||
inline DeprecatedInputStream& operator>>(DeprecatedInputStream& stream, Bytes bytes)
|
||||
{
|
||||
stream.read_or_error(bytes);
|
||||
return stream;
|
||||
}
|
||||
inline DeprecatedOutputStream& operator<<(DeprecatedOutputStream& stream, ReadonlyBytes bytes)
|
||||
{
|
||||
stream.write_or_error(bytes);
|
||||
return stream;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
DeprecatedInputStream& operator>>(DeprecatedInputStream& stream, LittleEndian<T>& value)
|
||||
{
|
||||
return stream >> Bytes { &value.m_value, sizeof(value.m_value) };
|
||||
}
|
||||
template<typename T>
|
||||
DeprecatedOutputStream& operator<<(DeprecatedOutputStream& stream, LittleEndian<T> value)
|
||||
{
|
||||
return stream << ReadonlyBytes { &value.m_value, sizeof(value.m_value) };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
DeprecatedInputStream& operator>>(DeprecatedInputStream& stream, BigEndian<T>& value)
|
||||
{
|
||||
return stream >> Bytes { &value.m_value, sizeof(value.m_value) };
|
||||
}
|
||||
template<typename T>
|
||||
DeprecatedOutputStream& operator<<(DeprecatedOutputStream& stream, BigEndian<T> value)
|
||||
{
|
||||
return stream << ReadonlyBytes { &value.m_value, sizeof(value.m_value) };
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
DeprecatedInputStream& operator>>(DeprecatedInputStream& stream, Optional<T>& value)
|
||||
{
|
||||
T temporary;
|
||||
stream >> temporary;
|
||||
value = temporary;
|
||||
return stream;
|
||||
}
|
||||
|
||||
template<Integral I>
|
||||
DeprecatedInputStream& operator>>(DeprecatedInputStream& stream, I& value)
|
||||
{
|
||||
stream.read_or_error({ &value, sizeof(value) });
|
||||
return stream;
|
||||
}
|
||||
template<Integral I>
|
||||
DeprecatedOutputStream& operator<<(DeprecatedOutputStream& stream, I value)
|
||||
{
|
||||
stream.write_or_error({ &value, sizeof(value) });
|
||||
return stream;
|
||||
}
|
||||
|
||||
#ifndef KERNEL
|
||||
|
||||
template<FloatingPoint F>
|
||||
DeprecatedInputStream& operator>>(DeprecatedInputStream& stream, F& value)
|
||||
{
|
||||
stream.read_or_error({ &value, sizeof(value) });
|
||||
return stream;
|
||||
}
|
||||
template<FloatingPoint F>
|
||||
DeprecatedOutputStream& operator<<(DeprecatedOutputStream& stream, F value)
|
||||
{
|
||||
stream.write_or_error({ &value, sizeof(value) });
|
||||
return stream;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/DeprecatedFlyString.h>
|
||||
#include <AK/DeprecatedStream.h>
|
||||
#include <AK/DeprecatedString.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Function.h>
|
||||
|
@ -416,29 +415,6 @@ bool DeprecatedString::operator==(char const* cstring) const
|
|||
return view() == cstring;
|
||||
}
|
||||
|
||||
DeprecatedInputStream& operator>>(DeprecatedInputStream& stream, DeprecatedString& string)
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
||||
for (;;) {
|
||||
char next_char;
|
||||
stream >> next_char;
|
||||
|
||||
if (stream.has_any_error()) {
|
||||
stream.set_fatal_error();
|
||||
string = nullptr;
|
||||
return stream;
|
||||
}
|
||||
|
||||
if (next_char) {
|
||||
builder.append(next_char);
|
||||
} else {
|
||||
string = builder.to_deprecated_string();
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DeprecatedString DeprecatedString::vformatted(StringView fmtstr, TypeErasedFormatParams& params)
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
|
|
@ -338,8 +338,6 @@ struct CaseInsensitiveStringTraits : public Traits<DeprecatedString> {
|
|||
|
||||
DeprecatedString escape_html_entities(StringView html);
|
||||
|
||||
DeprecatedInputStream& operator>>(DeprecatedInputStream& stream, DeprecatedString& string);
|
||||
|
||||
}
|
||||
|
||||
#if USING_AK_GLOBALLY
|
||||
|
|
24
AK/Endian.h
24
AK/Endian.h
|
@ -76,21 +76,9 @@ ALWAYS_INLINE T convert_between_host_and_network_endian(T value)
|
|||
return convert_between_host_and_big_endian(value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class LittleEndian;
|
||||
|
||||
template<typename T>
|
||||
DeprecatedInputStream& operator>>(DeprecatedInputStream&, LittleEndian<T>&);
|
||||
|
||||
template<typename T>
|
||||
DeprecatedOutputStream& operator<<(DeprecatedOutputStream&, LittleEndian<T>);
|
||||
|
||||
template<typename T>
|
||||
class [[gnu::packed]] LittleEndian {
|
||||
public:
|
||||
friend DeprecatedInputStream& operator>><T>(DeprecatedInputStream&, LittleEndian<T>&);
|
||||
friend DeprecatedOutputStream& operator<< <T>(DeprecatedOutputStream&, LittleEndian<T>);
|
||||
|
||||
constexpr LittleEndian() = default;
|
||||
|
||||
constexpr LittleEndian(T value)
|
||||
|
@ -108,21 +96,9 @@ private:
|
|||
T m_value { 0 };
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class BigEndian;
|
||||
|
||||
template<typename T>
|
||||
DeprecatedInputStream& operator>>(DeprecatedInputStream&, BigEndian<T>&);
|
||||
|
||||
template<typename T>
|
||||
DeprecatedOutputStream& operator<<(DeprecatedOutputStream&, BigEndian<T>);
|
||||
|
||||
template<typename T>
|
||||
class [[gnu::packed]] BigEndian {
|
||||
public:
|
||||
friend DeprecatedInputStream& operator>><T>(DeprecatedInputStream&, BigEndian<T>&);
|
||||
friend DeprecatedOutputStream& operator<< <T>(DeprecatedOutputStream&, BigEndian<T>);
|
||||
|
||||
constexpr BigEndian() = default;
|
||||
|
||||
constexpr BigEndian(T value)
|
||||
|
|
|
@ -22,10 +22,6 @@ class BigEndianInputBitStream;
|
|||
class BigEndianOutputBitStream;
|
||||
using ByteBuffer = Detail::ByteBuffer<32>;
|
||||
class CircularBuffer;
|
||||
class DeprecatedInputStream;
|
||||
class DeprecatedInputMemoryStream;
|
||||
class DeprecatedOutputStream;
|
||||
class DeprecatedOutputMemoryStream;
|
||||
class Error;
|
||||
class FlyString;
|
||||
class GenericLexer;
|
||||
|
@ -167,10 +163,6 @@ using AK::Bytes;
|
|||
using AK::CircularBuffer;
|
||||
using AK::CircularQueue;
|
||||
using AK::DeprecatedFlyString;
|
||||
using AK::DeprecatedInputMemoryStream;
|
||||
using AK::DeprecatedInputStream;
|
||||
using AK::DeprecatedOutputMemoryStream;
|
||||
using AK::DeprecatedOutputStream;
|
||||
using AK::DeprecatedString;
|
||||
using AK::DeprecatedStringCodePointIterator;
|
||||
using AK::DoublyLinkedList;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue