O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
input_stream.h
Go to the documentation of this file.
1#pragma once
2
3/* ************************************************************************** */
4/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
5/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
6/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
7/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
8/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
9/* */
16/* ************************************************************************** */
17
18#include "o2s/queue.h"
19
20#include <stdbool.h> // bool
21#include <stddef.h> // size_t
22
27typedef struct input_stream
28{
31 bool (*accumulate)(struct input_stream* self, size_t count);
32} istream_t;
33
35#define InputStreamInit(Size, Accumulate) istream_init(Size, ((bool (*)(istream_t*, size_t))(Accumulate)))
36
37istream_t istream_init(size_t buffer_size, bool (*accumulate)(istream_t*, size_t));
38void istream_close(istream_t* self);
39
40bool istream_has_at_least(const istream_t* self, size_t count);
41
44
45#define istream_accumulate(Stream, Count) ((istream_t*)(Stream))->accumulate((istream_t*)Stream, Count)
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
Realtime FIFO buffer.
deque_t queue_t
A queue is First In First Out.
Definition queue.h:21
Input Stream.
bool(* accumulate)(struct input_stream *self, size_t count)
Ask if the stream can provide at least count bytes to read.
queue_t buffer
Circular buffer of bytes.