Blame qtools/qcache.h

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