Fix for UBSan build
[platform/upstream/doxygen.git] / qtools / qgcache.h
1 /****************************************************************************
2 ** 
3 **
4 ** Definition of QGCache and QGCacheIterator classes
5 **
6 ** Created : 950208
7 **
8 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
9 **
10 ** This file is part of the tools module of the Qt GUI Toolkit.
11 **
12 ** This file may be distributed under the terms of the Q Public License
13 ** as defined by Trolltech AS of Norway and appearing in the file
14 ** LICENSE.QPL included in the packaging of this file.
15 **
16 ** This file may be distributed and/or modified under the terms of the
17 ** GNU General Public License version 2 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.GPL included in the
19 ** packaging of this file.
20 **
21 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22 ** licenses may use this file in accordance with the Qt Commercial License
23 ** Agreement provided with the Software.
24 **
25 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27 **
28 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29 **   information about Qt Commercial License Agreements.
30 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
31 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
32 **
33 ** Contact info@trolltech.com if any conditions of this licensing are
34 ** not clear to you.
35 **
36 **********************************************************************/
37
38 #ifndef QGCACHE_H
39 #define QGCACHE_H
40
41 #ifndef QT_H
42 #include "qcollection.h"
43 #include "qglist.h"
44 #include "qgdict.h"
45 #endif // QT_H
46
47
48 class QCList;                                   // internal classes
49 class QCListIt;
50 class QCDict;
51
52
53 class Q_EXPORT QGCache : public QCollection     // generic LRU cache
54 {
55 friend class QGCacheIterator;
56 protected:
57     enum KeyType { StringKey, AsciiKey, IntKey, PtrKey };
58       // identical to QGDict's, but PtrKey is not used at the moment
59
60     QGCache( int maxCost, uint size, KeyType kt, bool caseSensitive,
61              bool copyKeys );
62     QGCache( const QGCache & );                 // not allowed, calls fatal()
63    ~QGCache();
64     QGCache &operator=( const QGCache & );      // not allowed, calls fatal()
65
66     uint    count()     const   { return ((QGDict*)dict)->count(); }
67     uint    size()      const   { return ((QGDict*)dict)->size(); }
68     int     maxCost()   const   { return mCost; }
69     int     totalCost() const   { return tCost; }
70     void    setMaxCost( int maxCost );
71     void    clear();
72
73     bool    insert_string( const QString &key, QCollection::Item,
74                            int cost, int priority );
75     bool    insert_other( const char *key, QCollection::Item,
76                           int cost, int priority );
77     bool    remove_string( const QString &key );
78     bool    remove_other( const char *key );
79     QCollection::Item take_string( const QString &key );
80     QCollection::Item take_other( const char *key );
81
82     QCollection::Item find_string( const QString &key, bool ref=TRUE ) const;
83     QCollection::Item find_other( const char *key, bool ref=TRUE ) const;
84
85     void    statistics() const;
86     int     hits() const;
87     int     misses() const;
88
89 private:
90     bool    makeRoomFor( int cost, int priority = -1 );
91     KeyType keytype;
92     QCList *lruList;
93     QCDict *dict;
94     int     mCost;
95     int     tCost;
96     bool    copyk;
97 };
98
99
100 class Q_EXPORT QGCacheIterator                  // generic cache iterator
101 {
102 protected:
103     QGCacheIterator( const QGCache & );
104     QGCacheIterator( const QGCacheIterator & );
105    ~QGCacheIterator();
106     QGCacheIterator &operator=( const QGCacheIterator & );
107
108     uint              count()   const;
109     bool              atFirst() const;
110     bool              atLast()  const;
111     QCollection::Item toFirst();
112     QCollection::Item toLast();
113
114     QCollection::Item get() const;
115     QString           getKeyString() const;
116     const char       *getKeyAscii()  const;
117     long              getKeyInt()    const;
118
119     QCollection::Item operator()();
120     QCollection::Item operator++();
121     QCollection::Item operator+=( uint );
122     QCollection::Item operator--();
123     QCollection::Item operator-=( uint );
124
125 protected:
126     QCListIt *it;                               // iterator on cache list
127 };
128
129
130 #endif // QGCACHE_H