Helper class for converting strings to Array's. More...
#include <ArrayScanner.h>
Public Member Functions | |
ArrayScanner (std::istream &is) | |
Constructor. | |
bool | at_open () |
Read opening token. | |
bool | at_close () |
Read closing token. | |
bool | at_end () |
Test for end-of-stream. | |
template<class T > | |
bool | at_num (T &elt) |
Read number. |
Helper class for converting strings to Array's.
This class is a simple lexical analyzer used in converting strings to multidimensional array representations. We get a stream as input. This stream can contain three types of tokens: an open bracket, a close bracket, or a floating-point number. We provide methods to test if either of these three items is at the head of the stream. If so, the item is consumed. (An optional comma may follow a close bracket or a number; it is consumed when the item in front of it is consumed.) We can also test to see if we're at the end.
CxxUtils::ArrayScanner::ArrayScanner | ( | std::istream & | is | ) |
Constructor.
is | The stream from which to scan. |
Builds a new scanner reading from stream is.
bool CxxUtils::ArrayScanner::at_close | ( | ) |
Read closing token.
Consume any white space at the head of the stream. If we're then looking at `]', consume it and return true. If there's a comma following it, consume that too. Otherwise, return false.
bool CxxUtils::ArrayScanner::at_end | ( | ) |
Test for end-of-stream.
Consume any white space at the head of the stream. Return true if we're then at the end of the stream. Otherwise, return false.
bool CaloRec::ArrayScanner::at_num | ( | T & | elt | ) | [inline] |
Read number.
elt[out] | The number read. |
Consume any white space at the head of the stream. If we're then looking at a number that can be converted to type T
, read it and return true. The value is returned in elt. If there's a comma following it, consume that too. Otherwise, return false.
bool CxxUtils::ArrayScanner::at_open | ( | ) |
Read opening token.
Consume any white space at the head of the stream. If we're then looking at `[', consume it and return true. Otherwise, return false.