Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
StdOutputStream.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <utility>
7#include <memory>
8#include <ostream>
9#include <string>
10
11namespace ph
12{
13
15{
16public:
17 StdOutputStream() = default;
18 explicit StdOutputStream(std::unique_ptr<std::ostream> stream);
19 StdOutputStream(StdOutputStream&& other) noexcept;
20
21 void write(std::size_t numBytes, const std::byte* bytes) override;
22 void writeString(std::string_view str) override;
23 void seekPut(std::size_t pos) override;
24 std::optional<std::size_t> tellPut() override;
25 operator bool () const override;
26
27 std::ostream* getStream() const;
28
30
31protected:
32 bool isStreamGoodForWrite() const;
33
37 void ensureStreamIsGoodForWrite() const;
38
41 std::string getReasonForError() const;
42
43private:
44 std::unique_ptr<std::ostream> m_ostream;
45};
46
47// In-header Implementations:
48
50{
51 *this = std::move(other);
52}
53
55{
56 m_ostream = std::move(rhs.m_ostream);
57 return *this;
58}
59
60inline StdOutputStream::operator bool () const
61{
62 return isStreamGoodForWrite();
63}
64
65inline std::ostream* StdOutputStream::getStream() const
66{
67 return m_ostream.get();
68}
69
71{
72 return m_ostream != nullptr && m_ostream->good();
73}
74
75}// end namespace ph
Definition IOutputStream.h:13
Definition StdOutputStream.h:15
StdOutputStream & operator=(StdOutputStream &&rhs) noexcept
Definition StdOutputStream.h:54
StdOutputStream()=default
std::string getReasonForError() const
A description for why the stream is not in a good state.
Definition StdOutputStream.cpp:98
void write(std::size_t numBytes, const std::byte *bytes) override
Write data in the form of raw bytes in one go. The method does not return before finishing the writin...
Definition StdOutputStream.cpp:26
std::optional< std::size_t > tellPut() override
Get the current output position of the stream. The unit of the position is defined by the implementat...
Definition StdOutputStream.cpp:76
void writeString(std::string_view str) override
Write a string in one go.
Definition StdOutputStream.cpp:44
void seekPut(std::size_t pos) override
Set the output position of the stream. The unit of the position is defined by the implementation.
Definition StdOutputStream.cpp:60
bool isStreamGoodForWrite() const
Definition StdOutputStream.h:70
void ensureStreamIsGoodForWrite() const
Check if the stream has any error.
Definition StdOutputStream.cpp:90
std::ostream * getStream() const
Definition StdOutputStream.h:65
The root for all renderer implementations.
Definition EEngineProject.h:6