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

Bridges a QPatternist::SequenceIterator to QAbstractXmlPullProvider. More...

#include <qpullbridge_p.h>

Inheritance diagram for QPatternist::PullBridge:
QPatternist::AbstractXmlPullProvider

Public Functions

virtual QVariant atomicValue () const
 
virtual QHash< QXmlName, QXmlItemattributeItems ()
 
virtual QHash< QXmlName, QStringattributes ()
 If the current() is Element, the attributes of the element are returned, an empty list of attributes otherwise. More...
 
virtual Event current () const
 Returns the event that next() returned the last time it was called. More...
 
QXmlNodeModelIndex index () const
 
virtual QXmlName name () const
 If the current event is StartElement, EndElement, ProcessingInstruction, Attribute, or Namespace, the node's name is returned. More...
 
virtual Event next ()
 Advances this AbstractXmlPullProvider, and returns the new event. More...
 
 PullBridge (const QXmlNodeModelIndex::Iterator::Ptr &it)
 
QSourceLocation sourceLocation () const
 
virtual QString stringValue () const
 If current() is Text, the text node's value is returned. More...
 
- Public Functions inherited from QPatternist::AbstractXmlPullProvider
 AbstractXmlPullProvider ()
 Constucts a AbstractXmlPullProvider instance. More...
 
virtual ~AbstractXmlPullProvider ()
 Destructs this AbstractXmlPullProvider. More...
 

Private Types

typedef QStack< QPair< Event, QXmlNodeModelIndex::Iterator::Ptr > > IteratorStack
 

Properties

Event m_current
 
QXmlNodeModelIndex m_index
 
IteratorStack m_iterators
 

Additional Inherited Members

- Public Types inherited from QPatternist::AbstractXmlPullProvider
enum  Event {
  StartOfInput = 1, AtomicValue = 1 << 1, StartDocument = 1 << 2, EndDocument = 1 << 3,
  StartElement = 1 << 4, EndElement = 1 << 5, Text = 1 << 6, ProcessingInstruction = 1 << 7,
  Comment = 1 << 8, Attribute = 1 << 9, Namespace = 1 << 10, EndOfInput = 1 << 11
}
 

Detailed Description

Bridges a QPatternist::SequenceIterator to QAbstractXmlPullProvider.

Warning
This function is not part of the public interface.
Note
This class or function is reentrant.

The approach of this class is rather straight forward since QPatternist::SequenceIterator and QAbstractXmlPullProvider are conceptually similar. While QPatternist::SequenceIterator only delivers top level items(since it's not an event stream, it's a list of items), PullBridge needs to recursively iterate the children of nodes too, which is achieved through the stack m_iterators.

Definition at line 68 of file qpullbridge_p.h.

Typedefs

◆ IteratorStack

Definition at line 92 of file qpullbridge_p.h.

Constructors and Destructors

◆ PullBridge()

QPatternist::PullBridge::PullBridge ( const QXmlNodeModelIndex::Iterator::Ptr it)
inline

Definition at line 71 of file qpullbridge_p.h.

72  {
73  Q_ASSERT(it);
75  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
IteratorStack m_iterators
Definition: qpullbridge_p.h:93
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102

Functions

◆ atomicValue()

QVariant PullBridge::atomicValue ( ) const
virtual

Returns always an empty QVariant.

Implements QPatternist::AbstractXmlPullProvider.

Definition at line 188 of file qpullbridge.cpp.

Referenced by PullBridge().

189 {
190  return QVariant();
191 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

◆ attributeItems()

QHash< QXmlName, QXmlItem > PullBridge::attributeItems ( )
virtual

Implements QPatternist::AbstractXmlPullProvider.

Definition at line 216 of file qpullbridge.cpp.

Referenced by PullBridge(), and QPatternist::XsdInstanceReader::readNext().

217 {
219 
221 
223  QXmlNodeModelIndex index = it->next();
224  while (!index.isNull()) {
225  const Item attribute(index);
226  attributes.insert(index.name(), QXmlItem(index));
227 
228  index = it->next();
229  }
230 
231  return attributes;
232 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
bool isNull() const
Returns true if this QXmlNodeModelIndex is a default constructed value, otherwise false...
#define it(className, varName)
QXmlNodeModelIndex index() const
The QXmlItem class contains either an XML node or an atomic value.
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
virtual QHash< QXmlName, QString > attributes()
If the current() is Element, the attributes of the element are returned, an empty list of attributes ...
QXmlName name() const
Definition: qitem_p.h:446
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const Axis axis) const
Definition: qitem_p.h:456
QXmlNodeModelIndex m_index
Definition: qpullbridge_p.h:94

◆ attributes()

QHash< QXmlName, QString > PullBridge::attributes ( )
virtual

If the current() is Element, the attributes of the element are returned, an empty list of attributes otherwise.

Implements QPatternist::AbstractXmlPullProvider.

Definition at line 198 of file qpullbridge.cpp.

Referenced by attributeItems(), PullBridge(), and QPatternist::XsdInstanceReader::readNext().

199 {
201 
203 
205  QXmlNodeModelIndex index = it->next();
206  while (!index.isNull()) {
207  const Item attribute(index);
208  attributes.insert(index.name(), index.stringValue());
209 
210  index = it->next();
211  }
212 
213  return attributes;
214 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
bool isNull() const
Returns true if this QXmlNodeModelIndex is a default constructed value, otherwise false...
#define it(className, varName)
QXmlNodeModelIndex index() const
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
virtual QHash< QXmlName, QString > attributes()
If the current() is Element, the attributes of the element are returned, an empty list of attributes ...
QXmlName name() const
Definition: qitem_p.h:446
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const Axis axis) const
Definition: qitem_p.h:456
QString stringValue() const
Definition: qitem_p.h:509
QXmlNodeModelIndex m_index
Definition: qpullbridge_p.h:94

◆ current()

AbstractXmlPullProvider::Event PullBridge::current ( ) const
virtual

Returns the event that next() returned the last time it was called.

It doesn't alter this AbstractXmlPullProvider.

current() may not modify this AbstractXmlPullProvider's state. Subsequent calls to current() must return the same value.

See also
AbstractXmlPullProvider::Event

Implements QPatternist::AbstractXmlPullProvider.

Definition at line 168 of file qpullbridge.cpp.

Referenced by QPatternist::XsdInstanceReader::atEnd(), QPatternist::XsdInstanceReader::isEndElement(), QPatternist::XsdInstanceReader::isStartElement(), PullBridge(), and QPatternist::XsdInstanceReader::readNext().

169 {
170  return m_current;
171 }

◆ index()

QXmlNodeModelIndex PullBridge::index ( ) const

◆ name()

QXmlName PullBridge::name ( ) const
virtual

If the current event is StartElement, EndElement, ProcessingInstruction, Attribute, or Namespace, the node's name is returned.

If the current event is ProcessingInstruction, the processing instruction target is in in the local name.

If the current event is Namespace, the name's namespace URI is the namespace, and the local name is the prefix the name is binding to.

In all other cases, an invalid QName is returned.

Implements QPatternist::AbstractXmlPullProvider.

Definition at line 183 of file qpullbridge.cpp.

Referenced by QPatternist::XsdInstanceReader::name(), and PullBridge().

184 {
185  return m_index.name();
186 }
QXmlName name() const
Definition: qitem_p.h:446
QXmlNodeModelIndex m_index
Definition: qpullbridge_p.h:94

◆ next()

AbstractXmlPullProvider::Event PullBridge::next ( )
virtual

Advances this AbstractXmlPullProvider, and returns the new event.

See also
current()

Implements QPatternist::AbstractXmlPullProvider.

Definition at line 73 of file qpullbridge.cpp.

Referenced by PullBridge(), and QPatternist::XsdInstanceReader::readNext().

74 {
75  m_index = m_iterators.top().second->next();
76 
77  if(!m_index.isNull())
78  {
79  Item item(m_index);
80 
81  if(item && item.isAtomicValue())
83  else
84  {
85  Q_ASSERT(item.isNode());
86 
87  switch(m_index.kind())
88  {
90  {
92  break;
93  }
95  {
97  break;
98  }
100  {
103  break;
104  }
106  {
109  break;
110  }
112  {
114  break;
115  }
117  {
119  break;
120  }
122  {
123  m_current = Text;
124  break;
125  }
126  }
127  }
128  }
129  else
130  {
131  if(m_iterators.isEmpty())
133  else
134  {
135  switch(m_iterators.top().first)
136  {
137  case StartOfInput:
138  {
140  break;
141  }
142  case StartElement:
143  {
145  m_iterators.pop();
146  break;
147  }
148  case StartDocument:
149  {
151  m_iterators.pop();
152  break;
153  }
154  default:
155  {
156  Q_ASSERT_X(false, Q_FUNC_INFO,
157  "Invalid value.");
159  }
160  }
161  }
162 
163  }
164 
165  return m_current;
166 }
bool isNull() const
Returns true if this QXmlNodeModelIndex is a default constructed value, otherwise false...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
T pop()
Removes the top item from the stack and returns it.
Definition: qstack.h:67
Base class for all classes representing atomic values.
Definition: qitem_p.h:118
IteratorStack m_iterators
Definition: qpullbridge_p.h:93
void push(const T &t)
Adds element t to the top of the stack.
Definition: qstack.h:60
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
QExplicitlySharedDataPointer< QAbstractXmlForwardIterator< QXmlNodeModelIndex > > iterate(const Axis axis) const
Definition: qitem_p.h:456
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
NodeKind kind() const
Definition: qitem_p.h:471
QXmlNodeModelIndex m_index
Definition: qpullbridge_p.h:94
T & top()
Returns a reference to the stack&#39;s top item.
Definition: qstack.h:72
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ sourceLocation()

QSourceLocation PullBridge::sourceLocation ( ) const

Definition at line 178 of file qpullbridge.cpp.

Referenced by PullBridge(), and QPatternist::XsdInstanceReader::readNext().

179 {
180  return m_index.model()->sourceLocation(m_index);
181 }
const QAbstractXmlNodeModel * model() const
Returns the QAbstractXmlNodeModel that this node index refers to.
QSourceLocation sourceLocation(const QXmlNodeModelIndex &index) const
Returns the source location for the object with the given index or a default constructed QSourceLocat...
QXmlNodeModelIndex m_index
Definition: qpullbridge_p.h:94

◆ stringValue()

QString PullBridge::stringValue ( ) const
virtual

If current() is Text, the text node's value is returned.

If the current() event is Comment, its value is returned. The subclasser guarantees it does not contain the string "-->".

If the current() event is ProcessingInstruction, its data is returned. The subclasser guarantees the data does not contain the string "?>".

In other cases, it returns a default constructed string.

Implements QPatternist::AbstractXmlPullProvider.

Definition at line 193 of file qpullbridge.cpp.

Referenced by PullBridge().

194 {
195  return QString();
196 }
The QString class provides a Unicode character string.
Definition: qstring.h:83

Properties

◆ m_current

Event QPatternist::PullBridge::m_current
private

Definition at line 95 of file qpullbridge_p.h.

Referenced by attributeItems(), attributes(), current(), and next().

◆ m_index

QXmlNodeModelIndex QPatternist::PullBridge::m_index
private

Definition at line 94 of file qpullbridge_p.h.

Referenced by attributeItems(), attributes(), index(), name(), next(), and sourceLocation().

◆ m_iterators

IteratorStack QPatternist::PullBridge::m_iterators
private

Definition at line 93 of file qpullbridge_p.h.

Referenced by next(), and PullBridge().


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