32 class AsyncDataStream;
130 [[nodiscard]]
virtual bool isReadable() const noexcept {
return false; }
143 [[nodiscard]]
virtual size_t read(
void* data,
size_t n);
150 const ByteMemoryView byteMemoryView = memoryView.template as<Byte>();
151 return read(byteMemoryView.
data(), byteMemoryView.
size());
161 size_t totalBytesRead = 0;
162 for(
const size_t index : indices<std::size_t>(memoryView)) {
163 const size_t bytesRead = read(&memoryView[index],
sizeof(
T));
164 totalBytesRead += bytesRead;
166 if(bytesRead !=
sizeof(
T)) {
170 return totalBytesRead;
179 String::value_type buffer[1024];
181 while((length = read(buffer,
sizeof(buffer))) != 0) {
192 requires std::is_trivially_copyable_v<T>
196 const size_t bytes = read(&value,
sizeof(
T));
197 if(bytes !=
sizeof(
T)) {
200 return byteswap<std::endian::little>(value);
237 [[nodiscard]]
virtual bool isWritable() const noexcept {
return false; }
253 [[nodiscard]]
virtual size_t write(
const void* data,
size_t n);
261 return write(byteMemoryView.
data(), byteMemoryView.
size());
271 size_t totalBytesWritten = 0;
272 for(
const size_t index : indices<std::size_t>(memoryView)) {
273 const size_t bytesWritten = write(&memoryView[index],
sizeof(
T));
274 totalBytesWritten += bytesWritten;
276 if(bytesWritten !=
sizeof(
T)) {
280 return totalBytesWritten;
292 requires std::is_trivially_copyable_v<T>
295 value = byteswap<std::endian::little>(value);
297 return write(&value,
sizeof(
T)) ==
sizeof(
T);
339 [[nodiscard]]
virtual bool isSeekable(
Seek mode = Seek::Start)
const noexcept {
return false; }
352 return seek(std::streamsize(n), Seek::Current);
357 [[nodiscard]]
virtual bool isTellable() const noexcept {
return false; }
371 [[nodiscard]] virtual
Async<
size_t> size();
377 [[nodiscard]] virtual
Async<> wait() = 0;
390 [[nodiscard]]
virtual bool isReadable() const noexcept {
return false; }
421 [[nodiscard]]
virtual bool isWritable() const noexcept {
return false; }
460 class DataStream final :
public Poly<IDataStream, kStreamPolySize, false, IStream> {
518 [[nodiscard]]
bool isSeekable(const
Seek mode =
Seek::Start) const noexcept final {
520 return mDataStream->isSeekable(mode);
524 void seek(std::streamsize position,
Seek mode = Seek::Start)
final;
529 return mDataStream->isTellable();
533 [[nodiscard]]
size_t tell() final;
536 [[nodiscard]]
bool isSizeKnown() const noexcept final {
538 return mDataStream->isSizeKnown();
542 [[nodiscard]]
size_t size() final;
546 [[nodiscard]]
bool isReadable() const noexcept final {
548 return mDataStream->isReadable();
552 [[nodiscard]]
size_t read(
void* data,
size_t n)
final;
558 return mDataStream->isWritable();
562 [[nodiscard]]
size_t write(
const void* data,
size_t n)
final;
576 [[nodiscard]]
bool isSeekable(
const Seek mode = Seek::Start)
const noexcept final {
578 return mDataStream->isSeekable(mode);
587 return mDataStream->isTellable();
594 [[nodiscard]]
bool isSizeKnown() const noexcept final {
596 return mDataStream->isSizeKnown();
604 [[nodiscard]]
bool isReadable() const noexcept final {
606 return mDataStream->isReadable();
616 return mDataStream->isWritable();
634 FILE* stream =
nullptr;
655 [[nodiscard]] const
FilePath& getPath() const noexcept {
return path; }
658 [[nodiscard]] FILE*
getStream() const noexcept {
return stream; }
662 [[nodiscard]]
bool isSeekable(
Seek mode = Seek::Start)
const noexcept final {
return true; }
665 void seek(std::streamsize position,
Seek mode = Seek::Start)
final;
668 [[nodiscard]]
bool isTellable() const noexcept final {
return true; }
671 [[nodiscard]]
size_t tell() final;
674 [[nodiscard]]
bool isSizeKnown() const noexcept final {
return true; }
677 [[nodiscard]]
size_t size() final;
680 [[nodiscard]]
bool isReadable() const noexcept final {
return true; }
683 [[nodiscard]]
size_t read(
void* data,
size_t n)
final;
686 [[nodiscard]]
bool isWritable() const noexcept final {
return true; }
689 [[nodiscard]]
size_t write(
const void* data,
size_t n)
final;
695 std::size_t mSize = 0;
696 std::size_t mPosition = 0;
697 bool mOwnsBuffer =
true;
736 [[nodiscard]]
bool isGrowable()
const {
return mOwnsBuffer; }
740 [[nodiscard]]
bool isSeekable(
const Seek mode = Seek::Start)
const noexcept final {
744 case Seek::End:
return true;
745 default:
return false;
750 void seek(std::streamsize position,
Seek mode = Seek::Start)
final;
753 [[nodiscard]]
bool isTellable() const noexcept final {
return true; }
756 [[nodiscard]]
size_t tell() final {
return mPosition; }
759 [[nodiscard]]
bool isSizeKnown() const noexcept final {
return true; }
762 [[nodiscard]]
size_t size() final {
return mSize; }
765 [[nodiscard]]
bool isReadable() const noexcept final {
return true; }
768 [[nodiscard]]
size_t read(
void* data,
size_t n)
final;
769 using IDataStream::read;
772 [[nodiscard]]
bool isWritable() const noexcept final {
return true; }
775 [[nodiscard]]
size_t write(
const void* data,
size_t n)
final;
776 using IDataStream::write;
793 char* mBuffer =
nullptr;
805 int underflow() override;
818 char* mBuffer =
nullptr;
830 int underflow() override;
842 template<typename T, typename... Args> T binaryRead(
InputStream& stream, Args&&... args) {
847 template<
typename T,
typename S,
typename... Args>
T binaryRead(S& stream, Args&&... args) {
869 template<
typename T,
typename S,
typename... Args>
void binaryWrite(S& stream,
const T& value, Args&&... args) {
886 template<
typename S> [[nodiscard]]
static T read(S& stream) {
888 if(stream.read(&value,
sizeof(
T)) ==
sizeof(
T)) {
897 if(
co_await stream.read(&value,
sizeof(
T)) ==
sizeof(
T)) {
904 template<
typename S>
static void write(S& stream,
const T& value) {
905 if(stream.write(&value,
sizeof(
T)) ==
sizeof(
T))
912 if(
co_await stream.write(&value,
sizeof(
T)) ==
sizeof(
T))
923 template<
typename S,
typename... Args> [[nodiscard]]
static Type read(S& stream, Args&&... args) {
924 const UInt32 length = binaryRead<UInt32>(stream);
926 Type value(std::forward<Args>(args)...);
927 value.resize(length);
929 if(stream.read(&value, length *
sizeof(
T)) == length *
sizeof(
T)) {
937 const UInt32 length =
co_await binaryRead<UInt32>(stream);
939 Type value(std::forward<Args>(args)...);
940 value.resize(length);
942 if(
co_await stream.read(&value, length *
sizeof(
T)) == length *
sizeof(
T)) {
949 template<
typename S>
static void write(S& stream,
const Type& value) {
950 binaryWrite<UInt32>(stream,
UInt32(value.size()));
951 if(stream.write(value.data(), value.size() *
sizeof(
T)) == value.size() *
sizeof(
T)) {
952 return value.size() *
sizeof(
T);
959 co_await binaryWrite<UInt32>(stream,
UInt32(value.size()));
960 if(stream.write(value.data(), value.size() *
sizeof(
T)) == value.size() *
sizeof(
T)) {
961 co_return value.size() *
sizeof(
T);
974 binaryWrite<UInt32>(stream,
UInt32(value.size()));
975 if(stream.
write(value.data(), value.size() *
sizeof(
T)) == value.size() *
sizeof(
T)) {
995 template<
typename T,
typename... Args>
T read(Args&&... args) {
return binaryRead<T>(mInputStream, std::forward<Args>(args)...); }
1001 return read<T>(std::forward<Args>(args)...);
1008 [[nodiscard]]
size_t read(
void* data,
const size_t n) {
1010 return mInputStream->read(data, n);
1019 return mInputStream->isSeekable(mode);
1023 void seek(
const std::streamsize position,
const Seek mode = Seek::Start) {
1025 return mInputStream->seek(position, mode);
1031 return mInputStream->skip(n);
1037 return mInputStream->isTellable();
1043 return mInputStream->tell();
1049 return mInputStream->isSizeKnown();
1055 return mInputStream->size();
1078 template<
typename T,
typename... Args>
Async<T> read(Args&&... args) {
return asyncBinaryRead<T>(mInputStream, std::forward<Args>(args)...); }
1084 co_return read<T>(std::forward<Args>(args)...);
1093 return mInputStream->read(data, n);
1102 return mInputStream->isSeekable(mode);
1108 return mInputStream->seek(position, mode);
1114 return mInputStream->skip(n);
1120 return mInputStream->isTellable();
1126 return mInputStream->tell();
1132 return mInputStream->isSizeKnown();
1138 return mInputStream->size();
1161 template<
typename T,
typename... Args>
void write(
const T& value, Args&&... args) {
1162 return binaryWrite<T>(mOutputStream, value, std::forward<Args>(args)...);
1167 template<
typename T,
typename... Args>
bool tryWrite(
const T& value, Args&&... args) {
1169 write<T>(value, std::forward<Args>(args)...);
1177 [[nodiscard]]
size_t write(
const void* data,
const size_t n) {
1179 return mOutputStream->write(data, n);
1188 return mOutputStream->isSeekable(mode);
1192 void seek(
const std::streamsize position,
const Seek mode = Seek::Start) {
1194 return mOutputStream->seek(position, mode);
1200 return mOutputStream->skip(n);
1206 return mOutputStream->isTellable();
1212 return mOutputStream->tell();
1218 return mOutputStream->isSizeKnown();
1224 return mOutputStream->size();
1247 template<
typename T,
typename... Args>
Async<> write(
const T& value, Args&&... args) {
1248 return asyncBinaryWrite<T>(mOutputStream, value, std::forward<Args>(args)...);
1255 co_await write<T>(value, std::forward<Args>(args)...);
1265 return mOutputStream->write(data, n);
1274 return mOutputStream->isSeekable(mode);
1280 return mOutputStream->seek(position, mode);
1286 return mOutputStream->skip(n);
1292 return mOutputStream->isTellable();
1298 return mOutputStream->tell();
1304 return mOutputStream->isSizeKnown();
1310 return mOutputStream->size();
#define CE_EXCEPTION_DECL2(Name, Parent)
Definition Exception.hpp:100
#define CE_LIKELY
Definition Macros.hpp:396
#define CE_ASSERT(...)
Definition Macros.hpp:323
A reader that parses data from an underlying input stream as binary data.
Definition Stream.hpp:1067
bool isSizeKnown() const noexcept
Checks if the stream knows the size of the data.
Definition Stream.hpp:1130
Async seek(const std::streamsize position, const Seek mode=Seek::Start)
Changes the position of the data stream.
Definition Stream.hpp:1106
Async< size_t > tell()
Gets the absolute stream position, in bytes.
Definition Stream.hpp:1124
AsyncBinaryReader(AsyncInputStream inputStream)
Definition Stream.hpp:1073
Async skip(const size_t n)
Skips n bytes from the data stream.
Definition Stream.hpp:1112
AsyncInputStream mInputStream
The input stream to which data will be read from.
Definition Stream.hpp:1070
const AsyncInputStream & getInputStream() const
The input stream to which data will be read from.
Definition Stream.hpp:1146
Async< size_t > size()
Gets the number of bytes available on the stream.
Definition Stream.hpp:1136
Async< Optional< T > > tryRead(Args &&... args)
Tries to read a data type from the stream.
Definition Stream.hpp:1082
Async< size_t > read(void *data, const size_t n)
Reads data from the data stream to a buffer of raw memory data with length n.
Definition Stream.hpp:1091
Async< T > read(Args &&... args)
Reads a binary representation of T from the stream.
Definition Stream.hpp:1078
bool isTellable() const noexcept
Checks if the stream knows it's current absolute position.
Definition Stream.hpp:1118
bool isSeekable(const Seek mode=Seek::Start) const noexcept
Checks if the stream is seekable.
Definition Stream.hpp:1100
AsyncBinaryReader(IAsyncInputStream &inputStream)
Definition Stream.hpp:1074
AsyncInputStream & getInputStream()
The input stream to which data will be read from.
Definition Stream.hpp:1143
A writer that writes data to an underlying output stream as binary data.
Definition Stream.hpp:1236
Async< size_t > size()
Gets the number of bytes available on the stream.
Definition Stream.hpp:1308
bool isSizeKnown() const noexcept
Checks if the stream knows the size of the data.
Definition Stream.hpp:1302
bool isSeekable(const Seek mode=Seek::Start) const noexcept
Checks if the stream is seekable.
Definition Stream.hpp:1272
Async write(const T &value, Args &&... args)
Writes a binary representation of T to the stream.
Definition Stream.hpp:1247
AsyncBinaryWriter(AsyncOutputStream outputStream)
Definition Stream.hpp:1242
Async< size_t > write(const void *data, const size_t n)
Writes data to the data stream from a buffer of raw memory data with length n.
Definition Stream.hpp:1263
Async< bool > tryWrite(const T &value, Args &&... args)
Tries to write a data type to the stream.
Definition Stream.hpp:1253
AsyncOutputStream & getOutputStream()
The output stream to which data will be written to.
Definition Stream.hpp:1315
Async seek(const std::streamsize position, const Seek mode=Seek::Start)
Changes the position of the data stream.
Definition Stream.hpp:1278
const AsyncOutputStream & getOutputStream() const
The output stream to which data will be written to.
Definition Stream.hpp:1318
bool isTellable() const noexcept
Checks if the stream knows it's current absolute position.
Definition Stream.hpp:1290
Async skip(const size_t n)
Skips n bytes from the data stream.
Definition Stream.hpp:1284
AsyncBinaryWriter(IAsyncOutputStream &outputStream)
Definition Stream.hpp:1243
Async< size_t > tell()
Gets the absolute stream position, in bytes.
Definition Stream.hpp:1296
AsyncOutputStream mOutputStream
The output stream to which data will be written to.
Definition Stream.hpp:1239
An adapter stream that turns an AsyncDataStream into a DataStream.
Definition Stream.hpp:505
size_t size() final
Gets the number of bytes available on the stream.
AsyncDataStream mDataStream
Definition Stream.hpp:507
bool isTellable() const noexcept final
Checks if the stream knows it's current absolute position.
Definition Stream.hpp:527
AsyncDataStreamAdapter(AsyncDataStreamAdapter &&) noexcept=default
AsyncDataStreamAdapter(AsyncDataStream dataStream)
size_t write(const void *data, size_t n) final
Writes data to the data stream from a buffer of raw memory data with length n.
size_t read(void *data, size_t n) final
Reads data from the data stream to a buffer of raw memory data with length n.
void seek(std::streamsize position, Seek mode=Seek::Start) final
Changes the position of the data stream.
size_t tell() final
Gets the absolute stream position, in bytes.
bool isWritable() const noexcept final
Checks if the stream is writable.
Definition Stream.hpp:556
General purpose class used for encapsulating the reading and writing of data from and to various asyn...
Definition Stream.hpp:495
AsyncDataStream(DataStream dataStream, ExecutionContext &executionContext)
Definition Stream.hpp:446
Definition Stream.hpp:381
A reader that parses data from an underlying input stream as binary data.
Definition Stream.hpp:984
BinaryReader(IInputStream &inputStream)
Definition Stream.hpp:991
T read(Args &&... args)
Reads a binary representation of T from the stream.
Definition Stream.hpp:995
size_t tell()
Gets the absolute stream position, in bytes.
Definition Stream.hpp:1041
InputStream & getInputStream()
The input stream to which data will be read from.
Definition Stream.hpp:1060
void seek(const std::streamsize position, const Seek mode=Seek::Start)
Changes the position of the data stream.
Definition Stream.hpp:1023
void skip(const size_t n)
Skips n bytes from the data stream.
Definition Stream.hpp:1029
const InputStream & getInputStream() const
The input stream to which data will be read from.
Definition Stream.hpp:1063
size_t read(void *data, const size_t n)
Reads data from the data stream to a buffer of raw memory data with length n.
Definition Stream.hpp:1008
size_t size()
Gets the number of bytes available on the stream.
Definition Stream.hpp:1053
bool isTellable() const noexcept
Checks if the stream knows it's current absolute position.
Definition Stream.hpp:1035
BinaryReader(InputStream inputStream)
Definition Stream.hpp:990
InputStream mInputStream
The input stream to which data will be read from.
Definition Stream.hpp:987
bool isSizeKnown() const noexcept
Checks if the stream knows the size of the data.
Definition Stream.hpp:1047
bool isSeekable(const Seek mode=Seek::Start) const noexcept
Checks if the stream is seekable.
Definition Stream.hpp:1017
Optional< T > tryRead(Args &&... args)
Tries to read a data type from the stream.
Definition Stream.hpp:999
A writer that writes data to an underlying output stream as binary data.
Definition Stream.hpp:1150
void seek(const std::streamsize position, const Seek mode=Seek::Start)
Changes the position of the data stream.
Definition Stream.hpp:1192
bool tryWrite(const T &value, Args &&... args)
Tries to write a data type to the stream.
Definition Stream.hpp:1167
bool isSizeKnown() const noexcept
Checks if the stream knows the size of the data.
Definition Stream.hpp:1216
OutputStream & getOutputStream()
The output stream to which data will be written to.
Definition Stream.hpp:1229
size_t write(const void *data, const size_t n)
Writes data to the data stream from a buffer of raw memory data with length n.
Definition Stream.hpp:1177
OutputStream mOutputStream
The output stream to which data will be written to.
Definition Stream.hpp:1153
BinaryWriter(OutputStream outputStream)
Definition Stream.hpp:1156
void skip(const size_t n)
Skips n bytes from the data stream.
Definition Stream.hpp:1198
size_t tell()
Gets the absolute stream position, in bytes.
Definition Stream.hpp:1210
bool isSeekable(const Seek mode=Seek::Start) const noexcept
Checks if the stream is seekable.
Definition Stream.hpp:1186
void write(const T &value, Args &&... args)
Writes a binary representation of T to the stream.
Definition Stream.hpp:1161
BinaryWriter(IOutputStream &outputStream)
Definition Stream.hpp:1157
bool isTellable() const noexcept
Checks if the stream knows it's current absolute position.
Definition Stream.hpp:1204
const OutputStream & getOutputStream() const
The output stream to which data will be written to.
Definition Stream.hpp:1232
size_t size()
Gets the number of bytes available on the stream.
Definition Stream.hpp:1222
A streambuf implementation for a DataStream.
Definition Stream.hpp:784
DataStreamBuffer(DataStream dataStream, size_t bufferLength=1024)
Creates a new StreamBuffer.
DataStream mDataStream
The resource stream.
Definition Stream.hpp:787
~DataStreamBuffer() final
Releases the ResourceStream.
size_t mBufferLength
The length of the allocated buffer.
Definition Stream.hpp:790
General purpose class used for encapsulating the reading and writing of data from and to various sour...
Definition Stream.hpp:460
DataStream(const ByteMemoryView &buffer, bool freeOnClose=false)
Wrap an existing memory chunk in a stream.
DataStream(AsyncDataStream asyncDataStream)
DataStream(size_t size)
Allocates a new chunk of memory and wraps it in a stream.
static size_t copy(InputStream input, OutputStream output, size_t buffer=16 *1024)
Copies data by reading data from the input stream and writes it to output stream.
DataStream(const FilePath &path)
Creates a new file stream by opening the file at the given path.
A context for function object execution.
Definition ExecutionContext.hpp:90
A data stream that reads or writes data into a file.
Definition Stream.hpp:628
bool isTellable() const noexcept final
Checks if the stream knows it's current absolute position.
Definition Stream.hpp:668
size_t read(void *data, size_t n) final
Reads data from the data stream to a buffer of raw memory data with length n.
FileDataStream(const FileDataStream &other)
Creates a new file data stream by opening the same file as other.
size_t size() final
Gets the number of bytes available on the stream.
FilePath path
The path to the file open in the stream.
Definition Stream.hpp:631
~FileDataStream() final
Destroys the data stream and closes the file.
size_t tell() final
Gets the absolute stream position, in bytes.
FILE * getStream() const noexcept
The open stream descriptor.
Definition Stream.hpp:658
size_t write(const void *data, size_t n) final
Writes data to the data stream from a buffer of raw memory data with length n.
void seek(std::streamsize position, Seek mode=Seek::Start) final
Changes the position of the data stream.
FileDataStream(FileDataStream &&other) noexcept
Creates a new file data stream by moving the already open stream other.
FileDataStream(const FilePath &path, bool writing=false)
Creates a new file stream by opening the file at the given path.
bool isWritable() const noexcept final
Checks if the stream is writable.
Definition Stream.hpp:686
bool isSeekable(Seek mode=Seek::Start) const noexcept final
Checks if the stream is seekable.
Definition Stream.hpp:662
Path to file or directory.
Definition FilePath.hpp:37
An interface that all asynchronous data streams must implement.
Definition Stream.hpp:491
Definition Stream.hpp:417
virtual Async< size_t > write(const void *data, size_t n)
Writes data tp the data stream from a buffer of raw memory data with length n.
virtual Async< size_t > writeExactly(void *data, size_t n)
Similar to write(const void*, size_t), but ensures that the entire data buffer is written with exactl...
virtual bool isWritable() const noexcept
Checks if the stream is writable.
Definition Stream.hpp:421
Definition Stream.hpp:328
virtual Async seek(std::streamsize position, Seek mode=Seek::Start)
Changes the position of the data stream.
virtual Async< size_t > tell()
Gets the number of bytes available on the stream.
virtual ~IAsyncStream()=default
Default virtual destructor.
virtual bool isSizeKnown() const noexcept
Checks if the stream knows the size of the data.
Async skip(const size_t n)
Skips n bytes from the data stream.
Definition Stream.hpp:350
virtual bool isSeekable(Seek mode=Seek::Start) const noexcept
Checks if the stream is seekable.
Definition Stream.hpp:339
virtual bool isTellable() const noexcept
Checks if the stream knows the size of the data.
Definition Stream.hpp:357
An interface that all data streams must implement.
Definition Stream.hpp:456
Definition Exception.hpp:110
A stream that provides write-only stream functionality.
Definition Stream.hpp:233
size_t writeString(const StringView string)
Writes a string to the data stream.
Definition Stream.hpp:286
size_t write(const MemoryView< const T > &memoryView)
Writes data from a memory view to the stream.
Definition Stream.hpp:259
virtual size_t write(const void *data, size_t n)
Writes data to the data stream from a buffer of raw memory data with length n.
virtual bool flush()
In the stream is buffered, invalidates any buffered write data from to stream.
virtual bool isWritable() const noexcept
Checks if the stream is writable.
Definition Stream.hpp:237
bool write(T value)
Writes a trivially copyable object to the stream.
Definition Stream.hpp:293
size_t write(const StridedMemoryView< const T > &memoryView)
Writes data from a strided memory view to the stream.
Definition Stream.hpp:270
An interface that all data streams must implement.
Definition Stream.hpp:58
IStream(const IStream &) noexcept=delete
virtual size_t tell()
Gets the absolute stream position, in bytes.
void skip(const size_t n)
Skips n bytes from the data stream.
Definition Stream.hpp:91
virtual size_t size()
Gets the number of bytes available on the stream.
IStream & operator=(const IStream &) noexcept=delete
Seek
An enumeration that describes how a data stream should be seeked.
Definition Stream.hpp:72
virtual bool isSeekable(Seek mode=Seek::Start) const noexcept
Checks if the stream is seekable.
Definition Stream.hpp:80
IStream(IStream &&) noexcept=default
virtual bool isTellable() const noexcept
Checks if the stream knows it's current absolute position.
Definition Stream.hpp:98
virtual void seek(std::streamsize position, Seek mode=Seek::Start)
Changes the position of the data stream.
virtual bool isSizeKnown() const noexcept
Checks if the stream knows the size of the data.
A data stream that reads or writes data into a memory buffer.
Definition Stream.hpp:693
MemoryView< Byte > getData()
Gets a view to the underlying memory data.
Definition Stream.hpp:733
size_t size() final
Gets the number of bytes available on the stream.
Definition Stream.hpp:762
MemoryDataStream(const MemoryDataStream &)
MemoryDataStream()
Allocates a new empty memory data stream.
MemoryDataStream(const ByteMemoryView &buffer, bool freeOnClose=false)
Wrap an existing memory chunk in a stream.
MemoryDataStream(MemoryDataStream &&) noexcept
MemoryDataStream(Byte *memory, size_t size, bool freeOnClose=false)
Wrap an existing memory chunk in a stream.
bool isTellable() const noexcept final
Checks if the stream knows it's current absolute position.
Definition Stream.hpp:753
bool growIfNeeded(std::size_t desiredSize)
Grows the memory stream if needed.
MemoryDataStream(DataStream &stream)
Copies all contents of the existing data stream into a memory stream.
size_t tell() final
Gets the absolute stream position, in bytes.
Definition Stream.hpp:756
bool isReadable() const noexcept final
Checks if the stream is readable.
Definition Stream.hpp:765
ByteMemoryView mBuffer
Definition Stream.hpp:694
MemoryDataStream(size_t size)
Allocates a new chunk of memory and wraps it in a stream.
bool isSeekable(const Seek mode=Seek::Start) const noexcept final
Checks if the stream is seekable.
Definition Stream.hpp:740
size_t write(const void *data, size_t n) final
Writes data to the data stream from a buffer of raw memory data with length n.
bool isSizeKnown() const noexcept final
Checks if the stream knows the size of the data.
Definition Stream.hpp:759
void seek(std::streamsize position, Seek mode=Seek::Start) final
Changes the position of the data stream.
bool isGrowable() const
Determines if write or seek calls can grow the underlying memory buffer.
Definition Stream.hpp:736
bool isWritable() const noexcept final
Checks if the stream is writable.
Definition Stream.hpp:772
size_t read(void *data, size_t n) final
Reads data from the data stream to a buffer of raw memory data with length n.
A memory view is a class which attaches to an chunk of memory and provides a view to it (optionally c...
Definition MemoryView.hpp:62
SizeType size() const noexcept
Gets the size of the view as number of elements.
Definition MemoryView.hpp:294
MemoryView< T > slice(SizeType offset, SizeType length=~0ul) const noexcept
Slices the memory view by taking the element that starts at offset and returns a new view with the gi...
Definition MemoryView.hpp:145
ConstPointer data() const noexcept
Gets a pointer to the first element in the view.
Definition MemoryView.hpp:227
Definition Optional.hpp:17
A stream that provides write-only stream functionality.
Definition Stream.hpp:307
OutputStream(const ByteMemoryView &buffer, bool freeOnClose=false)
Wrap an existing memory chunk in a stream.
OutputStream(const FilePath &path)
Creates a new file stream by opening the file at the given path.
A pointer type that has value semantics.
Definition Poly.hpp:57
friend class Poly
Definition Poly.hpp:58
An interface that all data streams must implement.
Definition Stream.hpp:116
A memory view is a class which attaches to an chunk of memory and provides a view to it (optionally c...
Definition MemoryView.hpp:439
An adapter stream that turns an DataStream into an AsyncDataStream.
Definition Stream.hpp:566
bool isSeekable(const Seek mode=Seek::Start) const noexcept final
Checks if the stream is seekable.
Definition Stream.hpp:576
DataStream mDataStream
Definition Stream.hpp:568
bool isTellable() const noexcept final
Checks if the stream knows the size of the data.
Definition Stream.hpp:585
SyncDataStreamAdapter(DataStream dataStream, ExecutionContext &executionContext)
ExecutionContext & mExecutionContext
Definition Stream.hpp:569
Async wait() final
Waits until all pending operations on the stream are complete.
Async< size_t > size() final
Gets the number of bytes available on the stream.
Async< size_t > tell() final
Gets the number of bytes available on the stream.
bool isWritable() const noexcept final
Checks if the stream is writable.
Definition Stream.hpp:614
Async seek(std::streamsize position, Seek mode=Seek::Start) final
Changes the position of the data stream.
Async< size_t > read(void *data, size_t n) final
Reads data from the data stream to a buffer of raw memory data with length n.
Async< size_t > write(const void *data, size_t n) final
Writes data tp the data stream from a buffer of raw memory data with length n.
Definition Application.hpp:19
Byte
Definition DataTypes.hpp:40
Async asyncBinaryWrite(AsyncOutputStream &stream, const T &value, Args &&... args)
Definition Stream.hpp:874
constexpr std::size_t kStreamPolySize
The size used by Stream and other polymorphic types for small object optimization.
Definition Stream.hpp:42
cti::continuable< Args... > Async
Defines a non-copyable continuation type which uses the function2 backend for type erasure.
Definition Async.hpp:22
auto move(Vector3 position)
Moves a entity to the given position.
Definition Helpers.hpp:22
Async< T > asyncBinaryRead(AsyncInputStream &stream, Args &&... args)
Definition Stream.hpp:852
void binaryWrite(OutputStream &stream, const T &value, Args &&... args)
Writes a binary representation of T to the stream.
Definition Stream.hpp:864
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
T binaryRead(InputStream &stream, Args &&... args)
Reads a binary representation of T from the stream.
Definition Stream.hpp:842
static Async< Type > asyncRead(S &stream, Args &&... args)
Definition Stream.hpp:936
static Async asyncWrite(S &stream, const Type &value)
Definition Stream.hpp:958
static void write(S &stream, const Type &value)
Definition Stream.hpp:949
static Type read(S &stream, Args &&... args)
Definition Stream.hpp:923
static void write(IOutputStream &stream, const Type &value)
Definition Stream.hpp:973
static T read(S &stream)
Definition Stream.hpp:886
static void write(S &stream, const T &value)
Definition Stream.hpp:904
static Async asyncWrite(S &stream, T value)
Definition Stream.hpp:911
static Async< T > asyncRead(S &stream)
Definition Stream.hpp:895
A class that can be specialized to implement support for custom binary serialization of a type.
Definition Stream.hpp:837