xtd 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(sbyte value);
93 
97  void write(int16 value);
98 
102  void write(int32 value);
103 
107  void write(int64 value);
108 
112  void write(xtd::byte value);
113 
117  void write(uint16 value);
118 
122  void write(uint32 value);
123 
127  void write(uint64 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(sbyte value);
171 
175  void write_line(int16 value);
176 
180  void write_line(int32 value);
181 
185  void write_line(int64 value);
186 
190  void write_line(xtd::byte value);
191 
195  void write_line(uint16 value);
196 
200  void write_line(uint32 value);
201 
205  void write_line(uint64 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
int_least8_t sbyte
Represents a 8-bit signed integer.
Definition: types.h:112
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
uint_least16_t uint16
Represents a 16-bit unsigned integer.
Definition: types.h:144
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
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
int_least16_t int16
Represents a 16-bit signed integer.
Definition: types.h:66
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:31
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:74
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:701
uint_least64_t uint64
Represents a 64-bit unsigned integer.
Definition: types.h:160
int_least64_t int64
Represents a 64-bit signed integer.
Definition: types.h:82
uint_least8_t byte
Represents a 8-bit unsigned integer.
Definition: types.h:26
uint_least32_t uint32
Represents a 32-bit unsigned integer.
Definition: types.h:152
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