Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Input Class Reference

#include <elm/io/Input.h>

+ Inheritance diagram for Input:

Classes

struct  def_scanner
 
struct  enum_scanner
 
class  LineIter
 
class  LineRange
 

Public Member Functions

 Input (void)
 
 Input (InStream &stream)
 
InStreamstream (void) const
 
void setStream (InStream &stream)
 
bool ended () const
 
bool failed () const
 
bool error () const
 
bool ok () const
 
void resetState ()
 
bool scanBool (void)
 
char scanChar (void)
 
t::uint32 scanULong (int base=0)
 
t::int32 scanLong (int base=0)
 
t::uint64 scanULLong (int base=0)
 
t::int64 scanLLong (int base=0)
 
double scanDouble (void)
 
String scanWord (void)
 
String scanLine (void)
 
void swallow (char chr)
 
void swallow (CString str)
 
void swallow (const String &str)
 
void swallowBlank (void)
 
Inputoperator>> (bool &value)
 
Inputoperator>> (char &value)
 
Inputoperator>> (unsigned char &value)
 
Inputoperator>> (short &value)
 
Inputoperator>> (unsigned short &value)
 
Inputoperator>> (int &value)
 
Inputoperator>> (unsigned int &value)
 
Inputoperator>> (signed long &value)
 
Inputoperator>> (unsigned long &value)
 
Inputoperator>> (signed long long &value)
 
Inputoperator>> (unsigned long long &value)
 
Inputoperator>> (float &value)
 
Inputoperator>> (double &value)
 
Inputoperator>> (String &value)
 
Inputoperator>> (const string &text)
 
Inputoperator>> (cstring text)
 
Inputoperator>> (const char *text)
 
template<class T >
Inputoperator>> (T &v)
 
LineRange lines ()
 

Detailed Description

This class provides formatted scanning to input streams.

It is supported to support scan of several items separated by spaces. The possible errors are accumulated inside the state of the class and can accessed at the end of a scan session.

Each scan of a value can result in a success, in a failure (bad format) or in error (reflecting an error in the underlying stream). In addition its states records also the end of the stream.

Constructor & Destructor Documentation

◆ Input() [1/2]

Input ( void  )

Build a new input using the standard.

◆ Input() [2/2]

Input ( InStream stream)

Build a new input with the given input stream.

Parameters
streamUsed input stream.

Member Function Documentation

◆ ended()

bool ended ( ) const
inline

Test if the stream is ended. Once ended, any new scan will fail.

Returns
True if the stream is ended, false else.

Referenced by Input::LineIter::next().

◆ error()

bool error ( ) const
inline

◆ failed()

bool failed ( ) const
inline

◆ lines()

LineRange lines ( )
inline

◆ ok()

bool ok ( ) const
inline

◆ operator>>() [1/18]

Input & operator>> ( bool value)
inline

Shortcut scanBool.

References Input::scanBool().

◆ operator>>() [2/18]

Input & operator>> ( char &  value)
inline

Shortcut to scanChar().

References Input::scanChar().

◆ operator>>() [3/18]

Input& operator>> ( const char *  text)
inline

References Input::swallow().

◆ operator>>() [4/18]

Input & operator>> ( const string text)
inline

shortcut swallow(String).

References Input::swallow().

◆ operator>>() [5/18]

Input & operator>> ( cstring  text)
inline

Shortcut to swallow(CString).

References Input::swallow().

◆ operator>>() [6/18]

Input & operator>> ( double &  value)
inline

Shortcut to scanDouble().

References Input::scanDouble().

◆ operator>>() [7/18]

Input & operator>> ( float &  value)
inline

Shortcut to scanDouble().

References Input::scanDouble().

◆ operator>>() [8/18]

Input & operator>> ( int &  value)
inline

Shortcut to scanInt().

References Input::scanLong().

◆ operator>>() [9/18]

Input & operator>> ( short &  value)
inline

Shortcut to scanInt().

References Input::scanLong().

◆ operator>>() [10/18]

Input& operator>> ( signed long &  value)
inline

References Input::scanLong().

◆ operator>>() [11/18]

Input& operator>> ( signed long long &  value)
inline

References Input::scanLLong().

◆ operator>>() [12/18]

Input & operator>> ( String value)
inline

Shortcut to scanLine().

References Input::scanLine().

◆ operator>>() [13/18]

Input& operator>> ( T &  v)
inline

◆ operator>>() [14/18]

Input & operator>> ( unsigned char &  value)
inline

Shortcut to scanInt().

References Input::scanULong().

◆ operator>>() [15/18]

Input & operator>> ( unsigned int &  value)
inline

Shortcut to scanInt().

References Input::scanULong().

◆ operator>>() [16/18]

Input & operator>> ( unsigned long &  value)
inline

Shortcut to scanInt().

References Input::scanULong().

◆ operator>>() [17/18]

Input & operator>> ( unsigned long long &  value)
inline

Shortcut to scanLong().

References Input::scanULLong().

◆ operator>>() [18/18]

Input & operator>> ( unsigned short &  value)
inline

Shortcut to scanInt().

References Input::scanULong().

◆ resetState()

void resetState ( )
inline

bool Input::failed() const; Test if the last operation failed. Failed means that there were a format in the last read value.

Returns
True if the last operation failed. bool Input::error() const; Test if there has been an input error from the underlying stream.
True if there has been an input error. bool Input::ok() const; Test if the stream is ok (end not reached, no failed operation, no input error).
True if the input is ready to proceed.

Remove any failure or input error from the state.

◆ scanBool()

bool scanBool ( void  )

Read a boolean value, that is, 'true'/'false' or '1'/'0'.

Returns
Read boolean value.

References InStream::FAILED.

Referenced by Input::operator>>().

◆ scanChar()

char scanChar ( void  )

Read the next character.

Returns
Next character.

Referenced by Input::operator>>().

◆ scanDouble()

double scanDouble ( void  )

Scan a floating value.

Returns
Read value.

Referenced by Input::operator>>().

◆ scanLine()

String scanLine ( void  )

Scan a full line. The end is reached when the string is empty.

Returns
Read line (final
, if any, is appended).

References InStream::FAILED, and StringBuffer::toString().

Referenced by File::load(), Input::LineIter::next(), and Input::operator>>().

◆ scanLLong()

t::int64 scanLLong ( int  base = 0)

Scan a based long long, decimal as a default. Supported base prefixes are '0', '0[xX]' or '0[bB]'.

Parameters
baseBase of the number to read (default to 0 to scan prefixes).
Returns
Integer value.
Exceptions
IOExceptionIn case of IO or format error.

References elm::io::base(), and Input::scanULLong().

Referenced by Input::operator>>().

◆ scanLong()

t::int32 scanLong ( int  base = 0)

Scan a based long, decimal as a default. Supported base prefixes are '0', '0[xX]' or '0[bB]'.

Parameters
baseBase of the number to read (default to 0 to scan prefixes).
Returns
Integer value.
Exceptions
IOExceptionIn case of IO or format error.

References elm::io::base(), and Input::scanULong().

Referenced by Input::operator>>().

◆ scanULLong()

t::uint64 scanULLong ( int  base = 0)

Scan a based unsigned long long, decimal as a default. Supported base prefixes are '0', '0[xX]' or '0[bB]'.

Parameters
baseBase of the number to read (default to 0 to scan prefixes).
Returns
Integer value.
Exceptions
IOExceptionIn case of IO or format error.

References elm::io::base(), and elm::io::test_base().

Referenced by Input::operator>>(), and Input::scanLLong().

◆ scanULong()

t::uint32 scanULong ( int  base = 0)

Scan a based unsigned long, decimal as a default. Supported base prefixes are '0', '0[xX]' or '0[bB]'.

Parameters
baseBase of the number to read (default to 0 to scan prefixes).
Returns
Integer value.
Exceptions
IOExceptionIn case of IO error.

References elm::io::base(), and elm::io::test_base().

Referenced by Input::operator>>(), and Input::scanLong().

◆ scanWord()

String scanWord ( void  )

Scan a word from the text and return it.

Note
A word is separated from other words by a blank character.
Returns
Read word.

References StringBuffer::toString().

◆ setStream()

void setStream ( InStream stream)
inline

change the used input stream.

References Input::stream().

Referenced by FileInput::FileInput(), and XOMUnserializer::onValue().

◆ stream()

InStream & stream ( void  ) const
inline

Get the current input stream.

Returns
Current input stream.

Referenced by Input::setStream().

◆ swallow() [1/3]

void swallow ( char  chr)

Read a character if it is equal to the given one or throw an IOException.

Parameters
chrCharacter to read.

References elm::io::read().

Referenced by Input::operator>>(), and Input::swallow().

◆ swallow() [2/3]

void swallow ( const String str)

Read the character of the given string until finding a not matching character (and throw an exception in this case).

Parameters
strString to read.

References String::length(), elm::str(), and Input::swallow().

◆ swallow() [3/3]

void swallow ( CString  str)

Read the character of the given string until finding a not matching character (and throw an exception in this case).

Parameters
strString to read.

References elm::str(), and Input::swallow().

◆ swallowBlank()

void swallowBlank ( void  )

Swallow one or more characters.

Returns
True if some blanks have swallowed, false else.

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