• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
ksortablevaluelist.h
1/* This file is part of the KDE libraries
2 Copyright (C) 2001 Carsten Pfeiffer <pfeiffer@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KSORTABLEVALUELIST_H
21#define KSORTABLEVALUELIST_H
22
23#include <tqpair.h>
24#include <tqvaluelist.h>
25#include "tdelibs_export.h"
26
32template<class T, class Key = int> class KSortableItem : public TQPair<Key,T>
33{
34public:
40 KSortableItem( Key i, const T& t ) : TQPair<Key, T>( i, t ) {}
45 KSortableItem( const KSortableItem<T, Key> &rhs )
46 : TQPair<Key,T>( rhs.first, rhs.second ) {}
47
51 KSortableItem() {}
52
56 KSortableItem<T, Key> &operator=( const KSortableItem<T, Key>& i ) {
57 this->first = i.first;
58 this->second = i.second;
59 return *this;
60 }
61
62 // operators for sorting
67 bool operator> ( const KSortableItem<T, Key>& i2 ) const {
68 return (i2.first < this->first);
69 }
74 bool operator< ( const KSortableItem<T, Key>& i2 ) const {
75 return (this->first < i2.first);
76 }
81 bool operator>= ( const KSortableItem<T, Key>& i2 ) const {
82 return (this->first >= i2.first);
83 }
88 bool operator<= ( const KSortableItem<T, Key>& i2 ) const {
89 return !(i2.first < this->first);
90 }
95 bool operator== ( const KSortableItem<T, Key>& i2 ) const {
96 return (this->first == i2.first);
97 }
102 bool operator!= ( const KSortableItem<T, Key>& i2 ) const {
103 return (this->first != i2.first);
104 }
105
109 T& value() { return this->second; }
110
114 const T& value() const { return this->second; }
115
119 Key index() const { return this->first; }
120};
121
122
129template <class T, class Key = int>
130class KSortableValueList : public TQValueList<KSortableItem<T, Key> >
131{
132public:
138 void insert( Key i, const T& t ) {
139 TQValueList<KSortableItem<T, Key> >::append( KSortableItem<T, Key>( i, t ) );
140 }
141 // add more as you please...
142
147 T& operator[]( Key i ) {
148 return TQValueList<KSortableItem<T, Key> >::operator[]( i ).value();
149 }
150
155 const T& operator[]( Key i ) const {
156 return TQValueList<KSortableItem<T, Key> >::operator[]( i ).value();
157 }
158
162 void sort() {
163 qHeapSort( *this );
164 }
165};
166
167// template <class T> class KSortableValueListIterator : public TQValueListIterator<KSortableItem<T> >
168// {
169// };
170
171#endif // KSORTABLEVALUELIST_H
KSortableItem
KSortableItem is a TQPair that provides several operators for sorting.
Definition ksortablevaluelist.h:33
KSortableItem::operator=
KSortableItem< T, Key > & operator=(const KSortableItem< T, Key > &i)
Assignment operator, just copies the item.
Definition ksortablevaluelist.h:56
KSortableItem::operator!=
bool operator!=(const KSortableItem< T, Key > &i2) const
Compares the two items.
Definition ksortablevaluelist.h:102
KSortableItem::KSortableItem
KSortableItem(const KSortableItem< T, Key > &rhs)
Creates a new KSortableItem that copies another one.
Definition ksortablevaluelist.h:45
KSortableItem::index
Key index() const
Definition ksortablevaluelist.h:119
KSortableItem::operator>
bool operator>(const KSortableItem< T, Key > &i2) const
Compares the two items.
Definition ksortablevaluelist.h:67
KSortableItem::operator<=
bool operator<=(const KSortableItem< T, Key > &i2) const
Compares the two items.
Definition ksortablevaluelist.h:88
KSortableItem::value
const T & value() const
Returns the second value.
Definition ksortablevaluelist.h:114
KSortableItem::KSortableItem
KSortableItem(Key i, const T &t)
Creates a new KSortableItem with the given values.
Definition ksortablevaluelist.h:40
KSortableItem::operator==
bool operator==(const KSortableItem< T, Key > &i2) const
Compares the two items.
Definition ksortablevaluelist.h:95
KSortableItem::value
T & value()
Definition ksortablevaluelist.h:109
KSortableItem::KSortableItem
KSortableItem()
Creates a new KSortableItem with uninitialized values.
Definition ksortablevaluelist.h:51
KSortableItem::operator<
bool operator<(const KSortableItem< T, Key > &i2) const
Compares the two items.
Definition ksortablevaluelist.h:74
KSortableItem::operator>=
bool operator>=(const KSortableItem< T, Key > &i2) const
Compares the two items.
Definition ksortablevaluelist.h:81
KSortableValueList
KSortableValueList is a special TQValueList for KSortableItem.
Definition ksortablevaluelist.h:131
KSortableValueList::operator[]
T & operator[](Key i)
Returns the first value of the KSortableItem at the given position.
Definition ksortablevaluelist.h:147
KSortableValueList::sort
void sort()
Sorts the KSortableItems.
Definition ksortablevaluelist.h:162
KSortableValueList::insert
void insert(Key i, const T &t)
Insert a KSortableItem with the given values.
Definition ksortablevaluelist.h:138
KSortableValueList::operator[]
const T & operator[](Key i) const
Returns the first value of the KSortableItem at the given position.
Definition ksortablevaluelist.h:155

tdecore

Skip menu "tdecore"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.8
This website is maintained by Timothy Pearson.