summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibArchive/TarStream.cpp2
-rw-r--r--Userland/Libraries/LibArchive/TarStream.h5
-rw-r--r--Userland/Libraries/LibAudio/FlacLoader.cpp10
-rw-r--r--Userland/Libraries/LibAudio/MP3Loader.cpp4
-rw-r--r--Userland/Libraries/LibCompress/Brotli.cpp2
-rw-r--r--Userland/Libraries/LibCompress/Deflate.cpp8
-rw-r--r--Userland/Libraries/LibCompress/Deflate.h8
-rw-r--r--Userland/Libraries/LibCompress/Gzip.cpp8
-rw-r--r--Userland/Libraries/LibCompress/Gzip.h4
-rw-r--r--Userland/Libraries/LibCompress/Zlib.cpp8
-rw-r--r--Userland/Libraries/LibCompress/Zlib.h7
-rw-r--r--Userland/Libraries/LibCore/BitStream.h25
-rw-r--r--Userland/Libraries/LibCore/Stream.h42
-rw-r--r--Userland/Utilities/pro.cpp5
14 files changed, 50 insertions, 88 deletions
diff --git a/Userland/Libraries/LibArchive/TarStream.cpp b/Userland/Libraries/LibArchive/TarStream.cpp
index a01081c1ba..218520305e 100644
--- a/Userland/Libraries/LibArchive/TarStream.cpp
+++ b/Userland/Libraries/LibArchive/TarStream.cpp
@@ -136,7 +136,7 @@ TarFileStream TarInputStream::file_contents()
return TarFileStream(*this);
}
-TarOutputStream::TarOutputStream(Core::Stream::Handle<Core::Stream::Stream> stream)
+TarOutputStream::TarOutputStream(MaybeOwned<Core::Stream::Stream> stream)
: m_stream(move(stream))
{
}
diff --git a/Userland/Libraries/LibArchive/TarStream.h b/Userland/Libraries/LibArchive/TarStream.h
index c50a87b27e..f585d26ca1 100644
--- a/Userland/Libraries/LibArchive/TarStream.h
+++ b/Userland/Libraries/LibArchive/TarStream.h
@@ -7,6 +7,7 @@
#pragma once
+#include <AK/MaybeOwned.h>
#include <AK/Span.h>
#include <LibArchive/Tar.h>
#include <LibCore/Stream.h>
@@ -58,14 +59,14 @@ private:
class TarOutputStream {
public:
- TarOutputStream(Core::Stream::Handle<Core::Stream::Stream>);
+ TarOutputStream(MaybeOwned<Core::Stream::Stream>);
ErrorOr<void> add_file(StringView path, mode_t, ReadonlyBytes);
ErrorOr<void> add_link(StringView path, mode_t, StringView);
ErrorOr<void> add_directory(StringView path, mode_t);
ErrorOr<void> finish();
private:
- Core::Stream::Handle<Core::Stream::Stream> m_stream;
+ MaybeOwned<Core::Stream::Stream> m_stream;
bool m_finished { false };
friend class TarFileStream;
diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp
index 1010e77283..8a7c9faa17 100644
--- a/Userland/Libraries/LibAudio/FlacLoader.cpp
+++ b/Userland/Libraries/LibAudio/FlacLoader.cpp
@@ -60,7 +60,7 @@ MaybeLoaderError FlacLoaderPlugin::initialize()
// 11.5 STREAM
MaybeLoaderError FlacLoaderPlugin::parse_header()
{
- auto bit_input = LOADER_TRY(BigEndianInputBitStream::construct(Core::Stream::Handle<Core::Stream::Stream>(*m_stream)));
+ auto bit_input = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*m_stream)));
// A mixture of VERIFY and the non-crashing TRY().
#define FLAC_VERIFY(check, category, msg) \
@@ -79,7 +79,7 @@ MaybeLoaderError FlacLoaderPlugin::parse_header()
auto streaminfo = TRY(next_meta_block(*bit_input));
FLAC_VERIFY(streaminfo.type == FlacMetadataBlockType::STREAMINFO, LoaderError::Category::Format, "First block must be STREAMINFO");
auto streaminfo_data_memory = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(streaminfo.data.bytes()));
- auto streaminfo_data = LOADER_TRY(BigEndianInputBitStream::construct(Core::Stream::Handle<Core::Stream::Stream>(*streaminfo_data_memory)));
+ auto streaminfo_data = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*streaminfo_data_memory)));
// 11.10 METADATA_BLOCK_STREAMINFO
m_min_block_size = LOADER_TRY(streaminfo_data->read_bits<u16>(16));
@@ -150,7 +150,7 @@ MaybeLoaderError FlacLoaderPlugin::parse_header()
MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block)
{
auto memory_stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(block.data.bytes()));
- auto picture_block_bytes = LOADER_TRY(BigEndianInputBitStream::construct(Core::Stream::Handle<Core::Stream::Stream>(*memory_stream)));
+ auto picture_block_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*memory_stream)));
PictureData picture {};
@@ -187,7 +187,7 @@ MaybeLoaderError FlacLoaderPlugin::load_picture(FlacRawMetadataBlock& block)
MaybeLoaderError FlacLoaderPlugin::load_seektable(FlacRawMetadataBlock& block)
{
auto memory_stream = LOADER_TRY(Core::Stream::FixedMemoryStream::construct(block.data.bytes()));
- auto seektable_bytes = LOADER_TRY(BigEndianInputBitStream::construct(Core::Stream::Handle<Core::Stream::Stream>(*memory_stream)));
+ auto seektable_bytes = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*memory_stream)));
for (size_t i = 0; i < block.length / 18; ++i) {
// 11.14. SEEKPOINT
FlacSeekPoint seekpoint {
@@ -333,7 +333,7 @@ MaybeLoaderError FlacLoaderPlugin::next_frame(Span<Sample> target_vector)
} \
} while (0)
- auto bit_stream = LOADER_TRY(BigEndianInputBitStream::construct(Core::Stream::Handle<Core::Stream::Stream>(*m_stream)));
+ auto bit_stream = LOADER_TRY(BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*m_stream)));
// TODO: Check the CRC-16 checksum (and others) by keeping track of read data
diff --git a/Userland/Libraries/LibAudio/MP3Loader.cpp b/Userland/Libraries/LibAudio/MP3Loader.cpp
index 85fc0b6272..15c14eae33 100644
--- a/Userland/Libraries/LibAudio/MP3Loader.cpp
+++ b/Userland/Libraries/LibAudio/MP3Loader.cpp
@@ -41,7 +41,7 @@ Result<NonnullOwnPtr<MP3LoaderPlugin>, LoaderError> MP3LoaderPlugin::create(Byte
MaybeLoaderError MP3LoaderPlugin::initialize()
{
- m_bitstream = LOADER_TRY(Core::Stream::BigEndianInputBitStream::construct(Core::Stream::Handle<Core::Stream::Stream>(*m_stream)));
+ m_bitstream = LOADER_TRY(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(*m_stream)));
TRY(synchronize());
@@ -242,7 +242,7 @@ ErrorOr<MP3::MP3Frame, LoaderError> MP3LoaderPlugin::read_frame_data(MP3::Header
TRY(m_bit_reservoir.discard(old_reservoir_size - frame.main_data_begin));
- auto reservoir_stream = TRY(Core::Stream::BigEndianInputBitStream::construct(Core::Stream::Handle<Core::Stream::Stream>(m_bit_reservoir)));
+ auto reservoir_stream = TRY(Core::Stream::BigEndianInputBitStream::construct(MaybeOwned<Core::Stream::Stream>(m_bit_reservoir)));
for (size_t granule_index = 0; granule_index < 2; granule_index++) {
for (size_t channel_index = 0; channel_index < header.channel_count(); channel_index++) {
diff --git a/Userland/Libraries/LibCompress/Brotli.cpp b/Userland/Libraries/LibCompress/Brotli.cpp
index 00d2e7c3c0..ee16bff271 100644
--- a/Userland/Libraries/LibCompress/Brotli.cpp
+++ b/Userland/Libraries/LibCompress/Brotli.cpp
@@ -29,7 +29,7 @@ ErrorOr<size_t> BrotliDecompressionStream::CanonicalCode::read_symbol(LittleEndi
}
BrotliDecompressionStream::BrotliDecompressionStream(Stream& stream)
- : m_input_stream(Core::Stream::Handle(stream))
+ : m_input_stream(MaybeOwned(stream))
{
}
diff --git a/Userland/Libraries/LibCompress/Deflate.cpp b/Userland/Libraries/LibCompress/Deflate.cpp
index 2d462adf44..f6afe0eb56 100644
--- a/Userland/Libraries/LibCompress/Deflate.cpp
+++ b/Userland/Libraries/LibCompress/Deflate.cpp
@@ -188,13 +188,13 @@ ErrorOr<bool> DeflateDecompressor::UncompressedBlock::try_read_more()
return true;
}
-ErrorOr<NonnullOwnPtr<DeflateDecompressor>> DeflateDecompressor::construct(Core::Stream::Handle<Core::Stream::Stream> stream)
+ErrorOr<NonnullOwnPtr<DeflateDecompressor>> DeflateDecompressor::construct(MaybeOwned<Core::Stream::Stream> stream)
{
auto output_buffer = TRY(CircularBuffer::create_empty(32 * KiB));
return TRY(adopt_nonnull_own_or_enomem(new (nothrow) DeflateDecompressor(move(stream), move(output_buffer))));
}
-DeflateDecompressor::DeflateDecompressor(Core::Stream::Handle<Core::Stream::Stream> stream, CircularBuffer output_buffer)
+DeflateDecompressor::DeflateDecompressor(MaybeOwned<Core::Stream::Stream> stream, CircularBuffer output_buffer)
: m_input_stream(make<Core::Stream::LittleEndianInputBitStream>(move(stream)))
, m_output_buffer(move(output_buffer))
{
@@ -446,7 +446,7 @@ ErrorOr<void> DeflateDecompressor::decode_codes(CanonicalCode& literal_code, Opt
return {};
}
-ErrorOr<NonnullOwnPtr<DeflateCompressor>> DeflateCompressor::construct(Core::Stream::Handle<Core::Stream::Stream> stream, CompressionLevel compression_level)
+ErrorOr<NonnullOwnPtr<DeflateCompressor>> DeflateCompressor::construct(MaybeOwned<Core::Stream::Stream> stream, CompressionLevel compression_level)
{
auto bit_stream = TRY(Core::Stream::LittleEndianOutputBitStream::construct(move(stream)));
auto deflate_compressor = TRY(adopt_nonnull_own_or_enomem(new (nothrow) DeflateCompressor(move(bit_stream), compression_level)));
@@ -1017,7 +1017,7 @@ ErrorOr<void> DeflateCompressor::final_flush()
ErrorOr<ByteBuffer> DeflateCompressor::compress_all(ReadonlyBytes bytes, CompressionLevel compression_level)
{
auto output_stream = TRY(try_make<Core::Stream::AllocatingMemoryStream>());
- auto deflate_stream = TRY(DeflateCompressor::construct(Core::Stream::Handle<Core::Stream::Stream>(*output_stream), compression_level));
+ auto deflate_stream = TRY(DeflateCompressor::construct(MaybeOwned<Core::Stream::Stream>(*output_stream), compression_level));
TRY(deflate_stream->write_entire_buffer(bytes));
TRY(deflate_stream->final_flush());
diff --git a/Userland/Libraries/LibCompress/Deflate.h b/Userland/Libraries/LibCompress/Deflate.h
index a775d348eb..6268996c58 100644
--- a/Userland/Libraries/LibCompress/Deflate.h
+++ b/Userland/Libraries/LibCompress/Deflate.h
@@ -74,7 +74,7 @@ public:
friend CompressedBlock;
friend UncompressedBlock;
- static ErrorOr<NonnullOwnPtr<DeflateDecompressor>> construct(Core::Stream::Handle<Core::Stream::Stream> stream);
+ static ErrorOr<NonnullOwnPtr<DeflateDecompressor>> construct(MaybeOwned<Core::Stream::Stream> stream);
~DeflateDecompressor();
virtual ErrorOr<Bytes> read(Bytes) override;
@@ -86,7 +86,7 @@ public:
static ErrorOr<ByteBuffer> decompress_all(ReadonlyBytes);
private:
- DeflateDecompressor(Core::Stream::Handle<Core::Stream::Stream> stream, CircularBuffer buffer);
+ DeflateDecompressor(MaybeOwned<Core::Stream::Stream> stream, CircularBuffer buffer);
ErrorOr<u32> decode_length(u32);
ErrorOr<u32> decode_distance(u32);
@@ -100,7 +100,7 @@ private:
UncompressedBlock m_uncompressed_block;
};
- Core::Stream::Handle<Core::Stream::LittleEndianInputBitStream> m_input_stream;
+ MaybeOwned<Core::Stream::LittleEndianInputBitStream> m_input_stream;
CircularBuffer m_output_buffer;
};
@@ -139,7 +139,7 @@ public:
BEST // WARNING: this one can take an unreasonable amount of time!
};
- static ErrorOr<NonnullOwnPtr<DeflateCompressor>> construct(Core::Stream::Handle<Core::Stream::Stream>, CompressionLevel = CompressionLevel::GOOD);
+ static ErrorOr<NonnullOwnPtr<DeflateCompressor>> construct(MaybeOwned<Core::Stream::Stream>, CompressionLevel = CompressionLevel::GOOD);
~DeflateCompressor();
virtual ErrorOr<Bytes> read(Bytes) override;
diff --git a/Userland/Libraries/LibCompress/Gzip.cpp b/Userland/Libraries/LibCompress/Gzip.cpp
index ce856b9376..0b702f28b7 100644
--- a/Userland/Libraries/LibCompress/Gzip.cpp
+++ b/Userland/Libraries/LibCompress/Gzip.cpp
@@ -40,7 +40,7 @@ bool BlockHeader::supported_by_implementation() const
ErrorOr<NonnullOwnPtr<GzipDecompressor::Member>> GzipDecompressor::Member::construct(BlockHeader header, Core::Stream::Stream& stream)
{
- auto deflate_stream = TRY(DeflateDecompressor::construct(Core::Stream::Handle<Core::Stream::Stream>(stream)));
+ auto deflate_stream = TRY(DeflateDecompressor::construct(MaybeOwned<Core::Stream::Stream>(stream)));
return TRY(adopt_nonnull_own_or_enomem(new (nothrow) Member(header, move(deflate_stream))));
}
@@ -186,7 +186,7 @@ ErrorOr<size_t> GzipDecompressor::write(ReadonlyBytes)
return Error::from_errno(EBADF);
}
-GzipCompressor::GzipCompressor(Core::Stream::Handle<Core::Stream::Stream> stream)
+GzipCompressor::GzipCompressor(MaybeOwned<Core::Stream::Stream> stream)
: m_output_stream(move(stream))
{
}
@@ -207,7 +207,7 @@ ErrorOr<size_t> GzipCompressor::write(ReadonlyBytes bytes)
header.extra_flags = 3; // DEFLATE sets 2 for maximum compression and 4 for minimum compression
header.operating_system = 3; // unix
TRY(m_output_stream->write_entire_buffer({ &header, sizeof(header) }));
- auto compressed_stream = TRY(DeflateCompressor::construct(Core::Stream::Handle(*m_output_stream)));
+ auto compressed_stream = TRY(DeflateCompressor::construct(MaybeOwned(*m_output_stream)));
TRY(compressed_stream->write_entire_buffer(bytes));
TRY(compressed_stream->final_flush());
Crypto::Checksum::CRC32 crc32;
@@ -236,7 +236,7 @@ void GzipCompressor::close()
ErrorOr<ByteBuffer> GzipCompressor::compress_all(ReadonlyBytes bytes)
{
auto output_stream = TRY(try_make<Core::Stream::AllocatingMemoryStream>());
- GzipCompressor gzip_stream { Core::Stream::Handle<Core::Stream::Stream>(*output_stream) };
+ GzipCompressor gzip_stream { MaybeOwned<Core::Stream::Stream>(*output_stream) };
TRY(gzip_stream.write_entire_buffer(bytes));
diff --git a/Userland/Libraries/LibCompress/Gzip.h b/Userland/Libraries/LibCompress/Gzip.h
index 45c4b01733..ddda776f5e 100644
--- a/Userland/Libraries/LibCompress/Gzip.h
+++ b/Userland/Libraries/LibCompress/Gzip.h
@@ -80,7 +80,7 @@ private:
class GzipCompressor final : public Core::Stream::Stream {
public:
- GzipCompressor(Core::Stream::Handle<Core::Stream::Stream>);
+ GzipCompressor(MaybeOwned<Core::Stream::Stream>);
virtual ErrorOr<Bytes> read(Bytes) override;
virtual ErrorOr<size_t> write(ReadonlyBytes) override;
@@ -91,7 +91,7 @@ public:
static ErrorOr<ByteBuffer> compress_all(ReadonlyBytes bytes);
private:
- Core::Stream::Handle<Core::Stream::Stream> m_output_stream;
+ MaybeOwned<Core::Stream::Stream> m_output_stream;
};
}
diff --git a/Userland/Libraries/LibCompress/Zlib.cpp b/Userland/Libraries/LibCompress/Zlib.cpp
index db1f5558e5..ff2d78aa9c 100644
--- a/Userland/Libraries/LibCompress/Zlib.cpp
+++ b/Userland/Libraries/LibCompress/Zlib.cpp
@@ -69,13 +69,13 @@ u32 ZlibDecompressor::checksum()
return m_checksum;
}
-ErrorOr<NonnullOwnPtr<ZlibCompressor>> ZlibCompressor::construct(Core::Stream::Handle<Core::Stream::Stream> stream, ZlibCompressionLevel compression_level)
+ErrorOr<NonnullOwnPtr<ZlibCompressor>> ZlibCompressor::construct(MaybeOwned<Core::Stream::Stream> stream, ZlibCompressionLevel compression_level)
{
// Zlib only defines Deflate as a compression method.
auto compression_method = ZlibCompressionMethod::Deflate;
// FIXME: Find a way to compress with Deflate's "Best" compression level.
- auto compressor_stream = TRY(DeflateCompressor::construct(Core::Stream::Handle(*stream), static_cast<DeflateCompressor::CompressionLevel>(compression_level)));
+ auto compressor_stream = TRY(DeflateCompressor::construct(MaybeOwned(*stream), static_cast<DeflateCompressor::CompressionLevel>(compression_level)));
auto zlib_compressor = TRY(adopt_nonnull_own_or_enomem(new (nothrow) ZlibCompressor(move(stream), move(compressor_stream))));
TRY(zlib_compressor->write_header(compression_method, compression_level));
@@ -83,7 +83,7 @@ ErrorOr<NonnullOwnPtr<ZlibCompressor>> ZlibCompressor::construct(Core::Stream::H
return zlib_compressor;
}
-ZlibCompressor::ZlibCompressor(Core::Stream::Handle<Core::Stream::Stream> stream, NonnullOwnPtr<Core::Stream::Stream> compressor_stream)
+ZlibCompressor::ZlibCompressor(MaybeOwned<Core::Stream::Stream> stream, NonnullOwnPtr<Core::Stream::Stream> compressor_stream)
: m_output_stream(move(stream))
, m_compressor(move(compressor_stream))
{
@@ -164,7 +164,7 @@ ErrorOr<void> ZlibCompressor::finish()
ErrorOr<ByteBuffer> ZlibCompressor::compress_all(ReadonlyBytes bytes, ZlibCompressionLevel compression_level)
{
auto output_stream = TRY(try_make<Core::Stream::AllocatingMemoryStream>());
- auto zlib_stream = TRY(ZlibCompressor::construct(Core::Stream::Handle<Core::Stream::Stream>(*output_stream), compression_level));
+ auto zlib_stream = TRY(ZlibCompressor::construct(MaybeOwned<Core::Stream::Stream>(*output_stream), compression_level));
TRY(zlib_stream->write_entire_buffer(bytes));
diff --git a/Userland/Libraries/LibCompress/Zlib.h b/Userland/Libraries/LibCompress/Zlib.h
index 51bf4f30a9..a3ca0369d6 100644
--- a/Userland/Libraries/LibCompress/Zlib.h
+++ b/Userland/Libraries/LibCompress/Zlib.h
@@ -7,6 +7,7 @@
#pragma once
#include <AK/ByteBuffer.h>
+#include <AK/MaybeOwned.h>
#include <AK/Optional.h>
#include <AK/OwnPtr.h>
#include <AK/Span.h>
@@ -62,7 +63,7 @@ private:
class ZlibCompressor : public Core::Stream::Stream {
public:
- static ErrorOr<NonnullOwnPtr<ZlibCompressor>> construct(Core::Stream::Handle<Core::Stream::Stream>, ZlibCompressionLevel = ZlibCompressionLevel::Default);
+ static ErrorOr<NonnullOwnPtr<ZlibCompressor>> construct(MaybeOwned<Core::Stream::Stream>, ZlibCompressionLevel = ZlibCompressionLevel::Default);
~ZlibCompressor();
virtual ErrorOr<Bytes> read(Bytes) override;
@@ -75,11 +76,11 @@ public:
static ErrorOr<ByteBuffer> compress_all(ReadonlyBytes bytes, ZlibCompressionLevel = ZlibCompressionLevel::Default);
private:
- ZlibCompressor(Core::Stream::Handle<Core::Stream::Stream> stream, NonnullOwnPtr<Core::Stream::Stream> compressor_stream);
+ ZlibCompressor(MaybeOwned<Core::Stream::Stream> stream, NonnullOwnPtr<Core::Stream::Stream> compressor_stream);
ErrorOr<void> write_header(ZlibCompressionMethod, ZlibCompressionLevel);
bool m_finished { false };
- Core::Stream::Handle<Core::Stream::Stream> m_output_stream;
+ MaybeOwned<Core::Stream::Stream> m_output_stream;
NonnullOwnPtr<Core::Stream::Stream> m_compressor;
Crypto::Checksum::Adler32 m_adler32_checksum;
};
diff --git a/Userland/Libraries/LibCore/BitStream.h b/Userland/Libraries/LibCore/BitStream.h
index e1067c9514..db2f0c0c59 100644
--- a/Userland/Libraries/LibCore/BitStream.h
+++ b/Userland/Libraries/LibCore/BitStream.h
@@ -9,6 +9,7 @@
#include <AK/ByteBuffer.h>
#include <AK/Concepts.h>
#include <AK/Error.h>
+#include <AK/MaybeOwned.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/NonnullRefPtr.h>
#include <AK/OwnPtr.h>
@@ -23,7 +24,7 @@ namespace Core::Stream {
/// in big-endian order from another stream.
class BigEndianInputBitStream : public Stream {
public:
- static ErrorOr<NonnullOwnPtr<BigEndianInputBitStream>> construct(Handle<Stream> stream)
+ static ErrorOr<NonnullOwnPtr<BigEndianInputBitStream>> construct(MaybeOwned<Stream> stream)
{
return adopt_nonnull_own_or_enomem<BigEndianInputBitStream>(new BigEndianInputBitStream(move(stream)));
}
@@ -118,26 +119,26 @@ public:
ALWAYS_INLINE bool is_aligned_to_byte_boundary() const { return m_bit_offset == 0; }
private:
- BigEndianInputBitStream(Handle<Stream> stream)
+ BigEndianInputBitStream(MaybeOwned<Stream> stream)
: m_stream(move(stream))
{
}
Optional<u8> m_current_byte;
size_t m_bit_offset { 0 };
- Handle<Stream> m_stream;
+ MaybeOwned<Stream> m_stream;
};
/// A stream wrapper class that allows you to read arbitrary amounts of bits
/// in little-endian order from another stream.
class LittleEndianInputBitStream : public Stream {
public:
- static ErrorOr<NonnullOwnPtr<LittleEndianInputBitStream>> construct(Handle<Stream> stream)
+ static ErrorOr<NonnullOwnPtr<LittleEndianInputBitStream>> construct(MaybeOwned<Stream> stream)
{
return adopt_nonnull_own_or_enomem<LittleEndianInputBitStream>(new LittleEndianInputBitStream(move(stream)));
}
- LittleEndianInputBitStream(Handle<Stream> stream)
+ LittleEndianInputBitStream(MaybeOwned<Stream> stream)
: m_stream(move(stream))
{
}
@@ -234,14 +235,14 @@ public:
private:
Optional<u8> m_current_byte;
size_t m_bit_offset { 0 };
- Handle<Stream> m_stream;
+ MaybeOwned<Stream> m_stream;
};
/// A stream wrapper class that allows you to write arbitrary amounts of bits
/// in big-endian order to another stream.
class BigEndianOutputBitStream : public Stream {
public:
- static ErrorOr<NonnullOwnPtr<BigEndianOutputBitStream>> construct(Handle<Stream> stream)
+ static ErrorOr<NonnullOwnPtr<BigEndianOutputBitStream>> construct(MaybeOwned<Stream> stream)
{
return adopt_nonnull_own_or_enomem<BigEndianOutputBitStream>(new BigEndianOutputBitStream(move(stream)));
}
@@ -310,12 +311,12 @@ public:
}
private:
- BigEndianOutputBitStream(Handle<Stream> stream)
+ BigEndianOutputBitStream(MaybeOwned<Stream> stream)
: m_stream(move(stream))
{
}
- Handle<Stream> m_stream;
+ MaybeOwned<Stream> m_stream;
u8 m_current_byte { 0 };
size_t m_bit_offset { 0 };
};
@@ -324,7 +325,7 @@ private:
/// in little-endian order to another stream.
class LittleEndianOutputBitStream : public Stream {
public:
- static ErrorOr<NonnullOwnPtr<LittleEndianOutputBitStream>> construct(Handle<Stream> stream)
+ static ErrorOr<NonnullOwnPtr<LittleEndianOutputBitStream>> construct(MaybeOwned<Stream> stream)
{
return adopt_nonnull_own_or_enomem<LittleEndianOutputBitStream>(new LittleEndianOutputBitStream(move(stream)));
}
@@ -393,12 +394,12 @@ public:
}
private:
- LittleEndianOutputBitStream(Handle<Stream> stream)
+ LittleEndianOutputBitStream(MaybeOwned<Stream> stream)
: m_stream(move(stream))
{
}
- Handle<Stream> m_stream;
+ MaybeOwned<Stream> m_stream;
u8 m_current_byte { 0 };
size_t m_bit_offset { 0 };
};
diff --git a/Userland/Libraries/LibCore/Stream.h b/Userland/Libraries/LibCore/Stream.h
index 556c90ee12..0e58741b9b 100644
--- a/Userland/Libraries/LibCore/Stream.h
+++ b/Userland/Libraries/LibCore/Stream.h
@@ -27,48 +27,6 @@
namespace Core::Stream {
-template<DerivedFrom<Core::Stream::Stream> T>
-class Handle {
-public:
- template<DerivedFrom<T> U>
- Handle(NonnullOwnPtr<U> handle)
- : m_handle(adopt_own<T>(*handle.leak_ptr()))
- {
- }
-
- // This is made `explicit` to not accidentally create a non-owning Handle,
- // which may not always be intended.
- explicit Handle(T& handle)
- : m_handle(&handle)
- {
- }
-
- T* ptr()
- {
- if (m_handle.template has<T*>())
- return m_handle.template get<T*>();
- else
- return m_handle.template get<NonnullOwnPtr<T>>();
- }
-
- T const* ptr() const
- {
- if (m_handle.template has<T*>())
- return m_handle.template get<T*>();
- else
- return m_handle.template get<NonnullOwnPtr<T>>();
- }
-
- T* operator->() { return ptr(); }
- T const* operator->() const { return ptr(); }
-
- T& operator*() { return *ptr(); }
- T const& operator*() const { return *ptr(); }
-
-private:
- Variant<NonnullOwnPtr<T>, T*> m_handle;
-};
-
/// The base, abstract class for stream operations. This class defines the
/// operations one can perform on every stream in LibCore.
/// Operations without a sensible default that are unsupported by an implementation
diff --git a/Userland/Utilities/pro.cpp b/Userland/Utilities/pro.cpp
index 0756191ccc..79c6f56929 100644
--- a/Userland/Utilities/pro.cpp
+++ b/Userland/Utilities/pro.cpp
@@ -8,6 +8,7 @@
#include <AK/Base64.h>
#include <AK/GenericLexer.h>
#include <AK/LexicalPath.h>
+#include <AK/MaybeOwned.h>
#include <AK/NumberFormat.h>
#include <AK/String.h>
#include <AK/URL.h>
@@ -105,7 +106,7 @@ private:
template<typename ConditionT>
class ConditionalOutputStream final : public Core::Stream::Stream {
public:
- ConditionalOutputStream(ConditionT&& condition, Core::Stream::Handle<Core::Stream::Stream> stream)
+ ConditionalOutputStream(ConditionT&& condition, MaybeOwned<Core::Stream::Stream> stream)
: m_stream(move(stream))
, m_condition(condition)
{
@@ -140,7 +141,7 @@ public:
}
private:
- Core::Stream::Handle<Core::Stream::Stream> m_stream;
+ MaybeOwned<Core::Stream::Stream> m_stream;
ConditionT m_condition;
};