AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
IInputStream.h
1/*
2 * AUI Framework - Declarative UI toolkit for modern C++20
3 * Copyright (C) 2020-2024 Alex2772 and Contributors
4 *
5 * SPDX-License-Identifier: MPL-2.0
6 *
7 * This Source Code Form is subject to the terms of the Mozilla Public
8 * License, v. 2.0. If a copy of the MPL was not distributed with this
9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 */
11
12#pragma once
13
14#include <span>
15#include "AEOFException.h"
16#include <AUI/Traits/values.h>
17#include <glm/glm.hpp>
18
19class IOutputStream;
20
26{
27public:
28 virtual ~IInputStream() = default;
29
40 virtual size_t read(char* dst, size_t size) = 0;
41
52 size_t read(std::span<std::byte> destination) {
53 return read((char*)destination.data(), destination.size());
54 }
55
66 void readExact(char* dst, size_t size) {
67 char* begin = dst;
68 char* end = dst + size;
69 while (begin != end) {
70 size_t r = read(begin, end - begin);
71 if (r == 0) {
72 throw AEOFException();
73 }
74 begin += r;
75 }
76 }
77
82 template<typename T>
83 T deserialize();
84
89 template<typename T>
90 IInputStream& operator>>(T& dst);
95 template<typename T>
96 IInputStream& operator>>(T&& dst);
97};
98
99#include <AUI/Traits/serializable.h>
100
101template<typename T>
103 return aui::deserialize<T>(*this);
104}
105
106template<typename T>
108 aui::deserialize<T>(*this, dst);
109 return *this;
110}
111
112template<typename T>
114 aui::deserialize<T>(*this, dst);
115 return *this;
116}
Thrown when stream has reached end (end of file).
Definition: AEOFException.h:20
Represents an input stream.
Definition: IInputStream.h:26
IInputStream & operator>>(T &dst)
Definition: IInputStream.h:107
void readExact(char *dst, size_t size)
Reads exact size bytes from stream. Blocking (waiting for new data) is allowed.
Definition: IInputStream.h:66
virtual size_t read(char *dst, size_t size)=0
Reads up to size bytes from stream. Blocking (waiting for new data) is allowed.
T deserialize()
Definition: IInputStream.h:102
size_t read(std::span< std::byte > destination)
Reads up to destination.size() bytes from stream. Blocking (waiting for new data) is allowed.
Definition: IInputStream.h:52
Definition: IOutputStream.h:20