Jive reference manual
List of all members | Public Member Functions | Related Functions
jem::io::TextInput Class Referenceabstract

Provides an interface for reading text-based input. More...

#include <jem/io/TextInput.h>

Inheritance diagram for jem::io::TextInput:
Inheritance graph

Public Member Functions

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...
 

Related Functions

(Note that these are not member functions.)

TextInputoperator>> (TextInput &in, bool &b)
 Reads a boolean from a text input stream. More...
 
TextInputoperator>> (TextInput &in, byte &b)
 Reads a byte from a text input stream. More...
 
TextInputoperator>> (TextInput &in, char &c)
 Reads a character from a text input stream. More...
 
TextInputoperator>> (TextInput &in, short &i)
 Reads a short integer from a text input stream. More...
 
TextInputoperator>> (TextInput &in, int &i)
 Reads an integer from a text input stream. More...
 
TextInputoperator>> (TextInput &in, long &i)
 Reads a long integer from a text input stream. More...
 
TextInputoperator>> (TextInput &in, float &f)
 Reads a float from a text input stream. More...
 
TextInputoperator>> (TextInput &in, double &d)
 Reads a double from a text input stream. More...
 
TextInputoperator>> (TextInput &in, TextInput &(*manip)(TextInput &))
 Applies a manipulator function to a text input stream. More...
 
TextInputskipWhite (TextInput &in)
 Extracts white space from a text input stream. More...
 

Additional Inherited Members

- Protected Member Functions inherited from jem::Interface
virtual ~Interface ()
 Empty destructor. More...
 

Detailed Description

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.

Member Function Documentation

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
IOException- if an I/O error occurs.

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
IOException- if an I/O error occurs.

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
IOException- if an I/O error occurs.

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

Extracts white space from this input stream. A possible implementation could be:

int c;
for ( c = read(); c >= 0 && isspace(c); c = read() );
pushBack( c );
Postcondition
The next character returned by the read() member function either returns -1 or a non-white space character.
Exceptions
IOException- if an I/O error occurs.

Implemented in jem::io::Reader, jem::mt::ThreadSafeReader, jem::io::BufferedReader, jem::io::StringReader, jem::io::FilterReader, and jem::io::NullReader.

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
IOException- if an I/O error occurs.
ParseException- if the input is not in the correct format.
IllegalInputException- if the input is out of range.
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
IOException- if an I/O error occurs.
ParseException- if the input is not in the correct format.
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
IOException- if an I/O error occurs.
ParseException- if the input can not be converted to a long integer.
IllegalInputException- if the input is out of range.
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
IOException- if an I/O error occurs.
ParseException- if the input can not be converted to a double.
IllegalInputException- if the input is out of range.
See also
operator >> ( TextInput&, double& )

Implemented in jem::io::Reader.

Friends And Related Function Documentation

TextInput & operator>> ( TextInput in,
bool &  b 
)
related

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
IOException- if an I/O error occurs.
ParseException- if the input is not in the correct format.
TextInput & operator>> ( TextInput in,
byte &  b 
)
related

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
IOException- if an I/O error occurs.
ParseException- if the input is not in the correct format.
IllegalInputException- if the input is out of range.
TextInput & operator>> ( TextInput in,
char &  c 
)
related

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
IOException- if an I/O error occurs.
ParseException- if the end of the stream has been reached.
TextInput & operator>> ( TextInput in,
short &  i 
)
related

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
IOException- if an I/O error occurs.
ParseException- if the input is not in the correct format.
IllegalInputException- if the input is out of range.
See also
operator >> ( TextInput&, long& )
TextInput & operator>> ( TextInput in,
int &  i 
)
related

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
IOException- if an I/O error occurs.
ParseException- if the input is not in the correct format.
IllegalInputException- if the input is out of range.
See also
operator >> ( TextInput&, long& )
TextInput & operator>> ( TextInput in,
long &  i 
)
related

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
IOException- if an I/O error occurs.
ParseException- if the input can not be converted to a long integer.
IllegalInputException- if the input is out of range.
TextInput & operator>> ( TextInput in,
float &  f 
)
related

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
IOException- if an I/O error occurs.
ParseException- if the input is not in the correct format.
IllegalInputException- if the input is out of range.
See also
operator >> ( TextInput&, double& )
TextInput & operator>> ( TextInput in,
double &  d 
)
related

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
IOException- if an I/O error occurs.
ParseException- if the input can not be converted to a double.
IllegalInputException- if the input is out of range.
TextInput & operator>> ( TextInput in,
TextInput &(*)(TextInput &)  manip 
)
related

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
IOException- if an I/O error occurs.
TextInput & skipWhite ( TextInput in)
related

A manipulator function that extracts white space from the text input stream in by calling in.skipWhite().

Example:

int readChar ( TextInput& in )
{
in >> skipWhite;
return in.read();
}
Parameters
in- a text input stream.
Returns
in
Exceptions
IOException- if an I/O error occurs.