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_reader.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_reader;
20  class synchronized_text_reader;
22 
29  class core_export_ text_reader : public object {
30  public:
36  static null_text_reader& null() noexcept;
37 
39  virtual void close();
40 
43  virtual int32_t peek() const;
44 
47  virtual int32_t read();
48 
54  virtual size_t read(std::vector<char>& buffer, size_t index, size_t count);
55 
61  virtual size_t read_block(std::vector<char>& buffer, size_t index, size_t count);
62 
66 
71 
76 
77  protected:
79  text_reader() = default;
80  };
81 
86  class null_text_reader : public text_reader {
87  public:
88  int32_t read() override;
89  };
90 
96  public:
97  int32_t read() override;
98 
99  private:
100  friend class text_reader;
102  synchronized_text_reader() = delete;
103  xtd::io::text_reader& reader_;
104  std::mutex mutex_;
105  };
106  }
107 }
Represents a null text reader.
Definition: text_reader.h:86
int32_t read() override
Reads the next character from the input stream and advances the character position by one character.
Represents a synchronized text reader.
Definition: text_reader.h:95
int32_t read() override
Reads the next character from the input stream and advances the character position by one character.
Represents a reader that can read a sequential series of characters.
Definition: text_reader.h:29
virtual xtd::ustring read_line()
Reads a line of characters from the current stream and returns the data as a string.
virtual size_t read(std::vector< char > &buffer, size_t index, size_t count)
Reads a specified maximum number of characters from the current text reader and writes the data to a ...
virtual int32_t read()
Reads the next character from the input stream and advances the character position by one character.
virtual void close()
Closes the xtd::io::text_reader and releases any system resources associated with the text_reader.
virtual size_t read_block(std::vector< char > &buffer, size_t index, size_t count)
Reads a specified maximum number of characters from the current text reader and writes the data to a ...
virtual xtd::ustring read_to_end()
Reads all characters from the current position to the end of the text_reader and returns them as one ...
virtual int32_t peek() const
Reads the next character without changing the state of the reader or the character source....
text_reader()=default
Initializes a new instance of the xtd::io::text_reader class.
static synchronized_text_reader synchronised(text_reader &reader) noexcept
Creates a thread-safe (synchronized) wrapper around the specified text_reader object.
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
#define core_export_
Define shared library export.
Definition: core_export.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17