ATLAS Offline Software
Loading...
Searching...
No Matches
CxxUtils::ArrayScanner Class Reference

Helper class for converting strings to Array's. More...

#include <ArrayScanner.h>

Collaboration diagram for CxxUtils::ArrayScanner:

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.

Private Member Functions

bool at_char (char c)
 Read a character.
bool at_num_common ()
 The non-template part of reading a number.

Private Attributes

std::istream & m_is
 The stream from which we're reading.

Detailed Description

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.

Definition at line 39 of file ArrayScanner.h.

Constructor & Destructor Documentation

◆ ArrayScanner()

CxxUtils::ArrayScanner::ArrayScanner ( std::istream & is)

Constructor.

Parameters
isThe stream from which to scan.

Builds a new scanner reading from stream is.

Definition at line 26 of file ArrayScanner.cxx.

27 : m_is (is)
28{
29}
std::istream & m_is
The stream from which we're reading.

Member Function Documentation

◆ at_char()

bool CxxUtils::ArrayScanner::at_char ( char c)
private

Read a character.

Parameters
cThe character to read.
Returns
True if successful.

Consume any white space at the head of the stream. If we're then looking at c, consume it and return true. Otherwise, return false.

Parameters
Thecharacter to read.
Returns
True if successful.

Consume any white space at the head of the stream. If we're then looking at c, consume it and return true. Otherwise, return false.

Definition at line 97 of file ArrayScanner.cxx.

98{
99 std::istream::sentry s (m_is);
100 if (s && m_is.peek() == c) {
101 m_is.get();
102 return true;
103 }
104 return false;
105}

◆ at_close()

bool CxxUtils::ArrayScanner::at_close ( )

Read closing token.

Returns
True if successful.

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.

Definition at line 59 of file ArrayScanner.cxx.

60{
61 if (at_char (']')) {
62 at_char (',');
63
64 // Skip any closing quote marks.
65 at_char ('\'');
66 at_char ('"');
67 return true;
68 }
69 return false;
70}
bool at_char(char c)
Read a character.

◆ at_end()

bool CxxUtils::ArrayScanner::at_end ( )

Test for end-of-stream.

Returns
True if successful.

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.

Definition at line 81 of file ArrayScanner.cxx.

82{
83 std::istream::sentry s (m_is);
84 return !s;
85}

◆ at_num()

template<class T>
bool CxxUtils::ArrayScanner::at_num ( T & elt)

Read number.

Parameters
elt[out]The number read.
Returns
True if successful.

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.

Definition at line 125 of file ArrayScanner.h.

126{
127 m_is >> elt;
128 return at_num_common();
129}
bool at_num_common()
The non-template part of reading a number.

◆ at_num_common()

bool CxxUtils::ArrayScanner::at_num_common ( )
private

The non-template part of reading a number.

Returns
True if successful.

This is called after the attempt to read the number itself. This function checks that the read was in fact successful. If so, then it will also consume any following comma.

Definition at line 116 of file ArrayScanner.cxx.

117{
118 bool stat = !m_is.fail();
119 m_is.clear();
120 at_char (',');
121 return stat;
122}

◆ at_open()

bool CxxUtils::ArrayScanner::at_open ( )

Read opening token.

Returns
True if successful.

Consume any white space at the head of the stream. If we're then looking at ‘[’, consume it and return true. Otherwise, return false.

Definition at line 40 of file ArrayScanner.cxx.

41{
42 // Skip any opening quote marks.
43 at_char ('\'');
44 at_char ('"');
45
46 return at_char ('[');
47}

Member Data Documentation

◆ m_is

std::istream& CxxUtils::ArrayScanner::m_is
private

The stream from which we're reading.

Definition at line 120 of file ArrayScanner.h.


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