xtd 0.2.0
Loading...
Searching...
No Matches
xtd::io::text_reader Class Reference
Inheritance diagram for xtd::io::text_reader:
xtd::object xtd::io::null_text_reader xtd::io::stream_reader xtd::io::string_reader xtd::io::synchronized_text_reader

Definition

Represents a reader that can read a sequential series of characters.

text_reader()=default
Initializes a new instance of the xtd::io::text_reader class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
#define core_export_
Define shared library export.
Definition core_export.hpp:13
Inheritance
xtd::objectxtd::io::text_reader
Header
#include <xtd/io/text_reader>
Namespace
xtd::io
Library
xtd.core

Public Fields

static null_text_readernull () noexcept
 Provides a text_reader with no data to read from.
 

Public Static Methods

static auto synchronised (text_reader &reader) noexcept -> synchronized_text_reader
 Creates a thread-safe (synchronized) wrapper around the specified text_reader object.
 

Public Methods

virtual auto close () -> void
 Closes the xtd::io::text_reader and releases any system resources associated with the text_reader.
 
virtual auto peek () const -> xtd::int32
 Reads the next character without changing the state of the reader or the character source. Returns the next available character without actually reading it from the input stream.
 
virtual auto read () -> xtd::int32
 Reads the next character from the input stream and advances the character position by one character.
 
virtual auto read (xtd::span< char > &buffer) -> xtd::size
 Reads the characters from the current reader and writes the data to the specified buffer.
 
virtual auto read (xtd::array< char > &buffer, xtd::size index, xtd::size count) -> xtd::size
 Reads a specified maximum number of characters from the current text reader and writes the data to a buffer, beginning at the specified index.
 
virtual auto read_block (xtd::span< char > &buffer) -> xtd::size
 Reads the characters from the current stream and writes the data to a buffer.
 
virtual auto read_block (xtd::array< char > &buffer, xtd::size index, xtd::size count) -> xtd::size
 Reads a specified maximum number of characters from the current text reader and writes the data to a buffer, beginning at the specified index.
 
virtual auto read_line () -> xtd::string
 Reads a line of characters from the current stream and returns the data as a string.
 
virtual auto read_to_end () -> xtd::string
 Reads all characters from the current position to the end of the text_reader and returns them as one string.
 

Protected constructors

 text_reader ()=default
 Initializes a new instance of the xtd::io::text_reader class.
 

Additional Inherited Members

 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual xtd::size get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<class object_t>
xtd::unique_ptr_object< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
virtual xtd::string to_string () const
 Returns a xtd::string that represents the current object.
 
template<class object_a_t, class object_b_t>
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<class object_a_t, class object_b_t>
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Constructor & Destructor Documentation

◆ text_reader()

xtd::io::text_reader::text_reader ( )
protecteddefault

Initializes a new instance of the xtd::io::text_reader class.

Member Function Documentation

◆ null()

static null_text_reader & xtd::io::text_reader::null ( )
staticnoexcept

Provides a text_reader with no data to read from.

Remarks
Reading from the null text reader is similar to reading from the end of a stream:
read and peek methods return EOF.
read_block method returns zero.
read_line and read_to_end methods return a string Empty.

◆ close()

virtual auto xtd::io::text_reader::close ( ) -> void
virtual

Closes the xtd::io::text_reader and releases any system resources associated with the text_reader.

Reimplemented in xtd::io::stream_reader.

◆ peek()

virtual auto xtd::io::text_reader::peek ( ) const -> xtd::int32
nodiscardvirtual

Reads the next character without changing the state of the reader or the character source. Returns the next available character without actually reading it from the input stream.

Returns
An integer representing the next character to be read, or EOF if no more characters are available or the stream does not support seeking.

Reimplemented in xtd::io::stream_reader, and xtd::io::string_reader.

◆ read() [1/3]

virtual auto xtd::io::text_reader::read ( ) -> xtd::int32
nodiscardvirtual

Reads the next character from the input stream and advances the character position by one character.

Returns
The next character from the input stream, or EOF if no more characters are available.

Reimplemented in xtd::io::null_text_reader, xtd::io::stream_reader, xtd::io::string_reader, and xtd::io::synchronized_text_reader.

◆ read() [2/3]

virtual auto xtd::io::text_reader::read ( xtd::span< char > & buffer) -> xtd::size
virtual

Reads the characters from the current reader and writes the data to the specified buffer.

Parameters
bufferWhen this method returns, contains the specified span of characters replaced by the characters read from the current source.
Returns
The number of characters that have been read. The number will be less than or equal to the buffer length, depending on whether the data is available within the reader. This method returns 0 (zero) if it is called when no more characters are left to read.

◆ read() [3/3]

virtual auto xtd::io::text_reader::read ( xtd::array< char > & buffer,
xtd::size index,
xtd::size count ) -> xtd::size
virtual

Reads a specified maximum number of characters from the current text reader and writes the data to a buffer, beginning at the specified index.

Parameters
bufferWhen this method returns, this parameter contains the specified character array with the values between index and (index + count -1) replaced by the characters read from the current source.
indexThe position in buffer at which to begin writing.
countThe maximum number of characters to read.
Returns
The number of characters that have been read. The number will be less than or equal to count, depending on whether all input characters have been read.

◆ read_block() [1/2]

virtual auto xtd::io::text_reader::read_block ( xtd::span< char > & buffer) -> xtd::size
virtual

Reads the characters from the current stream and writes the data to a buffer.

Parameters
bufferWhen this method returns, contains the specified span of characters replaced by the characters read from the current source.
Returns
The number of characters that have been read. The number will be less than or equal to the buffer length, depending on whether all input characters have been read.

◆ read_block() [2/2]

virtual auto xtd::io::text_reader::read_block ( xtd::array< char > & buffer,
xtd::size index,
xtd::size count ) -> xtd::size
virtual

Reads a specified maximum number of characters from the current text reader and writes the data to a buffer, beginning at the specified index.

Parameters
bufferWhen this method returns, this parameter contains the specified character array with the values between index and (index + count -1) replaced by the characters read from the current source.
indexThe position in buffer at which to begin writing.
countThe maximum number of characters to read.
Returns
The number of characters that have been read. The number will be less than or equal to count, depending on whether all input characters have been read.

◆ read_line()

virtual auto xtd::io::text_reader::read_line ( ) -> xtd::string
nodiscardvirtual

Reads a line of characters from the current stream and returns the data as a string.

Returns
The next line from the input stream, or the empty string if all characters have been read.
Examples
test_forms.cpp.

◆ read_to_end()

virtual auto xtd::io::text_reader::read_to_end ( ) -> xtd::string
nodiscardvirtual

Reads all characters from the current position to the end of the text_reader and returns them as one string.

Returns
A string containing all characters from the current position to the end of the text_reader.
Exceptions
io::io_exceptionAn I/O error occurs.

◆ synchronised()

static auto xtd::io::text_reader::synchronised ( text_reader & reader) -> synchronized_text_reader
staticnodiscardnoexcept

Creates a thread-safe (synchronized) wrapper around the specified text_reader object.

Parameters
readerThe text_reader object to synchronize.
Returns
text_reader A thread-safe text_reader object.

The documentation for this class was generated from the following file: