Provides an interface for reading text-based input.
More...
#include <jem/io/TextInput.h>
|
virtual int | read ()=0 |
| Extracts the next character from this input stream. More...
|
|
virtual int | read (char *buf, int n)=0 |
| Extracts multiple characters from this input stream. More...
|
|
virtual void | pushBack (int c)=0 |
| Pushes back a previously read character. More...
|
|
virtual void | skipWhite ()=0 |
| Skips over white space. More...
|
|
virtual byte | parseByte ()=0 |
| Reads a byte from this input stream. More...
|
|
virtual bool | parseBool ()=0 |
| Reads a boolean from this input stream. More...
|
|
virtual long | parseInt ()=0 |
| Reads a long integer from this input stream. More...
|
|
virtual double | parseFloat ()=0 |
| Reads a double from this input stream. More...
|
|
The TextInput
interface provides a set of (abstract) functions for reading characters from an input stream. It is typically used to implement functions that parse text input and that do not care about the source of the input.
- See also
Reader
, TextOutput
, DataInput
.
virtual int jem::io::TextInput::read |
( |
| ) |
|
|
pure virtual |
Returns the next character, cast to an int
, from this input stream. If the end of the stream has been reached, -1
is returned.
- Returns
- The next character in the input stream, or
-1
.
- Exceptions
-
Implemented in jem::mt::ThreadSafeReader, jem::io::BufferedReader, jem::io::InputStreamReader, jem::io::StringReader, jem::io::LineNumberReader, jem::io::FilterReader, jem::io::StdinReader, and jem::io::NullReader.
virtual int jem::io::TextInput::read |
( |
char * |
buf, |
|
|
int |
n |
|
) |
| |
|
pure virtual |
Extracts up to n characters from this input stream and stores them into the the array buf. The number of characters extracted may be less than n if the end of the stream is encountered or if there are no more characters available at this moment.
- Parameters
-
buf | - a character array of which the size is at least n. |
n | - the maximum number of characters to be extracted from the input stream. |
- Returns
- The number of characters that have been extracted from the input stream and that have been stored in the character array buf. If n is larger than zero, this function will always return a positive integer, unless the end of the input stream is encountered before any character has been extracted.
- Precondition
n >= 0
and the array buf is at least n characters long.
- Postcondition
- If k denotes the value returned by this function, then the array elements
buf[0], ..., buf[k - 1]
have been filled.
- Exceptions
-
Implemented in jem::io::Reader.
virtual void jem::io::TextInput::pushBack |
( |
int |
c | ) |
|
|
pure virtual |
Pushes back the character c, cast to an unsigned char
, into this input stream. This character must have been previously extracted from the input stream by calling one of the read()
member functions. The pushed back character will be the first character to be extracted from the input stream when one of the read()
member functions is called.
Characters must be pushed back in the same order as they have been read; one is not allowed to alter the contents of the input stream.
If the character c has a negative value, this function does nothing.
Example:
void skipNumbers ( TextInput& in )
{
int c;
for ( c = in.read(); c >= 0 && isalpha(c); c = in.read() );
in.pushBack( c );
}
- Parameters
-
c | - the character to be pushed back. |
- Postcondition
- If c is non-negative, then
this->read() == c
.
- Exceptions
-
Implemented in jem::mt::ThreadSafeReader, jem::io::BufferedReader, jem::io::StringReader, jem::io::FilterReader, jem::io::InputStreamReader, jem::io::LineNumberReader, jem::io::StdinReader, and jem::io::NullReader.
virtual void jem::io::TextInput::skipWhite |
( |
| ) |
|
|
pure virtual |
virtual byte jem::io::TextInput::parseByte |
( |
| ) |
|
|
pure virtual |
Reads a byte from this input stream. On success, the read byte is returned; otherwise an exception is thrown. You should normally not call this function directly, but use one of the overloaded input operators.
- Returns
- The byte that has been read from this input stream.
- Exceptions
-
- See also
operator >> ( TextInput&, byte& )
Implemented in jem::io::Reader.
virtual bool jem::io::TextInput::parseBool |
( |
| ) |
|
|
pure virtual |
Reads a boolean from this input stream. On success, the read boolean is returned; otherwise an exception is thrown. You should normally not call this function directly, but use one of the overloaded input operators.
- Returns
- The bool that has been read from this input stream.
- Exceptions
-
- See also
operator >> ( TextInput&, bool& )
Implemented in jem::io::Reader.
virtual long jem::io::TextInput::parseInt |
( |
| ) |
|
|
pure virtual |
Reads a long integer from this input stream. On success, the read integer is returned; otherwise an exception is thrown. You should normally not call this function directly, but use one of the overloaded input operators.
- Returns
- The integer that has been read from this input stream.
- Exceptions
-
- See also
operator >> ( TextInput&, long& )
Implemented in jem::io::Reader.
virtual double jem::io::TextInput::parseFloat |
( |
| ) |
|
|
pure virtual |
Reads a double precision number from this input stream. On success, the read duoble is returned; otherwise an exception is thrown. You should normally not call this function directly, but use one of the overloaded input operators.
- Returns
- The double that has been read from this input stream.
- Exceptions
-
- See also
operator >> ( TextInput&, double& )
Implemented in jem::io::Reader.
Reads a boolean from the text input stream in and assigns it to the parameter b. This operator simply executes:
b = in.parseBool(); return in;
- Parameters
-
in | - a text input stream. |
b | - the boolean to be read. |
- Returns
- in
- Exceptions
-
Reads a byte from the text input stream in and assigns it to the parameter b. This operator simply executes:
b = in.parseByte(); return in;
- Parameters
-
in | - a text input stream. |
b | - the byte to be read. |
- Returns
- in
- Exceptions
-
Reads the next character from the text input stream in and assigns it to the parameter c. Leading white space is skipped by calling in.skipWhite()
.
- Parameters
-
in | - a text input stream. |
c | - the character to be read. |
- Returns
- in
- Exceptions
-
Reads a short integer from the text input stream in and assigns it to the parameter i. This operator first reads a long integer from the input stream and then tries to convert it to a short integer.
- Parameters
-
in | - a text input stream. |
i | - the short integer to be read. |
- Returns
- in
- Exceptions
-
- See also
operator >> ( TextInput&, long& )
Reads an integer from the text input stream in and assigns it to the parameter i. This operator first reads a long integer from the input stream and then tries to convert it to an int.
- Parameters
-
in | - a text input stream. |
i | - the integer to be read. |
- Returns
- in
- Exceptions
-
- See also
operator >> ( TextInput&, long& )
Reads a long integer from the text input stream in and assigns it to the parameter i. This operator simply executes:
i = in.parseInt(); return in;
- Parameters
-
in | - a text input stream. |
i | - the long integer to be read. |
- Returns
- in
- Exceptions
-
Reads a floating point number from the text input stream in and assigns it to the parameter f. This operator first reads a double from the input stream and then tries to convert it to a float.
- Parameters
-
in | - a text input stream. |
f | - the float to be read. |
- Returns
- in
- Exceptions
-
- See also
operator >> ( TextInput&, double& )
Reads a double precision number from the text input stream in and assigns it to the parameter d. This operator simply executes:
i = in.parseFloat(); return in;
- Parameters
-
in | - a text input stream. |
d | - the double to be read. |
- Returns
- in
- Exceptions
-
Applies the manipulator function manip to the text input stream in. This operator is equivalent with:
return manip( in );
- Parameters
-
in | - a text input stream. |
manip | - a text input stream manipulator function. |
- Returns
- in
- Exceptions
-
A manipulator function that extracts white space from the text input stream in by calling in.skipWhite()
.
Example:
int readChar ( TextInput& in )
{
return in.read();
}
- Parameters
-
- Returns
- in
- Exceptions
-