Qt 4.8
Public Types | Public Functions | Private Types | Properties | List of all members
QPatternist::OperandsIterator Class Reference

A helper class that iterates a tree of Expression instances. It is not a sub-class of QAbstractXmlForwardIterator. More...

#include <qoperandsiterator_p.h>

Public Types

enum  TreatParent { ExcludeParent, IncludeParent }
 

Public Functions

Expression::Ptr next ()
 Returns the current Expression and advances the iterator. More...
 
 OperandsIterator (const Expression::Ptr &start, const TreatParent treatParent)
 
Expression::Ptr skipOperands ()
 

Private Types

typedef QPair< Expression::List, int > Level
 

Properties

QStack< Levelm_exprs
 

Detailed Description

A helper class that iterates a tree of Expression instances. It is not a sub-class of QAbstractXmlForwardIterator.

The OperandsIterator delivers all Expression instances that are children at any depth of the Expression passed in the constructor. The order is delivered in a defined way, from left to right and depth first.

Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 77 of file qoperandsiterator_p.h.

Typedefs

◆ Level

The second value, the int, is the current position in the first.

Definition at line 82 of file qoperandsiterator_p.h.

Enumerations

◆ TreatParent

Enumerator
ExcludeParent 
IncludeParent 

Definition at line 85 of file qoperandsiterator_p.h.

Constructors and Destructors

◆ OperandsIterator()

QPatternist::OperandsIterator::OperandsIterator ( const Expression::Ptr start,
const TreatParent  treatParent 
)
inline

if treatParent is IncludeParent, start is excluded.

start must be a valid Expression.

Definition at line 96 of file qoperandsiterator_p.h.

98  {
99  Q_ASSERT(start);
100  if(treatParent == IncludeParent)
101  {
103  l.append(start);
104  m_exprs.push(qMakePair(l, -1));
105  }
106 
107  m_exprs.push(qMakePair(start->operands(), -1));
108  }
QList< Expression::Ptr > List
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
QFactoryLoader * l

Functions

◆ next()

Expression::Ptr QPatternist::OperandsIterator::next ( )
inline

Returns the current Expression and advances the iterator.

If the end has been reached, a default constructed pointer is returned.

We intentionally return by reference.

Definition at line 118 of file qoperandsiterator_p.h.

Referenced by QPatternist::Expression::dependencies(), QPatternist::ExpressionFactory::registerLastPath(), skipOperands(), and QPatternist::EvaluationCache< IsForGlobal >::typeCheck().

119  {
120  if(m_exprs.isEmpty())
121  return Expression::Ptr();
122 
123  Level &lvl = m_exprs.top();
124  ++lvl.second;
125 
126  if(lvl.second == lvl.first.size())
127  {
128  /* Resume iteration above us. */
129  m_exprs.pop();
130 
131  if(m_exprs.isEmpty())
132  return Expression::Ptr();
133 
134  while(true)
135  {
136  Level &previous = m_exprs.top();
137  ++previous.second;
138 
139  if(previous.second < previous.first.count())
140  {
141  const Expression::Ptr &op = previous.first.at(previous.second);
142  m_exprs.push(qMakePair(op->operands(), -1));
143  return op;
144  }
145  else
146  {
147  // We have already reached the end of this level.
148  m_exprs.pop();
149  if(m_exprs.isEmpty())
150  return Expression::Ptr();
151  }
152  }
153  }
154  else
155  {
156  const Expression::Ptr &op = lvl.first.at(lvl.second);
157  m_exprs.push(qMakePair(op->operands(), -1));
158  return op;
159  }
160  }
QPair< Expression::List, int > Level
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102

◆ skipOperands()

Expression::Ptr QPatternist::OperandsIterator::skipOperands ( )
inline

Advances this iterator by the current expression and its operands.

Definition at line 165 of file qoperandsiterator_p.h.

Referenced by QPatternist::ExpressionFactory::registerLastPath().

166  {
167  if(m_exprs.isEmpty())
168  return Expression::Ptr();
169 
170  Level &lvl = m_exprs.top();
171  ++lvl.second;
172 
173  if(lvl.second == lvl.first.size())
174  {
175  /* We've reached the end of this level, at least. */
176  m_exprs.pop();
177  }
178 
179  return next();
180  }
Expression::Ptr next()
Returns the current Expression and advances the iterator.
QPair< Expression::List, int > Level
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.

Properties

◆ m_exprs

QStack<Level> QPatternist::OperandsIterator::m_exprs
private

Definition at line 185 of file qoperandsiterator_p.h.

Referenced by next(), OperandsIterator(), and skipOperands().


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