Blame qtools/qdict.h

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