O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
input.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
3/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
4/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
5/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
6/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
7/* */
14/* ************************************************************************** */
15
16#include "o2s/input_stream.h"
17
22istream_t istream_init(size_t buffer_size, bool (*accumulate)(istream_t*, size_t))
23{
24 return (istream_t){.buffer = QueueAllocate(buffer_size, char), .accumulate = accumulate};
25}
26
29{
30 queue_free(&self->buffer);
31}
32
37bool istream_has_at_least(const istream_t* self, size_t count)
38{
39 return queue_count(&self->buffer) >= count;
40}
void istream_close(istream_t *self)
Free the buffer.
Definition input.c:28
bool istream_has_at_least(const istream_t *self, size_t count)
Test if enough characters are available.
Definition input.c:37
istream_t istream_init(size_t buffer_size, bool(*accumulate)(istream_t *, size_t))
Allocate a buffer and set the member function.
Definition input.c:22
Buffered input streams.
size_t queue_count(const queue_t *self)
Number of elements currently in the queue.
Definition queue.c:55
void queue_free(queue_t *self)
Release the allocated memory.
Definition queue.c:19
Input Stream.
queue_t buffer
Circular buffer of bytes.