From 11304d02942e9fa493e4e80943a828f9c65f6772 Mon Sep 17 00:00:00 2001 From: mickeyl Date: Fri, 28 Mar 2003 15:11:52 +0000 Subject: skeleton and the start of libopie2, please read README, ROADMAP and STATUS and comment... --- (limited to 'libopie2/qt3/opiecore/osortablevaluelist.h') 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 @@ +/* +                 This file is part of the Opie Project + Originally a part of the KDE Project + (C) 2001 Carsten Pfeiffer + =. + .=l. +           .>+-= + _;:,     .>    :=|. This program is free software; you can +.> <`_,   >  .   <= redistribute it and/or modify it under +:`=1 )Y*s>-.--   : the terms of the GNU Library General Public +.="- .-=="i,     .._ License as published by the Free Software + - .   .-<_>     .<> Foundation; either version 2 of the License, +     ._= =}       : or (at your option) any later version. +    .%`+i>       _;_. +    .i_,=:_.      -`: PARTICULAR PURPOSE. See the GNU +..}^=.=       =       ; Library General Public License for more +++=   -.     .`     .: details. + :     =  ...= . :.=- + -.   .:....=;==+<; You should have received a copy of the GNU +  -_. . .   )=.  = Library General Public License along with +    --        :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef OSORTABLEVALUELIST_H +#define OSORTABLEVALUELIST_H + +#if QT_VERSION > 290 +#include +#include +#else +#include +#include +#endif +#include + +template class OSortableItem : public QPair +{ +public: + OSortableItem( Key i, const T& t ) : QPair( i, t ) {} + OSortableItem( const OSortableItem &rhs ) + : QPair( rhs.first, rhs.second ) {} + + OSortableItem() {} + + OSortableItem &operator=( const OSortableItem& i ) { + first = i.first; + second = i.second; + return *this; + } + + // operators for sorting + bool operator> ( const OSortableItem& i2 ) const { + return (i2.first < first); + } + bool operator< ( const OSortableItem& i2 ) const { + return (first < i2.first); + } + bool operator>= ( const OSortableItem& i2 ) const { + return (first >= i2.first); + } + bool operator<= ( const OSortableItem& i2 ) const { + return !(i2.first < first); + } + bool operator== ( const OSortableItem& i2 ) const { + return (first == i2.first); + } + bool operator!= ( const OSortableItem& i2 ) const { + return (first != i2.first); + } + + T& value() { + return second; + } + const T& value() const { + return second; + } + + Key index() const { + return first; + } +}; + + +// convenience +template +class OSortableValueList : public QValueList > +{ +public: + void insert( Key i, const T& t ) { + QValueList >::append( OSortableItem( i, t ) ); + } + // add more as you please... + + T& operator[]( Key i ) { + return QValueList >::operator[]( i ).value(); + } + const T& operator[]( Key i ) const { + return QValueList >::operator[]( i ).value(); + } + + void sort() { + qHeapSort( *this ); + } +}; + +// template class OSortableValueListIterator : public QValueListIterator > +// { +// }; + +#endif // OSORTABLEVALUELIST_H -- cgit v0.9.0.2