dlr::common::InputStream Class Reference

The InputStream class is used to add convenience functions to existing istreams. More...

#include <inputStream.h>

List of all members.

Public Types

typedef std::istream::char_type char_type
 This typedef simply mirrors std::istream::char_type.
typedef unsigned int FormatFlag
 These bit flag constants are used to control InputStream behavior.

Public Member Functions

 InputStream (std::istream &inputStream, FormatFlag flags=NO_FLAG)
 This constructor pretends it's copying an input stream.
 ~InputStream ()
 The destructor does nothing.
 operator void * () const
 This operator converts to void* by dispatching to the std::istream conversion operator.
 operator std::istream & () const
 This operator converts to std::istream reference.
template<class Type>
InputStreamoperator>> (Type &typeInstance)
 This operator simply dispatches to the corresponding std::istream operator.
bool bad ()
 This member function simply dispatches to the corresponding std::istream member function.
void clear (std::istream::iostate state=std::istream::goodbit)
 This member function simply dispatches to the corresponding std::istream member function.
bool eof ()
 This member function simply dispatches to the corresponding std::istream member function.
bool fail ()
 This member function simply dispatches to the corresponding std::istream member function.
std::istream::int_type get ()
 This member function simply dispatches to the corresponding std::istream member function.
InputStream getline (char_type *inputBuffer, std::streamsize numberOfCharacters)
 This member function reads no more than the (numberOfCharacters
  • 1) characters into an inputBuffer, stopping at the first newline character, and terminating with ''.

std::istream::int_type peek ()
 This member function simply dispatches to the corresponding std::istream member function.
InputStreamexpect (std::istream::char_type inputChar)
 This member function reads one character from the input and sets failbit if doesn't match the specified value.
InputStreamexpect (const std::string &inputString)
 This member function reads characters from the input and sets failbit if they don't match the specified string.
InputStreamexpect (const char *inputCString, size_t stringSize=0)
 This member function reads characters from the input and sets failbit if they don't match the specified string.
void skipWhiteSpace ()
 This member function skips characters up to the next non-whitespace.

Static Public Attributes

static const FormatFlag NO_FLAG = 0x00
 NO_FLAG is the default state.
static const FormatFlag SKIP_WHITESPACE = 0x01
 SKIP_WHITESPACE indicates that expect() member function calls should remove any preceding whitespace from the stream input before comparing against the expected input.
static const FormatFlag SLOPPY_EXPECT = 0x02
 SLOPPY_EXPECT indicates that expect() member function calls should simply read the correct number of bytes from the input stream, but not actually verify the that the bytes have the right value.


Detailed Description

The InputStream class is used to add convenience functions to existing istreams.

For example, it provides the expect() member function which helps with reading strictly formatted input. Ideally, this would inherit most of its member functions from std::istream, but alas that requires access to stuff which isn't in the istream interface.

Definition at line 32 of file inputStream.h.


Member Typedef Documentation

typedef std::istream::char_type dlr::common::InputStream::char_type

This typedef simply mirrors std::istream::char_type.

Definition at line 37 of file inputStream.h.

typedef unsigned int dlr::common::InputStream::FormatFlag

These bit flag constants are used to control InputStream behavior.

You pass them as constructor arguments, or else as arguments to the (not yet implemented) setFlags member function.

Definition at line 48 of file inputStream.h.


Constructor & Destructor Documentation

dlr::common::InputStream::InputStream ( std::istream &  inputStream,
FormatFlag  flags = NO_FLAG 
) [inline]

This constructor pretends it's copying an input stream.

Unfortunately, the istream copy constructor is private, so instead we just take a reference. You might use this constructor like this:

InputStream myStream(std::cin, (InputStream::SKIP_WHITESPACE | InputStream::SLOPPY_EXPECT));

Parameters:
inputStream This is the stream to be copied.
flags This argument specifies flags which influence the behavior of the InputStream instance.

Definition at line 89 of file inputStream.h.

dlr::common::InputStream::~InputStream (  )  [inline]

The destructor does nothing.

Definition at line 98 of file inputStream.h.


Member Function Documentation

dlr::common::InputStream::operator void * (  )  const [inline]

This operator converts to void* by dispatching to the std::istream conversion operator.

Returns:
The return value is a void*, or 0 if this->fail().

Definition at line 108 of file inputStream.h.

dlr::common::InputStream::operator std::istream & (  )  const [inline]

This operator converts to std::istream reference.

Returns:
The return value is a reference to the std::istream we're pretending we're derived from.

Definition at line 119 of file inputStream.h.

template<class Type>
InputStream& dlr::common::InputStream::operator>> ( Type &  typeInstance  )  [inline]

This operator simply dispatches to the corresponding std::istream operator.

Parameters:
typeInstance This argument is passed directly to the corresponding istream operator.
Returns:
The return value is a reference to *this.

Definition at line 136 of file inputStream.h.

bool dlr::common::InputStream::bad (  )  [inline]

This member function simply dispatches to the corresponding std::istream member function.

Returns:
The return value is simply the return value of the corresponding std::istream member function.

Definition at line 152 of file inputStream.h.

void dlr::common::InputStream::clear ( std::istream::iostate  state = std::istream::goodbit  )  [inline]

This member function simply dispatches to the corresponding std::istream member function.

Parameters:
state This argument is passed directly to the corresponding istream member function.

Definition at line 165 of file inputStream.h.

bool dlr::common::InputStream::eof (  )  [inline]

This member function simply dispatches to the corresponding std::istream member function.

Returns:
The return value is simply the return value of the corresponding std::istream member function.

Definition at line 178 of file inputStream.h.

bool dlr::common::InputStream::fail (  )  [inline]

This member function simply dispatches to the corresponding std::istream member function.

Returns:
The return value is simply the return value of the corresponding std::istream member function.

Definition at line 191 of file inputStream.h.

std::istream::int_type dlr::common::InputStream::get (  )  [inline]

This member function simply dispatches to the corresponding std::istream member function.

Returns:
The return value is simply the return value of the corresponding std::istream member function.

Definition at line 204 of file inputStream.h.

InputStream dlr::common::InputStream::getline ( char_type inputBuffer,
std::streamsize  numberOfCharacters 
) [inline]

This member function reads no more than the (numberOfCharacters

Parameters:
inputBuffer This argument specifies buffer into which characters will be read.
numberOfCharacters This argument specifies the size of the buffer.
Returns:

Definition at line 223 of file inputStream.h.

std::istream::int_type dlr::common::InputStream::peek (  )  [inline]

This member function simply dispatches to the corresponding std::istream member function.

Returns:
The return value is simply the return value of the corresponding std::istream member function.

Definition at line 236 of file inputStream.h.

InputStream& dlr::common::InputStream::expect ( std::istream::char_type  inputChar  )  [inline]

This member function reads one character from the input and sets failbit if doesn't match the specified value.

Parameters:
inputChar This argument defines what the upcoming stream input character should be.
Returns:
The return value is a reference to *this.

Definition at line 253 of file inputStream.h.

InputStream& dlr::common::InputStream::expect ( const std::string &  inputString  )  [inline]

This member function reads characters from the input and sets failbit if they don't match the specified string.

Parameters:
inputString This argument defines what the upcoming stream input characters should be.
Returns:
The return value is a reference to *this.

Definition at line 273 of file inputStream.h.

InputStream& dlr::common::InputStream::expect ( const char *  inputCString,
size_t  stringSize = 0 
) [inline]

This member function reads characters from the input and sets failbit if they don't match the specified string.

The second argument is optional. If it is not provided, the number of characters to read and compare will be determined by calling strlen() on the first argument. If the second argument is provided, then it specifies the number of characters to read and compare. Note that this second mode does not respect '' termination of the input string, so this call:

inputStream.expect("hello world", 240); // Catastrophe!

will likely cause problems by reading past the end of the input string.

Parameters:
inputCString This argument defines what the upcoming stream input characters should be.
stringSize This argument, if specified, indicates how many characters to read and compare.
Returns:
The return value is a reference to *this.

Definition at line 302 of file inputStream.h.

void dlr::common::InputStream::skipWhiteSpace (  )  [inline]

This member function skips characters up to the next non-whitespace.

Definition at line 363 of file inputStream.h.


Member Data Documentation

const FormatFlag dlr::common::InputStream::NO_FLAG = 0x00 [static]

NO_FLAG is the default state.

Definition at line 54 of file inputStream.h.

const FormatFlag dlr::common::InputStream::SKIP_WHITESPACE = 0x01 [static]

SKIP_WHITESPACE indicates that expect() member function calls should remove any preceding whitespace from the stream input before comparing against the expected input.

Definition at line 62 of file inputStream.h.

const FormatFlag dlr::common::InputStream::SLOPPY_EXPECT = 0x02 [static]

SLOPPY_EXPECT indicates that expect() member function calls should simply read the correct number of bytes from the input stream, but not actually verify the that the bytes have the right value.

Definition at line 71 of file inputStream.h.


The documentation for this class was generated from the following file:
Generated on Mon Jul 9 20:34:20 2007 for dlrLibs Utility Libraries by  doxygen 1.5.2