Qt 4.8
qitem_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 Patternist_Item_H
53 #define Patternist_Item_H
54 
55 #include <QtXmlPatterns/private/qcppcastinghelper_p.h>
56 #include <QtXmlPatterns/private/qitemtype_p.h>
57 #include <QtXmlPatterns/private/qsingletoniterator_p.h>
58 #include <QtXmlPatterns/QAbstractXmlNodeModel>
59 
60 #include <QUrl>
61 #include <QVariant>
62 
76 
78 
79 template<typename T> class QList;
80 template<typename T> class QVector;
81 template<typename T> class QAbstractXmlForwardIterator;
82 
83 class QSourceLocation;
85 
86 namespace QPatternist
87 {
88  class DynamicContext;
89  class Item;
90  class ItemType;
91  class QObjectNodeModel;
92  template<typename T> class EmptyIterator;
93  template<typename T, typename ListType> class ListIterator;
94 
118  class AtomicValue : public QSharedData
119  , public CppCastingHelper<AtomicValue>
120  {
121  public:
122  virtual ~AtomicValue();
123 
128 
133 
140  virtual bool hasError() const;
141 
147  virtual bool evaluateEBV(const QExplicitlySharedDataPointer<DynamicContext> &context) const;
148 
149  virtual QString stringValue() const = 0;
150  virtual ItemType::Ptr type() const = 0;
151 
155  static QVariant toQt(const AtomicValue *const value);
156 
157  static inline QVariant toQt(const AtomicValue::Ptr &value)
158  {
159  return toQt(value.data());
160  }
161 
162  static Item toXDM(const QVariant &value);
163 
164  static ItemType::Ptr qtToXDMType(const QXmlItem &item);
165  protected:
166  inline AtomicValue()
167  {
168  }
169  };
170 
182  class Item
183  {
184  friend class QT_PREPEND_NAMESPACE(QXmlItem);
185 
186  public:
191 
195  typedef QList<Item> List;
196 
201 
204 
208  inline Item()
209  {
210  node.reset();
211  }
212 
213  inline Item(const QXmlNodeModelIndex &n) : node(n.m_storage)
214  {
215  }
216 
217  inline Item(const Item &other) : node(other.node)
218  {
220  "Since we're only copying the node member, it must be the largest.");
221  if(isAtomicValue())
222  atomicValue->ref.ref();
223  }
224 
225  inline Item(const AtomicValue::Ptr &a)
226  {
227  node.reset();
228  if(a)
229  {
230  atomicValue = a.data();
231  atomicValue->ref.ref();
232 
233  /* Signal that we're housing an atomic value. */
234  node.model = reinterpret_cast<const QAbstractXmlNodeModel *>(~0);
235  }
236  }
237 
238  inline Item(const AtomicValue *const a)
239  {
240  /* Note, the implementation is a copy of the constructor above. */
241  node.reset();
242  if(a)
243  {
244  atomicValue = a;
245  atomicValue->ref.ref();
246 
247  /* Signal that we're housing an atomic value. */
248  node.model = reinterpret_cast<const QAbstractXmlNodeModel *>(~0);
249  }
250  }
251 
252  inline ~Item()
253  {
254  if(isAtomicValue() && !atomicValue->ref.deref())
255  delete atomicValue;
256  }
257 
258  inline Item &operator=(const Item &other)
259  {
261  "If this doesn't hold, we won't copy all data.");
262 
263  if(other.isAtomicValue())
264  other.atomicValue->ref.ref();
265 
266  if(isAtomicValue())
267  {
268  if(!atomicValue->ref.deref())
269  delete atomicValue;
270  }
271 
272  node = other.node;
273 
274  return *this;
275  }
276 
277  template<typename TCastTarget>
278  inline TCastTarget *as() const
279  {
280 #if defined(Patternist_DEBUG) && !defined(Q_CC_XLC)
281 /* At least on aix-xlc-64, the compiler cries when it sees dynamic_cast. */
282  Q_ASSERT_X(atomicValue == 0 || dynamic_cast<const TCastTarget *>(atomicValue),
283  Q_FUNC_INFO,
284  "The cast is invalid. This class does not inherit the cast target.");
285 #endif
286  return const_cast<TCastTarget *>(static_cast<const TCastTarget *>(atomicValue));
287  }
288 
302  inline QString stringValue() const
303  {
304  if(isAtomicValue())
305  return atomicValue->stringValue();
306  else
307  return asNode().stringValue();
308  }
309 
325  Item::Iterator::Ptr sequencedTypedValue() const;
326 
335  inline bool isAtomicValue() const
336  {
337  /* Setting node.model to ~0, signals that it's an atomic value. */
338  return node.model == reinterpret_cast<QAbstractXmlNodeModel *>(~0);
339  }
340 
349  inline bool isNode() const
350  {
351  //return !isAtomicValue();
352  return node.model && node.model != reinterpret_cast<QAbstractXmlNodeModel *>(~0);
353  }
354 
366  {
367  if(isAtomicValue())
368  return atomicValue->type();
369  else
370  return asNode().type();
371  }
372 
373  inline const AtomicValue *asAtomicValue() const
374  {
375  Q_ASSERT(isAtomicValue());
376  return atomicValue;
377  }
378 
379  inline const QXmlNodeModelIndex &asNode() const
380  {
381  Q_ASSERT_X(isNode() || isNull(), Q_FUNC_INFO,
382  "This item isn't a valid QXmlNodeModelIndex.");
384  "If this doesn't hold, something is wrong.");
385 
386  return reinterpret_cast<const QXmlNodeModelIndex &>(node);
387  }
388 
389  inline operator bool() const
390  {
391  return node.model;
392  }
393 
394  inline bool isNull() const
395  {
396  return !node.model;
397  }
398 
399  inline void reset()
400  {
401  /* Delete the atomicValue if necessary*/
402  if(isAtomicValue() && !atomicValue->ref.deref())
403  delete atomicValue;
404 
405  node.reset();
406  }
407 
408  static inline Item fromPublic(const QXmlItem &i)
409  {
410  const Item it(i.m_node);
411  if(it.isAtomicValue())
412  it.asAtomicValue()->ref.ref();
413 
414  return it;
415  }
416 
417  static inline QXmlItem toPublic(const Item &i)
418  {
419  return QXmlItem(i);
420  }
421 
422  private:
423  union
424  {
427  };
428  };
429 
430  template<typename T>
431  inline Item toItem(const QExplicitlySharedDataPointer<T> atomicValue)
432  {
433  return Item(atomicValue.data());
434  }
435 
440  static inline QString formatData(const QXmlNodeModelIndex node)
441  {
442  return node.stringValue(); // This can be improved a lot.
443  }
444 }
445 
447  {
448  return m_storage.model->name(*this);
449  }
450 
452  {
453  return m_storage.model->root(*this);
454  }
455 
457  {
458  return m_storage.model->iterate(*this, axis);
459  }
460 
462  {
463  return m_storage.model->documentUri(*this);
464  }
465 
467  {
468  return m_storage.model->baseUri(*this);
469  }
470 
472  {
473  return m_storage.model->kind(*this);
474  }
475 
476  inline bool QXmlNodeModelIndex::isDeepEqual(const QXmlNodeModelIndex &other) const
477  {
478  return m_storage.model->isDeepEqual(*this, other);
479  }
480 
482  {
483  Q_ASSERT_X(model() == other.model(), Q_FUNC_INFO, "The API docs guarantees the two nodes are from the same model");
484  return m_storage.model->compareOrder(*this, other);
485  }
486 
487  inline bool QXmlNodeModelIndex::is(const QXmlNodeModelIndex &other) const
488  {
489  return m_storage.model == other.m_storage.model &&
490  m_storage.data == other.m_storage.data &&
491  m_storage.additionalData == other.m_storage.additionalData;
492  }
493 
494  inline void QXmlNodeModelIndex::sendNamespaces(QAbstractXmlReceiver *const receiver) const
495  {
496  m_storage.model->sendNamespaces(*this, receiver);
497  }
498 
500  {
501  return m_storage.model->namespaceBindings(*this);
502  }
503 
505  {
506  return m_storage.model->namespaceForPrefix(*this, prefix);
507  }
508 
510  {
511  return m_storage.model->stringValue(*this);
512  }
513 
515  {
516  return m_storage.model->type(*this);
517  }
518 
520  {
521  return m_storage.model->sequencedTypedValue(*this);
522  }
523 
524  inline QXmlItem::QXmlItem(const QPatternist::Item &i) : m_node(i.node)
525  {
526  if(isAtomicValue())
527  m_atomicValue->ref.ref();
528  }
529 
532 
534 
536 
537 #endif
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QAtomicInt ref
Definition: qshareddata.h:59
QExplicitlySharedDataPointer< AtomicValue > Ptr
Definition: qitem_p.h:127
bool isNull() const
Definition: qitem_p.h:394
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
QPatternist::ItemTypePtr type() const
Definition: qitem_p.h:514
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static QVariant toQt(const AtomicValue *const value)
DocumentOrder compareOrder(const QXmlNodeModelIndex &other) const
Definition: qitem_p.h:481
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
virtual bool hasError() const
#define it(className, varName)
NodeIndexStorage node
Definition: qitem_p.h:425
qint16 NamespaceCode
Definition: qxmlname.h:82
Provides convenience methods for performing static casts between C++ classes.
Item(const AtomicValue *const a)
Definition: qitem_p.h:238
Q_DECLARE_TYPEINFO(QPatternist::Item::Iterator::Ptr, Q_MOVABLE_TYPE)
The QXmlItem class contains either an XML node or an atomic value.
Item toItem(const QExplicitlySharedDataPointer< T > atomicValue)
Definition: qitem_p.h:431
const QPatternist::AtomicValue * m_atomicValue
long ASN1_INTEGER_get ASN1_INTEGER * a
bool ref()
Atomically increments the value of this QAtomicInt.
const AtomicValue * asAtomicValue() const
Definition: qitem_p.h:373
const AtomicValue * atomicValue
Definition: qitem_p.h:426
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isNode() const
Determines whether this item is an atomic value, or a node.
Definition: qitem_p.h:349
QPatternist::NodeIndexStorage m_node
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
QVector< QXmlName > namespaceBindings() const
Definition: qitem_p.h:499
const QAbstractXmlNodeModel * model
An QAbstractXmlForwardIterator over exactly one item.
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QPatternist::Item > > sequencedTypedValue() const
Definition: qitem_p.h:519
virtual bool evaluateEBV(const QExplicitlySharedDataPointer< DynamicContext > &context) const
Base class for all classes representing atomic values.
Definition: qitem_p.h:118
bool is(const QXmlNodeModelIndex &other) const
Definition: qitem_p.h:487
The QAbstractXmlNodeModel class is an abstract base class for modeling non-XML data to look like XML ...
DocumentOrder
Identifies the specific node comparison operator that should be used.
QPatternist::NodeIndexStorage m_storage
The QAbstractXmlForwardIterator class is a base class for forward iterators.
The namespace for the internal API of QtXmlPatterns.
virtual ItemType::Ptr type() const =0
QPatternist::SingletonIterator< Item > SingletonIterator
Definition: qitem_p.h:202
QXmlItem()
Constructs a null QXmlItem that is neither a node nor an atomic value.
The QSourceLocation class identifies a location in a resource by URI, line, and column.
QVector< Item > Vector
Definition: qitem_p.h:200
QString stringValue() const
Returns the string value of this Item.
Definition: qitem_p.h:302
virtual QString stringValue() const =0
QXmlName::NamespaceCode namespaceForPrefix(const QXmlName::PrefixCode prefix) const
Definition: qitem_p.h:504
QExplicitlySharedDataPointer< ItemType > type() const
Returns the ItemType this Item is of.
Definition: qitem_p.h:365
The Item is the most basic of all visual items in QML.
QUrl documentUri() const
Definition: qitem_p.h:461
virtual QXmlNodeModelIndex root(const QXmlNodeModelIndex &n) const =0
Returns the root node of the tree that contains the node whose index is n.
const QAbstractXmlNodeModel * model() const
Returns the QAbstractXmlNodeModel that this node index refers to.
QXmlName name() const
Definition: qitem_p.h:446
bool isAtomicValue() const
Determines whether this item is an atomic value, or a node.
Definition: qitem_p.h:335
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
The QAbstractXmlReceiver class provides a callback interface for transforming the output of a QXmlQue...
const QXmlNodeModelIndex & asNode() const
Definition: qitem_p.h:379
Item(const AtomicValue::Ptr &a)
Definition: qitem_p.h:225
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
QXmlNodeModelIndex root() const
Definition: qitem_p.h:451
The QSharedData class is a base class for shared data objects.
Definition: qshareddata.h:56
An QAbstractXmlForwardIterator which always is empty.
Definition: qitem_p.h:92
NodeKind
Identifies a kind of node.
void sendNamespaces(QAbstractXmlReceiver *const receiver) const
Definition: qitem_p.h:494
Item(const QXmlNodeModelIndex &n)
Definition: qitem_p.h:213
QList< Item > List
Definition: qitem_p.h:195
bool isAtomicValue() const
Returns true if this item is an atomic value.
bool isDeepEqual(const QXmlNodeModelIndex &other) const
Definition: qitem_p.h:476
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const Axis axis) const
Definition: qitem_p.h:456
Item(const Item &other)
Definition: qitem_p.h:217
static QVariant toQt(const AtomicValue::Ptr &value)
Definition: qitem_p.h:157
static Item fromPublic(const QXmlItem &i)
Definition: qitem_p.h:408
QUrl baseUri() const
Definition: qitem_p.h:466
static QXmlItem toPublic(const Item &i)
Definition: qitem_p.h:417
Axis
Identify the axes emanating from a node.
TCastTarget * as() const
Definition: qitem_p.h:278
QAbstractXmlForwardIterator< Item > Iterator
Definition: qitem_p.h:190
QList< AtomicValue::Ptr > List
Definition: qitem_p.h:132
Item & operator=(const Item &other)
Definition: qitem_p.h:258
QPatternist::EmptyIterator< Item > EmptyIterator
Definition: qitem_p.h:203
static ItemType::Ptr qtToXDMType(const QXmlItem &item)
#define QT_END_HEADER
Definition: qglobal.h:137
static Item toXDM(const QVariant &value)
QString stringValue() const
Definition: qitem_p.h:509
NodeKind kind() const
Definition: qitem_p.h:471
Bridges values in Qt&#39;s QList container class into an QAbstractXmlForwardIterator. ...
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
static QString formatData(const QXmlNodeModelIndex node)
Definition: qitem_p.h:440
#define Q_FUNC_INFO
Definition: qglobal.h:1871
NamespaceCode PrefixCode
Definition: qxmlname.h:83