|
Packit |
1c1d7e |
/****************************************************************************
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** Definition of QDict template class
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** Created : 920821
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** This file is part of the tools module of the Qt GUI Toolkit.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** This file may be distributed under the terms of the Q Public License
|
|
Packit |
1c1d7e |
** as defined by Trolltech AS of Norway and appearing in the file
|
|
Packit |
1c1d7e |
** LICENSE.QPL included in the packaging of this file.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** This file may be distributed and/or modified under the terms of the
|
|
Packit |
1c1d7e |
** GNU General Public License version 2 as published by the Free Software
|
|
Packit |
1c1d7e |
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
Packit |
1c1d7e |
** packaging of this file.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
|
Packit |
1c1d7e |
** licenses may use this file in accordance with the Qt Commercial License
|
|
Packit |
1c1d7e |
** Agreement provided with the Software.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|
Packit |
1c1d7e |
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|
Packit |
1c1d7e |
** information about Qt Commercial License Agreements.
|
|
Packit |
1c1d7e |
** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|
Packit |
1c1d7e |
** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
** Contact info@trolltech.com if any conditions of this licensing are
|
|
Packit |
1c1d7e |
** not clear to you.
|
|
Packit |
1c1d7e |
**
|
|
Packit |
1c1d7e |
**********************************************************************/
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#ifndef QDICT_H
|
|
Packit |
1c1d7e |
#define QDICT_H
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#ifndef QT_H
|
|
Packit |
1c1d7e |
#include "qgdict.h"
|
|
Packit |
1c1d7e |
#endif // QT_H
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#define USE_ASCII_STRING
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#ifdef USE_ASCII_STRING
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#define QAsciiDict QDict
|
|
Packit |
1c1d7e |
#define QAsciiDictIterator QDictIterator
|
|
Packit |
1c1d7e |
#include "qasciidict.h"
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#else
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
template<class type> class Q_EXPORT QDict : private QGDict
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
public:
|
|
Packit |
1c1d7e |
QDict(int size=17, bool caseSensitive=TRUE)
|
|
Packit |
1c1d7e |
: QGDict(size,StringKey,caseSensitive,FALSE) {}
|
|
Packit |
1c1d7e |
QDict( const QDict<type> &d ) : QGDict(d) {}
|
|
Packit |
1c1d7e |
~QDict() { clear(); }
|
|
Packit |
1c1d7e |
QDict<type> &operator=(const QDict<type> &d)
|
|
Packit |
1c1d7e |
{ return (QDict<type>&)QGDict::operator=(d); }
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
// capacity
|
|
Packit |
1c1d7e |
uint count() const { return QGDict::count(); }
|
|
Packit |
1c1d7e |
uint size() const { return QGDict::size(); }
|
|
Packit |
1c1d7e |
bool isEmpty() const { return QGDict::count() == 0; }
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
// modifiers
|
|
Packit |
1c1d7e |
void insert( const QString &k, const type *d )
|
|
Packit |
1c1d7e |
{ QGDict::look_string(k,(Item)d,1); }
|
|
Packit |
1c1d7e |
void replace( const QString &k, const type *d )
|
|
Packit |
1c1d7e |
{ QGDict::look_string(k,(Item)d,2); }
|
|
Packit |
1c1d7e |
bool remove( const QString &k ) { return QGDict::remove_string(k); }
|
|
Packit |
1c1d7e |
type *take( const QString &k ) { return (type *)QGDict::take_string(k); }
|
|
Packit |
1c1d7e |
void clear() { QGDict::clear(); }
|
|
Packit |
1c1d7e |
void resize( uint n ) { QGDict::resize(n); }
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
// search
|
|
Packit |
1c1d7e |
type *find( const QString &k ) const
|
|
Packit |
1c1d7e |
{ return (type *)((QGDict*)this)->QGDict::look_string(k,0,0); }
|
|
Packit |
1c1d7e |
type *operator[]( const QString &k ) const
|
|
Packit |
1c1d7e |
{ return (type *)((QGDict*)this)->QGDict::look_string(k,0,0); }
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
// operations
|
|
Packit |
1c1d7e |
void statistics() const { QGDict::statistics(); }
|
|
Packit |
1c1d7e |
private:
|
|
Packit |
1c1d7e |
void deleteItem( Item d );
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
// new to be reimplemented methods
|
|
Packit |
1c1d7e |
virtual int compareValues(const type *t1,const type *t2) const
|
|
Packit |
1c1d7e |
{ return const_cast<QDict<type>*>(this)->QGDict::compareItems((QCollection::Item)t1,(QCollection::Item)t2); }
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
// reimplemented methods
|
|
Packit |
1c1d7e |
virtual int compareItems(QCollection::Item i1,QCollection::Item i2)
|
|
Packit |
1c1d7e |
{ return compareValues((const type*)i1,(const type*)i2); }
|
|
Packit |
1c1d7e |
};
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#if defined(Q_DELETING_VOID_UNDEFINED)
|
|
Packit |
1c1d7e |
template<> inline void QDict<void>::deleteItem( Item )
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
#endif
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
template<class type> inline void QDict<type>::deleteItem( QCollection::Item d )
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
if ( del_item ) delete (type *)d;
|
|
Packit |
1c1d7e |
}
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
template<class type> class Q_EXPORT QDictIterator : public QGDictIterator
|
|
Packit |
1c1d7e |
{
|
|
Packit |
1c1d7e |
public:
|
|
Packit |
1c1d7e |
QDictIterator(const QDict<type> &d) :QGDictIterator((QGDict &)d) {}
|
|
Packit |
1c1d7e |
~QDictIterator() {}
|
|
Packit |
1c1d7e |
uint count() const { return dict->count(); }
|
|
Packit |
1c1d7e |
bool isEmpty() const { return dict->count() == 0; }
|
|
Packit |
1c1d7e |
type *toFirst() { return (type *)QGDictIterator::toFirst(); }
|
|
Packit |
1c1d7e |
operator type *() const { return (type *)QGDictIterator::get(); }
|
|
Packit |
1c1d7e |
type *current() const { return (type *)QGDictIterator::get(); }
|
|
Packit |
1c1d7e |
QString currentKey() const{ return QGDictIterator::getKeyString(); }
|
|
Packit |
1c1d7e |
type *operator()() { return (type *)QGDictIterator::operator()(); }
|
|
Packit |
1c1d7e |
type *operator++() { return (type *)QGDictIterator::operator++(); }
|
|
Packit |
1c1d7e |
type *operator+=(uint j) { return (type *)QGDictIterator::operator+=(j);}
|
|
Packit |
1c1d7e |
};
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#endif // USE_ASCII_STRING
|
|
Packit |
1c1d7e |
|
|
Packit |
1c1d7e |
#endif // QDICT_H
|