Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
StdInputStream.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <utility>
7#include <istream>
8#include <memory>
9#include <string>
10
11namespace ph
12{
13
15{
16public:
17 inline StdInputStream() = default;
18 explicit StdInputStream(std::unique_ptr<std::istream> stream);
19 StdInputStream(StdInputStream&& other) noexcept;
20
21 void read(std::size_t numBytes, std::byte* out_bytes) override;
22 void readString(std::string* out_string, char delimiter) override;
23 void seekGet(std::size_t pos) override;
24 std::optional<std::size_t> tellGet() override;
25 operator bool () const override;
26 std::size_t readSome(std::size_t numBytes, std::byte* out_bytes) override;
27
28 std::istream* getStream() const;
29
31
32protected:
33 bool isStreamGoodForRead() const;
34
38 void ensureStreamIsGoodForRead() const;
39
42 std::string getReasonForError() const;
43
44private:
45 std::unique_ptr<std::istream> m_istream;
46};
47
48// In-header Implementations:
49
51{
52 *this = std::move(other);
53}
54
56{
57 m_istream = std::move(rhs.m_istream);
58 return *this;
59}
60
61inline StdInputStream::operator bool () const
62{
63 return isStreamGoodForRead();
64}
65
66inline std::istream* StdInputStream::getStream() const
67{
68 return m_istream.get();
69}
70
72{
73 return m_istream != nullptr && m_istream->good();
74}
75
76}// end namespace ph
Definition IInputStream.h:13
Definition StdInputStream.h:15
std::size_t readSome(std::size_t numBytes, std::byte *out_bytes) override
Read some data in the form of raw bytes. The method may return before finish reading all bytes....
Definition StdInputStream.cpp:77
bool isStreamGoodForRead() const
Definition StdInputStream.h:71
void seekGet(std::size_t pos) override
Set the input position of the stream. The unit of the position is defined by the implementation.
Definition StdInputStream.cpp:104
StdInputStream & operator=(StdInputStream &&rhs) noexcept
Definition StdInputStream.h:55
void ensureStreamIsGoodForRead() const
Check if the stream has any error.
Definition StdInputStream.cpp:134
StdInputStream()=default
void readString(std::string *out_string, char delimiter) override
Read a string in one go. Note the EOF is also considered a delimiter (the final one).
Definition StdInputStream.cpp:56
void read(std::size_t numBytes, std::byte *out_bytes) override
Read specific number of raw bytes in one go. The method does not return before finishing the reading ...
Definition StdInputStream.cpp:37
std::optional< std::size_t > tellGet() override
Get the current input position of the stream. The unit of the position is defined by the implementati...
Definition StdInputStream.cpp:120
std::string getReasonForError() const
A description for why the stream is not in a good state.
Definition StdInputStream.cpp:142
std::istream * getStream() const
Definition StdInputStream.h:66
The root for all renderer implementations.
Definition EEngineProject.h:6