17 class OutputStreamInternal {
21 virtual std::ostream& stream() = 0;
23 virtual std::streampos tellp() {
24 return stream().tellp();
28 class Memory:
public Variant {
29 BackInsertStream m_stream;
31 friend class OutputStreamInternal;
33 inline Memory(BackInsertStream&& stream): m_stream(stream) {}
35 inline std::ostream& stream()
override {
36 return m_stream.stream();
39 inline Memory(Memory&& other):
40 m_stream(
std::move(other.m_stream)) {}
42 inline Memory(
const Memory& other) =
delete;
43 inline Memory() =
delete;
45 virtual std::streampos tellp()
override {
46 return m_stream.size();
49 class Stream:
public Variant {
50 std::ostream* m_stream;
52 friend class OutputStreamInternal;
54 inline Stream(std::ostream* stream): m_stream(stream) {}
56 inline std::ostream& stream()
override {
60 inline Stream(Stream&& other):
61 m_stream(
std::move(other.m_stream)) {}
63 inline Stream(
const Stream& other) =
delete;
64 inline Stream() =
delete;
66 class File:
public Variant {
68 std::unique_ptr<std::ofstream> m_stream;
71 friend class OutputStreamInternal;
73 inline File(std::string&& path,
bool overwrite =
false) {
76 m_stream = std::make_unique<std::ofstream>(m_path,
77 std::ios::out | std::ios::binary);
79 m_stream = std::make_unique<std::ofstream>(m_path,
80 std::ios::out | std::ios::binary | std::ios::app);
83 throw tdc_output_file_not_found_error(m_path);
87 inline File(File&& other):
88 m_path(
std::move(other.m_path)),
89 m_stream(
std::move(other.m_stream)) {}
91 inline std::ostream& stream()
override {
95 inline File(
const File& other) =
delete;
96 inline File() =
delete;
99 std::unique_ptr<Variant> m_variant;
100 std::unique_ptr<RestrictedOStreamBuf> m_restricted_ostream;
103 friend class OutputStream;
105 inline OutputStreamInternal(
const OutputStreamInternal& other) =
delete;
106 inline OutputStreamInternal() =
delete;
108 inline OutputStreamInternal(OutputStreamInternal::Memory&& mem,
109 const InputRestrictions& restrictions):
110 m_variant(
std::make_unique<Memory>(
std::move(mem)))
112 if (!restrictions.has_no_restrictions()) {
113 m_restricted_ostream = std::make_unique<RestrictedOStreamBuf>(
119 inline OutputStreamInternal(OutputStreamInternal::File&& s,
120 const InputRestrictions& restrictions):
121 m_variant(
std::make_unique<File>(
std::move(s)))
123 if (!restrictions.has_no_restrictions()) {
124 m_restricted_ostream = std::make_unique<RestrictedOStreamBuf>(
130 inline OutputStreamInternal(OutputStreamInternal::Stream&& s,
131 const InputRestrictions& restrictions):
132 m_variant(
std::make_unique<Stream>(
std::move(s)))
134 if (!restrictions.has_no_restrictions()) {
135 m_restricted_ostream = std::make_unique<RestrictedOStreamBuf>(
142 inline OutputStreamInternal(OutputStreamInternal&& other):
143 m_variant(
std::move(other.m_variant)),
144 m_restricted_ostream(
std::move(other.m_restricted_ostream)) {}
146 inline std::streambuf* internal_rdbuf() {
147 if (m_restricted_ostream) {
148 return &*m_restricted_ostream;
150 return m_variant->stream().rdbuf();
154 inline std::streampos tellp() {
155 return m_variant->tellp();
165 OutputStreamInternal(
std::move(mem)),
166 std::ostream(OutputStreamInternal::internal_rdbuf()) {
171 OutputStreamInternal(
std::move(mem)),
172 std::ostream(mem.rdbuf()) {}
181 return OutputStreamInternal::tellp();
187 OutputStreamInternal {
188 OutputStream::Memory {
189 BackInsertStream { *m_buffer }
199 auto overwrite = m_overwrite;
202 OutputStreamInternal {
214 OutputStreamInternal {
215 OutputStream::Stream {
224 return m_data->as_stream();
Contains the text compression and encoding framework.
Provides a character stream to the underlying output.
OutputStream as_stream() const
Creates a stream that allows for character-wise output.
An abstraction layer for algorithm output.
OutputStream(OutputStream &&mem)
Move constructor.
io::Output Output
Convenience shortcut to io::Output.