Stream Class Reference

A Representation of a stream of bytes that can be parsed quickly. See its related operator >> functions. The Stream does not own the bytes, and so they must not be changed or destroyed while the parsing process is in effect. More...

#include <BIscan.h>

List of all members.

Public Member Functions

bool bad () const
 Returns true if a misuse of the stream has occurred.
char const * begin () const
 Return iterator to first byte to be parsed.
bool empty () const
 return true if stream empty
char const * end () const
 Return iterator to last byte (not part of stream).
char first () const
 Returns the first character in the buffer. Does not check for errors.
 operator void const * () const
 Return true if no parse errors. That is, NOT BAD.
Streamoperator! ()
StreamparseDouble (double &d)
template<class IntType >
StreamparseInteger (IntType &object, int base=10, bool signable=true)
template<class StringType >
size_t parseString (StringType &s)
 Parse text into an stl style string.
template<size_t N>
size_t parseString (char(&array)[N])
 Parse a null terminated array of character.
void pop_front ()
 Discard the first character in the buffer.
void setBad (bool b)
 Set or clear the bad flag.
unsigned long size () const
 Return bytes left to be parsed.
bool skipCharset (char const *first, char const *last)
 Remove leading characters from the Stream that are found in the specified character set.
bool skipString (char const *s)
 Remove leading blanks from the input stream, then compare the stream contents with a specified string. If there is an exact match, then move the stream pointer past the string and return true.
void skipWS ()
 Skip whitespace in the input stream.

Private Member Functions

 Stream (char const *start, char const *end)

Private Attributes

bool bad_
char const * end_
bool invertedLogic_
char const * start_

Friends

Stream stream (char const *begin, size_t length)
 One of a family of overloaded functions that returns a stream whose type is based on its parameters.
template<class StringType >
Stream stream (StringType const &p)
 One of a family of overloaded functions that returns a stream whose type is based on its parameters.
Stream stream (char const *begin, char const *end)
 One of a family of overloaded functions that returns a stream whose type is based on its parameters.
Stream stream (char const *const &p)
 One of a family of overloaded functions that returns a stream whose type is based on its parameters.

Detailed Description

A Representation of a stream of bytes that can be parsed quickly. See its related operator >> functions. The Stream does not own the bytes, and so they must not be changed or destroyed while the parsing process is in effect.

The purpose of the Stream class is to simulate sscanf using C++ style syntax and not to create an alternative to the istream class. Streams are an extensible form of sscanf in that you can add your own operator>> functions to do things not originally included in the design -- which is basically targetted at numbers and strings.

Don't construct objects of this type directly, instead, use the stream() family of functions to interact with Streams. Their job is to construct streams from parameters that identify the type of the stream.

At its heart, a stream is a couple of pointers that refer to the as yet unparsed stream of data. The operator>> methods do all the work.

Example use:

          std::string somevar, textvar;
          int someInt;
       
          if( stream("some 99 text") >> somevar >> someInt >> sometext )
          {
            // Everything is good: somevar contains "some' and textvar contains
            // text.  The variable, someInt contains 99.
            //
          }
          else
          {
            // shouldn't get here because "some 99 text" can be parsed as
            // a string followed by white space followed by an integer followed by a string.
          }
       
          if( !stream("glarf") >> someInt )
          {
              // you should get here because "glarf" won't parse to an int.
          }
Warning:
When you use BIscan::Stream to extract a character, you will get a character not an eight bit signed integer. An unsigned char, however is treated as a number, not a character.

A Stream is NOT an iostream analog. Rather it is a super simplistic representation only of a stream of bytes. It has no internal state -- other than baddness. Instead of io manipulators, as iostreams use, there are wrapper classes which allow you to specify the numeric base of the conversion and or any other filtering like you might want to apply to strings. Consider the following wrappers that control the base of conversion:

These classes are not constructed directly but vi the following corresponding functions:

Definition at line 584 of file BIscan.h.


Constructor & Destructor Documentation

Stream ( char const *  start,
char const *  end 
) [private]

Definition at line 666 of file BIscan.h.


Member Function Documentation

bool bad (  )  const

Returns true if a misuse of the stream has occurred.

Definition at line 762 of file BIscan.h.

Here is the caller graph for this function:

char const* begin (  )  const

Return iterator to first byte to be parsed.

Definition at line 775 of file BIscan.h.

bool empty (  )  const

return true if stream empty

Definition at line 756 of file BIscan.h.

Here is the caller graph for this function:

char const* end (  )  const

Return iterator to last byte (not part of stream).

Definition at line 778 of file BIscan.h.

char first (  )  const

Returns the first character in the buffer. Does not check for errors.

Definition at line 758 of file BIscan.h.

Here is the caller graph for this function:

operator void const * (  )  const

Return true if no parse errors. That is, NOT BAD.

Definition at line 690 of file BIscan.h.

Stream& operator! (  ) 

Definition at line 708 of file BIscan.h.

Stream& parseDouble ( double &  d  ) 

Definition at line 802 of file BIscan.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Stream& parseInteger ( IntType &  object,
int  base = 10,
bool  signable = true 
)

Definition at line 784 of file BIscan.h.

Here is the call graph for this function:

Here is the caller graph for this function:

size_t parseString ( StringType &  s  ) 

Parse text into an stl style string.

Skip leading whitespace and parse until the end of the stream or the first whitespace character is found. Since the result is a std::string, no nul is appended.

Returns:
the size of the string parsed.
Parameters:
[out] s the array of characters to hold the parsed data.

Definition at line 961 of file BIscan.h.

Here is the call graph for this function:

size_t parseString ( char(&)  array[N]  ) 

Parse a null terminated array of character.

Skip leading whitespace and parse until the end of string or the first whitespace character is found.

Returns:
the number of bytes read into array (not counting the null null byte that will be appended).
Parameters:
[out] array the array of characters to hold the parsed data. Note that this must be an array not a pointer!

Definition at line 919 of file BIscan.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void pop_front (  ) 

Discard the first character in the buffer.

Definition at line 769 of file BIscan.h.

Here is the caller graph for this function:

void setBad ( bool  b  ) 

Set or clear the bad flag.

Parameters:
b the new state of the bad() flag.

Definition at line 765 of file BIscan.h.

Here is the caller graph for this function:

unsigned long size (  )  const

Return bytes left to be parsed.

Definition at line 772 of file BIscan.h.

bool skipCharset ( char const *  first,
char const *  last 
)

Remove leading characters from the Stream that are found in the specified character set.

Returns:
true to indicate that a character within the character set was actually found.
Parameters:
[in] first The first byte of a vector of characters that contains the character set of interest.
[in] last The last byte of the vector.

Leading whitespace is not skipped unless it is contained in the character set.

Definition at line 829 of file BIscan.h.

Here is the caller graph for this function:

bool skipString ( char const *  s  ) 

Remove leading blanks from the input stream, then compare the stream contents with a specified string. If there is an exact match, then move the stream pointer past the string and return true.

Otherwise return false.

Returns:
true only if the stream contains s.
Parameters:
[in] s the string to skip over.

Definition at line 877 of file BIscan.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void skipWS (  ) 

Skip whitespace in the input stream.

Definition at line 820 of file BIscan.h.

Here is the caller graph for this function:


Friends And Related Function Documentation

Stream stream ( char const *  begin,
size_t  length 
) [friend]

One of a family of overloaded functions that returns a stream whose type is based on its parameters.

The Stream returned does not have a copy of the stream data, only a pointer to it. You must not destruct or change the input pointer's data until parsing is complete.

This function converts a character byte range into a Stream

Definition at line 1729 of file BIscan.h.

Stream stream ( StringType const &  p  )  [friend]

One of a family of overloaded functions that returns a stream whose type is based on its parameters.

The Stream returned does not have a copy of the stream data, only a pointer to it. You must not destruct or change the input pointer's data until parsing is complete.

This function converts an stl style string into a Stream.

Definition at line 1746 of file BIscan.h.

Stream stream ( char const *  begin,
char const *  end 
) [friend]

One of a family of overloaded functions that returns a stream whose type is based on its parameters.

The Stream returned does not have a copy of the stream data, only a pointer to it. You must not destruct or change the input pointer's data until parsing is complete.

This function converts a character byte range into a Stream

Definition at line 1713 of file BIscan.h.

Stream stream ( char const *const &  p  )  [friend]

One of a family of overloaded functions that returns a stream whose type is based on its parameters.

The Stream returned does not have a copy of the stream data, only a pointer to it. You must not destruct or change the input pointer's data until parsing is complete.

This function converts a C style string into a Stream.

Definition at line 1698 of file BIscan.h.


Member Data Documentation

bool bad_ [private]

Definition at line 660 of file BIscan.h.

char const* end_ [private]

Definition at line 659 of file BIscan.h.

bool invertedLogic_ [private]

Definition at line 661 of file BIscan.h.

char const* start_ [private]

Definition at line 658 of file BIscan.h.


The documentation for this class was generated from the following file:
Generated on Wed Feb 29 22:52:19 2012 for CXXUtilities by  doxygen 1.6.3