xtd 0.2.0
stream_writer.h
Go to the documentation of this file.
1 #pragma once
5 #include "text_writer.h"
6 #include "../optional.h"
7 #include <fstream>
8 
10 namespace xtd {
12  namespace io {
26  class core_export_ stream_writer : public xtd::io::text_writer {
27  public:
29 
35  explicit stream_writer(const xtd::ustring& path);
38  explicit stream_writer(std::ostream& stream);
44  stream_writer(const xtd::ustring& path, bool append);
47  stream_writer(std::ostream& stream, bool append);
50  stream_writer(const stream_writer&) = delete;
51  stream_writer& operator =(const stream_writer&) = delete;
52  ~stream_writer();
54 
56 
64  bool auto_flush() const;
71  void auto_flush(bool auto_flush);
72 
75  std::optional<std::reference_wrapper<std::ostream>> base_stream() const;
77 
79 
82  void close() override;
83 
86  void flush() override;
87 
88  using text_writer::write;
92  void write(const xtd::ustring& value) override;
94 
95  private:
96  std::ostream* stream_ = nullptr;
97  bool auto_flush_ = false;
98  bool delete_when_destroy_ = false;
99  };
100  }
101 }
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:46
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:34
Implements a xtd::io::text_writer for writing characters to a stream.
Definition: stream_writer.h:26
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...