Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
FormattedTextOutputStream.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <string>
7#include <string_view>
8#include <format>
9#include <utility>
10
11namespace ph
12{
13
17{
18public:
19 inline FormattedTextOutputStream() = default;
20
24 explicit FormattedTextOutputStream(const Path& filePath);
25
29 explicit FormattedTextOutputStream(std::string initialStrContent);
30
32
33 std::string acquireName() const override;
34
38 void writeChar(char ch);
39
42 void writeNewLine();
43
45
50 template<typename... Args>
51 void writeString(std::format_string<Args...> strFormat, Args&&... args);
52
56 std::string getString() const;
57
59
60private:
61 std::string m_streamName;
62
63 // Unlike text input stream where input data can be pre-stored within the stream object and be
64 // accessed polymorphically, text output stream would need separate interface for accessing the
65 // output data. Using this flag so we can support string stream without introducing an extra class.
66 bool m_isStringStream;
67};
68
69// In-header Implementations:
70
71template<typename... Args>
72inline void FormattedTextOutputStream::writeString(const std::format_string<Args...> strFormat, Args&&... args)
73{
74 // Intentionally not forwarding to `std::make_format_args` due to P2905R2
76 std::vformat(strFormat.get(), std::make_format_args(args...)));
77}
78
79}// end namespace ph
Write text with basic auto formatting applied.
Definition FormattedTextOutputStream.h:17
void writeNewLine()
Write newline to the stream.
Definition FormattedTextOutputStream.cpp:32
FormattedTextOutputStream(FormattedTextOutputStream &&other)=default
FormattedTextOutputStream & operator=(FormattedTextOutputStream &&rhs)=default
std::string getString() const
Get the string that was written.
Definition FormattedTextOutputStream.cpp:53
void writeString(std::format_string< Args... > strFormat, Args &&... args)
Write formatted string to the stream.
Definition FormattedTextOutputStream.h:72
std::string acquireName() const override
Access to the stream's name. This method is not meant to be used in a high performance context,...
Definition FormattedTextOutputStream.cpp:75
void writeChar(char ch)
Write a single char to the stream.
Definition FormattedTextOutputStream.cpp:37
General path representation. Does not check whether the target actually exists (e....
Definition Path.h:21
Definition StdOutputStream.h:15
void writeString(std::string_view str) override
Write a string in one go.
Definition StdOutputStream.cpp:44
The root for all renderer implementations.
Definition EEngineProject.h:6