AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
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
51 size_t read(std::span<std::byte> destination) {
52 return read((char*)destination.data(), destination.size());
53 }
54
65 void readExact(char* dst, size_t size) {
66 char* begin = dst;
67 char* end = dst + size;
68 while (begin != end) {
69 size_t r = read(begin, end - begin);
70 if (r == 0) {
71 throw AEOFException();
72 }
73 begin += r;
74 }
75 }
76
81 template<typename T>
82 T deserialize();
83
88 template<typename T>
89 IInputStream& operator>>(T& dst);
94 template<typename T>
95 IInputStream& operator>>(T&& dst);
96};
97
98#include <AUI/Traits/serializable.h>
99
100template<typename T>
102 return aui::deserialize<T>(*this);
103}
104
105template<typename T>
107 aui::deserialize<T>(*this, dst);
108 return *this;
109}
110
111template<typename T>
113 aui::deserialize<T>(*this, dst);
114 return *this;
115}
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:106
void readExact(char *dst, size_t size)
Reads exact size bytes from stream. Blocking (waiting for new data) is allowed.
Definition IInputStream.h:65
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:101
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:51
Definition IOutputStream.h:18