xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
text_writer.h
Go to the documentation of this file.
1 #pragma once
5 
6 #include <cstdio>
7 #include <istream>
8 #include <mutex>
9 #include <string>
10 #include "../core_export.h"
11 #include "../object.h"
12 #include "../ustring.h"
13 
15 namespace xtd {
17  namespace io {
19  class null_text_writer;
20  class synchronized_text_writer;
22 
29  class core_export_ text_writer : public object {
30  public:
32  const xtd::ustring& new_line() const noexcept;
34  void new_line(const xtd::ustring& new_line) noexcept;
35 
39  static null_text_writer& null() noexcept;
40 
42  virtual void close();
43 
46  virtual void flush();
47 
51  static synchronized_text_writer synchronised(text_writer& writer) noexcept;
52 
56  virtual void write(const xtd::ustring& value);
57 
61  void write(bool value);
62 
66  void write(double value);
67 
71  void write(float value);
72 
76  void write(int8_t value);
77 
81  void write(int16_t value);
82 
86  void write(int32_t value);
87 
91  void write(int64_t value);
92 
96  void write(uint8_t value);
97 
101  void write(uint16_t value);
102 
106  void write(uint32_t value);
107 
111  void write(uint64_t value);
112 
117  template<typename value_t>
118  void write(value_t value) {write(xtd::ustring::format("{}", value));}
119 
124  template<typename ... args_t>
125  void write(const xtd::ustring& fmt, args_t&& ... args) noexcept {write(xtd::ustring::format(fmt, std::forward<args_t>(args)...));}
126 
129  void write_line();
130 
134  void write_line(const xtd::ustring& value);
135 
139  void write_line(bool value);
140 
144  void write_line(double value);
145 
149  void write_line(float value);
150 
154  void write_line(int8_t value);
155 
159  void write_line(int16_t value);
160 
164  void write_line(int32_t value);
165 
169  void write_line(int64_t value);
170 
174  void write_line(uint8_t value);
175 
179  void write_line(uint16_t value);
180 
184  void write_line(uint32_t value);
185 
189  void write_line(uint64_t value);
190 
195  template<typename value_t>
196  void write_line(value_t value) {write_line(xtd::ustring::format("{}", value));}
197 
202  template<typename ... args_t>
203  void write_line(const xtd::ustring& fmt, args_t&& ... args) noexcept {write_line(xtd::ustring::format(fmt, std::forward<args_t>(args)...));}
204 
205  protected:
207  text_writer() = default;
208  xtd::ustring new_line_ = "\n";
209  };
210 
215  class null_text_writer : public text_writer {
216  public:
217  void write(const xtd::ustring&) override;
218  };
219 
225  public:
226  void write(const xtd::ustring& value) override ;
227 
228  private:
229  friend class text_writer;
231  synchronized_text_writer() = delete;
232  xtd::io::text_writer& writer_;
233  std::mutex mutex_;
234  };
235  }
236 }
Represents a null text writer.
Definition: text_writer.h:215
void write(const xtd::ustring &) override
Writes the specified string value to the text stream.
Represents a synchronized text writer.
Definition: text_writer.h:224
void write(const xtd::ustring &value) override
Writes the specified string value to the text stream.
Represents a writer that can write a sequential series of characters.
Definition: text_writer.h:29
void write(value_t value)
Writes the specified value_t value to the text stream.
Definition: text_writer.h:118
const xtd::ustring & new_line() const noexcept
Gets the line terminator string used by the current text_writer.
void write_line(uint16_t value)
Writes the specified uint16_t value and new line to the text stream.
void write_line(double value)
Writes the specified double value and new line to the text stream.
void write_line(int32_t value)
Writes the specified int32_t value and new line to the text stream.
void write_line(uint64_t value)
Writes the specified uint64_t value and new line to the text stream.
void write_line(int8_t value)
Writes the specified int8_t value and new line to the text stream.
void write_line(const xtd::ustring &fmt, args_t &&... args) noexcept
Writes the specified arguments with specified format to the text stream.
Definition: text_writer.h:203
void write_line(const xtd::ustring &value)
Writes the specified string value and new line to the text stream.
text_writer()=default
Initializes a new instance of the xtd::io::text_writer class.
void write_line(value_t value)
Writes the specified value_t value and new line to the text stream.
Definition: text_writer.h:196
void write_line(int16_t value)
Writes the specified int16_t value and new line to the text stream.
void write(const xtd::ustring &fmt, args_t &&... args) noexcept
Writes the specified arguments with specified format to the text stream.
Definition: text_writer.h:125
void write_line(float value)
Writes the specified float value and new line to the text stream.
void write_line(bool value)
Writes the specified bool value and new line to the text stream.
void write_line(uint8_t value)
Writes the specified uint8_t value and new line to the text stream.
void write_line(uint32_t value)
Writes the specified uint32_t value and new line to the text stream.
void write_line(int64_t value)
Writes the specified int64_t value and new line to the text stream.
void write_line()
Writes new line to the text stream.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition: object.h:26
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:689
#define core_export_
Define shared library export.
Definition: core_export.h:13
std::nullptr_t null
Represents a null pointer value.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17