Commit Graph

1108 Commits

Author SHA1 Message Date
asynts
c8ed882b8e AK: Add OutputMemoryStream::fill_to_end. 2020-09-15 20:36:45 +02:00
asynts
83d0803861 AK: Re-add OutputMemoryStream for static buffers only. 2020-09-15 20:36:45 +02:00
asynts
f18e927827 AK: Remove OutputMemoryStream for DuplexMemoryStream.
OutputMemoryStream was originally a proxy for DuplexMemoryStream that
did not expose any reading API.

Now I need to add another class that is like OutputMemoryStream but only
for static buffers. My first idea was to make OutputMemoryStream do that
too, but I think it's much better to have a distinct class for that.

I originally wanted to call that class FixedOutputMemoryStream but that
name is really cumbersome and it's a bit unintuitive because
InputMemoryStream is already reading from a fixed buffer.

So let's just use DuplexMemoryStream instead of OutputMemoryStream for
any dynamic stuff and create a new OutputMemoryStream for static
buffers.
2020-09-15 20:36:45 +02:00
asynts
96edcbc27c AK: Lower the requirements for InputStream::eof and rename it.
Consider the following snippet:

    void foo(InputStream& stream) {
        if(!stream.eof()) {
            u8 byte;
            stream >> byte;
        }
    }

There is a very subtle bug in this snippet, for some input streams eof()
might return false even if no more data can be read. In this case an
error flag would be set on the stream.

Until now I've always ensured that this is not the case, but this made
the implementation of eof() unnecessarily complicated.
InputFileStream::eof had to keep a ByteBuffer around just to make this
possible. That meant a ton of unnecessary copies just to get a reliable
eof().

In most cases it isn't actually necessary to have a reliable eof()
implementation.

In most other cases a reliable eof() is avaliable anyways because in
some cases like InputMemoryStream it is very easy to implement.
2020-09-14 20:58:12 +02:00
AnotherTest
1674903dcc AK: Fix PrintfImplementation "%x" handling for u32
This also fixes an issue with the color input value being messed up.
oops :P
2020-09-12 15:01:19 +02:00
Ben Wiederhake
d16f510805 AK: Fix forward-declaration of Array 2020-09-12 13:46:15 +02:00
Ben Wiederhake
0d3a8d5397 AK: Fix accidentally-recursive call in BitStream 2020-09-12 00:13:29 +02:00
AnotherTest
72edb33670 AK: Generalise 'PrintfImplementation'
This makes PrintfImplementation usable with any sequence, provided that
a 'next element' function can be written for it.
Does not affect the behaviour of printf() and co.
2020-09-11 21:41:23 +02:00
asynts
049f709d0b AK: Calculate the chunk index correctly in DuplexMemoryStream. 2020-09-11 16:07:45 +02:00
asynts
0055a28710 AK: Replace LogStream operator for ReadonlyBytes with dump_bytes.
It wasn't actually possible to call

    const LogStream& operator<<(const LogStream&, ReadonlyBytes);

because it was shadowed by

    template<typename T>
    const LogStream& operator<<(const LogStream& stream, Span<T> span);

not sure how I didn't find this when I added the overload.

It would be possible to use SFINAE to disable the other overload,
however, I think it is better to use a different method entirely because
the output can be very verbose:

    void dump_bytes(ReadonlyBytes);
2020-09-10 14:15:02 +02:00
asynts
a7f786fc0a AK: Use TypedTransfer in Span::copy_to. 2020-09-09 20:15:50 +02:00
asynts
910924f559 AK: Moved TypedTransfer into it's own header. 2020-09-09 20:15:50 +02:00
Tom
92e400c7f9 AK: Add Bitmap::find_one_anywhere and optimize Bitmap::find_first
Leverage constexpr and __builtin_ffs for Bitmap::find_first. Also add
a variant Bitmap::find_one_anywhere that can start scanning at a
provided hint.

Also, merge Bitmap::fill_range into the already existing Bitmap::set_range
2020-09-09 13:02:14 +02:00
asynts
a7cbc7fcb2 AK: Remove empty destructor from JsonParser. 2020-09-08 14:01:21 +02:00
asynts
70dd97c46e AK: Remove FixedArray class. 2020-09-08 14:01:21 +02:00
asynts
ec1080b18a Refactor: Replace usages of FixedArray with Vector. 2020-09-08 14:01:21 +02:00
asynts
9c83d6ff46 Refactor: Replace usages of FixedArray with Array. 2020-09-08 14:01:21 +02:00
asynts
76e37e8c96 AK: Add Array<T, Size> template. 2020-09-08 14:01:21 +02:00
asynts
1b3ecb01a5 AK: Add generic SimpleIterator class to replace VectorIterator. 2020-09-08 14:01:21 +02:00
Muhammad Zahalqa
125ea6a214 AK: Vector use Traits<T>::equals in find
Use Traits<T>::equals for equality checking in search
functions instead of  operator==
2020-09-06 21:56:32 +02:00
Muhammad Zahalqa
ad3e6ef344 AK: SinglyLinkedList use Traits<T>::equals in find
Use Traits<T>::equals for equality checking in search
functions instead of  operator==
2020-09-06 21:56:32 +02:00
Tom
efac3d27d2 AK: Add Bitmap::count_in_range and Bitmap::fill_range 2020-09-06 21:20:08 +02:00
asynts
cd2815ed87 AK: Add LogStream overload for ReadonlyBytes.
This is extremely useful for debugging.
2020-09-06 20:47:35 +02:00
Andreas Kling
9dafbc82ff AK: Add JsonObject::remove() 2020-09-06 16:09:09 +02:00
asynts
4c317a94c7 LibCompress: Simplify logic in deflate implementation. 2020-09-06 12:54:45 +02:00
asynts
6de63782c7 Streams: Consistent behaviour when reading from stream with error.
The streaming operator doesn't short-circuit, consider the following
snippet:

    void foo(InputStream& stream) {
        int a, b;
        stream >> a >> b;
    }

If the first read fails, the second is called regardless. It should be
well defined what happens in this case: nothing.
2020-09-06 12:54:45 +02:00
asynts
359fcf348f AK: Add Buffered<T> which wraps a stream, adding input buffering. 2020-09-06 12:54:45 +02:00
asynts
b011f87d34 AK: Add log stream operator overload for Span. 2020-09-06 12:54:45 +02:00
Muhammad Zahalqa
fad0c8e712
AK: Make all DoublyLinkedList search methods use Traits<T>::equals (#3404) 2020-09-05 14:17:14 +02:00
asynts
7efd2a6d59 AK: Add OutputMemoryStream class. 2020-09-01 17:25:26 +02:00
asynts
3a2658951b AK: Add DuplexMemoryStream::copy_into_contiguous_buffer. 2020-09-01 17:25:26 +02:00
asynts
b68a873067 AK: Move memory streams into their own header. 2020-09-01 17:25:26 +02:00
asynts
f9516a99bf AK: Remove history from DuplexMemoryStream.
That feature was really only useful for Compress::DeflateDecompressor
but that is now using CircularDuplexBuffer instead.
2020-09-01 17:25:26 +02:00
asynts
9ce4475907 Streams: Distinguish recoverable and fatal errors. 2020-09-01 17:25:26 +02:00
AnotherTest
441807f96d AK: Add is_any_of(StringView) to GenericLexer 2020-08-31 23:05:58 +02:00
Nico Weber
f2135d7d00 AK: Make %llx work in printf 2020-08-30 17:37:20 +02:00
Sergey Bugaev
be6cce5530 AK: Add String::copy_characters_to_buffer()
This is a strcpy()-like method with actually sane semantics:

* It accepts a non-empty buffer along with its size in bytes.
* It copies as much of the string as fits into the buffer.
* It always null-terminates the result.
* It returns, as a non-discardable boolean, whether the whole string has been
copied.

Intended usage looks like this:

bool fits = string.copy_characters_to_buffer(buffer, sizeof(buffer));

and then either

if (!fits) {
    fprintf(stderr, "The name does not fit!!11");
    return nullptr;
}

or, if you're sure the buffer is large enough,

// I'm totally sure it fits because [reasons go here].
ASSERT(fits);

or if you're feeling extremely adventurous,

(void)fits;

but don't do that, please.
2020-08-30 17:35:27 +02:00
Tom
80560d1be3 AK: Fix FixedArray zero bytes allocations 2020-08-30 17:30:48 +02:00
Tom
f5bc7dbfda AK: Fix ByteBuffer zero bytes allocations 2020-08-30 17:30:48 +02:00
Andreas Kling
8ecc3d31d1 AK: Add missing declaration in StringImpl.cpp 2020-08-30 10:48:08 +02:00
asynts
e7df17d146 AK: Stream operators for String for generic streams.
I think this should really be a member function of InputStream instead,
but I don't want to include String in Stream.h. This will do for now...
2020-08-30 09:56:10 +02:00
asynts
deb85c47b5 AK: Add Optional::emplace method. 2020-08-30 09:56:10 +02:00
Ben Wiederhake
1ef26e0c09 AK: Provide off-switch for dbg() output 2020-08-30 09:43:49 +02:00
Ben Wiederhake
184b454e2f AK: Unbreak building with extra debug macros 2020-08-30 09:43:49 +02:00
asynts
e68b158a52 AK: Don't swap endianness when writing endian wrappers to stream. 2020-08-29 17:44:34 +02:00
asynts
1b3169f405 AK: Define MakeUnsigned and MakeSigned for char.
For some weird reason the C++ standard considers char, signed char and
unsigned char *three* different types. On the other hand int is just an
alias for signed int, meaning that int, signed int and unsigned int are
just *two* different types.

https://stackoverflow.com/a/32856568/8746648
2020-08-27 15:49:01 +02:00
Ben Wiederhake
9f7ec33180 Meta: Force semi-colon after MAKE_AK_NONXXXABLE()
Before, we had about these occurrence counts:
COPY: 13 without, 33 with
MOVE: 12 without, 28 with

Clearly, 'with' was the preferred way. However, this introduced double-semicolons
all over the place, and caused some warnings to trigger.

This patch *forces* the usage of a semi-colon when calling the macro,
by removing the semi-colon within the macro. (And thus also gets rid
of the double-semicolon.)
2020-08-27 10:12:04 +02:00
Ben Wiederhake
e5807d17b2 Tests: Document 'missing' tests
It's up for grabs. Anyone wants to write them? :)
2020-08-27 10:12:04 +02:00
asynts
71cbf72e8a AK: Add InputBitStream class. 2020-08-26 21:07:53 +02:00
asynts
a82fead38a AK: Add CircularDuplexStream class. 2020-08-26 21:07:53 +02:00