81 lines
3.2 KiB
C
81 lines
3.2 KiB
C
// vim:fileencoding=utf-8:foldmethod=marker
|
|
|
|
#ifndef STREAM_H
|
|
#define STREAM_H
|
|
|
|
#include "../../common/aliases/aliases.h"
|
|
#include "../../common/platform/platform.h"
|
|
|
|
#ifdef WP_PLATFORM_CPP
|
|
BEGIN_C_LINKAGE
|
|
#endif // !WP_PLATFORM_CPP
|
|
|
|
typedef struct {
|
|
void *data;
|
|
u64 count;
|
|
u64 position;
|
|
u64 item_size;
|
|
} WpStream;
|
|
|
|
// NOTE (Abdelrahman): WpStream typedefs for readability
|
|
typedef WpStream WpVoidPtrStream;
|
|
typedef WpStream WpC8Stream;
|
|
typedef WpStream WpC16Stream;
|
|
typedef WpStream WpC32Stream;
|
|
typedef WpStream WpU8Stream;
|
|
typedef WpStream WpU16Stream;
|
|
typedef WpStream WpU32Stream;
|
|
typedef WpStream WpU64Stream;
|
|
typedef WpStream WpB8Stream;
|
|
typedef WpStream WpI8Stream;
|
|
typedef WpStream WpI16Stream;
|
|
typedef WpStream WpI32Stream;
|
|
typedef WpStream WpI64Stream;
|
|
typedef WpStream WpF32Stream;
|
|
typedef WpStream WpF64Stream;
|
|
typedef WpStream WpF128Stream;
|
|
typedef WpStream WpUptrStream;
|
|
typedef WpStream WpIptrStream;
|
|
typedef WpStream WpStr8Stream;
|
|
|
|
#ifdef WP_PLATFORM_CPP
|
|
#define wpStream(TYPE, DATA, SIZE) ([&]() { \
|
|
return WpStream{ \
|
|
DATA, \
|
|
SIZE / sizeof(TYPE), \
|
|
0, \
|
|
sizeof(TYPE) \
|
|
}; \
|
|
}())
|
|
#else
|
|
#define wpStream(TYPE, DATA, SIZE) ( \
|
|
(WpStream){ \
|
|
.data = DATA, \
|
|
.count = SIZE / sizeof(TYPE), \
|
|
.position = 0, \
|
|
.item_size = sizeof(TYPE) \
|
|
} \
|
|
)
|
|
#endif
|
|
|
|
#define wpStreamHasNext(STREAM) _streamHasCount(STREAM, 1)
|
|
#define wpStreamHasCount(STREAM, COUNT) _streamHasCount(STREAM, COUNT)
|
|
#define wpStreamPeek(TYPE, STREAM) ((TYPE *)_streamPeekWithOffset(STREAM, 0, sizeof(TYPE)))
|
|
#define wpStreamPeekWithOffset(TYPE, STREAM, OFFSET) \
|
|
((TYPE *)_streamPeekWithOffset(STREAM, OFFSET, sizeof(TYPE)))
|
|
#define wpStreamConsume(TYPE, STREAM) ((TYPE *)_streamConsumeCount(STREAM, 1, sizeof(TYPE)))
|
|
#define wpStreamConsumeCount(TYPE, STREAM, COUNT) \
|
|
((TYPE *)_streamConsumeCount(STREAM, COUNT, sizeof(TYPE)))
|
|
|
|
b8 wpStreamAtEnd(const WpStream *stream);
|
|
|
|
b8 _streamHasCount(const WpStream *stream, u64 count);
|
|
void *_streamPeekWithOffset(const WpStream *stream, u64 offset, u64 item_size);
|
|
void *_streamConsumeCount(WpStream *stream, u64 count, u64 item_size);
|
|
|
|
#ifdef WP_PLATFORM_CPP
|
|
END_C_LINKAGE
|
|
#endif // !WP_PLATFORM_CPP
|
|
|
|
#endif // !STREAM_H
|