This commit is contained in:
+14
-11
@@ -6,28 +6,31 @@
|
||||
|
||||
void _streamValidate(const WpStream *stream, u64 item_size);
|
||||
|
||||
b8 _streamAtEnd(const WpStream *stream, u64 item_size) {
|
||||
_streamValidate(stream, item_size);
|
||||
b8 wpStreamAtEnd(const WpStream *stream) {
|
||||
return stream->position >= stream->count;
|
||||
}
|
||||
|
||||
b8 _streamHasNext(const WpStream *stream, u64 item_size) {
|
||||
_streamValidate(stream, item_size);
|
||||
return stream->position + 1 < stream->count;
|
||||
b8 _streamHasCount(const WpStream *stream, u64 count) {
|
||||
return stream->position + count <= stream->count;
|
||||
}
|
||||
|
||||
void *_streamPeek(const WpStream *stream, u64 item_size) {
|
||||
if (_streamHasNext(stream, item_size)) {
|
||||
u64 index = (stream->position + 1) * stream->item_size;
|
||||
void *_streamPeekWithOffset(const WpStream *stream, u64 offset, u64 item_size) {
|
||||
_streamValidate(stream, item_size);
|
||||
|
||||
if (_streamHasCount(stream, offset + 1)) {
|
||||
u64 index = (stream->position + offset) * stream->item_size;
|
||||
return (void *)(&((u8 *)(stream->data))[index]);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *_streamConsume(WpStream *stream, u64 item_size) {
|
||||
if (!_streamAtEnd(stream, item_size)) {
|
||||
u64 index = stream->position++ * stream->item_size;
|
||||
void *_streamConsumeCount(WpStream *stream, u64 count, u64 item_size) {
|
||||
_streamValidate(stream, item_size);
|
||||
|
||||
if (_streamHasCount(stream, count)) {
|
||||
u64 index = stream->position * stream->item_size;
|
||||
stream->position += count;
|
||||
return (void *)(&((u8 *)(stream->data))[index]);
|
||||
}
|
||||
|
||||
|
||||
@@ -58,15 +58,20 @@ typedef WpStream WpStr8Stream;
|
||||
)
|
||||
#endif
|
||||
|
||||
#define wpStreamAtEnd(TYPE, STREAM) _streamAtEnd(STREAM, sizeof(TYPE))
|
||||
#define wpStreamHasNext(TYPE, STREAM) _streamHasNext(STREAM, sizeof(TYPE))
|
||||
#define wpStreamPeek(TYPE, STREAM) ((TYPE *)_streamPeek(STREAM, sizeof(TYPE)))
|
||||
#define wpStreamConsume(TYPE, STREAM) ((TYPE *)_streamConsume(STREAM, sizeof(TYPE)))
|
||||
#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 _streamAtEnd(const WpStream *stream, u64 item_size);
|
||||
b8 _streamHasNext(const WpStream *stream, u64 item_size);
|
||||
void *_streamPeek(const WpStream *stream, u64 item_size);
|
||||
void *_streamConsume(WpStream *stream, u64 item_size);
|
||||
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
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
#include "../os/file/file.h"
|
||||
#include "../base/strings/str8/str8.h"
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
typedef enum {
|
||||
WP_LOG_LEVEL_FATAL,
|
||||
WP_LOG_LEVEL_CRITICAL,
|
||||
@@ -31,4 +35,8 @@ void wpLogError(const WpLogger *logger, WpStr8 msg);
|
||||
void wpLogCritical(const WpLogger *logger, WpStr8 msg);
|
||||
void wpLogFatal(const WpLogger *logger, WpStr8 msg);
|
||||
|
||||
#ifdef WP_PLATFORM_CPP
|
||||
END_C_LINKAGE
|
||||
#endif // !WP_PLATFORM_CPP
|
||||
|
||||
#endif // !LOG_H
|
||||
|
||||
Reference in New Issue
Block a user