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>
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. | |
Stream & | operator! () |
Stream & | parseDouble (double &d) |
template<class IntType > | |
Stream & | parseInteger (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. |
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. }
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.
bool bad | ( | ) | const |
char const* begin | ( | ) | const |
bool empty | ( | ) | const |
char const* end | ( | ) | const |
char first | ( | ) | const |
operator void const * | ( | ) | const |
Stream& parseDouble | ( | double & | d | ) |
Stream& parseInteger | ( | IntType & | object, | |
int | base = 10 , |
|||
bool | signable = true | |||
) |
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.
[out] | s | the array of characters to hold the parsed data. |
Definition at line 961 of file BIscan.h.
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.
[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.
void pop_front | ( | ) |
void setBad | ( | bool | b | ) |
unsigned long size | ( | ) | const |
bool skipCharset | ( | char const * | first, | |
char const * | last | |||
) |
Remove leading characters from the Stream that are found in the specified character set.
[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.
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.
[in] | s | the string to skip over. |
Definition at line 877 of file BIscan.h.
void skipWS | ( | ) |
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
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.
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
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.
bool invertedLogic_ [private] |