summaryrefslogtreecommitdiff
path: root/libopie2/qt3/opiecore/osortablevaluelist.h
Unidiff
Diffstat (limited to 'libopie2/qt3/opiecore/osortablevaluelist.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/qt3/opiecore/osortablevaluelist.h117
1 files changed, 117 insertions, 0 deletions
diff --git a/libopie2/qt3/opiecore/osortablevaluelist.h b/libopie2/qt3/opiecore/osortablevaluelist.h
new file mode 100644
index 0000000..f66cf25
--- a/dev/null
+++ b/libopie2/qt3/opiecore/osortablevaluelist.h
@@ -0,0 +1,117 @@
1/*
2                 This file is part of the Opie Project
3 Originally a part of the KDE Project
4 (C) 2001 Carsten Pfeiffer <pfeiffer@kde.org>
5 =.
6 .=l.
7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details.
22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA.
29*/
30
31#ifndef OSORTABLEVALUELIST_H
32#define OSORTABLEVALUELIST_H
33
34#if QT_VERSION > 290
35#include <qtl.h>
36#include <qpair.h>
37#else
38#include <opie2/otl.h>
39#include <opie2/opair.h>
40#endif
41#include <qvaluelist.h>
42
43template<class T, class Key = int> class OSortableItem : public QPair<Key,T>
44{
45public:
46 OSortableItem( Key i, const T& t ) : QPair<Key, T>( i, t ) {}
47 OSortableItem( const OSortableItem<T, Key> &rhs )
48 : QPair<Key,T>( rhs.first, rhs.second ) {}
49
50 OSortableItem() {}
51
52 OSortableItem<T, Key> &operator=( const OSortableItem<T, Key>& i ) {
53 first = i.first;
54 second = i.second;
55 return *this;
56 }
57
58 // operators for sorting
59 bool operator> ( const OSortableItem<T, Key>& i2 ) const {
60 return (i2.first < first);
61 }
62 bool operator< ( const OSortableItem<T, Key>& i2 ) const {
63 return (first < i2.first);
64 }
65 bool operator>= ( const OSortableItem<T, Key>& i2 ) const {
66 return (first >= i2.first);
67 }
68 bool operator<= ( const OSortableItem<T, Key>& i2 ) const {
69 return !(i2.first < first);
70 }
71 bool operator== ( const OSortableItem<T, Key>& i2 ) const {
72 return (first == i2.first);
73 }
74 bool operator!= ( const OSortableItem<T, Key>& i2 ) const {
75 return (first != i2.first);
76 }
77
78 T& value() {
79 return second;
80 }
81 const T& value() const {
82 return second;
83 }
84
85 Key index() const {
86 return first;
87 }
88};
89
90
91// convenience
92template <class T, class Key = int>
93class OSortableValueList : public QValueList<OSortableItem<T, Key> >
94{
95public:
96 void insert( Key i, const T& t ) {
97 QValueList<OSortableItem<T, Key> >::append( OSortableItem<T, Key>( i, t ) );
98 }
99 // add more as you please...
100
101 T& operator[]( Key i ) {
102 return QValueList<OSortableItem<T, Key> >::operator[]( i ).value();
103 }
104 const T& operator[]( Key i ) const {
105 return QValueList<OSortableItem<T, Key> >::operator[]( i ).value();
106 }
107
108 void sort() {
109 qHeapSort( *this );
110 }
111};
112
113// template <class T> class OSortableValueListIterator : public QValueListIterator<OSortableItem<T> >
114// {
115// };
116
117#endif // OSORTABLEVALUELIST_H