xtd - Reference Guide 0.2.0
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 
34  class core_export_ text_writer : public xtd::object {
35  public:
37 
42  static null_text_writer& null() noexcept;
44 
46 
49  const xtd::ustring& new_line() const noexcept;
51  void new_line(const xtd::ustring& new_line) noexcept;
53 
55 
58  virtual void close();
59 
62  virtual void flush();
63 
67  static synchronized_text_writer synchronised(text_writer& writer) noexcept;
68 
72  virtual void write(const xtd::ustring& value);
73 
77  void write(bool value);
78 
82  void write(double value);
83 
87  void write(float value);
88 
92  void write(int8_t value);
93 
97  void write(int16_t value);
98 
102  void write(int32_t value);
103 
107  void write(int64_t value);
108 
112  void write(uint8_t value);
113 
117  void write(uint16_t value);
118 
122  void write(uint32_t value);
123 
127  void write(uint64_t value);
128 
133  template<typename value_t>
134  void write(value_t value) {write(xtd::ustring::format("{}", value));}
135 
140  template<typename ... args_t>
141  void write(const xtd::ustring& fmt, args_t&& ... args) noexcept {write(xtd::ustring::format(fmt, std::forward<args_t>(args)...));}
142 
145  void write_line();
146 
150  void write_line(const xtd::ustring& value);
151 
155  void write_line(bool value);
156 
160  void write_line(double value);
161 
165  void write_line(float value);
166 
170  void write_line(int8_t value);
171 
175  void write_line(int16_t value);
176 
180  void write_line(int32_t value);
181 
185  void write_line(int64_t value);
186 
190  void write_line(uint8_t value);
191 
195  void write_line(uint16_t value);
196 
200  void write_line(uint32_t value);
201 
205  void write_line(uint64_t value);
206 
211  template<typename value_t>
212  void write_line(value_t value) {write_line(xtd::ustring::format("{}", value));}
213 
218  template<typename ... args_t>
219  void write_line(const xtd::ustring& fmt, args_t&& ... args) noexcept {write_line(xtd::ustring::format(fmt, std::forward<args_t>(args)...));}
221 
222  protected:
224 
227  text_writer() = default;
229 
230  private:
231  xtd::ustring new_line_ = "\n";
232  };
233 
245  class core_export_ null_text_writer : public xtd::io::text_writer {
246  public:
247  void write(const xtd::ustring&) override;
248  };
249 
261  class core_export_ synchronized_text_writer : public xtd::io::text_writer {
262  public:
263  void write(const xtd::ustring& value) override ;
264 
265  private:
266  friend class text_writer;
268  synchronized_text_writer() = delete;
269  xtd::io::text_writer& writer_;
270  std::mutex mutex_;
271  };
272  }
273 }
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:141
Represents a null text writer.
Definition: text_writer.h:245
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
void write(value_t value)
Writes the specified value_t value to the text stream.
Definition: text_writer.h:134
std::nullptr_t null
Represents a null pointer value.
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:219
Represents a writer that can write a sequential series of characters.
Definition: text_writer.h:34
void write_line(value_t value)
Writes the specified value_t value and new line to the text stream.
Definition: text_writer.h:212
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:30
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:708
Write access to the file. Data can be written to the file. Combine with Read for read/write access...
Represents a synchronized text writer.
Definition: text_writer.h:261