diff options
author | Dimitri van Heesch <dimitri@stack.nl> | 2013-12-30 17:55:14 (GMT) |
---|---|---|
committer | Dimitri van Heesch <dimitri@stack.nl> | 2013-12-30 17:55:14 (GMT) |
commit | 6e51abf63021dc9fe32c05f003232fe68a08591d (patch) | |
tree | e9fe6f526e4a2b22b1a55659331c15750969a019 /qtools | |
parent | 744d1ca52e25dfa9e3d656056d87ed7cb6320585 (diff) | |
download | Doxygen-6e51abf63021dc9fe32c05f003232fe68a08591d.zip Doxygen-6e51abf63021dc9fe32c05f003232fe68a08591d.tar.gz Doxygen-6e51abf63021dc9fe32c05f003232fe68a08591d.tar.bz2 |
Reduced and improved functionality of QList
- operations on current index and node (next(), prev(), last(), first()) have been removed.
- access to internal nodes has been removed.
- old QList has been renamed to QInternalList for use inside qtools only.
- added type safe compare, new, and delete operations (compareValues(), newValue(), deleteValue()).
- add compareValues also to QDict for consistency.
- changed doxygen's implementation to comply with the new QList and QDict interface.
Diffstat (limited to 'qtools')
-rw-r--r-- | qtools/Doxyfile | 4 | ||||
-rw-r--r-- | qtools/qdict.h | 20 | ||||
-rw-r--r-- | qtools/qdir.h | 4 | ||||
-rw-r--r-- | qtools/qgcache.cpp | 26 | ||||
-rw-r--r-- | qtools/qgdict.cpp | 10 | ||||
-rw-r--r-- | qtools/qinternallist.h | 139 | ||||
-rw-r--r-- | qtools/qlist.h | 72 | ||||
-rw-r--r-- | qtools/qstrlist.h | 10 | ||||
-rw-r--r-- | qtools/qtextcodec.cpp | 14 | ||||
-rw-r--r-- | qtools/qtools.pro.in | 2 | ||||
-rw-r--r-- | qtools/qwaitcondition_win32.cpp | 4 |
11 files changed, 238 insertions, 67 deletions
diff --git a/qtools/Doxyfile b/qtools/Doxyfile index fee2bd5..bc1eb53 100644 --- a/qtools/Doxyfile +++ b/qtools/Doxyfile @@ -276,10 +276,10 @@ PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- -CLASS_DIAGRAMS = NO +CLASS_DIAGRAMS = YES MSCGEN_PATH = HIDE_UNDOC_RELATIONS = YES -HAVE_DOT = YES +HAVE_DOT = NO DOT_NUM_THREADS = 0 DOT_FONTNAME = DOT_FONTSIZE = 10 diff --git a/qtools/qdict.h b/qtools/qdict.h index 682b270..efc5bd0 100644 --- a/qtools/qdict.h +++ b/qtools/qdict.h @@ -52,7 +52,7 @@ #else -template<class type> class Q_EXPORT QDict : public QGDict +template<class type> class Q_EXPORT QDict : private QGDict { public: QDict(int size=17, bool caseSensitive=TRUE) @@ -61,26 +61,40 @@ public: ~QDict() { clear(); } QDict<type> &operator=(const QDict<type> &d) { return (QDict<type>&)QGDict::operator=(d); } + + // capacity uint count() const { return QGDict::count(); } uint size() const { return QGDict::size(); } bool isEmpty() const { return QGDict::count() == 0; } + // modifiers void insert( const QString &k, const type *d ) { QGDict::look_string(k,(Item)d,1); } void replace( const QString &k, const type *d ) { QGDict::look_string(k,(Item)d,2); } bool remove( const QString &k ) { return QGDict::remove_string(k); } type *take( const QString &k ) { return (type *)QGDict::take_string(k); } + void clear() { QGDict::clear(); } + void resize( uint n ) { QGDict::resize(n); } + + // search type *find( const QString &k ) const { return (type *)((QGDict*)this)->QGDict::look_string(k,0,0); } type *operator[]( const QString &k ) const { return (type *)((QGDict*)this)->QGDict::look_string(k,0,0); } - void clear() { QGDict::clear(); } - void resize( uint n ) { QGDict::resize(n); } + // operations void statistics() const { QGDict::statistics(); } private: void deleteItem( Item d ); + + // new to be reimplemented methods + virtual int compareValues(const type *t1,const type *t2) const + { return const_cast<QDict<type>*>(this)->QGDict::compareItems((QCollection::Item)t1,(QCollection::Item)t2); } + + // reimplemented methods + virtual int compareItems(QCollection::Item i1,QCollection::Item i2) + { return compareValues((const type*)i1,(const type*)i2); } }; #if defined(Q_DELETING_VOID_UNDEFINED) diff --git a/qtools/qdir.h b/qtools/qdir.h index dd74271..cec3897 100644 --- a/qtools/qdir.h +++ b/qtools/qdir.h @@ -44,8 +44,8 @@ #endif // QT_H #ifndef QT_NO_DIR -typedef QList<QFileInfo> QFileInfoList; -typedef QListIterator<QFileInfo> QFileInfoListIterator; +typedef QInternalList<QFileInfo> QFileInfoList; +typedef QInternalListIterator<QFileInfo> QFileInfoListIterator; class QStringList; diff --git a/qtools/qgcache.cpp b/qtools/qgcache.cpp index 511c867..683c2a7 100644 --- a/qtools/qgcache.cpp +++ b/qtools/qgcache.cpp @@ -36,7 +36,7 @@ **********************************************************************/ #include "qgcache.h" -#include "qlist.h" +#include "qinternallist.h" #include "qdict.h" #include "qstring.h" @@ -73,7 +73,7 @@ struct QCacheItem QCList class (internal list of cache items) *****************************************************************************/ -class QCList : private QList<QCacheItem> +class QCList : private QInternalList<QCacheItem> { friend class QGCacheIterator; friend class QCListIt; @@ -88,13 +88,13 @@ public: void setAutoDelete( bool del ) { QCollection::setAutoDelete(del); } - bool removeFirst() { return QList<QCacheItem>::removeFirst(); } - bool removeLast() { return QList<QCacheItem>::removeLast(); } + bool removeFirst() { return QInternalList<QCacheItem>::removeFirst(); } + bool removeLast() { return QInternalList<QCacheItem>::removeLast(); } - QCacheItem *first() { return QList<QCacheItem>::first(); } - QCacheItem *last() { return QList<QCacheItem>::last(); } - QCacheItem *prev() { return QList<QCacheItem>::prev(); } - QCacheItem *next() { return QList<QCacheItem>::next(); } + QCacheItem *first() { return QInternalList<QCacheItem>::first(); } + QCacheItem *last() { return QInternalList<QCacheItem>::last(); } + QCacheItem *prev() { return QInternalList<QCacheItem>::prev(); } + QCacheItem *next() { return QInternalList<QCacheItem>::next(); } #if defined(DEBUG) int inserts; // variables for statistics @@ -125,7 +125,7 @@ void QCList::insert( QCacheItem *ci ) item = next(); } if ( item ) - QList<QCacheItem>::insert( at(), ci ); + QInternalList<QCacheItem>::insert( at(), ci ); else append( ci ); #if defined(DEBUG) @@ -136,7 +136,7 @@ void QCList::insert( QCacheItem *ci ) inline void QCList::insert( int i, QCacheItem *ci ) { - QList<QCacheItem>::insert( i, ci ); + QInternalList<QCacheItem>::insert( i, ci ); #if defined(DEBUG) ASSERT( ci->node == 0 ); #endif @@ -166,11 +166,11 @@ inline void QCList::reference( QCacheItem *ci ) } -class QCListIt: public QListIterator<QCacheItem> +class QCListIt: public QInternalListIterator<QCacheItem> { public: - QCListIt( const QCList *p ): QListIterator<QCacheItem>( *p ) {} - QCListIt( const QCListIt *p ): QListIterator<QCacheItem>( *p ) {} + QCListIt( const QCList *p ): QInternalListIterator<QCacheItem>( *p ) {} + QCListIt( const QCListIt *p ): QInternalListIterator<QCacheItem>( *p ) {} }; diff --git a/qtools/qgdict.cpp b/qtools/qgdict.cpp index 534a93c..2530986 100644 --- a/qtools/qgdict.cpp +++ b/qtools/qgdict.cpp @@ -36,7 +36,7 @@ **********************************************************************/ #include "qgdict.h" -#include "qlist.h" +#include "qinternallist.h" #include "qstring.h" #include "qdatastream.h" #include <ctype.h> @@ -63,14 +63,14 @@ static const int op_insert = 1; static const int op_replace = 2; -class QGDItList : public QList<QGDictIterator> +class QGDItList : public QInternalList<QGDictIterator> { public: - QGDItList() : QList<QGDictIterator>() {} - QGDItList( const QGDItList &list ) : QList<QGDictIterator>(list) {} + QGDItList() : QInternalList<QGDictIterator>() {} + QGDItList( const QGDItList &list ) : QInternalList<QGDictIterator>(list) {} ~QGDItList() { clear(); } QGDItList &operator=(const QGDItList &list) - { return (QGDItList&)QList<QGDictIterator>::operator=(list); } + { return (QGDItList&)QInternalList<QGDictIterator>::operator=(list); } }; diff --git a/qtools/qinternallist.h b/qtools/qinternallist.h new file mode 100644 index 0000000..09dbfce --- /dev/null +++ b/qtools/qinternallist.h @@ -0,0 +1,139 @@ +/**************************************************************************** +** +** +** Definition of QList template/macro class +** +** Created : 920701 +** +** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. +** +** This file is part of the tools module of the Qt GUI Toolkit. +** +** This file may be distributed under the terms of the Q Public License +** as defined by Trolltech AS of Norway and appearing in the file +** LICENSE.QPL included in the packaging of this file. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition +** licenses may use this file in accordance with the Qt Commercial License +** Agreement provided with the Software. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for +** information about Qt Commercial License Agreements. +** See http://www.trolltech.com/qpl/ for QPL licensing information. +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef QINTERNALLIST_H +#define QINTERNALLIST_H + +#ifndef QT_H +#include "qglist.h" +#endif // QT_H + + +template<class type> class Q_EXPORT QInternalList : public QGList +{ +public: + QInternalList() {} + QInternalList( const QInternalList<type> &l ) : QGList(l) {} + ~QInternalList() { clear(); } + QInternalList<type> &operator=(const QInternalList<type> &l) + { return (QInternalList<type>&)QGList::operator=(l); } + bool operator==( const QInternalList<type> &list ) const + { return QGList::operator==( list ); } + uint count() const { return QGList::count(); } + bool isEmpty() const { return QGList::count() == 0; } + bool insert( uint i, const type *d){ return QGList::insertAt(i,(QCollection::Item)d); } + void inSort( const type *d ) { QGList::inSort((QCollection::Item)d); } + void prepend( const type *d ) { QGList::insertAt(0,(QCollection::Item)d); } + void append( const type *d ) { QGList::append((QCollection::Item)d); } + bool remove( uint i ) { return QGList::removeAt(i); } + bool remove() { return QGList::remove((QCollection::Item)0); } + bool remove( const type *d ) { return QGList::remove((QCollection::Item)d); } + bool removeRef( const type *d ) { return QGList::removeRef((QCollection::Item)d); } + void removeNode( QLNode *n ) { QGList::removeNode(n); } + bool removeFirst() { return QGList::removeFirst(); } + bool removeLast() { return QGList::removeLast(); } + type *take( uint i ) { return (type *)QGList::takeAt(i); } + type *take() { return (type *)QGList::take(); } + type *takeNode( QLNode *n ) { return (type *)QGList::takeNode(n); } + void clear() { QGList::clear(); } + void sort() { QGList::sort(); } + int find( const type *d ) { return QGList::find((QCollection::Item)d); } + int findNext( const type *d ) { return QGList::find((QCollection::Item)d,FALSE); } + int findRef( const type *d ) { return QGList::findRef((QCollection::Item)d); } + int findNextRef( const type *d ){ return QGList::findRef((QCollection::Item)d,FALSE);} + uint contains( const type *d ) const { return QGList::contains((QCollection::Item)d); } + uint containsRef( const type *d ) const + { return QGList::containsRef((QCollection::Item)d); } + type *at( uint i ) { return (type *)QGList::at(i); } + int at() const { return QGList::at(); } + type *current() const { return (type *)QGList::get(); } + QLNode *currentNode() const { return QGList::currentNode(); } + type *getFirst() const { return (type *)QGList::cfirst(); } + type *getLast() const { return (type *)QGList::clast(); } + type *first() { return (type *)QGList::first(); } + type *last() { return (type *)QGList::last(); } + type *next() { return (type *)QGList::next(); } + type *prev() { return (type *)QGList::prev(); } + void toVector( QGVector *vec )const{ QGList::toVector(vec); } +private: + void deleteItem( QCollection::Item d ); +}; + +#if defined(Q_DELETING_VOID_UNDEFINED) +template<> inline void QInternalList<void>::deleteItem( QCollection::Item ) +{ +} +#endif + +template<class type> inline void QInternalList<type>::deleteItem( QCollection::Item d ) +{ + if ( del_item ) delete (type *)d; +} + + +template<class type> class Q_EXPORT QInternalListIterator : public QGListIterator +{ +public: + QInternalListIterator(const QInternalList<type> &l) :QGListIterator((QGList &)l) {} + ~QInternalListIterator() {} + uint count() const { return list->count(); } + bool isEmpty() const { return list->count() == 0; } + bool atFirst() const { return QGListIterator::atFirst(); } + bool atLast() const { return QGListIterator::atLast(); } + type *toFirst() { return (type *)QGListIterator::toFirst(); } + type *toLast() { return (type *)QGListIterator::toLast(); } + operator type *() const { return (type *)QGListIterator::get(); } + type *operator*() { return (type *)QGListIterator::get(); } + + // No good, since QList<char> (ie. QStrList fails... + // + // MSVC++ gives warning + // Sunpro C++ 4.1 gives error + // type *operator->() { return (type *)QGListIterator::get(); } + + type *current() const { return (type *)QGListIterator::get(); } + type *operator()() { return (type *)QGListIterator::operator()();} + type *operator++() { return (type *)QGListIterator::operator++(); } + type *operator+=(uint j) { return (type *)QGListIterator::operator+=(j);} + type *operator--() { return (type *)QGListIterator::operator--(); } + type *operator-=(uint j) { return (type *)QGListIterator::operator-=(j);} + QInternalListIterator<type>& operator=(const QInternalListIterator<type>&it) + { QGListIterator::operator=(it); return *this; } +}; + + +#endif // QINTERNALLIST_H diff --git a/qtools/qlist.h b/qtools/qlist.h index a4608fb..e9b908d 100644 --- a/qtools/qlist.h +++ b/qtools/qlist.h @@ -35,6 +35,14 @@ ** **********************************************************************/ +/* This is a stripped version of the original QList, which has been renamed to + QInternalList. This implementation doesn't expose the current node and index, + nor direct access to the list nodes. + This makes it possible to have more constant methods. It also provides + a typesafe method to compare elements called compareValues() and a typesafe + methods to create and delete elements called newValue() and deleteValue(). + */ + #ifndef QLIST_H #define QLIST_H @@ -43,7 +51,7 @@ #endif // QT_H -template<class type> class Q_EXPORT QList : public QGList +template<class type> class Q_EXPORT QList : private QGList { public: QList() {} @@ -53,57 +61,67 @@ public: { return (QList<type>&)QGList::operator=(l); } bool operator==( const QList<type> &list ) const { return QGList::operator==( list ); } + + // capacity uint count() const { return QGList::count(); } bool isEmpty() const { return QGList::count() == 0; } + + // modifiers add bool insert( uint i, const type *d){ return QGList::insertAt(i,(QCollection::Item)d); } void inSort( const type *d ) { QGList::inSort((QCollection::Item)d); } void prepend( const type *d ) { QGList::insertAt(0,(QCollection::Item)d); } void append( const type *d ) { QGList::append((QCollection::Item)d); } + + // modifiers remove bool remove( uint i ) { return QGList::removeAt(i); } - bool remove() { return QGList::remove((QCollection::Item)0); } bool remove( const type *d ) { return QGList::remove((QCollection::Item)d); } bool removeRef( const type *d ) { return QGList::removeRef((QCollection::Item)d); } - void removeNode( QLNode *n ) { QGList::removeNode(n); } bool removeFirst() { return QGList::removeFirst(); } bool removeLast() { return QGList::removeLast(); } type *take( uint i ) { return (type *)QGList::takeAt(i); } - type *take() { return (type *)QGList::take(); } - type *takeNode( QLNode *n ) { return (type *)QGList::takeNode(n); } void clear() { QGList::clear(); } + + // operations void sort() { QGList::sort(); } - int find( const type *d ) { return QGList::find((QCollection::Item)d); } - int findNext( const type *d ) { return QGList::find((QCollection::Item)d,FALSE); } - int findRef( const type *d ) { return QGList::findRef((QCollection::Item)d); } - int findNextRef( const type *d ){ return QGList::findRef((QCollection::Item)d,FALSE);} + + // search + int find( const type *d ) const { return const_cast<QList<type>*>(this)->QGList::find((QCollection::Item)d); } + int findRef( const type *d ) const { return const_cast<QList<type>*>(this)->QGList::findRef((QCollection::Item)d); } uint contains( const type *d ) const { return QGList::contains((QCollection::Item)d); } - uint containsRef( const type *d ) const - { return QGList::containsRef((QCollection::Item)d); } - type *at( uint i ) { return (type *)QGList::at(i); } - int at() const { return QGList::at(); } - type *current() const { return (type *)QGList::get(); } - QLNode *currentNode() const { return QGList::currentNode(); } + uint containsRef( const type *d ) const { return QGList::containsRef((QCollection::Item)d); } + + // element access + type *at( uint i ) const { return (type *)const_cast<QList<type>*>(this)->QGList::at(i); } type *getFirst() const { return (type *)QGList::cfirst(); } type *getLast() const { return (type *)QGList::clast(); } - type *first() { return (type *)QGList::first(); } - type *last() { return (type *)QGList::last(); } - type *next() { return (type *)QGList::next(); } - type *prev() { return (type *)QGList::prev(); } - void toVector( QGVector *vec )const{ QGList::toVector(vec); } + + // ownership + void setAutoDelete( bool enable ) { QGList::setAutoDelete(enable); } + private: - void deleteItem( QCollection::Item d ); + // new to be reimplemented methods + virtual int compareValues(const type *t1,const type *t2) const + { return const_cast<QList<type>*>(this)->QGList::compareItems((QCollection::Item)t1,(QCollection::Item)t2); } + virtual type *newValue(type *item) const + { return item; } + virtual void deleteValue(type *item) const + { if (del_item) delete item; } + + // reimplemented methods + virtual Item newItem( Item item) + { return (Item)newValue((type*)item); } + virtual void deleteItem( QCollection::Item item ) + { deleteValue((type *)item); } + virtual int compareItems(QCollection::Item i1,QCollection::Item i2) + { return compareValues((const type*)i1,(const type*)i2); } }; #if defined(Q_DELETING_VOID_UNDEFINED) -template<> inline void QList<void>::deleteItem( QCollection::Item ) +template<> inline void QList<void>::deleteValue(void *) const { } #endif -template<class type> inline void QList<type>::deleteItem( QCollection::Item d ) -{ - if ( del_item ) delete (type *)d; -} - template<class type> class Q_EXPORT QListIterator : public QGListIterator { diff --git a/qtools/qstrlist.h b/qtools/qstrlist.h index c6a1864..ebf97c5 100644 --- a/qtools/qstrlist.h +++ b/qtools/qstrlist.h @@ -40,18 +40,18 @@ #ifndef QT_H #include "qstring.h" -#include "qlist.h" +#include "qinternallist.h" #include "qdatastream.h" #endif // QT_H #if defined(Q_TEMPLATEDLL) -template class Q_EXPORT QList<char>; -template class Q_EXPORT QListIterator<char>; +template class Q_EXPORT QInternalList<char>; +template class Q_EXPORT QInternalListIterator<char>; #endif -typedef QList<char> QStrListBase; -typedef QListIterator<char> QStrListIterator; +typedef QInternalList<char> QStrListBase; +typedef QInternalListIterator<char> QStrListIterator; class Q_EXPORT QStrList : public QStrListBase diff --git a/qtools/qtextcodec.cpp b/qtools/qtextcodec.cpp index 9721c25..168445f 100644 --- a/qtools/qtextcodec.cpp +++ b/qtools/qtextcodec.cpp @@ -38,7 +38,7 @@ #include "qtextcodec.h" #ifndef QT_NO_TEXTCODEC -#include "qlist.h" +#include "qinternallist.h" #ifndef QT_NO_CODECS #include "qutfcodec.h" //#include "qgbkcodec.h" @@ -60,7 +60,7 @@ #include <locale.h> -static QList<QTextCodec> * all = 0; +static QInternalList<QTextCodec> * all = 0; static bool destroying_is_ok; // starts out as 0 /*! Deletes all the created codecs. @@ -84,7 +84,7 @@ void QTextCodec::deleteAllCodecs() return; destroying_is_ok = TRUE; - QList<QTextCodec> * ball = all; + QInternalList<QTextCodec> * ball = all; all = 0; ball->clear(); delete ball; @@ -101,7 +101,7 @@ static void realSetup() if ( destroying_is_ok ) qWarning( "creating new codec during codec cleanup" ); #endif - all = new QList<QTextCodec>; + all = new QInternalList<QTextCodec>; all->setAutoDelete( TRUE ); setupBuiltinCodecs(); } @@ -354,7 +354,7 @@ QTextCodec* QTextCodec::codecForIndex(int i) QTextCodec* QTextCodec::codecForMib(int mib) { setup(); - QListIterator<QTextCodec> i(*all); + QInternalListIterator<QTextCodec> i(*all); QTextCodec* result; for ( ; (result=i); ++i ) { if ( result->mibEnum()==mib ) @@ -626,7 +626,7 @@ QTextCodec* QTextCodec::codecForLocale() QTextCodec* QTextCodec::codecForName(const char* hint, int accuracy) { setup(); - QListIterator<QTextCodec> i(*all); + QInternalListIterator<QTextCodec> i(*all); QTextCodec* result = 0; int best=accuracy; for ( QTextCodec* cursor; (cursor=i); ++i ) { @@ -653,7 +653,7 @@ QTextCodec* QTextCodec::codecForName(const char* hint, int accuracy) QTextCodec* QTextCodec::codecForContent(const char* chars, int len) { setup(); - QListIterator<QTextCodec> i(*all); + QInternalListIterator<QTextCodec> i(*all); QTextCodec* result = 0; int best=0; for ( QTextCodec* cursor; (cursor=i); ++i ) { diff --git a/qtools/qtools.pro.in b/qtools/qtools.pro.in index 3eabed9..b760d14 100644 --- a/qtools/qtools.pro.in +++ b/qtools/qtools.pro.in @@ -26,7 +26,7 @@ HEADERS = qarray.h \ qgvector.h \ qintdict.h \ qiodevice.h \ - qlist.h \ + qinternallist.h \ qptrdict.h \ qqueue.h \ qregexp.h \ diff --git a/qtools/qwaitcondition_win32.cpp b/qtools/qwaitcondition_win32.cpp index 77eb039..80b7b67 100644 --- a/qtools/qwaitcondition_win32.cpp +++ b/qtools/qwaitcondition_win32.cpp @@ -42,7 +42,7 @@ #include <windows.h> #include "qwaitcondition.h" #include "qmutex.h" -#include "qlist.h" +#include "qinternallist.h" //*********************************************************************** // QWaitConditionPrivate @@ -61,7 +61,7 @@ public: HANDLE event; }; -class EventQueue : public QList<QWaitConditionEvent> +class EventQueue : public QInternalList<QWaitConditionEvent> { public: EventQueue() { setAutoDelete(TRUE); } |