AUI Framework  master
Cross-platform module-based framework for developing C++20 desktop applications
AFileInputStream.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#include <cstdio>
14#include "AUI/Core.h"
15#include "IInputStream.h"
16
17class AString;
18
23class API_AUI_CORE AFileInputStream: public IInputStream
24{
25private:
26 FILE* mFile = nullptr;
27
28public:
29 AFileInputStream(const AString& path);
30 virtual ~AFileInputStream();
31
32 AFileInputStream(AFileInputStream&& rhs) noexcept {
33 operator=(std::move(rhs));
34 }
35 AFileInputStream& operator=(AFileInputStream&& rhs) noexcept {
36 mFile = rhs.mFile;
37 rhs.mFile = nullptr;
38 return *this;
39 }
40
41 FILE* nativeHandle() const {
42 return mFile;
43 }
44
45 enum class Seek {
49 BEGIN,
50
54 CURRENT,
55
59 END
60 };
61
62 void seek(std::streamoff offset, Seek dir) noexcept;
63 void seek(std::streampos pos) noexcept;
64 std::streampos tell() noexcept;
65
66 std::size_t size() noexcept {
67 auto current = tell();
68 seek(0, Seek::END);
69 auto size = tell();
70 seek(current, Seek::BEGIN);
71 return size;
72 }
73
74 std::size_t read(char* dst, size_t size) override;
75};
Opens a file for a binary read.
Definition: AFileInputStream.h:24
Seek
Definition: AFileInputStream.h:45
Represents a Unicode character string.
Definition: AString.h:37
Represents an input stream.
Definition: IInputStream.h:26
virtual size_t read(char *dst, size_t size)=0
Reads up to size bytes from stream. Blocking (waiting for new data) is allowed.