Qt 4.8
qabstractxmlforwarditerator_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 //
43 // W A R N I N G
44 // -------------
45 //
46 // This file is not part of the Qt API. It exists purely as an
47 // implementation detail. This header file may change from version to
48 // version without notice, or even be removed.
49 //
50 // We mean it.
51 
52 #ifndef QABSTRACTXMLFORWARDITERATOR_H
53 #define QABSTRACTXMLFORWARDITERATOR_H
54 
55 #include <QtCore/QList>
56 #include <QtCore/QVector>
57 #include <QtCore/QSharedData>
58 #include <QtCore/QString>
59 
61 
63 
64 QT_MODULE(XmlPatterns)
65 
66 template<typename T> class QVector;
67 
68 /* In this file we in some cases do not use QAbstractXmlForwardIterator's Ptr typedef.
69  * This is a compiler workaround for MS VS 6.0. */
70 
71 template<typename T>
72 inline bool qIsForwardIteratorEnd(const T &unit)
73 {
74  return !unit;
75 }
76 
84 template<>
85 inline bool qIsForwardIteratorEnd(const QString &unit)
86 {
87  return unit.isNull();
88 }
89 
90 template<typename T> class QAbstractXmlForwardIterator;
91 
92 class QAbstractXmlForwardIteratorPrivate;
93 
94 template<typename T>
96 {
97 public:
101 
104 
105  virtual T next() = 0;
106  virtual T current() const = 0;
107 
108  virtual qint64 position() const = 0;
109 
111  virtual QList<T> toList();
112  virtual typename QAbstractXmlForwardIterator<T>::Ptr copy() const;
113  virtual T last();
114  virtual bool isEmpty();
115  virtual qint64 count();
116  virtual qint64 sizeHint() const;
117 
118 private:
120 
121  QAbstractXmlForwardIteratorPrivate *d_ptr; /* Currently not used. */
122 };
123 
124 /* The namespace QPatternist and its members are internal, not part of the public API, and
125  * unsupported. Using them leads to undefined behavior. */
126 namespace QPatternist
127 {
128  class DeduplicateIterator;
129 
130  template<typename InputType,
131  typename OutputType,
132  typename Derived,
133  typename ListType = QList<InputType> >
135  {
136  /* This declaration is a workaround for a set of GCC versions on OS X,
137  * amongst others powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1. In
138  * DeduplicateIterator, it fails to see the protected inheritance. */
139  friend class DeduplicateIterator;
140 
141  public:
142  virtual OutputType next()
143  {
144  if(m_position == -1)
145  return OutputType();
146 
147  if(m_position == m_list.count())
148  {
149  m_position = -1;
150  m_current = OutputType();
151  return OutputType();
152  }
153 
154  m_current = static_cast<const Derived *>(this)->inputToOutputItem(m_list.at(m_position));
155  ++m_position;
156  return m_current;
157  }
158 
159  virtual OutputType current() const
160  {
161  return m_current;
162  }
163 
164  virtual qint64 position() const
165  {
166  return m_position;
167  }
168 
169  virtual qint64 count()
170  {
171  return m_list.count();
172  }
173 
175  {
177  }
178 
179  protected:
180  inline ListIteratorPlatform(const ListType &list) : m_list(list)
181  , m_position(0)
182  {
183  }
184 
185  const ListType m_list;
187  OutputType m_current;
188  };
189 
190  template<typename T,
191  typename ListType = QList<T> >
192  class ListIterator : public ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>
193  {
194  /*
195  * This declaration is needed for MSVC 2005, 14.00.50727.42 for 80x86.
196  */
197  friend class IteratorVector;
198 
200 
201  static inline QVector<T> toVector(const QVector<T> &vector)
202  {
203  return vector;
204  }
205 
206  static inline QVector<T> toVector(const QList<T> &list)
207  {
208  return list.toVector();
209  }
210 
211  static inline QList<T> toList(const QVector<T> &vector)
212  {
213  return vector.toList();
214  }
215 
216  static inline QList<T> toList(const QList<T> &list)
217  {
218  return list;
219  }
220 
221  public:
222  inline ListIterator(const ListType &list) : ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>(list)
223  {
224  }
225 
226  virtual QList<T> toList()
227  {
228  return toList(m_list);
229  }
230 
232  {
233  return toVector(m_list);
234  }
235 
236  private:
237  inline const T &inputToOutputItem(const T &inputType) const
238  {
239  return inputType;
240  }
241  friend class ListIteratorPlatform<T, T, ListIterator<T, ListType>, ListType>;
242 
243  // needed for MSVC 2005
244  friend class DeduplicateIterator;
245  };
246 
247  template<typename T>
248  inline
251  {
252  return typename ListIterator<T>::Ptr(new ListIterator<T>(list));
253  }
254 
255  template<typename T>
256  inline
259  {
260  return typename ListIterator<T, QVector<T> >::Ptr(new ListIterator<T, QVector<T> >(vector));
261  }
262 }
263 
264 template<typename T>
266 {
267  QList<T> result;
268  T item(next());
269 
270  while(!qIsForwardIteratorEnd(item))
271  {
272  result.append(item);
273  item = next();
274  }
275 
276  return result;
277 }
278 
279 template<typename T>
281 {
282  qint64 retval = 0;
283 
284  while(!qIsForwardIteratorEnd(next()))
285  ++retval;
286 
287  return retval;
288 }
289 
290 template<typename T>
292 {
293  T item(next());
294  QList<T> result;
295 
296  while(!qIsForwardIteratorEnd(item))
297  {
298  result.prepend(item);
299  item = next();
300  }
301 
303 }
304 
305 template<typename T>
307 {
308  T item(next());
309 
310  while(!qIsForwardIteratorEnd(item))
311  item = next();
312 
313  return item;
314 }
315 
316 template<typename T>
318 {
319  Q_ASSERT_X(false, Q_FUNC_INFO,
320  "This function is internal, unsupported, and should never be called.");
321  return typename QAbstractXmlForwardIterator<T>::Ptr();
322 }
323 
324 template<typename T>
326 {
327  return qIsForwardIteratorEnd(next());
328 }
329 
330 template<typename T>
332 {
333  Q_ASSERT_X(false, Q_FUNC_INFO, "This function is currently not expected to be used.");
334  return -1;
335 }
336 
338 
340 
341 #endif
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QList< T > toList() const
Returns a QList object with the data contained in this QVector.
Definition: qvector.h:770
#define QT_MODULE(x)
Definition: qglobal.h:2783
virtual T current() const =0
Returns the current item in the sequence.
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
virtual bool isEmpty()
Returns true if the sequence is empty.
QList< QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > > List
A QList containing QAbstractXmlForwardIterator::Ptr instances.
virtual QAbstractXmlForwardIterator< OutputType >::Ptr copy() const
Copies this QAbstractXmlForwardIterator and returns the copy.
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
virtual QList< T > toList()
Performs a copy of this QAbstractXmlForwardIterator(with copy()), and returns its items in a QList...
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
QAbstractXmlForwardIterator< T >::Ptr makeListIterator(const QList< T > &list)
virtual OutputType next()
Returns the next item in the sequence, or a null object if the end has been reached.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QVector< T > toVector() const
Returns a QVector object with the data contained in this QList.
Definition: qvector.h:780
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
virtual OutputType current() const
Returns the current item in the sequence.
virtual qint64 count()
Determines the number of items this QAbstractXmlForwardIterator represents.
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > Ptr
A smart pointer wrapping an instance of a QAbstractXmlForwardIterator subclass.
QVector< QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< T > > > Vector
A QVector containing QAbstractXmlForwardIterator::Ptr instances.
virtual qint64 sizeHint() const
Gives a hint to the size of the contained sequence.
QAbstractXmlForwardIterator< T >::Ptr makeVectorIterator(const QVector< T > &vector)
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static QVector< T > toVector(const QList< T > &list)
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
The QAbstractXmlForwardIterator class is a base class for forward iterators.
The namespace for the internal API of QtXmlPatterns.
Performs deduplication of the nodes on its source list.
__int64 qint64
Definition: qglobal.h:942
Helper class for ListIterator, and should only be instantiated through sub-classing.
virtual T last()
Returns the item at the end of this QAbstractXmlForwardIterator.
virtual qint64 count()
Determines the number of items this QAbstractXmlForwardIterator represents.
ListIteratorPlatform(const ListType &list)
Constructs a ListIteratorPlatform that walks the given list.
virtual qint64 position() const =0
Returns the current position in the sequence represented by this.
virtual QAbstractXmlForwardIterator< T >::Ptr copy() const
Copies this QAbstractXmlForwardIterator and returns the copy.
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
bool qIsForwardIteratorEnd(const T &unit)
The Callback QAbstractXmlForwardIterator uses for determining whether unit is the end of a sequence...
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
virtual ~QAbstractXmlForwardIterator()
Destructor.
QAbstractXmlForwardIteratorPrivate * d_ptr
The QSharedData class is a base class for shared data objects.
Definition: qshareddata.h:56
const T & inputToOutputItem(const T &inputType) const
bool qIsForwardIteratorEnd(const QString &unit)
Helper class for StringSplitter.
virtual qint64 position() const
Returns the current position in the sequence represented by this.
virtual QList< T > toList()
Performs a copy of this QAbstractXmlForwardIterator(with copy()), and returns its items in a QList...
static QList< T > toList(const QList< T > &list)
QAbstractXmlForwardIterator()
Default constructor.
#define QT_END_HEADER
Definition: qglobal.h:137
static QVector< T > toVector(const QVector< T > &vector)
Bridges values in Qt&#39;s QList container class into an QAbstractXmlForwardIterator. ...
virtual T next()=0
Returns the next item in the sequence, or a null object if the end has been reached.
static QList< T > toList(const QVector< T > &vector)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
virtual QAbstractXmlForwardIterator< T >::Ptr toReversed()
Returns a reverse iterator for the sequence.
#define Q_FUNC_INFO
Definition: qglobal.h:1871