Blame qtools/qgcache.h

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