Qt 4.8
Public Functions | Properties | List of all members
QPatternist::CachingIterator Class Reference

An QAbstractXmlForwardIterator that gets its item from a cache unless its empty, in which case it continues to populate the cache as well as deliver on its own from a source QAbstractXmlForwardIterator. More...

#include <qcachingiterator_p.h>

Inheritance diagram for QPatternist::CachingIterator:
QAbstractXmlForwardIterator< Item > QSharedData

Public Functions

 CachingIterator (ItemSequenceCacheCell::Vector &cacheCells, const VariableSlotID slot, const DynamicContext::Ptr &context)
 
virtual Item::Iterator::Ptr copy () const
 Copies this QAbstractXmlForwardIterator and returns the copy. More...
 
virtual Item current () const
 Returns the current item in the sequence. More...
 
virtual Item next ()
 Returns the next item in the sequence, or a null object if the end has been reached. More...
 
virtual xsInteger position () const
 Returns the current position in the sequence represented by this. More...
 
- Public Functions inherited from QAbstractXmlForwardIterator< Item >
virtual qint64 count ()
 Determines the number of items this QAbstractXmlForwardIterator represents. More...
 
virtual bool isEmpty ()
 Returns true if the sequence is empty. More...
 
virtual Item last ()
 Returns the item at the end of this QAbstractXmlForwardIterator. More...
 
 QAbstractXmlForwardIterator ()
 Default constructor. More...
 
virtual qint64 sizeHint () const
 Gives a hint to the size of the contained sequence. More...
 
virtual QList< ItemtoList ()
 Performs a copy of this QAbstractXmlForwardIterator(with copy()), and returns its items in a QList. More...
 
virtual QAbstractXmlForwardIterator< Item >::Ptr toReversed ()
 Returns a reverse iterator for the sequence. More...
 
virtual ~QAbstractXmlForwardIterator ()
 Destructor. More...
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 

Properties

ItemSequenceCacheCell::Vectorm_cacheCells
 
const DynamicContext::Ptr m_context
 
Item m_current
 
xsInteger m_position
 
bool m_usingCache
 
const VariableSlotID m_varSlot
 

Additional Inherited Members

- Public Types inherited from QAbstractXmlForwardIterator< Item >
typedef QList< QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > > List
 A QList containing QAbstractXmlForwardIterator::Ptr instances. More...
 
typedef QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
 A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass. More...
 
typedef QVector< QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > > Vector
 A QVector containing QAbstractXmlForwardIterator::Ptr instances. More...
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

An QAbstractXmlForwardIterator that gets its item from a cache unless its empty, in which case it continues to populate the cache as well as deliver on its own from a source QAbstractXmlForwardIterator.

Author
Frans Englich frans.nosp@m..fra.nosp@m.ns.en.nosp@m.glic.nosp@m.h@nok.nosp@m.ia.c.nosp@m.om

Definition at line 75 of file qcachingiterator_p.h.

Constructors and Destructors

◆ CachingIterator()

CachingIterator::CachingIterator ( ItemSequenceCacheCell::Vector cacheCells,
const VariableSlotID  slot,
const DynamicContext::Ptr context 
)

We always use the same cache cell so why don't we use it directly, instead of passing the slot and ItemSequenceCacheCell::Vector to this class? Because the GenericDynamicContext might decide to resize the vector and that would invalidate the reference.

We intentionally pass in a non-const reference here.

Definition at line 50 of file qcachingiterator.cpp.

Referenced by copy().

52  : m_position(0),
53  m_varSlot(slot),
54  m_context(context),
55  m_cacheCells(cacheCells),
56  m_usingCache(true)
57 {
58  Q_ASSERT(m_varSlot > -1);
64  "It makes no sense to construct a CachingIterator for a cache that is ItemSequenceCacheCell::Full.");
65 }
const DynamicContext::Ptr m_context
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
ItemSequenceCacheCell::Vector & m_cacheCells
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
const VariableSlotID m_varSlot
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
Item::Iterator::Ptr sourceIterator
#define Q_FUNC_INFO
Definition: qglobal.h:1871

Functions

◆ copy()

Item::Iterator::Ptr CachingIterator::copy ( ) const
virtual

Copies this QAbstractXmlForwardIterator and returns the copy.

Warning
This function is not part of the public interface.

A copy and the original instance are completely independent of each other. Because evaluating an QAbstractXmlForwardIterator modifies it, one should always use a copy when an QAbstractXmlForwardIterator needs to be used several times.

Reimplemented from QAbstractXmlForwardIterator< Item >.

Definition at line 121 of file qcachingiterator.cpp.

122 {
125  return makeListIterator(cell.cachedItems);
126  else
128 }
CachingIterator(ItemSequenceCacheCell::Vector &cacheCells, const VariableSlotID slot, const DynamicContext::Ptr &context)
QAbstractXmlForwardIterator< T >::Ptr makeListIterator(const QList< T > &list)
const DynamicContext::Ptr m_context
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< Item > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
Represents a cache entry for a sequence of items.
ItemSequenceCacheCell::Vector & m_cacheCells
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
const VariableSlotID m_varSlot

◆ current()

Item CachingIterator::current ( ) const
virtual

Returns the current item in the sequence.

If this function is called before the first call to next(), a null object is returned. If the end of the sequence has been reached, a null object is returned.

Implements QAbstractXmlForwardIterator< Item >.

Definition at line 111 of file qcachingiterator.cpp.

112 {
113  return m_current;
114 }

◆ next()

Item CachingIterator::next ( )
virtual

Returns the next item in the sequence, or a null object if the end has been reached.

Implements QAbstractXmlForwardIterator< Item >.

Definition at line 67 of file qcachingiterator.cpp.

68 {
70  if(m_position == -1)
71  return Item();
72 
73  if(m_usingCache)
74  {
75  ++m_position;
76 
77  /* QAbstractXmlForwardIterator::position() starts at 1, while Qt's container classes
78  * starts at 0. */
79  if(m_position - 1 < cell.cachedItems.count())
80  {
81  m_current = cell.cachedItems.at(m_position - 1);
82  return m_current;
83  }
84  else
85  {
87  m_usingCache = false;
88  /* We decrement here so we don't have to add a branch for this
89  * when using the source QAbstractXmlForwardIterator below. */
90  --m_position;
91  }
92  }
93 
94  m_current = cell.sourceIterator->next();
95 
96  if(m_current)
97  {
100  ++m_position;
101  return m_current;
102  }
103  else
104  {
105  m_position = -1;
107  return Item();
108  }
109 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
Represents a cache entry for a sequence of items.
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
ItemSequenceCacheCell::Vector & m_cacheCells
const VariableSlotID m_varSlot
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Item::Iterator::Ptr sourceIterator

◆ position()

xsInteger CachingIterator::position ( ) const
virtual

Returns the current position in the sequence represented by this.

The first position is 1, not 0. If next() hasn't been called, 0 is returned. If this has reached the end, -1 is returned.

Implements QAbstractXmlForwardIterator< Item >.

Definition at line 116 of file qcachingiterator.cpp.

117 {
118  return m_position;
119 }

Properties

◆ m_cacheCells

ItemSequenceCacheCell::Vector& QPatternist::CachingIterator::m_cacheCells
private

We intentionally store a reference here such that we are able to modify the item.

Definition at line 115 of file qcachingiterator_p.h.

Referenced by CachingIterator(), copy(), and next().

◆ m_context

const DynamicContext::Ptr QPatternist::CachingIterator::m_context
private

We don't use the context. We only keep a reference such that it doesn't get deleted, and m_cacheCells starts to dangle.

Definition at line 109 of file qcachingiterator_p.h.

Referenced by CachingIterator(), and copy().

◆ m_current

Item QPatternist::CachingIterator::m_current
private

Definition at line 96 of file qcachingiterator_p.h.

Referenced by current(), and next().

◆ m_position

xsInteger QPatternist::CachingIterator::m_position
private

Definition at line 97 of file qcachingiterator_p.h.

Referenced by next(), and position().

◆ m_usingCache

bool QPatternist::CachingIterator::m_usingCache
private

Whether this CachingIterator is delivering items from m_cacheCell.cacheItems or from m_cacheCell.sourceIterator.

Definition at line 121 of file qcachingiterator_p.h.

Referenced by next().

◆ m_varSlot

const VariableSlotID QPatternist::CachingIterator::m_varSlot
private

This variable cannot be called m_slot, because /usr/include/sys/sysmacros.h on hpuxi-acc defines it.

Definition at line 103 of file qcachingiterator_p.h.

Referenced by CachingIterator(), copy(), and next().


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