1 /****************************************************************************
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
5 ** This file is part of the QxtCore module of the Qt eXTension library
7 ** This library is free software; you can redistribute it and/or modify it
8 ** under the terms of th Common Public License, version 1.0, as published by
11 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
12 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
13 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
14 ** FITNESS FOR A PARTICULAR PURPOSE.
16 ** You should have received a copy of the CPL along with this file.
17 ** See the LICENSE file and the cpl1.0.txt file included with the source
18 ** distribution for more information. If you did not receive a copy of the
19 ** license, contact the Qxt Foundation.
21 ** <http://libqxt.sourceforge.net> <foundation@libqxt.org>
23 ****************************************************************************/
27 \class QxtPairList QxtPairList
31 \brief Searchable List of Pairs
34 Pair list provides a list with two values, a bit like QHash, but with posibility to operate on both values.
36 in contrast to QHash, every entry has a unique id, you can work with. like a QList.
39 QxtPairList<int,int> list;
45 qDebug()<< list.find(1); // "0,1"
46 qDebug()<< list.find(SKIP,5); // "2"
47 qDebug()<< list.find(5); // "2"
50 you may allso play around with the list itself
53 list.list.append(qMakePair(1,2));
62 #include <QxtNullable>
63 #include <qxtglobal.h>
67 template <typename T, typename K>
68 class QXT_CORE_EXPORT QxtPairList
77 QxtPairList( const QxtPairList<T,K> & other )
82 QxtPairList operator= ( const QxtPairList<T,K> & other )
88 void append(T v1, K v2)
90 list.append(qMakePair(v1,v2));
94 /** \brief search entrys by match
96 both arguments are optional, due to the use of QxtNullable
106 QList<int> find( qxNull(T,v1) , qxNull(K,v2) )
110 if ((!v1.isNull()) and (!v2.isNull()))
112 for (int i=0;i<list.count();i++)
113 if ((list[i].first()==v1)and(list[i].second()==v2))
119 if ((!v1.isNull()) and (v2.isNull()))
121 for (int i=0;i<list.count();i++)
122 if (list[i].first()==v1)
128 if ((v1.isNull()) and (!v2.isNull()))
130 for (int i=0;i<list.count();i++)
131 if (list[i].second()==v2)
143 ///remove an entrys position by position
149 ///remove a list of entrys by position
150 void remove(QList<int> nrs)
160 /** \brief operate on the list directly
162 you may use the internal list directly, but be carefull
163 dont expect to work the QxPairList to work normal if you mess around with it.
167 QList<QPair<T,K> > list;