- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

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
## Functions
template<typename T >
QDataStream & | operator>> (QDataStream &s, QList< T > &l)
template<typename T >
QDataStream & | operator<< (QDataStream &s, const QList< T > &l)
template<typename T >
QDataStream & | operator>> (QDataStream &s, QLinkedList< T > &l)
template<typename T >
QDataStream & | operator<< (QDataStream &s, const QLinkedList< T > &l)
template<typename T >
QDataStream & | operator>> (QDataStream &s, QVector< T > &v)
template<typename T >
QDataStream & | operator<< (QDataStream &s, const QVector< T > &v)
template<typename T >
QDataStream & | operator>> (QDataStream &in, QSet< T > &set)
template<typename T >
QDataStream & | operator<< (QDataStream &out, const QSet< T > &set)
template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QDataStream & | operator>> (QDataStream &in, QHash< Key, T > &hash)
template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QDataStream & | operator<< (QDataStream &out, const QHash< Key, T > &hash)
template<class aKey , class aT >
Q_OUTOFLINE_TEMPLATE QDataStream & | operator>> (QDataStream &in, QMap< aKey, aT > &map)
template<class Key , class T >
Q_OUTOFLINE_TEMPLATE QDataStream & | operator<< (QDataStream &out, const QMap< Key, T > &map)

## Function Documentation

QDataStream& operator>> | ( | QDataStream & | s,
|  | QList< T > & | l
| ) |  |

Definition at line 241 of file qdatastream.h.

    {
        l.clear();
        quint32 c;
        s >> c;
        l.reserve(c);
        for(quint32 i = 0; i < c; ++i)
        {
            T t;
            s >> t;
            l.append(t);
            if (s.atEnd())
                break;
        }
        return s;
    }

QDataStream& operator<< | ( | QDataStream & | s,
|  | const QList< T > & | l
| ) |  |

Definition at line 259 of file qdatastream.h.

    {
        s << quint32(l.size());
        for (int i = 0; i < l.size(); ++i)
            s << l.at(i);
        return s;
    }

QDataStream& operator>> | ( | QDataStream & | s,
|  | QLinkedList< T > & | l
| ) |  |

Definition at line 268 of file qdatastream.h.

    {
        l.clear();
        quint32 c;
        s >> c;
        for(quint32 i = 0; i < c; ++i)
        {
            T t;
            s >> t;
            l.append(t);
            if (s.atEnd())
                break;
        }
        return s;
    }

QDataStream& operator<< | ( | QDataStream & | s,
|  | const QLinkedList< T > & | l
| ) |  |

Definition at line 285 of file qdatastream.h.

    {
        s << quint32(l.size());
        typename QLinkedList<T>::ConstIterator it = l.constBegin();
        for(; it != l.constEnd(); ++it)
            s << *it;
        return s;
    }

QDataStream& operator>> | ( | QDataStream & | s,
|  | QVector< T > & | v
| ) |  |

Definition at line 295 of file qdatastream.h.

    {
        v.clear();
        quint32 c;
        s >> c;
        v.resize(c);
        for(quint32 i = 0; i < c; ++i) {
            T t;
            s >> t;
            v[i] = t;
        }
        return s;
    }

QDataStream& operator<< | ( | QDataStream & | s,
|  | const QVector< T > & | v
| ) |  |

Definition at line 310 of file qdatastream.h.

    {
        s << quint32(v.size());
        for (typename QVector<T>::const_iterator it = v.begin(); it != v.end(); ++it)
            s << *it;
        return s;
    }

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

Definition at line 319 of file qdatastream.h.

    {
        set.clear();
        quint32 c;
        in >> c;
        for (quint32 i = 0; i < c; ++i) {
            T t;
            in >> t;
            set << t;
            if (in.atEnd())
                break;
        }
        return in;
    }

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

Definition at line 335 of file qdatastream.h.

    {
        out << quint32(set.size());
        typename QSet<T>::const_iterator i = set.constBegin();
        while (i != set.constEnd()) {
            out << *i;
            ++i;
        }
        return out;
    }

Q_OUTOFLINE_TEMPLATE QDataStream& operator>> | ( | QDataStream & | in,
|  | QHash< Key, T > & | hash
| ) |  |

Definition at line 347 of file qdatastream.h.

    {
        QDataStream::Status oldStatus = in.status();
        in.resetStatus();
        hash.clear();

        quint32 n;
        in >> n;

        for (quint32 i = 0; i < n; ++i) {
            if (in.status() != QDataStream::Ok)
                break;

            Key k;
            T t;
            in >> k >> t;
            hash.insertMulti(k, t);
        }

        if (in.status() != QDataStream::Ok)
            hash.clear();
        if (oldStatus != QDataStream::Ok)
            in.setStatus(oldStatus);
        return in;
    }

Q_OUTOFLINE_TEMPLATE QDataStream& operator<< | ( | QDataStream & | out,
|  | const QHash< Key, T > & | hash
| ) |  |

Definition at line 374 of file qdatastream.h.

    {
        out << quint32(hash.size());
        typename QHash<Key, T>::ConstIterator it = hash.end();
        typename QHash<Key, T>::ConstIterator begin = hash.begin();
        while (it != begin) {
            --it;
            out << it.key() << it.value();
        }
        return out;
    }

Q_OUTOFLINE_TEMPLATE QDataStream& operator>> | ( | QDataStream & | in,
|  | QMap< aKey, aT > & | map
| ) |  |

Definition at line 390 of file qdatastream.h.

    {
        QDataStream::Status oldStatus = in.status();
        in.resetStatus();
        map.clear();

        quint32 n;
        in >> n;

        map.detach();
        map.setInsertInOrder(true);
        for (quint32 i = 0; i < n; ++i) {
            if (in.status() != QDataStream::Ok)
                break;

            aKey key;
            aT value;
            in >> key >> value;
            map.insertMulti(key, value);
        }
        map.setInsertInOrder(false);
        if (in.status() != QDataStream::Ok)
            map.clear();
        if (oldStatus != QDataStream::Ok)
            in.setStatus(oldStatus);
        return in;
    }

Q_OUTOFLINE_TEMPLATE QDataStream& operator<< | ( | QDataStream & | out,
|  | const QMap< Key, T > & | map
| ) |  |

Definition at line 420 of file qdatastream.h.

    {
        out << quint32(map.size());
        typename QMap<Key, T>::ConstIterator it = map.end();
        typename QMap<Key, T>::ConstIterator begin = map.begin();
        while (it != begin) {
            --it;
            out << it.key() << it.value();
        }
        return out;
    }