Blame qtools/qcache.h

Packit 1c1d7e
/****************************************************************************
Packit 1c1d7e
** 
Packit 1c1d7e
**
Packit 1c1d7e
** Definition of QCache template class
Packit 1c1d7e
**
Packit 1c1d7e
** Created : 950209
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 QCACHE_H
Packit 1c1d7e
#define QCACHE_H
Packit 1c1d7e
Packit 1c1d7e
#ifndef QT_H
Packit 1c1d7e
#include "qgcache.h"
Packit 1c1d7e
#endif // QT_H
Packit 1c1d7e
Packit 1c1d7e
#define USE_ASCII_STRING
Packit 1c1d7e
Packit 1c1d7e
#ifndef USE_ASCII_STRING
Packit 1c1d7e
Packit 1c1d7e
template<class type> class Q_EXPORT QCache : public QGCache
Packit 1c1d7e
{
Packit 1c1d7e
public:
Packit 1c1d7e
    QCache( const QCache<type> &c ) : QGCache(c) {}
Packit 1c1d7e
    QCache( int maxCost=100, int size=17, bool caseSensitive=TRUE )
Packit 1c1d7e
	: QGCache( maxCost, size, StringKey, caseSensitive, FALSE ) {}
Packit 1c1d7e
   ~QCache()				{ clear(); }
Packit 1c1d7e
    QCache<type> &operator=( const QCache<type> &c )
Packit 1c1d7e
			{ return (QCache<type>&)QGCache::operator=(c); }
Packit 1c1d7e
    int	  maxCost()   const		{ return QGCache::maxCost(); }
Packit 1c1d7e
    int	  totalCost() const		{ return QGCache::totalCost(); }
Packit 1c1d7e
    void  setMaxCost( int m )		{ QGCache::setMaxCost(m); }
Packit 1c1d7e
    uint  count()     const		{ return QGCache::count(); }
Packit 1c1d7e
    uint  size()      const		{ return QGCache::size(); }
Packit 1c1d7e
    bool  isEmpty()   const		{ return QGCache::count() == 0; }
Packit 1c1d7e
    void  clear()			{ QGCache::clear(); }
Packit 1c1d7e
    bool  insert( const QString &k, const type *d, int c=1, int p=0 )
Packit 1c1d7e
			{ return QGCache::insert_string(k,(Item)d,c,p);}
Packit 1c1d7e
    bool  remove( const QString &k )
Packit 1c1d7e
			{ return QGCache::remove_string(k); }
Packit 1c1d7e
    type *take( const QString &k )
Packit 1c1d7e
			{ return (type *)QGCache::take_string(k); }
Packit 1c1d7e
    type *find( const QString &k, bool ref=TRUE ) const
Packit 1c1d7e
			{ return (type *)QGCache::find_string(k,ref);}
Packit 1c1d7e
    type *operator[]( const QString &k ) const
Packit 1c1d7e
			{ return (type *)QGCache::find_string(k);}
Packit 1c1d7e
    void  statistics() const	      { QGCache::statistics(); }
Packit 1c1d7e
    int   hits() const                { return QGCache::hits(); }
Packit 1c1d7e
    int   misses() const              { return QGCache::misses(); }
Packit 1c1d7e
private:
Packit 1c1d7e
    void  deleteItem( Item d )	      { if ( del_item ) delete (type *)d; }
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
#else
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
template<class type> class Q_EXPORT QCache : public QGCache
Packit 1c1d7e
{
Packit 1c1d7e
public:
Packit 1c1d7e
    QCache( const QCache<type> &c ) : QGCache(c) {}
Packit 1c1d7e
    QCache( int maxCost=100, int size=17, bool caseSensitive=TRUE )
Packit 1c1d7e
	: QGCache( maxCost, size, AsciiKey, caseSensitive, TRUE ) {}
Packit 1c1d7e
   ~QCache()				{ clear(); }
Packit 1c1d7e
    QCache<type> &operator=( const QCache<type> &c )
Packit 1c1d7e
			{ return (QCache<type>&)QGCache::operator=(c); }
Packit 1c1d7e
    int	  maxCost()   const		{ return QGCache::maxCost(); }
Packit 1c1d7e
    int	  totalCost() const		{ return QGCache::totalCost(); }
Packit 1c1d7e
    void  setMaxCost( int m )		{ QGCache::setMaxCost(m); }
Packit 1c1d7e
    uint  count()     const		{ return QGCache::count(); }
Packit 1c1d7e
    uint  size()      const		{ return QGCache::size(); }
Packit 1c1d7e
    bool  isEmpty()   const		{ return QGCache::count() == 0; }
Packit 1c1d7e
    void  clear()			{ QGCache::clear(); }
Packit 1c1d7e
    bool  insert( const char *k, const type *d, int c=1, int p=0 )
Packit 1c1d7e
			{ return QGCache::insert_other(k,(Item)d,c,p);}
Packit 1c1d7e
    bool  remove( const char *k )
Packit 1c1d7e
			{ return QGCache::remove_other(k); }
Packit 1c1d7e
    type *take( const char *k )
Packit 1c1d7e
			{ return (type *)QGCache::take_other(k); }
Packit 1c1d7e
    type *find( const char *k, bool ref=TRUE ) const
Packit 1c1d7e
			{ return (type *)QGCache::find_other(k,ref);}
Packit 1c1d7e
    type *operator[]( const char *k ) const
Packit 1c1d7e
			{ return (type *)QGCache::find_other(k);}
Packit 1c1d7e
    void  statistics() const	      { QGCache::statistics(); }
Packit 1c1d7e
    int   hits() const                { return QGCache::hits(); }
Packit 1c1d7e
    int   misses() const              { return QGCache::misses(); }
Packit 1c1d7e
private:
Packit 1c1d7e
    void  deleteItem( Item d )	      { if ( del_item ) delete (type *)d; }
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
#endif
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
template<class type> class Q_EXPORT QCacheIterator : public QGCacheIterator
Packit 1c1d7e
{
Packit 1c1d7e
public:
Packit 1c1d7e
    QCacheIterator( const QCache<type> &c ):QGCacheIterator((QGCache &)c) {}
Packit 1c1d7e
    QCacheIterator( const QCacheIterator<type> &ci)
Packit 1c1d7e
				: QGCacheIterator( (QGCacheIterator &)ci ) {}
Packit 1c1d7e
    QCacheIterator<type> &operator=(const QCacheIterator<type>&ci)
Packit 1c1d7e
	{ return ( QCacheIterator<type>&)QGCacheIterator::operator=( ci ); }
Packit 1c1d7e
    uint  count()   const     { return QGCacheIterator::count(); }
Packit 1c1d7e
    bool  isEmpty() const     { return QGCacheIterator::count() == 0; }
Packit 1c1d7e
    bool  atFirst() const     { return QGCacheIterator::atFirst(); }
Packit 1c1d7e
    bool  atLast()  const     { return QGCacheIterator::atLast(); }
Packit 1c1d7e
    type *toFirst()	      { return (type *)QGCacheIterator::toFirst(); }
Packit 1c1d7e
    type *toLast()	      { return (type *)QGCacheIterator::toLast(); }
Packit 1c1d7e
    operator type *() const   { return (type *)QGCacheIterator::get(); }
Packit 1c1d7e
    type *current()   const   { return (type *)QGCacheIterator::get(); }
Packit 1c1d7e
#ifndef USE_ASCII_STRING
Packit 1c1d7e
    QString currentKey() const{ return QGCacheIterator::getKeyString(); }
Packit 1c1d7e
#else
Packit 1c1d7e
    const char *currentKey() const{ return QGCacheIterator::getKeyAscii(); }
Packit 1c1d7e
#endif
Packit 1c1d7e
    type *operator()()	      { return (type *)QGCacheIterator::operator()();}
Packit 1c1d7e
    type *operator++()	      { return (type *)QGCacheIterator::operator++(); }
Packit 1c1d7e
    type *operator+=(uint j)  { return (type *)QGCacheIterator::operator+=(j);}
Packit 1c1d7e
    type *operator--()	      { return (type *)QGCacheIterator::operator--(); }
Packit 1c1d7e
    type *operator-=(uint j)  { return (type *)QGCacheIterator::operator-=(j);}
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
#endif // QCACHE_H