Qt 4.8
Classes | Functions
qdatastream.h File Reference
#include <QtCore/qscopedpointer.h>
#include <QtCore/qiodevice.h>
#include <QtCore/qglobal.h>

Go to the source code of this file.

Classes

class  QDataStream
 The QDataStream class provides serialization of binary data to a QIODevice. More...
 
class  QHash< Key, T >
 The QHash class is a template class that provides a hash-table-based dictionary. More...
 
class  QLinkedList< T >
 The QLinkedList class is a template class that provides linked lists. More...
 
class  QList< T >
 The QList class is a template class that provides lists. More...
 
class  QMap< Key, T >
 The QMap class is a template class that provides a skip-list-based dictionary. More...
 
class  QSet< T >
 
class  QVector< T >
 The QVector class is a template class that provides a dynamic array. More...
 

Functions

template<typename T >
QDataStreamoperator<< (QDataStream &s, const QList< T > &l)
 
template<typename T >
QDataStreamoperator<< (QDataStream &s, const QLinkedList< T > &l)
 
template<typename T >
QDataStreamoperator<< (QDataStream &s, const QVector< T > &v)
 
template<typename T >
QDataStreamoperator<< (QDataStream &out, const QSet< T > &set)
 
template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QDataStreamoperator<< (QDataStream &out, const QHash< Key, T > &hash)
 
template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QDataStreamoperator<< (QDataStream &out, const QMap< Key, T > &map)
 
template<typename T >
QDataStreamoperator>> (QDataStream &s, QList< T > &l)
 
template<typename T >
QDataStreamoperator>> (QDataStream &s, QLinkedList< T > &l)
 
template<typename T >
QDataStreamoperator>> (QDataStream &s, QVector< T > &v)
 
template<typename T >
QDataStreamoperator>> (QDataStream &in, QSet< T > &set)
 
template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QDataStreamoperator>> (QDataStream &in, QHash< Key, T > &hash)
 
template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QDataStreamoperator>> (QDataStream &in, QMap< Key, T > &map)
 

Function Documentation

◆ operator<<() [1/6]

template<typename T >
QDataStream& operator<< ( QDataStream s,
const QList< T > &  l 
)
related

Definition at line 261 of file qdatastream.h.

262 {
263  s << quint32(l.size());
264  for (int i = 0; i < l.size(); ++i)
265  s << l.at(i);
266  return s;
267 }
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
unsigned int quint32
Definition: qglobal.h:938
int size() const
Returns the number of items in the list.
Definition: qlist.h:137

◆ operator<<() [2/6]

template<typename T >
QDataStream& operator<< ( QDataStream s,
const QLinkedList< T > &  l 
)
related

Definition at line 287 of file qdatastream.h.

288 {
289  s << quint32(l.size());
291  for(; it != l.constEnd(); ++it)
292  s << *it;
293  return s;
294 }
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlinkedlist.h:184
#define it(className, varName)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlinkedlist.h:187
The QLinkedList::const_iterator class provides an STL-style const iterator for QLinkedList.
Definition: qlinkedlist.h:151
unsigned int quint32
Definition: qglobal.h:938
int size() const
Returns the number of items in the list.
Definition: qlinkedlist.h:96

◆ operator<<() [3/6]

template<typename T >
QDataStream& operator<< ( QDataStream s,
const QVector< T > &  v 
)
related

Definition at line 312 of file qdatastream.h.

313 {
314  s << quint32(v.size());
315  for (typename QVector<T>::const_iterator it = v.begin(); it != v.end(); ++it)
316  s << *it;
317  return s;
318 }
#define it(className, varName)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
unsigned int quint32
Definition: qglobal.h:938
const T * const_iterator
The QVector::const_iterator typedef provides an STL-style const iterator for QVector and QStack...
Definition: qvector.h:245
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ operator<<() [4/6]

template<typename T >
QDataStream& operator<< ( QDataStream out,
const QSet< T > &  set 
)

Definition at line 337 of file qdatastream.h.

338 {
339  out << quint32(set.size());
340  typename QSet<T>::const_iterator i = set.constBegin();
341  while (i != set.constEnd()) {
342  out << *i;
343  ++i;
344  }
345  return out;
346 }
unsigned int quint32
Definition: qglobal.h:938

◆ operator<<() [5/6]

template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QDataStream& operator<< ( QDataStream out,
const QHash< Key, T > &  hash 
)
related

Definition at line 376 of file qdatastream.h.

377 {
378  out << quint32(hash.size());
379  typename QHash<Key, T>::ConstIterator it = hash.end();
380  typename QHash<Key, T>::ConstIterator begin = hash.begin();
381  while (it != begin) {
382  --it;
383  out << it.key() << it.value();
384  }
385  return out;
386 }
The QHash::const_iterator class provides an STL-style const iterator for QHash and QMultiHash...
Definition: qhash.h:395
#define it(className, varName)
int size() const
Returns the number of items in the hash.
Definition: qhash.h:295
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
unsigned int quint32
Definition: qglobal.h:938
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464

◆ operator<<() [6/6]

template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QDataStream& operator<< ( QDataStream out,
const QMap< Key, T > &  map 
)
related

Definition at line 422 of file qdatastream.h.

423 {
424  out << quint32(map.size());
425  typename QMap<Key, T>::ConstIterator it = map.end();
426  typename QMap<Key, T>::ConstIterator begin = map.begin();
427  while (it != begin) {
428  --it;
429  out << it.key() << it.value();
430  }
431  return out;
432 }
#define it(className, varName)
int size() const
Returns the number of (key, value) pairs in the map.
Definition: qmap.h:201
iterator begin()
Returns an STL-style iterator pointing to the first item in the map.
Definition: qmap.h:372
The QMap::const_iterator class provides an STL-style const iterator for QMap and QMultiMap.
Definition: qmap.h:301
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the map...
Definition: qmap.h:375
unsigned int quint32
Definition: qglobal.h:938

◆ operator>>() [1/6]

template<typename T >
QDataStream& operator>> ( QDataStream s,
QList< T > &  l 
)
related

Definition at line 243 of file qdatastream.h.

244 {
245  l.clear();
246  quint32 c;
247  s >> c;
248  l.reserve(c);
249  for(quint32 i = 0; i < c; ++i)
250  {
251  T t;
252  s >> t;
253  l.append(t);
254  if (s.atEnd())
255  break;
256  }
257  return s;
258 }
unsigned char c[8]
Definition: qnumeric_p.h:62
bool atEnd() const
Returns true if the I/O device has reached the end position (end of the stream or file) or if there i...
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
void clear()
Removes all items from the list.
Definition: qlist.h:764
unsigned int quint32
Definition: qglobal.h:938
void reserve(int size)
Reserve space for alloc elements.
Definition: qlist.h:496

◆ operator>>() [2/6]

template<typename T >
QDataStream& operator>> ( QDataStream s,
QLinkedList< T > &  l 
)
related

Definition at line 270 of file qdatastream.h.

271 {
272  l.clear();
273  quint32 c;
274  s >> c;
275  for(quint32 i = 0; i < c; ++i)
276  {
277  T t;
278  s >> t;
279  l.append(t);
280  if (s.atEnd())
281  break;
282  }
283  return s;
284 }
void clear()
Removes all the items in the list.
Definition: qlinkedlist.h:311
unsigned char c[8]
Definition: qnumeric_p.h:62
bool atEnd() const
Returns true if the I/O device has reached the end position (end of the stream or file) or if there i...
void append(const T &)
Inserts value at the end of the list.
Definition: qlinkedlist.h:350
unsigned int quint32
Definition: qglobal.h:938

◆ operator>>() [3/6]

template<typename T >
QDataStream& operator>> ( QDataStream s,
QVector< T > &  v 
)
related

Definition at line 297 of file qdatastream.h.

298 {
299  v.clear();
300  quint32 c;
301  s >> c;
302  v.resize(c);
303  for(quint32 i = 0; i < c; ++i) {
304  T t;
305  s >> t;
306  v[i] = t;
307  }
308  return s;
309 }
unsigned char c[8]
Definition: qnumeric_p.h:62
void resize(int size)
Sets the size of the vector to size.
Definition: qvector.h:342
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
unsigned int quint32
Definition: qglobal.h:938

◆ operator>>() [4/6]

template<typename T >
QDataStream& operator>> ( QDataStream in,
QSet< T > &  set 
)

Definition at line 321 of file qdatastream.h.

322 {
323  set.clear();
324  quint32 c;
325  in >> c;
326  for (quint32 i = 0; i < c; ++i) {
327  T t;
328  in >> t;
329  set << t;
330  if (in.atEnd())
331  break;
332  }
333  return in;
334 }
unsigned char c[8]
Definition: qnumeric_p.h:62
bool atEnd() const
Returns true if the I/O device has reached the end position (end of the stream or file) or if there i...
unsigned int quint32
Definition: qglobal.h:938

◆ operator>>() [5/6]

template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QDataStream& operator>> ( QDataStream in,
QHash< Key, T > &  hash 
)
related

Definition at line 349 of file qdatastream.h.

350 {
351  QDataStream::Status oldStatus = in.status();
352  in.resetStatus();
353  hash.clear();
354 
355  quint32 n;
356  in >> n;
357 
358  for (quint32 i = 0; i < n; ++i) {
359  if (in.status() != QDataStream::Ok)
360  break;
361 
362  Key k;
363  T t;
364  in >> k >> t;
365  hash.insertMulti(k, t);
366  }
367 
368  if (in.status() != QDataStream::Ok)
369  hash.clear();
370  if (oldStatus != QDataStream::Ok)
371  in.setStatus(oldStatus);
372  return in;
373 }
Status status() const
Returns the status of the data stream.
void clear()
Removes all items from the hash.
Definition: qhash.h:574
Status
This enum describes the current status of the data stream.
Definition: qdatastream.h:101
void setStatus(Status status)
Sets the status of the data stream to the status given.
void resetStatus()
Resets the status of the data stream.
unsigned int quint32
Definition: qglobal.h:938
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:772

◆ operator>>() [6/6]

template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QDataStream& operator>> ( QDataStream in,
QMap< Key, T > &  map 
)
related

Definition at line 389 of file qdatastream.h.

394 {
395  QDataStream::Status oldStatus = in.status();
396  in.resetStatus();
397  map.clear();
398 
399  quint32 n;
400  in >> n;
401 
402  map.detach();
403  map.setInsertInOrder(true);
404  for (quint32 i = 0; i < n; ++i) {
405  if (in.status() != QDataStream::Ok)
406  break;
407 
408  aKey key;
409  aT value;
410  in >> key >> value;
411  map.insertMulti(key, value);
412  }
413  map.setInsertInOrder(false);
414  if (in.status() != QDataStream::Ok)
415  map.clear();
416  if (oldStatus != QDataStream::Ok)
417  in.setStatus(oldStatus);
418  return in;
419 }
Status status() const
Returns the status of the data stream.
void setInsertInOrder(bool ordered)
Definition: qmap.h:209
Status
This enum describes the current status of the data stream.
Definition: qdatastream.h:101
void setStatus(Status status)
Sets the status of the data stream to the status given.
iterator insertMulti(const Key &key, const T &value)
Inserts a new item with the key key and a value of value.
Definition: qmap.h:595
void detach()
Detaches this map from any other maps with which it may share data.
Definition: qmap.h:205
void resetStatus()
Resets the status of the data stream.
int key
unsigned int quint32
Definition: qglobal.h:938
void clear()
Removes all items from the map.
Definition: qmap.h:444