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

kdecore

  • kdecore
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 "kdelibs_export.h"
26 
32 template<class T, class Key = int> class KSortableItem : public TQPair<Key,T>
33 {
34 public:
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 
129 template <class T, class Key = int>
130 class KSortableValueList : public TQValueList<KSortableItem<T, Key> >
131 {
132 public:
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
KSortableValueList::operator[]
const T & operator[](Key i) const
Returns the first value of the KSortableItem at the given position.
Definition: ksortablevaluelist.h:155
KSortableItem::operator>
bool operator>(const KSortableItem< T, Key > &i2) const
Compares the two items.
Definition: ksortablevaluelist.h:67
KSortableItem
KSortableItem is a TQPair that provides several operators for sorting.
Definition: ksortablevaluelist.h:32
KSortableValueList::insert
void insert(Key i, const T &t)
Insert a KSortableItem with the given values.
Definition: ksortablevaluelist.h:138
KSortableValueList
KSortableValueList is a special TQValueList for KSortableItem.
Definition: ksortablevaluelist.h:130
KSortableItem::operator=
KSortableItem< T, Key > & operator=(const KSortableItem< T, Key > &i)
Assignment operator, just copies the item.
Definition: ksortablevaluelist.h:56
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:102
KSortableValueList::sort
void sort()
Sorts the KSortableItems.
Definition: ksortablevaluelist.h:162
KSortableItem::index
Key index() const
Definition: ksortablevaluelist.h:119
KSortableItem::KSortableItem
KSortableItem(const KSortableItem< T, Key > &rhs)
Creates a new KSortableItem that copies another one.
Definition: ksortablevaluelist.h:45
KSortableItem::operator>=
bool operator>=(const KSortableItem< T, Key > &i2) const
Compares the two items.
Definition: ksortablevaluelist.h:81
KSortableValueList::operator[]
T & operator[](Key i)
Returns the first value of the KSortableItem at the given position.
Definition: ksortablevaluelist.h:147
KSortableItem::operator==
bool operator==(const KSortableItem< T, Key > &i2) const
Compares the two items.
Definition: ksortablevaluelist.h:95
KSortableItem::value
const T & value() const
Returns the second value.
Definition: ksortablevaluelist.h:114
KSortableItem::KSortableItem
KSortableItem()
Creates a new KSortableItem with uninitialized values.
Definition: ksortablevaluelist.h:51
KSortableItem::value
T & value()
Definition: ksortablevaluelist.h:109

kdecore

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

kdecore

Skip menu "kdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdecore by doxygen 1.8.11
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |