xtd - Reference Guide 0.2.0
stream_writer.h
Go to the documentation of this file.
1 #pragma once
5 
6 #include <fstream>
7 #include <optional>
8 #include "text_writer.h"
9 
11 namespace xtd {
13  namespace io {
25  class core_export_ stream_writer : public xtd::io::text_writer {
26  public:
28 
34  explicit stream_writer(const xtd::ustring& path);
37  explicit stream_writer(std::ostream& stream);
43  stream_writer(const xtd::ustring& path, bool append);
46  stream_writer(std::ostream& stream, bool append);
49  stream_writer(const stream_writer&) = delete;
50  stream_writer& operator=(const stream_writer&) = delete;
51  ~stream_writer();
53 
55 
63  bool auto_flush() const;
70  void auto_flush(bool auto_flush);
71 
74  std::optional<std::reference_wrapper<std::ostream>> base_stream() const;
76 
78 
81  void close() override;
82 
85  void flush() override;
86 
87  using text_writer::write;
91  void write(const xtd::ustring& value) override;
93 
94  private:
95  std::ostream* stream_ = nullptr;
96  bool auto_flush_ = false;
97  bool delete_when_destroy_ = false;
98  };
99  }
100 }
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:50
Represents a writer that can write a sequential series of characters.
Definition: text_writer.h:34
Performs operations on std::basic_string instances that contain file or directory path information...
Definition: path.h:32
Implements a xtd::io::text_writer for writing characters to a stream.
Definition: stream_writer.h:25
virtual void write(const xtd::ustring &value)
Writes the specified string value to the text stream.
Contains xtd::io::text_writer class.
Write access to the file. Data can be written to the file. Combine with Read for read/write access...