| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the documentation of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:FDL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in a
|
|---|
| 14 | ** written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Free Documentation License
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
|---|
| 18 | ** Documentation License version 1.3 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file included in the packaging of this
|
|---|
| 20 | ** file.
|
|---|
| 21 | **
|
|---|
| 22 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 23 | ** Nokia at [email protected].
|
|---|
| 24 | ** $QT_END_LICENSE$
|
|---|
| 25 | **
|
|---|
| 26 | ****************************************************************************/
|
|---|
| 27 |
|
|---|
| 28 | /*!
|
|---|
| 29 | \class QPair
|
|---|
| 30 | \brief The QPair class is a template class that stores a pair of items.
|
|---|
| 31 |
|
|---|
| 32 | \ingroup tools
|
|---|
| 33 |
|
|---|
| 34 | QPair\<T1, T2\> can be used in your application if the STL \c
|
|---|
| 35 | pair type is not available. It stores one value of type T1 and
|
|---|
| 36 | one value of type T2. It can be used as a return value for a
|
|---|
| 37 | function that needs to return two values, or as the value type of
|
|---|
| 38 | a \l{Container classes}{generic container}.
|
|---|
| 39 |
|
|---|
| 40 | Here's an example of a QPair that stores one QString and one \c
|
|---|
| 41 | double value:
|
|---|
| 42 |
|
|---|
| 43 | \snippet doc/src/snippets/code/doc_src_qpair.qdoc 0
|
|---|
| 44 |
|
|---|
| 45 | The components are accessible as public data members called \l
|
|---|
| 46 | first and \l second. For example:
|
|---|
| 47 |
|
|---|
| 48 | \snippet doc/src/snippets/code/doc_src_qpair.qdoc 1
|
|---|
| 49 |
|
|---|
| 50 | QPair's template data types (T1 and T2) must be \l{assignable
|
|---|
| 51 | data types}. You cannot, for example, store a QWidget as a value;
|
|---|
| 52 | instead, store a QWidget *. A few functions have additional
|
|---|
| 53 | requirements; these requirements are documented on a per-function
|
|---|
| 54 | basis.
|
|---|
| 55 |
|
|---|
| 56 | \sa {Container Classes}
|
|---|
| 57 | */
|
|---|
| 58 |
|
|---|
| 59 | /*! \typedef QPair::first_type
|
|---|
| 60 |
|
|---|
| 61 | The type of the first element in the pair (T1).
|
|---|
| 62 |
|
|---|
| 63 | \sa first
|
|---|
| 64 | */
|
|---|
| 65 |
|
|---|
| 66 | /*! \typedef QPair::second_type
|
|---|
| 67 |
|
|---|
| 68 | The type of the second element in the pair (T2).
|
|---|
| 69 |
|
|---|
| 70 | \sa second
|
|---|
| 71 | */
|
|---|
| 72 |
|
|---|
| 73 | /*! \variable QPair::first
|
|---|
| 74 |
|
|---|
| 75 | The first element in the pair.
|
|---|
| 76 | */
|
|---|
| 77 |
|
|---|
| 78 | /*! \variable QPair::second
|
|---|
| 79 |
|
|---|
| 80 | The second element in the pair.
|
|---|
| 81 | */
|
|---|
| 82 |
|
|---|
| 83 | /*! \fn QPair::QPair()
|
|---|
| 84 |
|
|---|
| 85 | Constructs an empty pair. The \c first and \c second elements are
|
|---|
| 86 | initialized with \l{default-constructed values}.
|
|---|
| 87 | */
|
|---|
| 88 |
|
|---|
| 89 | /*!
|
|---|
| 90 | \fn QPair::QPair(const T1 &value1, const T2 &value2)
|
|---|
| 91 |
|
|---|
| 92 | Constructs a pair and initializes the \c first element with \a
|
|---|
| 93 | value1 and the \c second element with \a value2.
|
|---|
| 94 |
|
|---|
| 95 | \sa qMakePair()
|
|---|
| 96 | */
|
|---|
| 97 |
|
|---|
| 98 | /*!
|
|---|
| 99 | \fn QPair<T1, T2> &QPair::operator=(const QPair<T1, T2> &other)
|
|---|
| 100 |
|
|---|
| 101 | Assigns \a other to this pair.
|
|---|
| 102 | */
|
|---|
| 103 |
|
|---|
| 104 | /*! \fn bool operator==(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
|
|---|
| 105 |
|
|---|
| 106 | \relates QPair
|
|---|
| 107 |
|
|---|
| 108 | Returns true if \a p1 is equal to \a p2; otherwise returns false.
|
|---|
| 109 | Two pairs compare equal if their \c first data members compare
|
|---|
| 110 | equal and if their \c second data members compare equal.
|
|---|
| 111 |
|
|---|
| 112 | This function requires the T1 and T2 types to have an
|
|---|
| 113 | implementation of \c operator==().
|
|---|
| 114 | */
|
|---|
| 115 |
|
|---|
| 116 | /*! \fn bool operator!=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
|
|---|
| 117 |
|
|---|
| 118 | \relates QPair
|
|---|
| 119 |
|
|---|
| 120 | Returns true if \a p1 is not equal to \a p2; otherwise returns
|
|---|
| 121 | false. Two pairs compare as not equal if their \c first data
|
|---|
| 122 | members are not equal or if their \c second data members are not
|
|---|
| 123 | equal.
|
|---|
| 124 |
|
|---|
| 125 | This function requires the T1 and T2 types to have an
|
|---|
| 126 | implementation of \c operator==().
|
|---|
| 127 | */
|
|---|
| 128 |
|
|---|
| 129 | /*! \fn bool operator<(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
|
|---|
| 130 |
|
|---|
| 131 | \relates QPair
|
|---|
| 132 |
|
|---|
| 133 | Returns true if \a p1 is less than \a p2; otherwise returns
|
|---|
| 134 | false. The comparison is done on the \c first members of \a p1
|
|---|
| 135 | and \a p2; if they compare equal, the \c second members are
|
|---|
| 136 | compared to break the tie.
|
|---|
| 137 |
|
|---|
| 138 | This function requires the T1 and T2 types to have an
|
|---|
| 139 | implementation of \c operator<().
|
|---|
| 140 | */
|
|---|
| 141 |
|
|---|
| 142 | /*! \fn bool operator>(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
|
|---|
| 143 |
|
|---|
| 144 | \relates QPair
|
|---|
| 145 |
|
|---|
| 146 | Returns true if \a p1 is greater than \a p2; otherwise returns
|
|---|
| 147 | false. The comparison is done on the \c first members of \a p1
|
|---|
| 148 | and \a p2; if they compare equal, the \c second members are
|
|---|
| 149 | compared to break the tie.
|
|---|
| 150 |
|
|---|
| 151 | This function requires the T1 and T2 types to have an
|
|---|
| 152 | implementation of \c operator<().
|
|---|
| 153 | */
|
|---|
| 154 |
|
|---|
| 155 | /*! \fn bool operator<=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
|
|---|
| 156 |
|
|---|
| 157 | \relates QPair
|
|---|
| 158 |
|
|---|
| 159 | Returns true if \a p1 is less than or equal to \a p2; otherwise
|
|---|
| 160 | returns false. The comparison is done on the \c first members of
|
|---|
| 161 | \a p1 and \a p2; if they compare equal, the \c second members are
|
|---|
| 162 | compared to break the tie.
|
|---|
| 163 |
|
|---|
| 164 | This function requires the T1 and T2 types to have an
|
|---|
| 165 | implementation of \c operator<().
|
|---|
| 166 | */
|
|---|
| 167 |
|
|---|
| 168 | /*! \fn bool operator>=(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2)
|
|---|
| 169 |
|
|---|
| 170 | \relates QPair
|
|---|
| 171 |
|
|---|
| 172 | Returns true if \a p1 is greater than or equal to \a p2;
|
|---|
| 173 | otherwise returns false. The comparison is done on the \c first
|
|---|
| 174 | members of \a p1 and \a p2; if they compare equal, the \c second
|
|---|
| 175 | members are compared to break the tie.
|
|---|
| 176 |
|
|---|
| 177 | This function requires the T1 and T2 types to have an
|
|---|
| 178 | implementation of \c operator<().
|
|---|
| 179 | */
|
|---|
| 180 |
|
|---|
| 181 | /*!
|
|---|
| 182 | \fn QPair<T1, T2> qMakePair(const T1 &value1, const T2 &value2)
|
|---|
| 183 |
|
|---|
| 184 | \relates QPair
|
|---|
| 185 |
|
|---|
| 186 | Returns a QPair\<T1, T2\> that contains \a value1 and \a value2.
|
|---|
| 187 | Example:
|
|---|
| 188 |
|
|---|
| 189 | \snippet doc/src/snippets/code/doc_src_qpair.qdoc 2
|
|---|
| 190 |
|
|---|
| 191 | This is equivalent to QPair<T1, T2>(\a value1, \a value2), but
|
|---|
| 192 | usually requires less typing.
|
|---|
| 193 | */
|
|---|
| 194 |
|
|---|
| 195 | /*! \fn QDataStream &operator>>(QDataStream &in, QPair<T1, T2> &pair)
|
|---|
| 196 |
|
|---|
| 197 | \relates QPair
|
|---|
| 198 |
|
|---|
| 199 | Reads a pair from stream \a in into \a pair.
|
|---|
| 200 |
|
|---|
| 201 | This function requires the T1 and T2 types to implement \c operator>>().
|
|---|
| 202 |
|
|---|
| 203 | \sa {Serializing Qt Data Types}
|
|---|
| 204 | */
|
|---|
| 205 |
|
|---|
| 206 | /*! \fn QDataStream &operator<<(QDataStream &out, const QPair<T1, T2> &pair)
|
|---|
| 207 |
|
|---|
| 208 | \relates QPair
|
|---|
| 209 |
|
|---|
| 210 | Writes the pair \a pair to stream \a out.
|
|---|
| 211 |
|
|---|
| 212 | This function requires the T1 and T2 types to implement \c operator<<().
|
|---|
| 213 |
|
|---|
| 214 | \sa {Serializing Qt Data Types}
|
|---|
| 215 | */
|
|---|