core: stream: convert to a b_object interface and base class
This commit is contained in:
@@ -1,26 +1,23 @@
|
||||
#ifndef BLUELIB_CORE_STREAM_H_
|
||||
#define BLUELIB_CORE_STREAM_H_
|
||||
#ifndef BLUE_CORE_STREAM_H_
|
||||
#define BLUE_CORE_STREAM_H_
|
||||
|
||||
#include <blue/core/macros.h>
|
||||
#include <blue/core/misc.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define b_stdin (z__b_stream_get_stdin())
|
||||
#define b_stdout (z__b_stream_get_stdout())
|
||||
#define b_stderr (z__b_stream_get_stderr())
|
||||
B_DECLS_BEGIN;
|
||||
|
||||
typedef enum b_stream_pipeline_flags {
|
||||
B_STREAM_PIPELINE_F_NONE = 0x00u,
|
||||
B_STREAM_PIPELINE_F_DYNAMIC = 0x01u,
|
||||
B_STREAM_PIPELINE_F_BUF_DYNAMIC = 0x02u,
|
||||
} b_stream_pipeline_flags;
|
||||
#define b_stdin (z__b_stream_get_stdin())
|
||||
#define b_stdout (z__b_stream_get_stdout())
|
||||
#define b_stderr (z__b_stream_get_stderr())
|
||||
|
||||
typedef struct b_stream_pipeline {
|
||||
b_stream_pipeline_flags p_flags;
|
||||
void *p_buf;
|
||||
size_t p_buf_len;
|
||||
} b_stream_pipeline;
|
||||
#define B_TYPE_STREAM (b_stream_get_type())
|
||||
#define B_TYPE_STREAM_BUFFER (b_stream_buffer_get_type())
|
||||
|
||||
B_DECLARE_TYPE(b_stream);
|
||||
B_DECLARE_TYPE(b_stream_buffer);
|
||||
|
||||
typedef enum b_stream_mode {
|
||||
B_STREAM_READ = 0x01u,
|
||||
@@ -35,40 +32,35 @@ typedef enum b_stream_seek_origin {
|
||||
B_STREAM_SEEK_END = 0x03u,
|
||||
} b_stream_seek_origin;
|
||||
|
||||
typedef struct b_stream {
|
||||
typedef struct b_stream_cfg {
|
||||
b_stream_mode s_mode;
|
||||
size_t s_cursor;
|
||||
int *s_istack;
|
||||
int s_add_indent;
|
||||
size_t s_istack_ptr, s_istack_size;
|
||||
void *s_ptr0, *s_ptr1;
|
||||
} b_stream_cfg;
|
||||
|
||||
b_status (*s_close)(struct b_stream *);
|
||||
b_status (*s_seek)(struct b_stream *, long long, b_stream_seek_origin);
|
||||
b_status (*s_tell)(const struct b_stream *, size_t *);
|
||||
b_status (*s_getc)(struct b_stream *, int *);
|
||||
b_status (*s_read)(struct b_stream *, unsigned char *, size_t, size_t *);
|
||||
b_status (*s_write)(
|
||||
struct b_stream *, const unsigned char *, size_t, size_t *);
|
||||
b_status (*s_reserve)(struct b_stream *, size_t);
|
||||
} b_stream;
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_stream)
|
||||
b_status (*s_close)(b_stream *);
|
||||
b_status (*s_seek)(b_stream *, long long, b_stream_seek_origin);
|
||||
b_status (*s_tell)(const b_stream *, size_t *);
|
||||
b_status (*s_getc)(b_stream *, int *);
|
||||
b_status (*s_read)(b_stream *, unsigned char *, size_t, size_t *);
|
||||
b_status (*s_write)(b_stream *, const unsigned char *, size_t, size_t *);
|
||||
b_status (*s_reserve)(b_stream *, size_t);
|
||||
B_TYPE_CLASS_DECLARATION_END(b_stream)
|
||||
|
||||
B_TYPE_CLASS_DECLARATION_BEGIN(b_stream_buffer)
|
||||
B_TYPE_CLASS_DECLARATION_END(b_stream_buffer)
|
||||
|
||||
BLUE_API b_type b_stream_get_type();
|
||||
BLUE_API b_type b_stream_buffer_get_type();
|
||||
|
||||
BLUE_API b_stream *z__b_stream_get_stdin(void);
|
||||
BLUE_API b_stream *z__b_stream_get_stdout(void);
|
||||
BLUE_API b_stream *z__b_stream_get_stderr(void);
|
||||
|
||||
BLUE_API b_status b_stream_pipeline_create(
|
||||
size_t buffer_size, b_stream_pipeline **out);
|
||||
|
||||
BLUE_API b_status b_stream_pipeline_create(
|
||||
size_t buffer_size, b_stream_pipeline **out);
|
||||
BLUE_API b_status b_stream_pipeline_init(
|
||||
void *p, size_t len, b_stream_pipeline *out);
|
||||
BLUE_API b_status b_stream_pipeline_destroy(b_stream_pipeline *pipeline);
|
||||
BLUE_API b_stream_buffer *b_stream_buffer_create(void *p, size_t len);
|
||||
BLUE_API b_stream_buffer *b_stream_buffer_create_dynamic(size_t buffer_size);
|
||||
|
||||
BLUE_API b_stream *b_stream_open_fp(FILE *fp);
|
||||
|
||||
BLUE_API b_status b_stream_close(b_stream *stream);
|
||||
BLUE_API b_status b_stream_reserve(b_stream *stream, size_t len);
|
||||
BLUE_API b_status b_stream_seek(
|
||||
b_stream *stream, long long offset, b_stream_seek_origin origin);
|
||||
@@ -88,8 +80,7 @@ BLUE_API b_status b_stream_read_line_s(b_stream *src, b_stream *dest);
|
||||
BLUE_API b_status b_stream_read_all_bytes(
|
||||
b_stream *stream, void *p, size_t max, size_t *nr_read);
|
||||
BLUE_API b_status b_stream_read_all_bytes_s(
|
||||
b_stream *src, b_stream *dest, b_stream_pipeline *pipeline,
|
||||
size_t *nr_read);
|
||||
b_stream *src, b_stream *dest, b_stream_buffer *buffer, size_t *nr_read);
|
||||
|
||||
BLUE_API b_status b_stream_write_char(b_stream *stream, char c);
|
||||
BLUE_API b_status b_stream_write_string(
|
||||
@@ -103,4 +94,6 @@ BLUE_API b_status b_stream_write_fmt(
|
||||
BLUE_API b_status b_stream_write_vfmt(
|
||||
b_stream *stream, size_t *nr_written, const char *format, va_list arg);
|
||||
|
||||
B_DECLS_END;
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user