Blame qtools/qgcache.h

Packit 1c1d7e
/****************************************************************************
Packit 1c1d7e
** 
Packit 1c1d7e
**
Packit 1c1d7e
** Definition of QGCache and QGCacheIterator classes
Packit 1c1d7e
**
Packit 1c1d7e
** Created : 950208
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 QGCACHE_H
Packit 1c1d7e
#define QGCACHE_H
Packit 1c1d7e
Packit 1c1d7e
#ifndef QT_H
Packit 1c1d7e
#include "qcollection.h"
Packit 1c1d7e
#include "qglist.h"
Packit 1c1d7e
#include "qgdict.h"
Packit 1c1d7e
#endif // QT_H
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
class QCList;					// internal classes
Packit 1c1d7e
class QCListIt;
Packit 1c1d7e
class QCDict;
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
class Q_EXPORT QGCache : public QCollection	// generic LRU cache
Packit 1c1d7e
{
Packit 1c1d7e
friend class QGCacheIterator;
Packit 1c1d7e
protected:
Packit 1c1d7e
    enum KeyType { StringKey, AsciiKey, IntKey, PtrKey };
Packit 1c1d7e
      // identical to QGDict's, but PtrKey is not used at the moment
Packit 1c1d7e
Packit 1c1d7e
    QGCache( int maxCost, uint size, KeyType kt, bool caseSensitive,
Packit 1c1d7e
	     bool copyKeys );
Packit 1c1d7e
    QGCache( const QGCache & );			// not allowed, calls fatal()
Packit 1c1d7e
   ~QGCache();
Packit 1c1d7e
    QGCache &operator=( const QGCache & );	// not allowed, calls fatal()
Packit 1c1d7e
Packit 1c1d7e
    uint    count()	const	{ return ((QGDict*)dict)->count(); }
Packit 1c1d7e
    uint    size()	const	{ return ((QGDict*)dict)->size(); }
Packit 1c1d7e
    int	    maxCost()	const	{ return mCost; }
Packit 1c1d7e
    int	    totalCost() const	{ return tCost; }
Packit 1c1d7e
    void    setMaxCost( int maxCost );
Packit 1c1d7e
    void    clear();
Packit 1c1d7e
Packit 1c1d7e
    bool    insert_string( const QString &key, QCollection::Item,
Packit 1c1d7e
			   int cost, int priority );
Packit 1c1d7e
    bool    insert_other( const char *key, QCollection::Item,
Packit 1c1d7e
			  int cost, int priority );
Packit 1c1d7e
    bool    remove_string( const QString &key );
Packit 1c1d7e
    bool    remove_other( const char *key );
Packit 1c1d7e
    QCollection::Item take_string( const QString &key );
Packit 1c1d7e
    QCollection::Item take_other( const char *key );
Packit 1c1d7e
Packit 1c1d7e
    QCollection::Item find_string( const QString &key, bool ref=TRUE ) const;
Packit 1c1d7e
    QCollection::Item find_other( const char *key, bool ref=TRUE ) const;
Packit 1c1d7e
Packit 1c1d7e
    void    statistics() const;
Packit 1c1d7e
    int     hits() const;
Packit 1c1d7e
    int     misses() const;
Packit 1c1d7e
Packit 1c1d7e
private:
Packit 1c1d7e
    bool    makeRoomFor( int cost, int priority = -1 );
Packit 1c1d7e
    KeyType keytype;
Packit 1c1d7e
    QCList *lruList;
Packit 1c1d7e
    QCDict *dict;
Packit 1c1d7e
    int	    mCost;
Packit 1c1d7e
    int	    tCost;
Packit 1c1d7e
    bool    copyk;
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
class Q_EXPORT QGCacheIterator			// generic cache iterator
Packit 1c1d7e
{
Packit 1c1d7e
protected:
Packit 1c1d7e
    QGCacheIterator( const QGCache & );
Packit 1c1d7e
    QGCacheIterator( const QGCacheIterator & );
Packit 1c1d7e
   ~QGCacheIterator();
Packit 1c1d7e
    QGCacheIterator &operator=( const QGCacheIterator & );
Packit 1c1d7e
Packit 1c1d7e
    uint	      count()   const;
Packit 1c1d7e
    bool	      atFirst() const;
Packit 1c1d7e
    bool	      atLast()  const;
Packit 1c1d7e
    QCollection::Item toFirst();
Packit 1c1d7e
    QCollection::Item toLast();
Packit 1c1d7e
Packit 1c1d7e
    QCollection::Item get() const;
Packit 1c1d7e
    QString	      getKeyString() const;
Packit 1c1d7e
    const char       *getKeyAscii()  const;
Packit 1c1d7e
    intptr_t	      getKeyInt()    const;
Packit 1c1d7e
Packit 1c1d7e
    QCollection::Item operator()();
Packit 1c1d7e
    QCollection::Item operator++();
Packit 1c1d7e
    QCollection::Item operator+=( uint );
Packit 1c1d7e
    QCollection::Item operator--();
Packit 1c1d7e
    QCollection::Item operator-=( uint );
Packit 1c1d7e
Packit 1c1d7e
protected:
Packit 1c1d7e
    QCListIt *it;				// iterator on cache list
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
#endif // QGCACHE_H