medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 42557991478771d8eef311ffb1e1ac01f26fff9e
parent 1607e7a0d84b3c5ff1ed0028419e5c2799b23137
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat Dec 24 16:25:25 +0200

WriteStream space reservation

Diffstat:
stream.h | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/stream.h b/stream.h @@ -126,6 +126,20 @@ inline void write( WriteStream * stream, const T & x ) { visit( x, StreamSerialiser( stream ) ); } +// TODO: endianness +inline void * reserve( WriteStream * stream, size_t size ) { + static u8 dummy_memory[ 64 ]; + ASSERT( size < sizeof( dummy_memory ) ); + + if( !stream->ok || checked_cast< size_t >( stream->one_past_end - stream->cursor ) < size ) { + stream->ok = false; + return dummy_memory; + } + + stream->cursor += size; + return stream->cursor - size; +} + #define DEF_READ_WRITE( T ) \ inline T read_##T( ReadStream * stream ) { \ T x; \ @@ -134,6 +148,9 @@ inline void write( WriteStream * stream, const T & x ) { } \ inline void write_##T( WriteStream * stream, const T & x ) { \ write( stream, x ); \ + } \ + inline void * reserve_##T( WriteStream * stream ) { \ + return reserve( stream, sizeof( T ) ); \ } DEF_READ_WRITE( u8 )