ATLAS Offline Software
Loading...
Searching...
No Matches
ChainNameParser::LegInfoIterator Class Reference

Iterate over the legs of a chain. More...

#include <ChainNameParser.h>

Collaboration diagram for ChainNameParser::LegInfoIterator:

Public Types

using iterator_category = std::input_iterator_tag
using value_type = LegInfo
using reference = const value_type &
using pointer = const value_type *
using difference_type = std::ptrdiff_t

Public Member Functions

 LegInfoIterator ()=default
 Default constructor creates a past-the-end iterator.
 LegInfoIterator (const std::string &chain)
 Create an iterator from the beginning of a chain name.
bool operator== (const LegInfoIterator &other) const
 Check (in)equality against another iterator.
bool operator!= (const LegInfoIterator &other) const
reference operator* () const
 Dereference the iterator.
pointer operator-> () const
LegInfoIteratoroperator++ ()
 pre-increment operator
LegInfoIterator operator++ (int)
 post-increment operator
bool exhausted () const
 Whether the iterator is exhausted.

Private Member Functions

bool advance ()

Private Attributes

std::string::const_iterator m_itr
std::string::const_iterator m_end
LegInfo m_current
std::size_t m_peekMultiplicity {0}
std::string m_peekSignature {""}
int m_peekThreshold {-1}

Detailed Description

Iterate over the legs of a chain.

Definition at line 35 of file ChainNameParser.h.

Member Typedef Documentation

◆ difference_type

Definition at line 42 of file ChainNameParser.h.

◆ iterator_category

using ChainNameParser::LegInfoIterator::iterator_category = std::input_iterator_tag

Definition at line 38 of file ChainNameParser.h.

◆ pointer

Definition at line 41 of file ChainNameParser.h.

◆ reference

Definition at line 40 of file ChainNameParser.h.

◆ value_type

Constructor & Destructor Documentation

◆ LegInfoIterator() [1/2]

ChainNameParser::LegInfoIterator::LegInfoIterator ( )
default

Default constructor creates a past-the-end iterator.

◆ LegInfoIterator() [2/2]

ChainNameParser::LegInfoIterator::LegInfoIterator ( const std::string & chain)

Create an iterator from the beginning of a chain name.

Parameters
chainThe full chain name

Definition at line 78 of file ChainNameParser.cxx.

78 :
79 m_itr(chain.begin()), m_end(chain.end())
80 {
81 // Move the iterator until we've found the start of a leg
82 while (!advance()) {}
83 // Now we have the next leg info stored in the peek variables, but not the current.
84 // Advance the iterator once to store these in the current
85 this->operator++();
86 }
LegInfoIterator & operator++()
pre-increment operator
std::string::const_iterator m_itr
std::string::const_iterator m_end

Member Function Documentation

◆ advance()

bool ChainNameParser::LegInfoIterator::advance ( )
private

Definition at line 145 of file ChainNameParser.cxx.

146 {
147 std::string::const_iterator next = std::find(m_itr, m_end, '_');
148 std::smatch match;
149 if (std::regex_match(m_itr, next, match, legHeadRegex()))
150 {
151 // This means we've found the start of the next leg. Record its data and return true
152 if (match.str(1).empty())
154 else
155 m_peekMultiplicity = std::atoi(match.str(1).c_str());
156 m_peekSignature = match.str(2);
157 if (match.str(3).empty())
158 m_peekThreshold = -1;
159 else
160 m_peekThreshold = std::atoi(match.str(3).c_str());
161 // Advance the iterator (skip the underscore if there is one)
162 m_itr = next == m_end ? next : next + 1;
163 return true;
164 }
165 else if (next == m_end)
166 {
167 m_current.legParts.emplace_back(m_itr, next);
168 // Setting the iterator to the end
169 m_itr = m_end;
170 return true;
171 }
172 else
173 {
174 // Otherwise this is just a leg
175 m_current.legParts.emplace_back(m_itr, next);
176 // Advance the iterator (skip the underscore if there is one)
177 m_itr = next == m_end ? next : next + 1;
178 return false;
179 }
180 }
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition hcg.cxx:357

◆ exhausted()

bool ChainNameParser::LegInfoIterator::exhausted ( ) const

Whether the iterator is exhausted.

Definition at line 140 of file ChainNameParser.cxx.

141 {
142 return m_itr == std::string::const_iterator();
143 }

◆ operator!=()

bool ChainNameParser::LegInfoIterator::operator!= ( const LegInfoIterator & other) const

Definition at line 93 of file ChainNameParser.cxx.

94 {
95 return !(*this == other);
96 }

◆ operator*()

LegInfoIterator::reference ChainNameParser::LegInfoIterator::operator* ( ) const

Dereference the iterator.

Dereferencing a past-the-end iterator returns an invalid LegInfo object

Definition at line 98 of file ChainNameParser.cxx.

99 {
100 return m_current;
101 }

◆ operator++() [1/2]

LegInfoIterator & ChainNameParser::LegInfoIterator::operator++ ( )

pre-increment operator

Definition at line 108 of file ChainNameParser.cxx.

109 {
110 if (m_peekSignature.empty() && m_itr == m_end)
111 {
112 // No more signatures to find, exhaust the iterator
113 m_current = {};
114 m_itr = std::string::const_iterator();
115 m_end = std::string::const_iterator();
117 m_peekThreshold = -1;
118 }
119 else
120 {
121 // Copy the peeked information into the current info
122 m_current.multiplicity = m_peekMultiplicity;
123 m_current.signature = m_peekSignature;
124 m_current.threshold = m_peekThreshold;
125 m_current.legParts.clear();
126 m_peekSignature.clear();
127 // Now step through until we find the next leg
128 while (!advance()) {}
129 }
130 return *this;
131 }

◆ operator++() [2/2]

LegInfoIterator ChainNameParser::LegInfoIterator::operator++ ( int )

post-increment operator

Definition at line 133 of file ChainNameParser.cxx.

134 {
135 LegInfoIterator itr(*this);
136 this->operator++();
137 return itr;
138 }
LegInfoIterator()=default
Default constructor creates a past-the-end iterator.

◆ operator->()

LegInfoIterator::pointer ChainNameParser::LegInfoIterator::operator-> ( ) const

Definition at line 103 of file ChainNameParser.cxx.

104 {
105 return &m_current;
106 }

◆ operator==()

bool ChainNameParser::LegInfoIterator::operator== ( const LegInfoIterator & other) const

Check (in)equality against another iterator.

Definition at line 88 of file ChainNameParser.cxx.

89 {
90 return m_itr == other.m_itr && m_end == other.m_end && m_peekSignature == other.m_peekSignature;
91 }

Member Data Documentation

◆ m_current

LegInfo ChainNameParser::LegInfoIterator::m_current
private

Definition at line 75 of file ChainNameParser.h.

◆ m_end

std::string::const_iterator ChainNameParser::LegInfoIterator::m_end
private

Definition at line 74 of file ChainNameParser.h.

◆ m_itr

std::string::const_iterator ChainNameParser::LegInfoIterator::m_itr
private

Definition at line 73 of file ChainNameParser.h.

◆ m_peekMultiplicity

std::size_t ChainNameParser::LegInfoIterator::m_peekMultiplicity {0}
private

Definition at line 76 of file ChainNameParser.h.

76{0};

◆ m_peekSignature

std::string ChainNameParser::LegInfoIterator::m_peekSignature {""}
private

Definition at line 77 of file ChainNameParser.h.

77{""};

◆ m_peekThreshold

int ChainNameParser::LegInfoIterator::m_peekThreshold {-1}
private

Definition at line 78 of file ChainNameParser.h.

78{-1};

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