From b89561e0c61aec5cae6eafc354f81a3bf071a777 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Fri, 22 Jan 2021 21:40:27 +0100 Subject: Refactoring: cleanup unused qtools headers --- qtools/qasciidict.h | 107 ----- qtools/qcstringlist.h | 2 +- qtools/qdict.doc | 492 ----------------------- qtools/qdict.h | 49 --- qtools/qglobal.cpp | 6 +- qtools/qglobal.h | 6 +- qtools/qintdict.doc | 475 ---------------------- qtools/qintdict.h | 102 ----- qtools/qlist.doc | 1035 ------------------------------------------------ qtools/qlist.h | 158 -------- qtools/qmap.cpp | 22 +- qtools/qmap.h | 607 ---------------------------- qtools/qmap_p.h | 607 ++++++++++++++++++++++++++++ qtools/qqueue.h | 70 ---- qtools/qsortedlist.doc | 94 ----- qtools/qsortedlist.h | 59 --- qtools/qstack.doc | 135 ------- qtools/qstack.h | 71 ---- qtools/qstack_p.h | 71 ++++ qtools/qstring.cpp | 6 +- qtools/qstringlist.h | 4 +- qtools/qstrvec.h | 90 ----- qtools/qvaluelist.doc | 772 ------------------------------------ qtools/qvaluelist.h | 455 --------------------- qtools/qvaluelist_p.h | 455 +++++++++++++++++++++ qtools/qvaluestack.h | 64 --- qtools/qvaluestack_p.h | 64 +++ qtools/qxml.h | 6 +- src/configgen.py | 2 - src/context.cpp | 29 +- src/context.h | 1 - src/definition.h | 2 - src/diagram.cpp | 2 - src/docbookgen.cpp | 1 - src/docbookvisitor.h | 2 - src/doctokenizer.h | 1 - src/doctokenizer.l | 1 - src/doxygen.cpp | 3 - src/doxygen.h | 3 - src/fortranscanner.l | 3 - src/layout.h | 1 - src/memberdef.h | 1 - src/membergroup.h | 1 - src/membername.h | 1 - src/perlmodgen.cpp | 1 - src/reflist.h | 3 +- src/scanner.l | 1 - src/textdocvisitor.h | 13 +- src/vhdljjparser.cpp | 1 - src/vhdljjparser.h | 6 +- src/xmlgen.cpp | 100 +++-- 51 files changed, 1295 insertions(+), 4968 deletions(-) delete mode 100644 qtools/qasciidict.h delete mode 100644 qtools/qdict.doc delete mode 100644 qtools/qdict.h delete mode 100644 qtools/qintdict.doc delete mode 100644 qtools/qintdict.h delete mode 100644 qtools/qlist.doc delete mode 100644 qtools/qlist.h delete mode 100644 qtools/qmap.h create mode 100644 qtools/qmap_p.h delete mode 100644 qtools/qqueue.h delete mode 100644 qtools/qsortedlist.doc delete mode 100644 qtools/qsortedlist.h delete mode 100644 qtools/qstack.doc delete mode 100644 qtools/qstack.h create mode 100644 qtools/qstack_p.h delete mode 100644 qtools/qstrvec.h delete mode 100644 qtools/qvaluelist.doc delete mode 100644 qtools/qvaluelist.h create mode 100644 qtools/qvaluelist_p.h delete mode 100644 qtools/qvaluestack.h create mode 100644 qtools/qvaluestack_p.h diff --git a/qtools/qasciidict.h b/qtools/qasciidict.h deleted file mode 100644 index 6a93a02..0000000 --- a/qtools/qasciidict.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** -** Definition of QAsciiDict template class -** -** Created : 920821 -** -** 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 QASCIIDICT_H -#define QASCIIDICT_H - -#ifndef QT_H -#include "qgdict.h" -#endif // QT_H - - -template class Q_EXPORT QAsciiDict : public QGDict -{ -public: - QAsciiDict(uint size=17, bool caseSensitive=TRUE, bool copyKeys=TRUE ) - : QGDict(size,AsciiKey,caseSensitive,copyKeys) {} - QAsciiDict( const QAsciiDict &d ) : QGDict(d) {} - ~QAsciiDict() { clear(); } - QAsciiDict &operator=(const QAsciiDict &d) - { return (QAsciiDict&)QGDict::operator=(d); } - uint count() const { return QGDict::count(); } - uint size() const { return QGDict::size(); } - bool isEmpty() const { return QGDict::count() == 0; } - - void insert( const char *k, const type *d ) - { QGDict::look_ascii(k,(Item)d,1); } - void replace( const char *k, const type *d ) - { QGDict::look_ascii(k,(Item)d,2); } - bool remove( const char *k ) { return QGDict::remove_ascii(k); } - type *take( const char *k ) { return (type *)QGDict::take_ascii(k); } - type *find( const char *k ) const - { return (type *)((QGDict*)this)->QGDict::look_ascii(k,0,0); } - type *operator[]( const char *k ) const - { return (type *)((QGDict*)this)->QGDict::look_ascii(k,0,0); } - - void clear() { QGDict::clear(); } - void resize( uint n ) { QGDict::resize(n); } - void statistics() const { QGDict::statistics(); } -private: - void deleteItem( Item d ); -}; - -#if defined(Q_DELETING_VOID_UNDEFINED) -template<> inline void QAsciiDict::deleteItem( Item ) -{ -} -#endif - -template inline void QAsciiDict::deleteItem( QCollection::Item d ) -{ - if ( del_item ) delete (type *)d; -} - - -template class Q_EXPORT QAsciiDictIterator : public QGDictIterator -{ -public: - QAsciiDictIterator(const QAsciiDict &d) - : QGDictIterator((QGDict &)d) {} - ~QAsciiDictIterator() {} - uint count() const { return dict->count(); } - bool isEmpty() const { return dict->count() == 0; } - type *toFirst() { return (type *)QGDictIterator::toFirst(); } - operator type *() const { return (type *)QGDictIterator::get(); } - type *current() const { return (type *)QGDictIterator::get(); } - const char *currentKey() const { return QGDictIterator::getKeyAscii(); } - type *operator()() { return (type *)QGDictIterator::operator()(); } - type *operator++() { return (type *)QGDictIterator::operator++(); } - type *operator+=(uint j) { return (type *)QGDictIterator::operator+=(j);} -}; - - -#endif // QASCIIDICT_H diff --git a/qtools/qcstringlist.h b/qtools/qcstringlist.h index 7ffd4d2..a7d79b0 100644 --- a/qtools/qcstringlist.h +++ b/qtools/qcstringlist.h @@ -14,7 +14,7 @@ #ifndef QCSTRINGLIST_H #define QCSTRINGLIST_H -#include "qvaluelist.h" +#include "qvaluelist_p.h" #include "qcstring.h" #include "qregexp.h" diff --git a/qtools/qdict.doc b/qtools/qdict.doc deleted file mode 100644 index bf1ea01..0000000 --- a/qtools/qdict.doc +++ /dev/null @@ -1,492 +0,0 @@ -/**************************************************************************** -** -** -** QDict and QDictIterator class documentation -** -** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. -** -** This file is part 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. -** -**********************************************************************/ - - -/***************************************************************************** - QDict documentation - *****************************************************************************/ - -/*! - \class QDict qdict.h - \brief The QDict class is a template class that provides a dictionary based on \c QString keys. - - \ingroup collection - \ingroup tools - - QDict is implemented as a template class. Define a template instance - QDict\ to create a dictionary that operates on pointers to X, or X*. - - A dictionary is a collection that associates an item with a key. - The key is used for inserting and looking up an item. QDict has - \l QString keys, which are Unicode strings. If you want to use - non-Unicode, plain 8-bit \c char* keys, use the QAsciiDict template. - A QDict has the same performance as a QAsciiDict. - - The dictionary has very fast insertion and lookup. - - Example: - \code - #include - #include - - void main() - { - // Creates a dictionary that maps QString ==> char* (case insensitive) - QDict dict( 17, FALSE ); - - dict.insert( "France", "Paris" ); - dict.insert( "Russia", "Moscow" ); - dict.insert( "Norway", "Oslo" ); - - printf( "%s\n", dict["Norway"] ); - printf( "%s\n", dict["FRANCE"] ); - printf( "%s\n", dict["russia"] ); - - if ( !dict["Italy"] ) - printf( "Italy not defined\n" ); - } - \endcode - - Program output: - \code - Oslo - Paris - Moscow - Italy not defined - \endcode - - The dictionary in our example maps \c QString keys to \c char* items. - Note that the mapping is case insensitive (specified in the - \link QDict::QDict() constructor\endlink). - QDict implements the \link operator[] [] operator\endlink to lookup an item. - - QDict is implemented by QGDict as a hash array with a fixed number of - entries. Each array entry points to a singly linked list of buckets, in - which the dictionary items are stored. - - When an item is inserted with a key, the key is converted (hashed) to - an integer index into the hash array. The item is inserted before the - first bucket in the list of buckets. - - Looking up an item is normally very fast. The key is again hashed to an - array index. Then QDict scans the list of buckets and returns the item - found or null if the item was not found. You cannot insert null pointers - into a dictionary. - - The size of the hash array is very important. In order to get good - performance, you should use a suitably large \link primes.html prime - number\endlink. Suitable means equal to or larger than the maximum - expected number of dictionary items. - - Items with equal keys are allowed. When inserting two items with the - same key, only the last inserted item will be visible (last in, first out) - until it is removed. - - Example: - \code - #include - #include - - void main() - { - // Creates a dictionary that maps QString ==> char* (case sensitive) - QDict dict; - - dict.insert( "Germany", "Berlin" ); - dict.insert( "Germany", "Bonn" ); - - printf( "%s\n", dict["Germany"] ); - dict.remove( "Germany" ); // Oct 3rd 1990 - printf( "%s\n", dict["Germany"] ); - } - \endcode - - Program output: - \code - Bonn - Berlin - \endcode - - The QDictIterator class can traverse the dictionary contents, but only - in an arbitrary order. Multiple iterators may independently traverse the - same dictionary. - - Calling setAutoDelete(TRUE) for a dictionary tells it to delete items - that are removed . The default is to not delete items when they are - removed. - - When inserting an item into a dictionary, only the pointer is copied, not - the item itself. This is called a shallow copy. It is possible to make the - dictionary copy all of the item's data (known as a deep copy) when an - item is inserted. insert() calls the virtual function - QCollection::newItem() for the item to be inserted. - Inherit a dictionary and reimplement it if you want deep copies. - - When removing a dictionary item, the virtual function - QCollection::deleteItem() is called. QDict's default implementation - is to delete the item if auto-deletion is enabled. - - \sa QDictIterator, QAsciiDict, QIntDict, QPtrDict, - \link collection.html Collection Classes\endlink -*/ - - -/*! - \fn QDict::QDict( int size, bool caseSensitive ) - Constructs a dictionary with the following properties: - \arg \e size is the size of the internal hash array. - \arg \e caseSensitive specifies whether to use case sensitive lookup or not. - - Setting \e size to a suitably large \link primes.html prime - number\endlink (equal to or greater than the expected number of entries) - makes the hash distribution better and hence the lookup faster. - - Setting \e caseSensitive to TRUE will treat "abc" and "Abc" as different - keys. Setting it to FALSE will make the dictionary ignore case. - Case insensitive comparison includes the whole Unicode alphabet. -*/ - -/*! - \fn QDict::QDict( const QDict &dict ) - Constructs a copy of \e dict. - - Each item in \e dict are inserted into this dictionary. - Only the pointers are copied (shallow copy). -*/ - -/*! - \fn QDict::~QDict() - Removes all items from the dictionary and destroys it. - All iterators that access this dictionary will be reset. - - \sa setAutoDelete() -*/ - -/*! - \fn QDict &QDict::operator=(const QDict &dict) - Assigns \e dict to this dictionary and returns a reference to this - dictionary. - - This dictionary is first cleared, then each item in \e dict is inserted - into this dictionary. - Only the pointers are copied (shallow copy), unless newItem() has been - reimplemented(). -*/ - -/*! - \fn uint QDict::count() const - Returns the number of items in the dictionary. - \sa isEmpty() -*/ - -/*! - \fn uint QDict::size() const - Returns the size of the internal hash array (as specified in the - constructor). - \sa count() -*/ - -/*! - \fn void QDict::resize( uint newsize ) - Changes the size of the hashtable the \a newsize. - The contents of the dictionary are preserved, - but all iterators on the dictionary become invalid. -*/ - -/*! - \fn bool QDict::isEmpty() const - Returns TRUE if the dictionary is empty, i.e. count() == 0. Returns FALSE - otherwise. - \sa count() -*/ - -/*! - \fn void QDict::insert( const QString &key, const type *item ) - - Inserts the \e key with the \e item into the dictionary. - - The key does not have to be a unique dictionary key. If multiple items - are inserted with the same key, only the last item will be visible. - - Null items are not allowed. - - \sa replace() -*/ - -/*! - \fn void QDict::replace( const QString &key, const type *item ) - - Replaces an item which has a key equal to \e key with \e item. - - If the item does not already exist, it will be inserted. - - Null items are not allowed. - - Equivalent to: - \code - QDict dict; - ... - if ( dict.find(key) ) - dict.remove( key ); - dict.insert( key, item ); - \endcode - - If there are two or more items with equal keys, then the last inserted - of these will be replaced. - - \sa insert() -*/ - -/*! - \fn bool QDict::remove( const QString &key ) - - Removes the item associated with \e key from the dictionary. - Returns TRUE if successful, or FALSE if the key does not exist in the - dictionary. - - If there are two or more items with equal keys, then the last inserted - of these will be removed. - - The removed item is deleted if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled. - - All dictionary iterators that refer to the removed item will be set to - point to the next item in the dictionary traversing order. - - \sa take(), clear(), setAutoDelete() -*/ - -/*! - \fn type *QDict::take( const QString &key ) - - Takes the item associated with \e key out of the dictionary without - deleting it (even if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled). - - If there are two or more items with equal keys, then the last inserted - of these will be taken. - - Returns a pointer to the item taken out, or null if the key does not - exist in the dictionary. - - All dictionary iterators that refer to the taken item will be set to - point to the next item in the dictionary traversal order. - - \sa remove(), clear(), setAutoDelete() -*/ - -/*! - \fn void QDict::clear() - - Removes all items from the dictionary. - - The removed items are deleted if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled. - - All dictionary iterators that operate on dictionary are reset. - - \sa remove(), take(), setAutoDelete() -*/ - -/*! - \fn type *QDict::find( const QString &key ) const - - Returns the item associated with \e key, or null if the key does not - exist in the dictionary. - - This function uses an internal hashing algorithm to optimize lookup. - - If there are two or more items with equal keys, then the last inserted - of these will be found. - - Equivalent to the [] operator. - - \sa operator[]() -*/ - -/*! - \fn type *QDict::operator[]( const QString &key ) const - - Returns the item associated with \e key, or null if the key does not - exist in the dictionary. - - This function uses an internal hashing algorithm to optimize lookup. - - If there are two or more items with equal keys, then the last inserted - of these will be found. - - Equivalent to the find() function. - - \sa find() -*/ - -/*! - \fn void QDict::statistics() const - Debugging-only function that prints out the dictionary distribution - using qDebug(). -*/ - - -/***************************************************************************** - QDictIterator documentation - *****************************************************************************/ - -/*! - \class QDictIterator qdict.h - \brief The QDictIterator class provides an iterator for QDict collections. - - \ingroup collection - \ingroup tools - - QDictIterator is implemented as a template class. - Define a template instance QDictIterator\ to create a - dictionary iterator that operates on QDict\ (dictionary of X*). - - Example: - \code - #include - #include - - void main() - { - // Creates a dictionary that maps QString ==> char* (case insensitive) - QDict dict( 17, FALSE ); - - dict.insert( "France", "Paris" ); - dict.insert( "Russia", "Moscow" ); - dict.insert( "Norway", "Oslo" ); - - QDictIterator it( dict ); // iterator for dict - - while ( it.current() ) { - printf( "%s -> %s\n", it.currentKey().latin1(), it.current() ); - ++it; - } - } - \endcode - - Program output: - \code - Russia -> Moscow - Norway -> Oslo - France -> Paris - \endcode - - Note that the traversal order is arbitrary, you are not guaranteed the - order above. - - Multiple iterators may independently traverse the same dictionary. - A QDict knows about all iterators that are operating on the dictionary. - When an item is removed from the dictionary, QDict update all iterators - that are referring the removed item to point to the next item in the - traversing order. - - \sa QDict, \link collection.html Collection Classes\endlink -*/ - -/*! - \fn QDictIterator::QDictIterator( const QDict &dict ) - Constructs an iterator for \e dict. The current iterator item is - set to point on the first item in the \e dict. -*/ - -/*! - \fn QDictIterator::~QDictIterator() - Destroys the iterator. -*/ - -/*! - \fn uint QDictIterator::count() const - Returns the number of items in the dictionary this iterator operates on. - \sa isEmpty() -*/ - -/*! - \fn bool QDictIterator::isEmpty() const - Returns TRUE if the dictionary is empty, i.e. count() == 0, otherwise FALSE. - \sa count() -*/ - -/*! - \fn type *QDictIterator::toFirst() - Sets the current iterator item to point to the first item in the - dictionary and returns a pointer to the item. - If the dictionary is empty it sets the current item to null and - returns null. -*/ - -/*! - \fn QDictIterator::operator type *() const - Cast operator. Returns a pointer to the current iterator item. - Same as current(). -*/ - -/*! - \fn type *QDictIterator::current() const - Returns a pointer to the current iterator item. -*/ - -/*! - \fn QString QDictIterator::currentKey() const - Returns a pointer to the key for the current iterator item. -*/ - -/*! - \fn type *QDictIterator::operator()() - Makes the succeeding item current and returns the original current item. - - If the current iterator item was the last item in the dictionary or if it - was null, null is returned. -*/ - -/*! - \fn type *QDictIterator::operator++() - Prefix ++ makes the succeeding item current and returns the new current - item. - - If the current iterator item was the last item in the dictionary or if it - was null, null is returned. -*/ - -/*! - \fn type *QDictIterator::operator+=( uint jump ) - Sets the current item to the item \e jump positions after the current item, - and returns a pointer to that item. - - If that item is beyond the last item or if the dictionary is empty, - it sets the current item to null and returns null. -*/ - - diff --git a/qtools/qdict.h b/qtools/qdict.h deleted file mode 100644 index 12db365..0000000 --- a/qtools/qdict.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** -** Definition of QDict template class -** -** Created : 920821 -** -** 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 QDICT_H -#define QDICT_H - -#ifndef QT_H -#include "qgdict.h" -#endif // QT_H - -#define QAsciiDict QDict -#define QAsciiDictIterator QDictIterator -#include "qasciidict.h" - -#endif // QDICT_H diff --git a/qtools/qglobal.cpp b/qtools/qglobal.cpp index 444cb3b..0e0871e 100644 --- a/qtools/qglobal.cpp +++ b/qtools/qglobal.cpp @@ -1,5 +1,5 @@ /**************************************************************************** -** +** ** ** Global functions ** @@ -36,7 +36,7 @@ **********************************************************************/ #include "qglobal.h" -#include "qasciidict.h" +//#include "qasciidict.h" #include "qstring.h" #include #include @@ -554,6 +554,7 @@ bool qt_check_pointer( bool c, const char *n, int l ) } +#if 0 static bool firstObsoleteWarning(const char *obj, const char *oldfunc ) { static QAsciiDict *obsoleteDict = 0; @@ -617,6 +618,7 @@ void qObsolete( const char *message ) return; qDebug( "%s", message ); } +#endif /*! diff --git a/qtools/qglobal.h b/qtools/qglobal.h index 0deef5d..1fbe2f7 100644 --- a/qtools/qglobal.h +++ b/qtools/qglobal.h @@ -1,5 +1,5 @@ /**************************************************************************** -** +** ** ** Global type declarations and definitions ** @@ -276,7 +276,7 @@ #define _CC_V2002 #else #define _CC_V1998 -#endif +#endif #endif #ifndef Q_PACKED @@ -612,6 +612,7 @@ Q_EXPORT msg_handler qInstallMsgHandler( msg_handler ); Q_EXPORT void qSuppressObsoleteWarnings( bool = TRUE ); +#if 0 #if !defined(QT_REJECT_OBSOLETE) #define QT_OBSOLETE Q_EXPORT void qObsolete( const char *obj, const char *oldfunc, @@ -619,6 +620,7 @@ Q_EXPORT void qObsolete( const char *obj, const char *oldfunc, Q_EXPORT void qObsolete( const char *obj, const char *oldfunc ); Q_EXPORT void qObsolete( const char *message ); #endif +#endif // DvH: added to avoid warnings on recent gcc versions #define Q_DELETING_VOID_UNDEFINED diff --git a/qtools/qintdict.doc b/qtools/qintdict.doc deleted file mode 100644 index 90625da..0000000 --- a/qtools/qintdict.doc +++ /dev/null @@ -1,475 +0,0 @@ -/**************************************************************************** -** -** -** QIntDict and QIntDictIterator class documentation -** -** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. -** -** This file is part 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. -** -**********************************************************************/ - - -/***************************************************************************** - QIntDict documentation - *****************************************************************************/ - -/*! - \class QIntDict qintdict.h - \brief The QIntDict class is a template class that provides a dictionary based on \c long keys. - - \ingroup collection - \ingroup tools - - QIntDict is implemented as a template class. Define a - template instance QIntDict\ to create a dictionary that operates on - pointers to X, or X*. - - A dictionary is a collection that associates an item with a key. - The key is used for inserting and looking up an item. QIntDict has - \c long keys. - - The dictionary has very fast insertion and lookup. - - Example: - \code - #include - #include - - void main() - { - QIntDict dict; // maps long ==> char* - - dict.insert( 33, "France" ); - dict.insert( 7, "Russia" ); - dict.insert( 49, "Norway" ); - - printf( "%s\n", dict[49] ); - printf( "%s\n", dict[33] ); - printf( "%s\n", dict[7] ); - - if ( !dict[39] ) - printf( "39 not defined\n" ); - } - \endcode - - Program output: - \code - Norway - France - Russia - 39 not defined - \endcode - - The dictionary in our example maps \c long keys to \c char* items. - QIntDict implements the \link operator[] [] operator\endlink to lookup - an item. - - QIntDict is implemented by QGDict as a hash array with a fixed number of - entries. Each array entry points to a singly linked list of buckets, in - which the dictionary items are stored. - - When an item is inserted with a key, the key is converted (hashed) to - an integer index into the hash array using the \c mod operation. The - item is inserted before the first bucket in the list of buckets. - - Looking up an item is normally very fast. The key is again hashed to an - array index. Then QIntDict scans the list of buckets and returns the item - found or null if the item was not found. You cannot insert null pointers - into a dictionary. - - The size of the hash array is very important. In order to get good - performance, you should use a suitably large \link primes.html prime - number\endlink. Suitable means equal to or larger than the maximum - expected number of dictionary items. - - Items with equal keys are allowed. When inserting two items with the - same key, only the last inserted item will be visible (last in, first out) - until it is removed. - - Example: - \code - #include - #include - - void main() - { - QIntDict dict; // maps long ==> char* - - dict.insert( 7, "Russia" ); - dict.insert( 7, "USSR" ); - - printf( "%s\n", dict[7] ); - dict.remove( 7 ); // Gorbie was here - printf( "%s\n", dict[7] ); - } - \endcode - - Program output: - \code - USSR - Russia - \endcode - - The QIntDictIterator class can traverse the dictionary contents, but only - in an arbitrary order. Multiple iterators may independently traverse the - same dictionary. - - Calling setAutoDelete(TRUE) for a dictionary tells it to delete items - that are removed . The default is to not delete items when they are - removed. - - When inserting an item into a dictionary, only the pointer is copied, not - the item itself. This is called a shallow copy. It is possible to make the - dictionary copy all of the item's data (known as a deep copy) when an - item is inserted. insert() calls the virtual function - QCollection::newItem() for the item to be inserted. - Inherit a dictionary and reimplement it if you want deep copies. - - When removing a dictionary item, the virtual function - QCollection::deleteItem() is called. QIntDict's default implementation - is to delete the item if auto-deletion is enabled. - - \sa QIntDictIterator, QDict, QAsciiDict, QPtrDict, - \link collection.html Collection Classes\endlink -*/ - - -/*! - \fn QIntDict::QIntDict( int size ) - Constructs a dictionary using an internal hash array with the size - \e size. - - Setting \e size to a suitably large \link primes.html prime number\endlink - (equal to or greater than the expected number of entries) makes the hash - distribution better and hence the lookup faster. -*/ - -/*! - \fn QIntDict::QIntDict( const QIntDict &dict ) - Constructs a copy of \e dict. - - Each item in \e dict are inserted into this dictionary. - Only the pointers are copied (shallow copy). -*/ - -/*! - \fn QIntDict::~QIntDict() - Removes all items from the dictionary and destroys it. - - All iterators that access this dictionary will be reset. - - \sa setAutoDelete() -*/ - -/*! - \fn QIntDict &QIntDict::operator=(const QIntDict &dict) - Assigns \e dict to this dictionary and returns a reference to this - dictionary. - - This dictionary is first cleared, then each item in \e dict is inserted - into this dictionary. - Only the pointers are copied (shallow copy), unless newItem() has been - reimplemented. -*/ - -/*! - \fn uint QIntDict::count() const - Returns the number of items in the dictionary. - \sa isEmpty() -*/ - -/*! - \fn uint QIntDict::size() const - Returns the size of the internal hash array (as specified in the - constructor). - \sa count() -*/ - -/*! - \fn void QIntDict::resize( uint newsize ) - Changes the size of the hashtable the \a newsize. - The contents of the dictionary are preserved, - but all iterators on the dictionary become invalid. -*/ - -/*! - \fn bool QIntDict::isEmpty() const - Returns TRUE if the dictionary is empty, i.e. count() == 0. Returns FALSE - otherwise. - \sa count() -*/ - -/*! - \fn void QIntDict::insert( long key, const type *item ) - Inserts the \e key with the \e item into the dictionary. - - The key does not have to be a unique dictionary key. If multiple items - are inserted with the same key, only the last item will be visible. - - Null items are not allowed. - - \sa replace() -*/ - -/*! - \fn void QIntDict::replace( long key, const type *item ) - Replaces an item which has a key equal to \e key with \e item. - - If the item does not already exist, it will be inserted. - - Null items are not allowed. - - Equivalent to: - \code - QIntDict dict; - ... - if ( dict.find(key) ) - dict.remove( key ); - dict.insert( key, item ); - \endcode - - If there are two or more items with equal keys, then the last inserted - of these will be replaced. - - \sa insert() -*/ - -/*! - \fn bool QIntDict::remove( long key ) - Removes the item associated with \e key from the dictionary. - Returns TRUE if successful, or FALSE if the key does not exist in the - dictionary. - - If there are two or more items with equal keys, then the last inserted - of these will be removed. - - The removed item is deleted if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled. - - All dictionary iterators that refer to the removed item will be set to - point to the next item in the dictionary traversing order. - - \sa take(), clear(), setAutoDelete() -*/ - -/*! - \fn type *QIntDict::take( long key ) - Takes the item associated with \e key out of the dictionary without - deleting it (even if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled). - - If there are two or more items with equal keys, then the last inserted - of these will be taken. - - Returns a pointer to the item taken out, or null if the key does not - exist in the dictionary. - - All dictionary iterators that refer to the taken item will be set to - point to the next item in the dictionary traversing order. - - \sa remove(), clear(), setAutoDelete() -*/ - -/*! - \fn void QIntDict::clear() - Removes all items from the dictionary. - - The removed items are deleted if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled. - - All dictionary iterators that access this dictionary will be reset. - - \sa remove(), take(), setAutoDelete() -*/ - -/*! - \fn type *QIntDict::find( long key ) const - Returns the item associated with \e key, or null if the key does not - exist in the dictionary. - - This function uses an internal hashing algorithm to optimize lookup. - - If there are two or more items with equal keys, then the last inserted - of these will be found. - - Equivalent to the [] operator. - - \sa operator[]() -*/ - -/*! - \fn type *QIntDict::operator[]( long key ) const - Returns the item associated with \e key, or null if the key does not - exist in the dictionary. - - This function uses an internal hashing algorithm to optimize lookup. - - If there are two or more items with equal keys, then the last inserted - of these will be found. - - Equivalent to the find() function. - - \sa find() -*/ - -/*! - \fn void QIntDict::statistics() const - Debugging-only function that prints out the dictionary distribution - using qDebug(). -*/ - - -/***************************************************************************** - QIntDictIterator documentation - *****************************************************************************/ - -/*! - \class QIntDictIterator qintdict.h - \brief The QIntDictIterator class provides an iterator for QIntDict collections. - - \ingroup collection - \ingroup tools - - QIntDictIterator is implemented as a template class. - Define a template instance QIntDictIterator\ to create a - dictionary iterator that operates on QIntDict\ (dictionary of X*). - - Example: - \code - #include - #include - - void main() - { - QIntDict dict; // maps long ==> char* - - dict.insert( 33, "France" ); - dict.insert( 7, "Russia" ); - dict.insert( 49, "Norway" ); - - QIntDictIterator it( dict ); // iterator for dict - - while ( it.current() ) { - printf( "%d -> %s\n", it.currentKey(), it.current() ); - ++it; - } - } - \endcode - - Program output: - \code - 7 -> Russia - 49 -> Norway - 33 -> France - \endcode - - Note that the traversal order is arbitrary, you are not guaranteed the - order above. - - Multiple iterators may independently traverse the same dictionary. - A QIntDict knows about all iterators that are operating on the dictionary. - When an item is removed from the dictionary, QIntDict update all - iterators that are referring the removed item to point to the next item - in the traversing order. - - \sa QIntDict, \link collection.html Collection Classes\endlink -*/ - -/*! - \fn QIntDictIterator::QIntDictIterator( const QIntDict &dict ) - Constructs an iterator for \e dict. The current iterator item is - set to point on the first item in the \e dict. -*/ - -/*! - \fn QIntDictIterator::~QIntDictIterator() - Destroys the iterator. -*/ - -/*! - \fn uint QIntDictIterator::count() const - Returns the number of items in the dictionary this iterator operates on. - \sa isEmpty() -*/ - -/*! - \fn bool QIntDictIterator::isEmpty() const - Returns TRUE if the dictionary is empty, i.e. count() == 0. Returns FALSE - otherwise. - \sa count() -*/ - -/*! - \fn type *QIntDictIterator::toFirst() - Sets the current iterator item to point to the first item in the - dictionary and returns a pointer to the item. - If the dictionary is empty it sets the current item to null and - returns null. -*/ - -/*! - \fn QIntDictIterator::operator type *() const - Cast operator. Returns a pointer to the current iterator item. - Same as current(). -*/ - -/*! - \fn type *QIntDictIterator::current() const - Returns a pointer to the current iterator item. -*/ - -/*! - \fn long QIntDictIterator::currentKey() const - Returns the key for the current iterator item. -*/ - -/*! - \fn type *QIntDictIterator::operator()() - Makes the succeeding item current and returns the original current item. - - If the current iterator item was the last item in the dictionary or if it - was null, null is returned. -*/ - -/*! - \fn type *QIntDictIterator::operator++() - Prefix ++ makes the succeeding item current and returns the new current - item. - - If the current iterator item was the last item in the dictionary or if it - was null, null is returned. -*/ - -/*! - \fn type *QIntDictIterator::operator+=( uint jump ) - Sets the current item to the item \e jump positions after the current item, - and returns a pointer to that item. - - If that item is beyond the last item or if the dictionary is empty, - it sets the current item to null and returns null. -*/ diff --git a/qtools/qintdict.h b/qtools/qintdict.h deleted file mode 100644 index 0606ec8..0000000 --- a/qtools/qintdict.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** -** Definition of QIntDict template class -** -** Created : 940624 -** -** 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 QINTDICT_H -#define QINTDICT_H - -#ifndef QT_H -#include "qgdict.h" -#endif // QT_H - - -template class Q_EXPORT QIntDict : public QGDict -{ -public: - QIntDict(uint size=17) : QGDict(size,IntKey,0,0) {} - QIntDict( const QIntDict &d ) : QGDict(d) {} - ~QIntDict() { clear(); } - QIntDict &operator=(const QIntDict &d) - { return (QIntDict&)QGDict::operator=(d); } - uint count() const { return QGDict::count(); } - uint size() const { return QGDict::size(); } - bool isEmpty() const { return QGDict::count() == 0; } - void insert( long k, const type *d ) - { QGDict::look_int(k,(Item)d,1); } - void replace( long k, const type *d ) - { QGDict::look_int(k,(Item)d,2); } - bool remove( long k ) { return QGDict::remove_int(k); } - type *take( long k ) { return (type*)QGDict::take_int(k); } - type *find( long k ) const - { return (type *)((QGDict*)this)->QGDict::look_int(k,0,0); } - type *operator[]( long k ) const - { return (type *)((QGDict*)this)->QGDict::look_int(k,0,0); } - void clear() { QGDict::clear(); } - void resize( uint n ) { QGDict::resize(n); } - void statistics() const { QGDict::statistics(); } -private: - void deleteItem( Item d ); -}; - -#if defined(Q_DELETING_VOID_UNDEFINED) -template<> inline void QIntDict::deleteItem( QCollection::Item ) -{ -} -#endif - -template inline void QIntDict::deleteItem( QCollection::Item d ) -{ - if ( del_item ) delete (type *)d; -} - -template class Q_EXPORT QIntDictIterator : public QGDictIterator -{ -public: - QIntDictIterator(const QIntDict &d) :QGDictIterator((QGDict &)d) {} - ~QIntDictIterator() {} - uint count() const { return dict->count(); } - bool isEmpty() const { return dict->count() == 0; } - type *toFirst() { return (type *)QGDictIterator::toFirst(); } - operator type *() const { return (type *)QGDictIterator::get(); } - type *current() const { return (type *)QGDictIterator::get(); } - long currentKey() const { return QGDictIterator::getKeyInt(); } - type *operator()() { return (type *)QGDictIterator::operator()(); } - type *operator++() { return (type *)QGDictIterator::operator++(); } - type *operator+=(uint j) { return (type *)QGDictIterator::operator+=(j);} -}; - - -#endif // QINTDICT_H diff --git a/qtools/qlist.doc b/qtools/qlist.doc deleted file mode 100644 index d28d662..0000000 --- a/qtools/qlist.doc +++ /dev/null @@ -1,1035 +0,0 @@ -/**************************************************************************** -** -** -** QList and QListIterator class documentation -** -** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. -** -** This file is part 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. -** -**********************************************************************/ - - -/***************************************************************************** - QList documentation - *****************************************************************************/ - -/*! - \class QList qlist.h - \brief The QList class is a template class that provides doubly linked lists. - - \ingroup collection - \ingroup tools - - In Qt 2.0 QList is only implemented as a template class. Define a - template instance QList\ to create a list that operates on pointers - to X, or X*. - - Example: - \code - #include - #include - #include - - class Employee - { - public: - Employee( const QString& name, int salary ) { n=name; s=salary; } - QString name() const { return n; } - int salary() const { return s; } - private: - QString n; - int s; - }; - - void main() - { - QList list; // list of pointers to Employee - list.setAutoDelete( TRUE ); // delete items when they are removed - - list.append( new Employee("Bill", 50000) ); - list.append( new Employee("Steve",80000) ); - list.append( new Employee("Ron", 60000) ); - - Employee *emp; - for ( emp=list.first(); emp != 0; emp=list.next() ) - printf( "%s earns %d\n", emp->name().latin1(), emp->salary() ); - } - \endcode - - Program output: - \code - Bill earns 50000 - Steve earns 80000 - Ron earns 60000 - \endcode - - The list class is indexable and has a \link at() current index\endlink - and a \link current() current item\endlink. The first item corresponds - to index 0. The current index is -1 if the current item is null. - - QList has several member functions for traversing the list, but using - a QListIterator can be more practical. Multiple list iterators may - traverse the same list, independent of each other and independent of - the current list item. - - In the example above, we make the call setAutoDelete(TRUE). - Enabling auto-deletion tells the list to delete items that are removed - from the list. The default is to not delete items when they are - removed, but that would cause a memory leak in our example since we have - no other references to the list items. - - List items are stored as \c void* in an internal QLNode, which also - holds pointers to the next and previous list items. The functions - currentNode(), removeNode() and takeNode() operate directly on the - QLNode, but they should be used with care. - - When inserting an item into a list, only the pointer is copied, not the - item itself. This is called a shallow copy. It is possible to make the - list copy all of the item's data (known as a deep copy) when an item is - inserted. insert(), inSort() and append() call the virtual function - QCollection::newItem() for the item to be inserted. - Inherit a list and reimplement it if you want deep copies. - - When removing an item from a list, the virtual function - QCollection::deleteItem() is called. QList's default implementation - is to delete the item if auto-deletion is enabled. - - The virtual function QGList::compareItems() can be reimplemented to - compare two list items. This function is called from all list functions - that need to compare list items, for instance remove(const type*). - If you only want to deal with pointers, there are functions that - compare pointers instead, for instance removeRef(const type*). - These functions are somewhat faster than those that call compareItems(). - - The QStrList class in qstrlist.h is a list of \c char*. QStrList is - a good example of a list that reimplements newItem(), deleteItem() and - compareItems() - - \sa QListIterator, \link collection.html Collection Classes\endlink -*/ - - -/*! - \fn QList::QList() - Constructs an empty list. -*/ - -/*! - \fn QList::QList( const QList &list ) - Constructs a copy of \e list. - - Each item in \e list is \link append() appended\endlink to this list. - Only the pointers are copied (shallow copy). -*/ - -/*! - \fn QList::~QList() - Removes all items from the list and destroys the list. - - All list iterators that access this list will be reset. - - \sa setAutoDelete() -*/ - -/*! - \fn QList &QList::operator=(const QList &list) - Assigns \e list to this list and returns a reference to this list. - - This list is first cleared, then each item in \e list is - \link append() appended\endlink to this list. Only the pointers are copied - (shallow copy), unless newItem() has been reimplemented(). -*/ - -/*! - \fn bool QList::operator==(const QList &list ) const - - Compares this list with \a list. Returns TRUE if the lists - contain the same data, else FALSE. -*/ - -/*! - \fn uint QList::count() const - Returns the number of items in the list. - \sa isEmpty() -*/ - -/*! - \fn void QList::sort() - - Sorts the list by the result of the virtual compareItems() function. - - The Heap-Sort algorithm is used for sorting. It sorts n items with - O(n*log n) compares. This is the asymptotic optimal solution of the - sorting problem. - - If the items in your list support operator< and operator== then you - might be better off with QSortedList since it implements the - compareItems() function for you using these two operators. - - \sa inSort() -*/ - -/*! - \fn bool QList::isEmpty() const - Returns TRUE if the list is empty, i.e. count() == 0. Returns FALSE - otherwise. - \sa count() -*/ - -/*! - \fn bool QList::insert( uint index, const type *item ) - Inserts the \e item at the position \e index in the list. - - Returns TRUE if successful, or FALSE if \e index is out of range. - The valid range is 0 .. count() inclusive. - The item is appended if \e index == count(). - - The inserted item becomes the current list item. - - The \e item must not be a null pointer. - - \sa append(), current() -*/ - -/*! - \fn void QList::inSort( const type *item ) - Inserts the \e item at its sorted position in the list. - - The sort order depends on the virtual QGList::compareItems() function. - All items must be inserted with inSort() to maintain the sorting order. - - The inserted item becomes the current list item. - - The \e item must not be a null pointer. - - Please note that inSort is slow. If you want to insert lots of items - in a list and sort after inserting then you should use sort(). - inSort() takes up to O(n) compares. That means inserting n items in - your list will need O(n^2) compares while sort() only needs O(n*logn) - for the same task. So you inSort() only if you already have a pre-sorted - list and want to insert only few additional items. - - \sa insert(), QGList::compareItems(), current(), sort() -*/ - -/*! - \fn void QList::append( const type *item ) - Inserts the \e item at the end of the list. - - The inserted item becomes the current list item. - This is equivalent to \c insert(count(),item). - - - The \e item must not be a null pointer. - - \sa insert(), current(), prepend() -*/ - -/*! - \fn void QList::prepend( const type *item ) - - Inserts the \e item at the start of the list. - - The inserted item becomes the current list item. - This is equivalent to \c insert(0,item). - - The \e item must not be a null pointer. - - \sa append(), insert(), current() -*/ - -/*! - \fn bool QList::remove( uint index ) - Removes the item at position \e index in the list. - - Returns TRUE if successful, or FALSE if \e index is out of range. - The valid range is 0 .. (count() - 1) inclusive. - - The removed item is deleted if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled. - - The item after the removed item becomes the new current list item if - the removed item is not the last item in the list. If the last item - is removed, the new last item becomes the current item in Qt 2.x. - In 3.0, the current item will be set to null. The current item is - set to null if the list becomes empty. - - All list iterators that refer to the removed item will be set to point - to the new current item. - - \sa take(), clear(), setAutoDelete(), current() removeRef() -*/ - -/*! - \fn bool QList::remove() - Removes the current list item. - - Returns TRUE if successful, or FALSE if the current item is null. - - The removed item is deleted if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled. - - The item after the removed item becomes the new current list item if - the removed item is not the last item in the list. If the last item - is removed, the new last item becomes the current item in Qt 2.x. - In 3.0, the current item will be set to null. The current item is - set to null if the list becomes empty. - - All list iterators that refer to the removed item will be set to point - to the new current item. - - \sa take(), clear(), setAutoDelete(), current() removeRef() -*/ - -/*! - \fn bool QList::remove( const type *item ) - Removes the first occurrence of \e item from the list. - - Returns TRUE if successful, or FALSE if the item could not be found in the - list. - - The removed item is deleted if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled. - - The compareItems() function is called when searching for the item - in the list. If compareItems() is not reimplemented, it is more - efficient to call removeRef(). - - The item after the removed item becomes the new current list item if - the removed item is not the last item in the list. If the last item - is removed, the new last item becomes the current item in Qt 2.x. - In 3.0, the current item will be set to null. The current item is - set to null if the list becomes empty. - - All list iterators that refer to the removed item will be set to point - to the new current item. - - \sa removeRef(), take(), clear(), setAutoDelete(), compareItems(), current() -*/ - -/*! - \fn bool QList::removeRef( const type *item ) - Removes the first occurrence of \e item from the list. - - Returns TRUE if successful, or FALSE if the item cannot be found in the - list. - - The removed item is deleted if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled. - - The list is scanned until the pointer \e item is found. It is removed - if it is found. - - Equivalent to: - \code - if ( list.findRef(item) != -1 ) - list.remove(); - \endcode - - The item after the removed item becomes the new current list item if - the removed item is not the last item in the list. If the last item - is removed, the new last item becomes the current item in Qt 2.x. - In 3.0, the current item will be set to null. The current item is - set to null if the list becomes empty. - - All list iterators that refer to the removed item will be set to point - to the new current item. - - \sa remove(), clear(), setAutoDelete(), current() -*/ - -/*! - \fn void QList::removeNode( QLNode *node ) - Removes the \e node from the list. - - This node must exist in the list, otherwise the program may crash. - - The removed item is deleted if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled. - - The first item in the list will become the new current list item. - The current item is set to null if the list becomes empty. - - All list iterators that refer to the removed item will be set to point to - the item succeeding this item, or the preceding item if the removed item - was the last item. - - \warning Do not call this function unless you are an expert. - - \sa takeNode(), currentNode() remove() removeRef() -*/ - -/*! - \fn bool QList::removeFirst() - Removes the first item from the list. - Returns TRUE if successful, or FALSE if the list is empty. - - The removed item is deleted if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled. - - The first item in the list becomes the new current list item. - The current item is set to null if the list becomes empty. - - All list iterators that refer to the removed item will be set to point - to the new current item. - - \sa removeLast(), setAutoDelete(), current() remove() -*/ - -/*! - \fn bool QList::removeLast() - Removes the last item from the list. - Returns TRUE if successful, or FALSE if the list is empty. - - The removed item is deleted if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled. - - The last item in the list becomes the new current list item. - The current item is set to null if the list becomes empty. - - All list iterators that refer to the removed item will be set to point - to the new current item. - - \sa removeFirst(), setAutoDelete(), current() -*/ - -/*! - \fn type *QList::take( uint index ) - Takes the item at position \e index out of the list without - deleting it (even if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled). - - Returns a pointer to the item taken out of the list, or null if - the index is out of range. - The valid range is 0 .. (count() - 1) inclusive. - - The item after the taken item becomes the new current list item if - the taken item is not the last item in the list. If the last item - is taken, the new last item becomes the current item in Qt 2.x. In - 3.0, the current item will be set to null. The current item is set - to null if the list becomes empty. - - All list iterators that refer to the taken item will be set to point to - the new current item. - - \sa remove(), clear(), current() -*/ - -/*! - \fn type *QList::take() - Takes the current item out of the list without deleting it (even if - \link QCollection::setAutoDelete() auto-deletion\endlink is enabled). - Returns a pointer to the item taken out of the list, or null if - the current item is null. - - The item after the taken item becomes the new current list item if - the taken item is not the last item in the list. If the last item - is taken, the new last item becomes the current item in Qt 2.x. In - 3.0, the current item will be set to null. The current item is set - to null if the list becomes empty. - - All list iterators that refer to the taken item will be set to point to - the new current item. - - \sa remove(), clear(), current() -*/ - -/*! - \fn type *QList::takeNode( QLNode *node ) - Takes the \e node out of the list without deleting its item (even if - \link QCollection::setAutoDelete() auto-deletion\endlink is enabled). - Returns a pointer to the item taken out of the list. - - This node must exist in the list, otherwise the program may crash. - - The first item in the list becomes the new current list item. - - All list iterators that refer to the taken item will be set to point to - the item succeeding this item, or the preceding item if the taken item - was the last item. - - \warning Do not call this function unless you are an expert. - - \sa removeNode(), currentNode() -*/ - -/*! - \fn void QList::clear() - Removes all items from the list. - - The removed items are deleted if \link QCollection::setAutoDelete() - auto-deletion\endlink is enabled. - - All list iterators that access this list will be reset. - - \sa remove(), take(), setAutoDelete() -*/ - -/*! - \fn int QList::find( const type *item ) - Finds the first occurrence of \e item in the list. - - If the item is found, the list sets the current item to point to - the found item and returns the index of this item. - If the item is not found, the list sets the current item to null, - the current index to -1 and returns -1. - - The compareItems() function is called when searching for the item - in the list. If compareItems() is not reimplemented, it is more - efficient to call findRef(). - - \sa findNext(), findRef(), compareItems(), current() -*/ - -/*! - \fn int QList::findNext( const type *item ) - Finds the next occurrence of \e item in the list, starting from - the current list item. - - If the item is found, the list sets the current item to point to - the found item and returns the index of this item. - If the item is not found, the list sets the current item to null, - the current index to -1 and returns -1. - - The compareItems() function is called when searching for the item - in the list. If compareItems() is not reimplemented, it is more - efficient to call findNextRef(). - - \sa find(), findNextRef(), compareItems(), current() -*/ - -/*! - \fn int QList::findRef( const type *item ) - Finds the first occurrence of \e item in the list. - - If the item is found, the list sets the current item to point to - the found item and returns the index of this item. - If the item is not found, the list sets the current item to null, - the current index to -1 and returns -1. - - Calling this function is must faster than find(), because find() - compares \e item with each list item using compareItems(). - This function only compares the pointers. - - \sa findNextRef(), find(), current() -*/ - -/*! - \fn int QList::findNextRef( const type *item ) - Finds the next occurrence of \e item in the list, starting from the - current list item. - - If the item is found, the list sets the current item to point to - the found item and returns the index of this item. - If the item is not found, the list sets the current item to null, - the current index to -1 and returns -1. - - Calling this function is must faster than findNext(), because findNext() - compares \e item with each list item using compareItems(). - This function only compares the pointers. - - \sa findRef(), findNext(), current() -*/ - -/*! - \fn uint QList::contains( const type *item ) const - Counts and returns the number of occurrences of \e item in the list. - - The compareItems() function is called when looking for the \e item - in the list. If compareItems() is not reimplemented, it is more - efficient to call containsRef(). - - Does not affect the current list item. - - \sa containsRef(), compareItems() -*/ - -/*! - \fn uint QList::containsRef( const type *item ) const - Counts and returns the number of occurrences of \e item in the list. - - Calling this function is must faster than contains(), because contains() - compares \e item with each list item using compareItems(). - This function only compares the pointers. - - Does not affect the current list item. - - \sa contains() -*/ - -/*! - \fn type *QList::at( uint index ) - Returns a pointer to the item at position \e index in the list, or - null if the index is out of range. - - Sets the current list item to this item if \e index is valid. - The valid range is 0 .. (count() - 1) inclusive. - - This function is very efficient. It starts scanning from the first - item, last item or current item, whichever is closest to \e index. - - \sa current() -*/ - -/*! - \fn int QList::at() const - Returns the index of the current list item. The returned value is -1 - if the current item is null. - \sa current() -*/ - -/*! - \fn type *QList::current() const - Returns a pointer to the current list item. The current item may be - null (implies that the current index is -1). - \sa at() -*/ - -/*! - \fn QLNode *QList::currentNode() const - Returns a pointer to the current list node. - - The node can be kept and removed later using removeNode(). - The advantage is that the item can be removed directly without - searching the list. - - \warning Do not call this function unless you are an expert. - - \sa removeNode(), takeNode(), current() -*/ - -/*! - \fn type *QList::getFirst() const - Returns a pointer to the first item in the list, or null if the - list is empty. - - Does not affect the current list item. - - \sa first(), getLast() -*/ - -/*! - \fn type *QList::getLast() const - Returns a pointer to the last item in the list, or null if the - list is empty. - - Does not affect the current list item. - - \sa last(), getFirst() -*/ - -/*! - \fn type *QList::first() - Returns a pointer to the first item in the list and makes this the - current list item, or null if the list is empty. - \sa getFirst(), last(), next(), prev(), current() -*/ - -/*! - \fn type *QList::last() - Returns a pointer to the last item in the list and makes this the - current list item, or null if the list is empty. - \sa getLast(), first(), next(), prev(), current() -*/ - -/*! - \fn type *QList::next() - Returns a pointer to the item succeeding the current item. - Returns null if the current item is null or equal to the last item. - - Makes the succeeding item current. If the current item before this - function call was the last item, the current item will be set to null. - If the current item was null, this function does nothing. - - \sa first(), last(), prev(), current() -*/ - -/*! - \fn type *QList::prev() - Returns a pointer to the item preceding the current item. - Returns null if the current item is null or equal to the first item. - - Makes the preceding item current. If the current item before this - function call was the first item, the current item will be set to null. - If the current item was null, this function does nothing. - - \sa first(), last(), next(), current() -*/ - -/***************************************************************************** - QListIterator documentation - *****************************************************************************/ - -/*! - \class QListIterator qlist.h - \brief The QListIterator class provides an iterator for QList collections. - - \ingroup collection - \ingroup tools - - Define a template instance QListIterator\ to create a list iterator - that operates on QList\ (list of X*). - - Example: - \code - #include - #include - #include - - class Employee - { - public: - Employee( const char *name, int salary ) { n=name; s=salary; } - const char *name() const { return n; } - int salary() const { return s; } - private: - QString n; - int s; - }; - - void main() - { - QList list; // list of pointers to Employee - list.setAutoDelete( TRUE ); // delete items when they are removed - - list.append( new Employee("Bill", 50000) ); - list.append( new Employee("Steve",80000) ); - list.append( new Employee("Ron", 60000) ); - - QListIterator it(list); // iterator for employee list - for ( ; it.current(); ++it ) { - Employee *emp = it.current(); - printf( "%s earns %d\n", emp->name().latin1(), emp->salary() ); - } - } - \endcode - - Program output: - \code - Bill earns 50000 - Steve earns 80000 - Ron earns 60000 - \endcode - - Although QList has member functions to traverse the doubly linked list - structure, using a list iterator is a much more robust way of traversing - the list, because multiple list iterators can operate on the same list, - independent of each other and independent of the QList's current item. - An iterator has its own current list item and can get the next and - previous list items. It can only traverse the list, never modify it. - - A QList knows about all list iterators that are operating on the list. - When an item is removed from the list, the list update all iterators - that are pointing the removed item to point to the new current list item. - - Example: - \code - #include - #include - #include - - class Employee - { - ... // same as above - }; - - void main() - { - QList list; // list of pointers to Employee - list.setAutoDelete( TRUE ); // delete items when they are removed - - list.append( new Employee("Bill", 50000) ); - list.append( new Employee("Steve",80000) ); - list.append( new Employee("Ron", 60000) ); - - QListIterator it(list); - - list.at( 1 ); // current list item: "Steve" - it.toLast(); // it: "Ron" - --it; // it: "Steve" - - // Now, both the list and the iterator are referring the same item - - list.remove(); - printf( "%s\n", it.current()->name().latin1() ); - } - \endcode - - Program output: - \code - Ron - \endcode - - \sa QList, \link collection.html collection classes\endlink -*/ - -/*! - \fn QListIterator::QListIterator( const QList &list ) - Constructs an iterator for \e list. The current iterator item is - set to point on the first item in the \e list. -*/ - -/*! - \fn QListIterator::~QListIterator() - Destroys the iterator. -*/ - -/*! - \fn uint QListIterator::count() const - Returns the number of items in the list this iterator operates on. - \sa isEmpty() -*/ - -/*! - \fn bool QListIterator::isEmpty() const - Returns TRUE if the list is empty, i.e. count() == 0, otherwise FALSE. - \sa count() -*/ - -/*! - \fn bool QListIterator::atFirst() const - Returns TRUE if the current iterator item is the first list item, otherwise - FALSE. - \sa toFirst(), atLast() -*/ - -/*! - \fn bool QListIterator::atLast() const - Returns TRUE if the current iterator item is the last list item, otherwise - FALSE. - \sa toLast(), atFirst() -*/ - -/*! - \fn type *QListIterator::toFirst() - Sets the current iterator item to point to the first list item and returns - a pointer to the item. Sets the current item to null and returns null - if the list is empty. - \sa toLast(), atFirst() -*/ - -/*! - \fn type *QListIterator::toLast() - Sets the current iterator item to point to the last list item and returns - a pointer to the item. Sets the current item to null and returns null - if the list is empty. - \sa toFirst(), atLast() -*/ - -/*! - \fn QListIterator::operator type *() const - Cast operator. Returns a pointer to the current iterator item. - Same as current(). -*/ - -/*! - \fn type *QListIterator::operator*() - Asterisk operator. Returns a pointer to the current iterator item. - Same as current(). -*/ - -/*! - \fn type *QListIterator::current() const - Returns a pointer to the current iterator item. -*/ - -/*! - \fn type *QListIterator::operator()() - Makes the succeeding item current and returns the original current item. - - If the current iterator item was the last item in the list or if it was - null, null is returned. -*/ - -/*! - \fn char *QStrListIterator::operator()() - Makes the succeeding item current and returns the original current item. - - If the current iterator item was the last item in the list or if it was - null, null is returned. -*/ - -/*! - \fn type *QListIterator::operator++() - Prefix ++ makes the succeeding item current and returns the new current - item. - - If the current iterator item was the last item in the list or if it was - null, null is returned. -*/ - -/*! - \fn type *QListIterator::operator+=( uint jump ) - Sets the current item to the item \e jump positions after the current item, - and returns a pointer to that item. - - If that item is beyond the last item or if the dictionary is empty, - it sets the current item to null and returns null -*/ - -/*! - \fn type *QListIterator::operator--() - Prefix -- makes the preceding item current and returns the new current - item. - - If the current iterator item was the first item in the list or if it was - null, null is returned. -*/ - -/*! - \fn type *QListIterator::operator-=( uint jump ) - Returns the item \e jump positions before the current item, or null if - it is beyond the first item. Makes this the current item. -*/ - -/*! - \fn QListIterator& QListIterator::operator=( const QListIterator &it ) - Assignment. Makes a copy of the iterator \a it and returns a reference - to this iterator. -*/ - - -/***************************************************************************** - QStrList documentation - *****************************************************************************/ - -//typedef QList QStrList - -/*! - \class QStrList qstrlist.h - \brief The QStrList class provides a doubly linked list of \c char*. - - \ingroup collection - \ingroup tools - - This class is a QList\ instance (a list of char*). - - QStrList can make deep or shallow copies of the strings that are inserted. - - A deep copy means to allocate space for the string and then copy the string - data into it. A shallow copy is just a copy of the pointer value and not - the string data. - - The disadvantage with shallow copies is that since a pointer can only - be deleted once, the program must put all strings in a central place and - know when it is safe to delete them (i.e. when the strings are no longer - referenced by other parts of the program). This can make the program - more complex. The advantage of shallow copies is that shallow copies - consume far less memory than deep copies. It is also much faster - to copy a pointer (typically 4 or 8 bytes) than to copy string data. - - A QStrList that operates on deep copies will by default turn on - auto-deletion (see setAutoDelete()). Thus, by default, QStrList will - deallocate any string copies it allocates. - - The virtual compareItems() function is reimplemented and does a case - sensitive string comparison. The inSort() function will insert - strings in a sorted order. - - The QStrListIterator class is an iterator for QStrList. -*/ - -/*! - \fn QStrList::QStrList( bool deepCopies ) - Constructs an empty list of strings. Will make deep copies of all inserted - strings if \e deepCopies is TRUE, or uses shallow copies if \e deepCopies - is FALSE. -*/ - -/*! - \fn QStrList::QStrList( const QStrList &list ) - Constructs a copy of \e list. - - If \e list has deep copies, this list will also get deep copies. - Only the pointers are copied (shallow copy) if the other list does not - use deep copies. -*/ - -/*! - \fn QStrList::~QStrList() - Destroys the list. All strings are removed. -*/ - -/*! - \fn QStrList& QStrList::operator=( const QStrList& list ) - Assigns \e list to this list and returns a reference to this list. - - If \e list has deep copies, this list will also get deep copies. - Only the pointers are copied (shallow copy) if the other list does not - use deep copies. -*/ - - -/***************************************************************************** - QStrIList documentation - *****************************************************************************/ - -/*! - \class QStrIList qstrlist.h - \brief The QStrIList class provides a doubly linked list of \c char* with -case insensitive compare. - - \ingroup collection - \ingroup tools - - This class is a QList\ instance (a list of char*). - - QStrIList is similar to QStrList except that it is case insensitive. - The virtual compareItems() function is reimplemented and does a - case insensitive string comparison. - The inSort() function will insert strings in a sorted order. - - The QStrListIterator class is an iterator for QStrList. -*/ - -/*! - \fn QStrIList::QStrIList( bool deepCopies ) - Constructs a list of strings. Will make deep copies of all inserted - strings if \e deepCopies is TRUE, or uses shallow copies if \e deepCopies - is FALSE. -*/ - -/*! - \fn QStrIList::~QStrIList() - Destroys the list. All strings are removed. -*/ - - -/***************************************************************************** - QStrListIterator documentation - *****************************************************************************/ - -/*! - \class QStrListIterator qstrlist.h - \brief The QStrListIterator class is an iterator for the QStrList and QStrIList classes. - - \ingroup tools - - This class is a QListIterator\ instance. - It can traverse the strings in the QStrList and QStrIList classes. -*/ diff --git a/qtools/qlist.h b/qtools/qlist.h deleted file mode 100644 index eaaa674..0000000 --- a/qtools/qlist.h +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** -** -** -** 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. -** -**********************************************************************/ - -/* 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 - -#ifndef QT_H -#include "qglist.h" -#endif // QT_H - - -template class Q_EXPORT QList : private QGList -{ -public: - QList() {} - QList( const QList &l ) : QGList(l) {} - ~QList() { clear(); } - QList &operator=(const QList &l) - { return (QList&)QGList::operator=(l); } - bool operator==( const QList &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( const type *d ) { return QGList::remove((QCollection::Item)d); } - bool removeRef( const type *d ) { return QGList::removeRef((QCollection::Item)d); } - bool removeFirst() { return QGList::removeFirst(); } - bool removeLast() { return QGList::removeLast(); } - type *take( uint i ) { return (type *)QGList::takeAt(i); } - void clear() { QGList::clear(); } - - // operations - void sort() { QGList::sort(); } - - // search - int find( const type *d ) const { return const_cast*>(this)->QGList::find((QCollection::Item)d); } - int findRef( const type *d ) const { return const_cast*>(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); } - - // element access - type *at( uint i ) const { return (type *)const_cast*>(this)->QGList::at(i); } - type *getFirst() const { return (type *)QGList::cfirst(); } - type *getLast() const { return (type *)QGList::clast(); } - - // ownership - void setAutoDelete( bool enable ) { QGList::setAutoDelete(enable); } - bool autoDelete() const { return QGList::autoDelete(); } - -private: - // new to be reimplemented methods - virtual int compareValues(const type *t1,const type *t2) const - { return const_cast*>(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::deleteValue(void *) const -{ -} -#endif - - -template class Q_EXPORT QListIterator : public QGListIterator -{ -public: - QListIterator(const QList &l) :QGListIterator((QGList &)l) {} - ~QListIterator() {} - 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 (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);} - QListIterator& operator=(const QListIterator&it) - { QGListIterator::operator=(it); return *this; } -}; - - -#endif // QLIST_H diff --git a/qtools/qmap.cpp b/qtools/qmap.cpp index 1d2510a..bb69bf0 100644 --- a/qtools/qmap.cpp +++ b/qtools/qmap.cpp @@ -1,5 +1,5 @@ /**************************************************************************** -** +** ** ** Implementation of QMap ** @@ -35,7 +35,7 @@ ** **********************************************************************/ -#include "qmap.h" +#include "qmap_p.h" typedef QMapNodeBase* NodePtr; typedef QMapNodeBase Node; @@ -105,7 +105,7 @@ void QMapPrivateBase::rebalance( NodePtr x, NodePtr& root) x->parent->parent->color = Node::Red; x = x->parent->parent; } else { - if (x == x->parent->left) { + if (x == x->parent->left) { x = x->parent; rotateRight( x, root ); } @@ -140,7 +140,7 @@ NodePtr QMapPrivateBase::removeAndRebalance( NodePtr z, NodePtr& root, } } if (y != z) { - z->left->parent = y; + z->left->parent = y; y->left = z->left; if (y != z->right) { x_parent = y->parent; @@ -150,13 +150,13 @@ NodePtr QMapPrivateBase::removeAndRebalance( NodePtr z, NodePtr& root, y->right = z->right; z->right->parent = y; } else { - x_parent = y; + x_parent = y; } if (root == z) root = y; else if (z->parent->left == z) z->parent->left = y; - else + else z->parent->right = y; y->parent = z->parent; // Swap the colors @@ -164,10 +164,10 @@ NodePtr QMapPrivateBase::removeAndRebalance( NodePtr z, NodePtr& root, y->color = z->color; z->color = c; y = z; - } else { + } else { x_parent = y->parent; if (x) - x->parent = y->parent; + x->parent = y->parent; if (root == z) root = x; else if (z->parent->left == z) @@ -182,12 +182,12 @@ NodePtr QMapPrivateBase::removeAndRebalance( NodePtr z, NodePtr& root, } if (rightmost == z) { if (z->left == 0) - rightmost = z->parent; + rightmost = z->parent; else rightmost = x->maximum(); } } - if (y->color != Node::Red) { + if (y->color != Node::Red) { while (x != root && (x == 0 || x->color == Node::Black)) { if (x == x_parent->left) { NodePtr w = x_parent->right; @@ -232,7 +232,7 @@ NodePtr QMapPrivateBase::removeAndRebalance( NodePtr z, NodePtr& root, x_parent = x_parent->parent; } else { if (w->left == 0 || w->left->color == Node::Black) { - if (w->right) + if (w->right) w->right->color = Node::Black; w->color = Node::Red; rotateLeft(w, root); diff --git a/qtools/qmap.h b/qtools/qmap.h deleted file mode 100644 index 0031e0d..0000000 --- a/qtools/qmap.h +++ /dev/null @@ -1,607 +0,0 @@ -/**************************************************************************** -** -** -** Definition of QMap class -** -** Created : 990406 -** -** 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 QMAP_H -#define QMAP_H - -#ifndef QT_H -#include "qshared.h" -#include "qdatastream.h" -#endif // QT_H - - -struct QMapNodeBase -{ - enum Color { Red, Black }; - - QMapNodeBase* left; - QMapNodeBase* right; - QMapNodeBase* parent; - - Color color; - - QMapNodeBase* minimum() { - QMapNodeBase* x = this; - while ( x->left ) - x = x->left; - return x; - } - - QMapNodeBase* maximum() { - QMapNodeBase* x = this; - while ( x->right ) - x = x->right; - return x; - } -}; - - -template -struct QMapNode : public QMapNodeBase -{ - QMapNode( const K& _key, const T& _data ) { data = _data; key = _key; } - QMapNode( const K& _key ) { key = _key; } - QMapNode( const QMapNode& _n ) { key = _n.key; data = _n.data; } - QMapNode() { } - T data; - K key; -}; - - -template -class Q_EXPORT QMapIterator -{ - public: - /** - * Typedefs - */ - typedef QMapNode< K, T >* NodePtr; - - /** - * Variables - */ - QMapNode* node; - - /** - * Functions - */ - QMapIterator() : node( 0 ) {} - QMapIterator( QMapNode* p ) : node( p ) {} - QMapIterator( const QMapIterator& it ) : node( it.node ) {} - QMapIterator &operator=(const QMapIterator &it) = default; - - bool operator==( const QMapIterator& it ) const { return node == it.node; } - bool operator!=( const QMapIterator& it ) const { return node != it.node; } - T& operator*() { return node->data; } - const T& operator*() const { return node->data; } - - // Cannot have this - some compilers are too stupid - //T* operator->() const { return &(node->data); } - - const K& key() const { return node->key; } - T& data() { return node->data; } - const T& data() const { return node->data; } - -private: - int inc() { - QMapNodeBase* tmp = node; - if ( tmp->right ) { - tmp = tmp->right; - while ( tmp->left ) - tmp = tmp->left; - } else { - QMapNodeBase* y = tmp->parent; - while (tmp == y->right) { - tmp = y; - y = y->parent; - } - if (tmp->right != y) - tmp = y; - } - node = (NodePtr)tmp; - return 0; - } - - int dec() { - QMapNodeBase* tmp = node; - if (tmp->color == QMapNodeBase::Red && - tmp->parent->parent == tmp ) { - tmp = tmp->right; - } else if (tmp->left != 0) { - QMapNodeBase* y = tmp->left; - while ( y->right ) - y = y->right; - tmp = y; - } else { - QMapNodeBase* y = tmp->parent; - while (tmp == y->left) { - tmp = y; - y = y->parent; - } - tmp = y; - } - node = (NodePtr)tmp; - return 0; - } - -public: - QMapIterator& operator++() { - inc(); - return *this; - } - - QMapIterator operator++(int) { - QMapIterator tmp = *this; - inc(); - return tmp; - } - - QMapIterator& operator--() { - dec(); - return *this; - } - - QMapIterator operator--(int) { - QMapIterator tmp = *this; - dec(); - return tmp; - } -}; - -template -class Q_EXPORT QMapConstIterator -{ - public: - /** - * Typedefs - */ - typedef QMapNode< K, T >* NodePtr; - - /** - * Variables - */ - QMapNode* node; - - /** - * Functions - */ - QMapConstIterator() : node( 0 ) {} - QMapConstIterator( QMapNode* p ) : node( p ) {} - QMapConstIterator( const QMapConstIterator& it ) : node( it.node ) {} - QMapConstIterator( const QMapIterator& it ) : node( it.node ) {} - - bool operator==( const QMapConstIterator& it ) const { return node == it.node; } - bool operator!=( const QMapConstIterator& it ) const { return node != it.node; } - const T& operator*() const { return node->data; } - - // Cannot have this - some compilers are too stupid - //const T* operator->() const { return &(node->data); } - - const K& key() const { return node->key; } - const T& data() const { return node->data; } - -private: - int inc() { - QMapNodeBase* tmp = node; - if ( tmp->right ) { - tmp = tmp->right; - while ( tmp->left ) - tmp = tmp->left; - } else { - QMapNodeBase* y = tmp->parent; - while (tmp == y->right) { - tmp = y; - y = y->parent; - } - if (tmp->right != y) - tmp = y; - } - node = (NodePtr)tmp; - return 0; - } - - int dec() { - QMapNodeBase* tmp = node; - if (tmp->color == QMapNodeBase::Red && - tmp->parent->parent == tmp ) { - tmp = tmp->right; - } else if (tmp->left != 0) { - QMapNodeBase* y = tmp->left; - while ( y->right ) - y = y->right; - tmp = y; - } else { - QMapNodeBase* y = tmp->parent; - while (tmp == y->left) { - tmp = y; - y = y->parent; - } - tmp = y; - } - node = (NodePtr)tmp; - return 0; - } - -public: - QMapConstIterator& operator++() { - inc(); - return *this; - } - - QMapConstIterator operator++(int) { - QMapConstIterator tmp = *this; - inc(); - return tmp; - } - - QMapConstIterator& operator--() { - dec(); - return *this; - } - - QMapConstIterator operator--(int) { - QMapConstIterator tmp = *this; - dec(); - return tmp; - } -}; - - -class Q_EXPORT QMapPrivateBase : public QShared -{ -public: - QMapPrivateBase() { - node_count = 0; - } - QMapPrivateBase( const QMapPrivateBase* _map) { - node_count = _map->node_count; - } - - /** - * Implementations of basic tree algorithms - */ - void rotateLeft( QMapNodeBase* x, QMapNodeBase*& root); - void rotateRight( QMapNodeBase* x, QMapNodeBase*& root ); - void rebalance( QMapNodeBase* x, QMapNodeBase*& root ); - QMapNodeBase* removeAndRebalance( QMapNodeBase* z, QMapNodeBase*& root, - QMapNodeBase*& leftmost, - QMapNodeBase*& rightmost ); - - /** - * Variables - */ - int node_count; -}; - - -template -class QMapPrivate : public QMapPrivateBase -{ -public: - /** - * Typedefs - */ - typedef QMapIterator< Key, T > Iterator; - typedef QMapConstIterator< Key, T > ConstIterator; - typedef QMapNode< Key, T > Node; - typedef QMapNode< Key, T >* NodePtr; - - /** - * Functions - */ - QMapPrivate() { - header = new Node; - header->color = QMapNodeBase::Red; // Mark the header - header->parent = 0; - header->left = header->right = header; - } - QMapPrivate( const QMapPrivate< Key, T >* _map ) : QMapPrivateBase( _map ) { - header = new Node; - header->color = QMapNodeBase::Red; // Mark the header - if ( _map->header->parent == 0 ) { - header->parent = 0; - header->left = header->right = header; - } else { - header->parent = copy( (NodePtr)(_map->header->parent) ); - header->parent->parent = header; - header->left = header->parent->minimum(); - header->right = header->parent->maximum(); - } - } - ~QMapPrivate() { clear(); delete header; } - - NodePtr copy( NodePtr p ) { - if ( !p ) - return 0; - NodePtr n = new Node( *p ); - n->color = p->color; - if ( p->left ) { - n->left = copy( (NodePtr)(p->left) ); - n->left->parent = n; - } else { - n->left = 0; - } - if ( p->right ) { - n->right = copy( (NodePtr)(p->right) ); - n->right->parent = n; - } else { - n->right = 0; - } - return n; - } - - void clear() { - clear( (NodePtr)(header->parent) ); - header->color = QMapNodeBase::Red; - header->parent = 0; - header->left = header->right = header; - node_count = 0; - } - - void clear( NodePtr p ) { - while ( p != 0 ) { - clear( (NodePtr)p->right ); - NodePtr y = (NodePtr)p->left; - delete p; - p = y; - } - } - - Iterator begin() { return Iterator( (NodePtr)(header->left ) ); } - Iterator end() { return Iterator( header ); } - ConstIterator begin() const { return ConstIterator( (NodePtr)(header->left ) ); } - ConstIterator end() const { return ConstIterator( header ); } - - ConstIterator find(const Key& k) const { - QMapNodeBase* y = header; // Last node - QMapNodeBase* x = header->parent; // Root node. - - while ( x != 0 ) { - // If as k <= key(x) go left - if ( !( key(x) < k ) ) { - y = x; - x = x->left; - } else { - x = x->right; - } - } - - // Was k bigger/smaller then the biggest/smallest - // element of the tree ? Return end() - if ( y == header || k < key(y) ) - return ConstIterator( header ); - return ConstIterator( (NodePtr)y ); - } - - void remove( Iterator it ) { - NodePtr del = (NodePtr) removeAndRebalance( it.node, header->parent, header->left, header->right ); - delete del; - --node_count; - } - -#ifdef QT_QMAP_DEBUG - void inorder( QMapNodeBase* x = 0, int level = 0 ){ - if ( !x ) - x = header->parent; - if ( x->left ) - inorder( x->left, level + 1 ); - //cout << level << " Key=" << key(x) << " Value=" << ((NodePtr)x)->data << endl; - if ( x->right ) - inorder( x->right, level + 1 ); - } -#endif - - Iterator insertMulti(const Key& v){ - QMapNodeBase* y = header; - QMapNodeBase* x = header->parent; - while (x != 0){ - y = x; - x = ( v < key(x) ) ? x->left : x->right; - } - return insert(x, y, v); - } - - Iterator insertSingle( const Key& k ) { - // Search correct position in the tree - QMapNodeBase* y = header; - QMapNodeBase* x = header->parent; - bool result = TRUE; - while ( x != 0 ) { - result = ( k < key(x) ); - y = x; - x = result ? x->left : x->right; - } - // Get iterator on the last not empty one - Iterator j( (NodePtr)y ); - if ( result ) { - // Smaller then the leftmost one ? - if ( j == begin() ) { - return insert(x, y, k ); - } else { - // Perhaps daddy is the right one ? - --j; - } - } - // Really bigger ? - if ( (j.node->key) < k ) - return insert(x, y, k ); - // We are going to replace a node - return j; - } - - Iterator insert( QMapNodeBase* x, QMapNodeBase* y, const Key& k ) { - NodePtr z = new Node( k ); - if (y == header || x != 0 || k < key(y) ) { - y->left = z; // also makes leftmost = z when y == header - if ( y == header ) { - header->parent = z; - header->right = z; - } else if ( y == header->left ) - header->left = z; // maintain leftmost pointing to min node - } else { - y->right = z; - if ( y == header->right ) - header->right = z; // maintain rightmost pointing to max node - } - z->parent = y; - z->left = 0; - z->right = 0; - rebalance( z, header->parent ); - ++node_count; - return Iterator(z); - } - -protected: - /** - * Helpers - */ - const Key& key( QMapNodeBase* b ) const { return ((NodePtr)b)->key; } - - /** - * Variables - */ - NodePtr header; -}; - - -template -class Q_EXPORT QMap -{ -public: - /** - * Typedefs - */ - typedef QMapIterator< Key, T > Iterator; - typedef QMapConstIterator< Key, T > ConstIterator; - typedef T ValueType; - typedef QMapPrivate< Key, T > Priv; - - /** - * API - */ - QMap() { sh = new QMapPrivate< Key, T >; } - QMap( const QMap& m ) { sh = m.sh; sh->ref(); } - ~QMap() { if ( sh->deref() ) delete sh; } - - QMap& operator= ( const QMap& m ) - { m.sh->ref(); if ( sh->deref() ) delete sh; sh = m.sh; return *this; } - - Iterator begin() { detach(); return sh->begin(); } - Iterator end() { detach(); return sh->end(); } - ConstIterator begin() const { return ((const Priv*)sh)->begin(); } - ConstIterator end() const { return ((const Priv*)sh)->end(); } - - Iterator find ( const Key& k ) - { detach(); return Iterator( sh->find( k ).node ); } - ConstIterator find ( const Key& k ) const - { return sh->find( k ); } - T& operator[] ( const Key& k ) { - detach(); QMapNode* p = sh->find( k ).node; - if ( p != sh->end().node ) return p->data; - return insert( k, T() ).data(); } - const T& operator[] ( const Key& k ) const - { return sh->find( k ).data(); } - bool contains ( const Key& k ) const - { return find( k ) != end(); } - //{ return sh->find( k ) != ((const Priv*)sh)->end(); } - - uint count() const { return sh->node_count; } - - bool isEmpty() const { return sh->node_count == 0; } - - Iterator insert( const Key& key, const T& value ) { - detach(); - Iterator it = sh->insertSingle( key ); - it.data() = value; - return it; - } - - void remove( Iterator it ) { detach(); sh->remove( it ); } - void remove( const Key& k ) { - detach(); - Iterator it( sh->find( k ).node ); - if ( it != end() ) - sh->remove( it ); - } - - Iterator replace( const Key& k, const T& v ) { - remove( k ); - return insert( k, v ); - } - - void clear() { if ( sh->count == 1 ) sh->clear(); else { sh->deref(); sh = new QMapPrivate; } } - -#if defined(Q_FULL_TEMPLATE_INSTANTIATION) - bool operator==( const QMap& ) const { return FALSE; } -#endif - -protected: - /** - * Helpers - */ - void detach() { if ( sh->count > 1 ) { sh->deref(); sh = new QMapPrivate( sh ); } } - - Priv* sh; -}; - - -#ifndef QT_NO_DATASTREAM -template -inline QDataStream& operator>>( QDataStream& s, QMap& m ) { - m.clear(); - Q_UINT32 c; - s >> c; - for( Q_UINT32 i = 0; i < c; ++i ) { - Key k; T t; - s >> k >> t; - m.insert( k, t ); - } - return s; -} - - -template -inline QDataStream& operator<<( QDataStream& s, const QMap& m ) { - s << (Q_UINT32)m.count(); - QMapConstIterator it = m.begin(); - for( ; it != m.end(); ++it ) - s << it.key() << it.data(); - return s; -} -#endif - -#endif // QMAP_H diff --git a/qtools/qmap_p.h b/qtools/qmap_p.h new file mode 100644 index 0000000..0031e0d --- /dev/null +++ b/qtools/qmap_p.h @@ -0,0 +1,607 @@ +/**************************************************************************** +** +** +** Definition of QMap class +** +** Created : 990406 +** +** 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 QMAP_H +#define QMAP_H + +#ifndef QT_H +#include "qshared.h" +#include "qdatastream.h" +#endif // QT_H + + +struct QMapNodeBase +{ + enum Color { Red, Black }; + + QMapNodeBase* left; + QMapNodeBase* right; + QMapNodeBase* parent; + + Color color; + + QMapNodeBase* minimum() { + QMapNodeBase* x = this; + while ( x->left ) + x = x->left; + return x; + } + + QMapNodeBase* maximum() { + QMapNodeBase* x = this; + while ( x->right ) + x = x->right; + return x; + } +}; + + +template +struct QMapNode : public QMapNodeBase +{ + QMapNode( const K& _key, const T& _data ) { data = _data; key = _key; } + QMapNode( const K& _key ) { key = _key; } + QMapNode( const QMapNode& _n ) { key = _n.key; data = _n.data; } + QMapNode() { } + T data; + K key; +}; + + +template +class Q_EXPORT QMapIterator +{ + public: + /** + * Typedefs + */ + typedef QMapNode< K, T >* NodePtr; + + /** + * Variables + */ + QMapNode* node; + + /** + * Functions + */ + QMapIterator() : node( 0 ) {} + QMapIterator( QMapNode* p ) : node( p ) {} + QMapIterator( const QMapIterator& it ) : node( it.node ) {} + QMapIterator &operator=(const QMapIterator &it) = default; + + bool operator==( const QMapIterator& it ) const { return node == it.node; } + bool operator!=( const QMapIterator& it ) const { return node != it.node; } + T& operator*() { return node->data; } + const T& operator*() const { return node->data; } + + // Cannot have this - some compilers are too stupid + //T* operator->() const { return &(node->data); } + + const K& key() const { return node->key; } + T& data() { return node->data; } + const T& data() const { return node->data; } + +private: + int inc() { + QMapNodeBase* tmp = node; + if ( tmp->right ) { + tmp = tmp->right; + while ( tmp->left ) + tmp = tmp->left; + } else { + QMapNodeBase* y = tmp->parent; + while (tmp == y->right) { + tmp = y; + y = y->parent; + } + if (tmp->right != y) + tmp = y; + } + node = (NodePtr)tmp; + return 0; + } + + int dec() { + QMapNodeBase* tmp = node; + if (tmp->color == QMapNodeBase::Red && + tmp->parent->parent == tmp ) { + tmp = tmp->right; + } else if (tmp->left != 0) { + QMapNodeBase* y = tmp->left; + while ( y->right ) + y = y->right; + tmp = y; + } else { + QMapNodeBase* y = tmp->parent; + while (tmp == y->left) { + tmp = y; + y = y->parent; + } + tmp = y; + } + node = (NodePtr)tmp; + return 0; + } + +public: + QMapIterator& operator++() { + inc(); + return *this; + } + + QMapIterator operator++(int) { + QMapIterator tmp = *this; + inc(); + return tmp; + } + + QMapIterator& operator--() { + dec(); + return *this; + } + + QMapIterator operator--(int) { + QMapIterator tmp = *this; + dec(); + return tmp; + } +}; + +template +class Q_EXPORT QMapConstIterator +{ + public: + /** + * Typedefs + */ + typedef QMapNode< K, T >* NodePtr; + + /** + * Variables + */ + QMapNode* node; + + /** + * Functions + */ + QMapConstIterator() : node( 0 ) {} + QMapConstIterator( QMapNode* p ) : node( p ) {} + QMapConstIterator( const QMapConstIterator& it ) : node( it.node ) {} + QMapConstIterator( const QMapIterator& it ) : node( it.node ) {} + + bool operator==( const QMapConstIterator& it ) const { return node == it.node; } + bool operator!=( const QMapConstIterator& it ) const { return node != it.node; } + const T& operator*() const { return node->data; } + + // Cannot have this - some compilers are too stupid + //const T* operator->() const { return &(node->data); } + + const K& key() const { return node->key; } + const T& data() const { return node->data; } + +private: + int inc() { + QMapNodeBase* tmp = node; + if ( tmp->right ) { + tmp = tmp->right; + while ( tmp->left ) + tmp = tmp->left; + } else { + QMapNodeBase* y = tmp->parent; + while (tmp == y->right) { + tmp = y; + y = y->parent; + } + if (tmp->right != y) + tmp = y; + } + node = (NodePtr)tmp; + return 0; + } + + int dec() { + QMapNodeBase* tmp = node; + if (tmp->color == QMapNodeBase::Red && + tmp->parent->parent == tmp ) { + tmp = tmp->right; + } else if (tmp->left != 0) { + QMapNodeBase* y = tmp->left; + while ( y->right ) + y = y->right; + tmp = y; + } else { + QMapNodeBase* y = tmp->parent; + while (tmp == y->left) { + tmp = y; + y = y->parent; + } + tmp = y; + } + node = (NodePtr)tmp; + return 0; + } + +public: + QMapConstIterator& operator++() { + inc(); + return *this; + } + + QMapConstIterator operator++(int) { + QMapConstIterator tmp = *this; + inc(); + return tmp; + } + + QMapConstIterator& operator--() { + dec(); + return *this; + } + + QMapConstIterator operator--(int) { + QMapConstIterator tmp = *this; + dec(); + return tmp; + } +}; + + +class Q_EXPORT QMapPrivateBase : public QShared +{ +public: + QMapPrivateBase() { + node_count = 0; + } + QMapPrivateBase( const QMapPrivateBase* _map) { + node_count = _map->node_count; + } + + /** + * Implementations of basic tree algorithms + */ + void rotateLeft( QMapNodeBase* x, QMapNodeBase*& root); + void rotateRight( QMapNodeBase* x, QMapNodeBase*& root ); + void rebalance( QMapNodeBase* x, QMapNodeBase*& root ); + QMapNodeBase* removeAndRebalance( QMapNodeBase* z, QMapNodeBase*& root, + QMapNodeBase*& leftmost, + QMapNodeBase*& rightmost ); + + /** + * Variables + */ + int node_count; +}; + + +template +class QMapPrivate : public QMapPrivateBase +{ +public: + /** + * Typedefs + */ + typedef QMapIterator< Key, T > Iterator; + typedef QMapConstIterator< Key, T > ConstIterator; + typedef QMapNode< Key, T > Node; + typedef QMapNode< Key, T >* NodePtr; + + /** + * Functions + */ + QMapPrivate() { + header = new Node; + header->color = QMapNodeBase::Red; // Mark the header + header->parent = 0; + header->left = header->right = header; + } + QMapPrivate( const QMapPrivate< Key, T >* _map ) : QMapPrivateBase( _map ) { + header = new Node; + header->color = QMapNodeBase::Red; // Mark the header + if ( _map->header->parent == 0 ) { + header->parent = 0; + header->left = header->right = header; + } else { + header->parent = copy( (NodePtr)(_map->header->parent) ); + header->parent->parent = header; + header->left = header->parent->minimum(); + header->right = header->parent->maximum(); + } + } + ~QMapPrivate() { clear(); delete header; } + + NodePtr copy( NodePtr p ) { + if ( !p ) + return 0; + NodePtr n = new Node( *p ); + n->color = p->color; + if ( p->left ) { + n->left = copy( (NodePtr)(p->left) ); + n->left->parent = n; + } else { + n->left = 0; + } + if ( p->right ) { + n->right = copy( (NodePtr)(p->right) ); + n->right->parent = n; + } else { + n->right = 0; + } + return n; + } + + void clear() { + clear( (NodePtr)(header->parent) ); + header->color = QMapNodeBase::Red; + header->parent = 0; + header->left = header->right = header; + node_count = 0; + } + + void clear( NodePtr p ) { + while ( p != 0 ) { + clear( (NodePtr)p->right ); + NodePtr y = (NodePtr)p->left; + delete p; + p = y; + } + } + + Iterator begin() { return Iterator( (NodePtr)(header->left ) ); } + Iterator end() { return Iterator( header ); } + ConstIterator begin() const { return ConstIterator( (NodePtr)(header->left ) ); } + ConstIterator end() const { return ConstIterator( header ); } + + ConstIterator find(const Key& k) const { + QMapNodeBase* y = header; // Last node + QMapNodeBase* x = header->parent; // Root node. + + while ( x != 0 ) { + // If as k <= key(x) go left + if ( !( key(x) < k ) ) { + y = x; + x = x->left; + } else { + x = x->right; + } + } + + // Was k bigger/smaller then the biggest/smallest + // element of the tree ? Return end() + if ( y == header || k < key(y) ) + return ConstIterator( header ); + return ConstIterator( (NodePtr)y ); + } + + void remove( Iterator it ) { + NodePtr del = (NodePtr) removeAndRebalance( it.node, header->parent, header->left, header->right ); + delete del; + --node_count; + } + +#ifdef QT_QMAP_DEBUG + void inorder( QMapNodeBase* x = 0, int level = 0 ){ + if ( !x ) + x = header->parent; + if ( x->left ) + inorder( x->left, level + 1 ); + //cout << level << " Key=" << key(x) << " Value=" << ((NodePtr)x)->data << endl; + if ( x->right ) + inorder( x->right, level + 1 ); + } +#endif + + Iterator insertMulti(const Key& v){ + QMapNodeBase* y = header; + QMapNodeBase* x = header->parent; + while (x != 0){ + y = x; + x = ( v < key(x) ) ? x->left : x->right; + } + return insert(x, y, v); + } + + Iterator insertSingle( const Key& k ) { + // Search correct position in the tree + QMapNodeBase* y = header; + QMapNodeBase* x = header->parent; + bool result = TRUE; + while ( x != 0 ) { + result = ( k < key(x) ); + y = x; + x = result ? x->left : x->right; + } + // Get iterator on the last not empty one + Iterator j( (NodePtr)y ); + if ( result ) { + // Smaller then the leftmost one ? + if ( j == begin() ) { + return insert(x, y, k ); + } else { + // Perhaps daddy is the right one ? + --j; + } + } + // Really bigger ? + if ( (j.node->key) < k ) + return insert(x, y, k ); + // We are going to replace a node + return j; + } + + Iterator insert( QMapNodeBase* x, QMapNodeBase* y, const Key& k ) { + NodePtr z = new Node( k ); + if (y == header || x != 0 || k < key(y) ) { + y->left = z; // also makes leftmost = z when y == header + if ( y == header ) { + header->parent = z; + header->right = z; + } else if ( y == header->left ) + header->left = z; // maintain leftmost pointing to min node + } else { + y->right = z; + if ( y == header->right ) + header->right = z; // maintain rightmost pointing to max node + } + z->parent = y; + z->left = 0; + z->right = 0; + rebalance( z, header->parent ); + ++node_count; + return Iterator(z); + } + +protected: + /** + * Helpers + */ + const Key& key( QMapNodeBase* b ) const { return ((NodePtr)b)->key; } + + /** + * Variables + */ + NodePtr header; +}; + + +template +class Q_EXPORT QMap +{ +public: + /** + * Typedefs + */ + typedef QMapIterator< Key, T > Iterator; + typedef QMapConstIterator< Key, T > ConstIterator; + typedef T ValueType; + typedef QMapPrivate< Key, T > Priv; + + /** + * API + */ + QMap() { sh = new QMapPrivate< Key, T >; } + QMap( const QMap& m ) { sh = m.sh; sh->ref(); } + ~QMap() { if ( sh->deref() ) delete sh; } + + QMap& operator= ( const QMap& m ) + { m.sh->ref(); if ( sh->deref() ) delete sh; sh = m.sh; return *this; } + + Iterator begin() { detach(); return sh->begin(); } + Iterator end() { detach(); return sh->end(); } + ConstIterator begin() const { return ((const Priv*)sh)->begin(); } + ConstIterator end() const { return ((const Priv*)sh)->end(); } + + Iterator find ( const Key& k ) + { detach(); return Iterator( sh->find( k ).node ); } + ConstIterator find ( const Key& k ) const + { return sh->find( k ); } + T& operator[] ( const Key& k ) { + detach(); QMapNode* p = sh->find( k ).node; + if ( p != sh->end().node ) return p->data; + return insert( k, T() ).data(); } + const T& operator[] ( const Key& k ) const + { return sh->find( k ).data(); } + bool contains ( const Key& k ) const + { return find( k ) != end(); } + //{ return sh->find( k ) != ((const Priv*)sh)->end(); } + + uint count() const { return sh->node_count; } + + bool isEmpty() const { return sh->node_count == 0; } + + Iterator insert( const Key& key, const T& value ) { + detach(); + Iterator it = sh->insertSingle( key ); + it.data() = value; + return it; + } + + void remove( Iterator it ) { detach(); sh->remove( it ); } + void remove( const Key& k ) { + detach(); + Iterator it( sh->find( k ).node ); + if ( it != end() ) + sh->remove( it ); + } + + Iterator replace( const Key& k, const T& v ) { + remove( k ); + return insert( k, v ); + } + + void clear() { if ( sh->count == 1 ) sh->clear(); else { sh->deref(); sh = new QMapPrivate; } } + +#if defined(Q_FULL_TEMPLATE_INSTANTIATION) + bool operator==( const QMap& ) const { return FALSE; } +#endif + +protected: + /** + * Helpers + */ + void detach() { if ( sh->count > 1 ) { sh->deref(); sh = new QMapPrivate( sh ); } } + + Priv* sh; +}; + + +#ifndef QT_NO_DATASTREAM +template +inline QDataStream& operator>>( QDataStream& s, QMap& m ) { + m.clear(); + Q_UINT32 c; + s >> c; + for( Q_UINT32 i = 0; i < c; ++i ) { + Key k; T t; + s >> k >> t; + m.insert( k, t ); + } + return s; +} + + +template +inline QDataStream& operator<<( QDataStream& s, const QMap& m ) { + s << (Q_UINT32)m.count(); + QMapConstIterator it = m.begin(); + for( ; it != m.end(); ++it ) + s << it.key() << it.data(); + return s; +} +#endif + +#endif // QMAP_H diff --git a/qtools/qqueue.h b/qtools/qqueue.h deleted file mode 100644 index 94bc130..0000000 --- a/qtools/qqueue.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** -** Definition of QQueue template/macro class -** -** Created : 920917 -** -** 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 QQUEUE_H -#define QQUEUE_H - -#ifndef QT_H -#include "qglist.h" -#endif // QT_H - - -template class QQueue : private QGList -{ -public: - QQueue() {} - QQueue( const QQueue &q ) : QGList(q) {} - ~QQueue() { clear(); } - QQueue& operator=(const QQueue &q) - { return (QQueue&)QGList::operator=(q); } - bool autoDelete() const { return QCollection::autoDelete(); } - void setAutoDelete( bool del ) { QCollection::setAutoDelete(del); } - uint count() const { return QGList::count(); } - bool isEmpty() const { return QGList::count() == 0; } - void enqueue( const type *d ) { QGList::append(Item(d)); } - type *dequeue() { return (type *)QGList::takeFirst();} - bool remove() { return QGList::removeFirst(); } - void clear() { QGList::clear(); } - type *head() const { return (type *)QGList::cfirst(); } - operator type *() const { return (type *)QGList::cfirst(); } - type *current() const { return (type *)QGList::cfirst(); } -private: - void deleteItem( Item d ) { if ( del_item ) delete (type *)d; } -}; - - -#endif // QQUEUE_H diff --git a/qtools/qsortedlist.doc b/qtools/qsortedlist.doc deleted file mode 100644 index 6f16f19..0000000 --- a/qtools/qsortedlist.doc +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** -** QSortedList documentation -** -** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. -** -** This file is part 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. -** -**********************************************************************/ - - -/***************************************************************************** - QSortedList documentation - *****************************************************************************/ - -/*! - \class QSortedList qsortedlist.h - \brief The QSortedList class provides a list sorted by operator< and operator== - - \ingroup collection - \ingroup tools - - If you want to sort a QList you have to reimplement the - QGList::compareItems() method. If the elements of your list support - operator<() and operator==() then you can use QSortedList instead. - Its compareItems() calls operator<() and operator==() and returns an - appropriate result. - - Otherwise, this is as QList. - - \sa QList, \link collection.html Collection Classes\endlink -*/ - - -/*! - \fn QSortedList::QSortedList() - Constructs an empty list. -*/ - -/*! - \fn QSortedList::QSortedList( const QSortedList &list ) - Constructs a copy of \e list. - - Each item in \e list is copied to this new list. -*/ - -/*! - \fn QSortedList::~QSortedList() - Removes all items from the list and destroys the list. - - All list iterators that access this list will be reset. -*/ - -/*! - \fn QSortedList& QSortedList::operator=(const QSortedList& list) - Assigns \e list to this list and returns a reference to this list. - - This list is first cleared, then each item in \e list is - appended to this list. Only the pointers are copied - (shallow copy), unless newItem() has been reimplemented(). -*/ - -/*! - \fn int QSortedList::compareItems( QCollection::Item s1, QCollection::Item s2 ) - - \reimp - - This reimplementation uses operator< and operator== to compare. -*/ diff --git a/qtools/qsortedlist.h b/qtools/qsortedlist.h deleted file mode 100644 index aeadd90..0000000 --- a/qtools/qsortedlist.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** -** 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 QSORTEDLIST_H -#define QSORTEDLIST_H - -#ifndef QT_H -#include "qlist.h" -#endif // QT_H - - -template class Q_EXPORT QSortedList : public QList -{ -public: - QSortedList() {} - QSortedList( const QSortedList &l ) : QList(l) {} - ~QSortedList() { clear(); } - QSortedList &operator=(const QSortedList &l) - { return (QSortedList&)QList::operator=(l); } - - virtual int compareItems( QCollection::Item s1, QCollection::Item s2 ) - { if ( *((type*)s1) == *((type*)s2) ) return 0; return ( *((type*)s1) < *((type*)s2) ? -1 : 1 ); } -}; - -#endif diff --git a/qtools/qstack.doc b/qtools/qstack.doc deleted file mode 100644 index ece1e2a..0000000 --- a/qtools/qstack.doc +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** -** QStack class documentation -** -** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. -** -** This file is part 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. -** -**********************************************************************/ - - -/***************************************************************************** - QStack documentation - *****************************************************************************/ - -/*! - \class QStack qstack.h - \brief The QStack class is a template class that provides a stack. - - \ingroup collection - \ingroup tools - - QStack is implemented as a template class. Define a template - instance QStack\ to create a stack that operates on pointers to - X, or X*. - - A stack is a Last In, First Out (LIFO) structure. Items are added to - the top of the stack with push() and retrieved from the top - with pop(). - - \sa \link collection.html Collection Classes\endlink -*/ - -/*! \fn QStack::QStack () - Creates and empty stack. -*/ - -/*! \fn QStack::QStack (const QStack& s) - Creates a stack by making a shallow copy of another stack. -*/ - -/*! \fn QStack::~QStack () - Destroys the stack. All items will be deleted if autoDelete() is TRUE. -*/ - -/*! \fn QStack& QStack::operator= (const QStack& s) - Sets the contents of this stack by making a shallow copy of another stack. - Elements currently in this stack will be deleted if autoDelete() is TRUE. -*/ - -/*! \fn bool QStack::isEmpty () const - Returns TRUE is the stack contains no elements to be \link pop() popped\endlink. -*/ - -/*! \fn void QStack::push (const type* d) - Adds an element to the top of the stack. Last in, first out. -*/ - -/*! \fn type* QStack::pop () - Removes the top item from the stack and returns it. -*/ - -/*! \fn bool QStack::remove () - Removes the top item from the stack and deletes it if - autoDelete() is TRUE. Returns TRUE if there was an item to pop. - - \sa clear() -*/ - -/*! \fn void QStack::clear() - Removes all items from the stack, deleting them if - autoDelete() is TRUE. - - \sa remove() -*/ - -/*! \fn uint QStack::count() const - Returns the number of items in the stack. - - \sa isEmpty() -*/ - -/*! \fn type* QStack::top () const - Returns a reference to the top item on the stack (most recently pushed). - The stack is not changed. -*/ - -/*! \fn QStack::operator type* ()const - Returns a reference to the top item on the stack (most recently pushed). - The stack is not changed. -*/ - -/*! \fn type* QStack::current () const - Returns a reference to the top item on the stack (most recently pushed). - The stack is not changed. -*/ - -/*! \fn bool QStack::autoDelete() const - - The same as QCollection::autoDelete(). - - \sa setAutoDelete() -*/ - -/*! \fn void QStack::setAutoDelete( bool enable ) - - The same as QCollection::setAutoDelete(). - - \sa autoDelete() -*/ diff --git a/qtools/qstack.h b/qtools/qstack.h deleted file mode 100644 index c84d8d2..0000000 --- a/qtools/qstack.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** -** Definition of QStack template/macro class -** -** Created : 920917 -** -** 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 QSTACK_H -#define QSTACK_H - -#ifndef QT_H -#include "qglist.h" -#endif // QT_H - - -template class QStack : private QGList -{ -public: - QStack() {} - QStack( const QStack &s ) : QGList(s) {} - ~QStack() { clear(); } - QStack &operator=(const QStack &s) - { return (QStack&)QGList::operator=(s); } - bool autoDelete() const { return QCollection::autoDelete(); } - void setAutoDelete( bool del ) { QCollection::setAutoDelete(del); } - uint count() const { return QGList::count(); } - bool isEmpty() const { return QGList::count() == 0; } - void push( const type *d ) { QGList::insertAt(0,Item(d)); } - type *pop() { return (type *)QGList::takeFirst(); } - bool remove() { return QGList::removeFirst(); } - void clear() { QGList::clear(); } - type *bottom() const { return (type *)QGList::clast(); } - type *top() const { return (type *)QGList::cfirst(); } - operator type *() const { return (type *)QGList::cfirst(); } - type *current() const { return (type *)QGList::cfirst(); } -private: - void deleteItem( Item d ) { if ( del_item ) delete (type *)d; } -}; - - -#endif // QSTACK_H diff --git a/qtools/qstack_p.h b/qtools/qstack_p.h new file mode 100644 index 0000000..c84d8d2 --- /dev/null +++ b/qtools/qstack_p.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** +** Definition of QStack template/macro class +** +** Created : 920917 +** +** 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 QSTACK_H +#define QSTACK_H + +#ifndef QT_H +#include "qglist.h" +#endif // QT_H + + +template class QStack : private QGList +{ +public: + QStack() {} + QStack( const QStack &s ) : QGList(s) {} + ~QStack() { clear(); } + QStack &operator=(const QStack &s) + { return (QStack&)QGList::operator=(s); } + bool autoDelete() const { return QCollection::autoDelete(); } + void setAutoDelete( bool del ) { QCollection::setAutoDelete(del); } + uint count() const { return QGList::count(); } + bool isEmpty() const { return QGList::count() == 0; } + void push( const type *d ) { QGList::insertAt(0,Item(d)); } + type *pop() { return (type *)QGList::takeFirst(); } + bool remove() { return QGList::removeFirst(); } + void clear() { QGList::clear(); } + type *bottom() const { return (type *)QGList::clast(); } + type *top() const { return (type *)QGList::cfirst(); } + operator type *() const { return (type *)QGList::cfirst(); } + type *current() const { return (type *)QGList::cfirst(); } +private: + void deleteItem( Item d ) { if ( del_item ) delete (type *)d; } +}; + + +#endif // QSTACK_H diff --git a/qtools/qstring.cpp b/qtools/qstring.cpp index 3d57839..a964aca 100644 --- a/qtools/qstring.cpp +++ b/qtools/qstring.cpp @@ -1,5 +1,5 @@ /**************************************************************************** -** +** ** ** Implementation of the QString class and related Unicode functions ** @@ -45,7 +45,7 @@ #include "qregexp.h" #include "qdatastream.h" #include "qtextcodec.h" -#include "qstack.h" +#include "qstack_p.h" #include #include #include @@ -12745,7 +12745,7 @@ bool QString::findArg(int& pos, int& len) const arbitrary list of arguments. The format string supports all the escape sequences of printf() in the standard C library. - The %s escape sequence expects a utf8() encoded string. + The %s escape sequence expects a utf8() encoded string. The format string \e cformat is expected to be in latin1. If you need a unicode format string, use QString::arg() instead. For typesafe string building, with full Unicode support, you can use QTextOStream diff --git a/qtools/qstringlist.h b/qtools/qstringlist.h index 3f9fbb2..5e1e258 100644 --- a/qtools/qstringlist.h +++ b/qtools/qstringlist.h @@ -1,5 +1,5 @@ /**************************************************************************** -** +** ** ** Definition of QStringList class ** @@ -39,7 +39,7 @@ #define QSTRINGLIST_H #ifndef QT_H -#include "qvaluelist.h" +#include "qvaluelist_p.h" #include "qstring.h" #include "qregexp.h" #endif // QT_H diff --git a/qtools/qstrvec.h b/qtools/qstrvec.h deleted file mode 100644 index 15d3abb..0000000 --- a/qtools/qstrvec.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** -** Definition of QStrVec and QStrIVec classes -** -** Created : 931203 -** -** 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 QSTRVEC_H -#define QSTRVEC_H - -#ifndef QT_H -#include "qstring.h" -#include "qvector.h" -#include "qdatastream.h" -#endif // QT_H - - -#if defined(Q_TEMPLATEDLL) -template class Q_EXPORT QVector -#endif - -typedef QVector QStrVecBase; - - -class Q_EXPORT QStrVec : public QStrVecBase -{ -public: - QStrVec() { dc = TRUE; } - QStrVec( uint size, bool deepc = TRUE ) : QStrVecBase(size) {dc=deepc;} - ~QStrVec() { clear(); } -private: - Item newItem( Item d ) { return dc ? qstrdup( (const char*)d ) : d; } - void deleteItem( Item d ) { if ( dc ) delete[] (char*)d; } - int compareItems( Item s1, Item s2 ) - { return qstrcmp((const char*)s1, - (const char*)s2); } -#ifndef QT_NO_DATASTREAM - QDataStream &read( QDataStream &s, Item &d ) - { s >> (char *&)d; return s; } - QDataStream &write( QDataStream &s, Item d ) const - { return s << (const char*)d; } -#endif - bool dc; -}; - - -class Q_EXPORT QStrIVec : public QStrVec // case insensitive string vec -{ -public: - QStrIVec() {} - QStrIVec( uint size, bool dc = TRUE ) : QStrVec( size, dc ) {} - ~QStrIVec() { clear(); } -private: - int compareItems( Item s1, Item s2 ) - { return qstricmp((const char*)s1, - (const char*)s2); } -}; - - -#endif // QSTRVEC_H diff --git a/qtools/qvaluelist.doc b/qtools/qvaluelist.doc deleted file mode 100644 index 9f34c8e..0000000 --- a/qtools/qvaluelist.doc +++ /dev/null @@ -1,772 +0,0 @@ -/**************************************************************************** -** -** -** QValueList and QValueListIterator class documentation -** -** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. -** -** This file is part 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. -** -**********************************************************************/ - - -/***************************************************************************** - QValueList documentation - *****************************************************************************/ - -/*! - \class QValueList qvaluelist.h - \brief The QValueList class is a value based template class that provides doubly linked lists. - - \ingroup qtl - \ingroup tools - \ingroup shared - - Define a template instance QValueList\ to create a list of values which all - have the class X. Please notice that QValueList does not store pointers to the - members of the list. It holds a copy of every member. That is the reason why this - kind of classes are called "value based" while QList and QDict are "reference based". - - Some classes can not be used within a QValueList, for example everything - derived from QObject and thus all classes that implement widgets. - Only values can be used in a QValueList. To qualify as a value, the class - must provide -
    -
  • a copy constructor, -
  • an assignment operator and -
  • a default constructor, i.e. a constructor that does not take any arguments. -
- - Note that C++ defaults to field-by-field assignment operators and - copy constructors if no explicit version is supplied. In many cases, - this is sufficient. - - Example: - \code - #include - #include - #include - - class Employee - { - public: - Employee(): s(0) {} - Employee( const QString& name, int salary ) - : n(name), s(salary) - {} - - QString name() const { return n; } - int salary() const { return s; } - void setSalary( int salary ) { s = salary; } - private: - QString n; - int s; - }; - - void main() - { - typedef QValueList EmployeeList; - EmployeeList list; // list of Employee - - list.append( Employee("Bill", 50000) ); - list.append( Employee("Steve",80000) ); - list.append( Employee("Ron", 60000) ); - - Employee joe( "Joe", 50000 ); - list.append( joe ); - joe.setSalary( 4000 ); - - EmployeeList::Iterator it; - for( it = list.begin(); it != list.end(); ++it ) - printf( "%s earns %d\n", (*it).name().latin1(), (*it).salary().latin1() ); - } - \endcode - - Program output: - \code - Bill earns 50000 - Steve earns 80000 - Ron earns 60000 - Joe earns 50000 - \endcode - - As you can see, the latest changes to Joes salary did not affect the value - in the list because the list created a copy of Joes entry. - - There are three ways of finding items in the list. The first one is by using - the at() function. It returns an iterator. The advantages of - getting an iterator is that you can now move forward or backward from this - position by incrementing/decrementing the iterator. To get the amount of - items in the list call count(). Valid indices are 0..count(). - - The second way of accessing a list is with operator[]. That means you can address - it like an array. The return value is a reference to the value stored in the list. - There exist two versions of this operator. The first one is const and returns a - const reference to the value. The second on is non const and returns a non const - reference to the value. It is up to your compiler to choose the correct one. - - The third method is to use the functions begin() and end(). - With a simple for loop as shown in the example you can iterate over the complete list. - It is save to have multiple iterators at the same time. If some member of the list is - removed then only iterators pointing to the removed member become invalid. Inserting in - the list does not invalidate any iterator. For convenience the function last() returns - an iterator for the last and first() for the first element in the list. - - In addition you can search items in the list with the find() function. It exists in a const - and a non const version. It starts searching from the beginning of the list, but another - flavor of the find() function allows you to specify where searching should start. - If you just want to know whether a certain item is at least once in the list, then you - can use the contains() function. - - Since QValueList is value based there is no need to care about deleting elements in the - list. The list holds its own copies and will free them if the corresponding member or - the list itself is deleted. You can force the list to free all of its item with clear(). - - QValueList is implicitly shared. That means you can just make copies of the list - in time O(1). If multiple QValueList instances share the same data and one - is doing a modification of the lists data then this modifying instance makes a copy - and modifies its private copy. So it does not affect the other instances. - From a developers point of view you can think that a QValueList and a copy of this - list have nothing to do with each other. Developers may only notice that copying is - very fast. People known to a CPUs MMU architecture will know this pattern as "copy on write". - - There exist three functions to insert items in the list. append() - inserts an item at the end, prepend() inserts at the beginning - and insert() inserts in front of the position given by an iterator. - - Items can be removed from the list in two ways. The first is to pass an iterator to - the remove(). The other possibility is to pass a value to remove() which will - delete all members which match this value. - - Lists can be sorted with the algorithms provided by the Qt Template Library, for example with - qHeapSort(): - - Example: - \code - QValueList l; - l.append( 5 ); - l.append( 8 ); - l.append( 3 ); - l.append( 4 ); - qHeapSort( l ); - \endcode - - \sa QValueListIterator -*/ - - -/*! - \fn QValueList::QValueList() - Constructs an empty list. -*/ - -/*! - \fn QValueList::QValueList( const QValueList& l ) - Constructs a copy of \e l. - - This operation costs O(1) time since QValueList is implicit shared. - The first instance applying modifications to a shared list will create - a copy which takes in turn O(n) time. However returning a QValueList from - a function is very fast. -*/ - -/*! - \fn QValueList::~QValueList() - Destroys the list. References to the values in the list and all iterators - of this list become invalidated. Since QValueList is highly tuned for performance - you won't see warnings if you use invalid iterators, - because it is impossible for - an iterator to check whether it is valid or not. -*/ - -/*! - \fn QValueList& QValueList::operator= ( const QValueList& l ) - Assigns \e l to this list and returns a reference to this list. - - All iterators of the current list become invalidated by this operation. - The cost of such an assignment is O(1) since QValueList is implicitly shared. -*/ - -/*! - \fn QValueList QValueList::operator+ ( const QValueList& l ) const - Creates a new list and fills it with the elements of this list. Then the - elements of \e l are appended. - - Returns the new list. -*/ - -/*! - \fn QValueList& QValueList::operator+= ( const QValueList& l ) - Adds \e list to this list. - - Returns a reference to this list. -*/ - -/*! - \fn bool QValueList::operator== ( const QValueList& l ) const - Compares both lists. - - Returns TRUE if both list are equal. -*/ - -/*! - \fn bool QValueList::operator!= ( const QValueList& l ) const - Compares both lists. - - Returns TRUE if both list are unequal. -*/ - -/*! - \fn QValueList& QValueList::operator+= ( const T& x ) - Adds the value \e x to the end of the list. - - Returns a reference to the list. -*/ - -/*! - \fn QValueList& QValueList::operator<< ( const T& x ) - Adds the value \e x to the end of the list. - - Returns a reference to the list. -*/ - -/*! - \fn const T& QValueList::operator[] ( uint i ) const - Returns a const reference to the item with index \e i in the list. - It is up to you to check whether this item really exists. You can do that easily - with the count() function. However this operator does not check whether \e i - is in range and will deliver undefined results if it does not exist. -*/ - -/*! - \fn T& QValueList::operator[] ( uint i ) - Returns a reference to the item with index \e i in the list. - It is up to you to check whether this item really exists. You can do that easily - with the count() function. However this operator does not check whether \e i - is in range and will deliver undefined results if it does not exist. - In contrast to the const operator[] you may manipulate the value returned by this - operator. -*/ - -/*! - \fn uint QValueList::count() const - Returns the number of items in the list. - \sa isEmpty() -*/ - -/*! - \fn bool QValueList::isEmpty() const - Returns TRUE if the list is empty, i.e. count() == 0. Returns FALSE - otherwise. - \sa count() -*/ - -/*! - \fn Iterator QValueList::insert( Iterator it, const T& x ) - Inserts the value \e x in front of the iterator \e it. - - Returns an iterator pointing at the inserted item. - - \sa append(), prepend() -*/ - -/*! - \fn Iterator QValueList::append( const T& x ) - Inserts the value \e x at the end of the list. - - Returns an iterator pointing at the inserted item. - - \sa insert(), prepend() -*/ - -/*! - \fn Iterator QValueList::prepend( const T& x ) - Inserts the value \e x at the beginning of the list. - - Returns an iterator pointing at the inserted item. - - \sa insert(), append() -*/ - -/*! - \fn Iterator QValueList::remove( Iterator it ) - Removes the item at position \e it in the list. - - Returns an iterator pointing to the item following the - removed on or end() if the last item was deleted. - - \sa clear() -*/ - -/*! - \fn void QValueList::remove( const T& x ) - Removes all items which have the value \e x. - - \sa clear() -*/ - -/*! - \fn void QValueList::clear() - Removes all items from the list. - - \sa remove() -*/ - -/*! - \fn Iterator QValueList::find( const T& x ) - Finds the first occurrence of \e x in the list. - - Returns end() if no item did match. -*/ - -/*! - \fn ConstIterator QValueList::find( const T& x ) const - Finds the first occurrence of \e x in the list. - - Returns end() if no item did match. -*/ - -/*! - \fn Iterator QValueList::find( Iterator it, const T& x ) - Finds the first occurrence of \e x in the list starting at - the position given by \e it. - - Returns end() if no item did match. -*/ - -/*! - \fn ConstIterator QValueList::find( ConstIterator it, const T& x ) const - Finds the first occurrence of \e x in the list starting at - the position given by \e it. - - Returns end() if no item did match. -*/ - -/*! - \fn uint QValueList::contains( const T& x ) const - Counts and returns the number of occurrences of the value \e x in the list. -*/ - -/*! - \fn int QValueList::findIndex( const T& x ) const - Returns the first index of the value \e x in the list or -1 if no such value - can be found in the list. -*/ - -/*! - \fn Iterator QValueList::at( uint i ) - Returns an iterator pointing to the item at position \e i in the list, or - end() if the index is out of range. -*/ - -/*! - \fn ConstIterator QValueList::at( uint i ) const - Returns an iterator pointing to the item at position \e i in the list, or - end() if the index is out of range. -*/ - -/*! - \fn T& QValueList::first() - Returns a reference to the first item in the list or the item - referenced by end() - if no such items exists. Please note that you may not change - the value the end() Iterator is pointing to. - - \sa begin(), last() -*/ - -/*! - \fn const T& QValueList::first() const - Returns a reference to the first item in the list or the item - referenced by end() if - no such items exists. - - \sa begin(), last() -*/ - -/*! - \fn Iterator QValueList::fromLast() - Returns an iterator pointing to the last element in the list or - end() if no such item exists. - - \sa last() -*/ - -/*! - \fn ConstIterator QValueList::fromLast() const - Returns an iterator pointing to the last element in the list or - end() if no such item exists. - - \sa last() -*/ - -/*! - \fn T& QValueList::last() - Returns a reference to the last item in the list or the item - referenced by end() if no - such item exists. Please note that you may not change - the value the end() Iterator is pointing to. - - \sa end(), first(), fromLast() -*/ - -/*! - \fn const T& QValueList::last() const - Returns a reference to the last item in the list or the item - referenced by end() if no such item exists. - - \sa end(), first(), fromLast() -*/ - -/*! - \fn Iterator QValueList::begin() - Returns an iterator pointing to the first element in the list. This - iterator equals end() if the list is empty; - \sa first(), end() -*/ - -/*! - \fn ConstIterator QValueList::begin() const - Returns an iterator pointing to the first element in the list. This - iterator equals end() if the list is empty; - \sa first(), end() -*/ - -/*! - \fn Iterator QValueList::end() - Returns an iterator pointing behind the last element in the list. This - iterator equals begin() if the list is empty. - - \sa last(), begin() -*/ - -/*! - \fn ConstIterator QValueList::end() const - Returns an iterator pointing behind the last element in the list. This - iterator equals begin() if the list is empty. - - \sa last(), begin() -*/ - -/*! - \fn void QValueList::detach() - If the list does not share its data with another QValueList instance, then nothing - happens, otherwise the function creates a new copy of this data and detaches - from the shared one. This function is called whenever the list is modified. - The implicit sharing mechanism is implemented this way. -*/ - -/*! - \fn QDataStream& operator>>( QDataStream& s, QValueList& l ) - \relates QValueList - Reads a list from the stream. The type \e T stored in the list must implement - the streaming operator, too. -*/ - -/*! - \fn QDataStream& operator<<( QDataStream& s, const QValueList& l ) - \relates QValueList - Writes a list to the stream. The type \e T stored in the list must implement - the streaming operator, too. -*/ - -/***************************************************************************** - QValueListIterator documentation - *****************************************************************************/ - -/*! - \class QValueListIterator qvaluelist.h - \brief The QValueListIterator class provides an iterator for QValueList. - - \ingroup qtl - \ingroup tools - - You can not create an iterator by yourself. Instead you have to - ask a list to give you one. An iterator has only the size of a pointer. - On 32 bit machines that means 4 bytes otherwise 8 bytes. That makes them - very fast. In fact they resemble the semantics of pointers as good as possible - and they are almost as fast as usual pointers. - - Example: - \code - #include - #include - #include - - class Employee - { - public: - Employee(): s(0) {} - Employee( const QString& name, int salary ) - : n(name), s(salary) - {} - - QString name() const { return n; } - int salary() const { return s; } - void setSalary( int salary ) { s = salary; } - private: - QString n; - int s; - }; - - void main() - { - typedef QValueList EmployeeList; - EmployeeList list; // list of Employee - - list.append( Employee("Bill", 50000) ); - list.append( Employee("Steve",80000) ); - list.append( Employee("Ron", 60000) ); - - Employee joe( "Joe", 50000 ); - list.append( joe ); - joe.setSalary( 4000 ); - - EmployeeList::Iterator it; - for( it = list.begin(); it != list.end(); ++it ) - printf( "%s earns %d\n", (*it).name().latin1(), (*it).salary() ); - } - \endcode - - Program output: - \code - Bill earns 50000 - Steve earns 80000 - Ron earns 60000 - Joe earns 50000 - \endcode - - In contrast to QList there are no built in functions in QValueList to - traverse the list. The only way to do this is to use iterators. - QValueList is highly optimized for performance and memory usage. - On the other hand that means that you have to be a bit more careful - by what you are doing. QValueList does not know about all its iterators - and the iterators don't even know to which list they belong. That makes - things fast and slim but a bit dangerous because it is up to you to make - sure that iterators you are using are still valid. QListIterator will be able - to give warnings while QValueListIterator may end up in an undefined state. - - For every Iterator there is a ConstIterator. When accessing a QValueList - in a const environment or if the reference or pointer to the list is itself - const, then you have to use the ConstIterator. Its semantics are the same, - but it returns only const references to the item it points to. - - \sa QValueList, QValueListConstIterator -*/ - -/*! - \fn QValueListIterator::QValueListIterator() - Creates un uninitialized iterator. -*/ - -/*! - \fn QValueListIterator::QValueListIterator( NodePtr p ) - Internal function. -*/ - -/*! - \fn QValueListIterator::QValueListIterator( const QValueListIterator& it ) - Constructs a copy of the iterator \e it. -*/ - -/*! - \fn QValueListIterator::~QValueListIterator() - Destroys the iterator. -*/ - -/* Unfortunately not with MSVC - \fn T *QValueListIterator::operator->() - Pointer operator. Returns a pointer to the current iterator item. - The great advantage of this operator is that you can treat the - iterator like a pointer. - - Example: - \code - QValueList::Iterator it = list.begin(); - for( ; it != end(); ++it ) - it->show(); - \endcode -*/ - -/*! - \fn T& QValueListIterator::operator*() - Asterisk operator. Returns a reference to the current iterator item. -*/ - -/*! - \fn const T& QValueListIterator::operator*() const - Asterisk operator. Returns a reference to the current iterator item. -*/ - -/*! - \fn QValueListIterator& QValueListIterator::operator++() - Prefix ++ makes the succeeding item current and returns - an iterator pointing to the new current item. - The iterator can not check whether it reached the end of the list. Incrementing - the iterator as returned by end() causes undefined results. -*/ - -/*! - \fn QValueListIterator QValueListIterator::operator++(int) - Postfix ++ makes the succeeding item current and returns - an iterator pointing to the new current item. - The iterator can not check whether it reached the end of the list. Incrementing - the iterator as returned by end() causes undefined results. -*/ - -/*! - \fn QValueListIterator& QValueListIterator::operator--() - Prefix -- makes the previous item current and returns - an iterator pointing to the new current item. - The iterator can not check whether it reached the beginning of the list. Decrementing - the iterator as returned by begin() causes undefined results. -*/ - -/*! - \fn QValueListIterator QValueListIterator::operator--(int) - Postfix -- makes the previous item current and returns - an iterator pointing to the new current item. - The iterator can not check whether it reached the beginning of the list. Decrementing - the iterator as returned by begin() causes undefined results. -*/ - -/*! - \fn bool QValueListIterator::operator==( const QValueListIterator& it ) const - Compares both iterators and returns TRUE if they point to the same item. -*/ - -/*! - \fn bool QValueListIterator::operator!=( const QValueListIterator& it ) const - Compares both iterators and returns TRUE if they point to different items. -*/ - -/***************************************************************************** - QValueListConstIterator documentation - *****************************************************************************/ - -/*! - \class QValueListConstIterator qvaluelist.h - \brief The QValueListConstIterator class provides an iterator for QValueList. - - \ingroup qtl - \ingroup tools - - In contrast to QValueListIterator this class is used to iterate over a const - list. It does not allow to modify the values of the list since this would - break the const semantics. - - For more information on QValueList iterators see QValueListIterator. - - \sa QValueListIterator, QValueList -*/ - -/*! - \fn QValueListConstIterator::QValueListConstIterator() - Creates un uninitialized iterator. -*/ - -/*! - \fn QValueListConstIterator::QValueListConstIterator( NodePtr p ) - Internal function. -*/ - -/*! - \fn QValueListConstIterator::QValueListConstIterator( const QValueListConstIterator& it ) - Constructs a copy of the iterator \e it. -*/ - -/*! - \fn QValueListConstIterator::QValueListConstIterator( const QValueListIterator& it ) - Constructs a copy of the iterator \e it. -*/ - -/*! - \fn QValueListConstIterator::~QValueListConstIterator() - Destroys the iterator. -*/ - -/* Unfortunately not with MSVC - \fn const T *QValueListConstIterator::operator->() - Pointer operator. Returns a pointer to the current iterator item. - The great advantage of this operator is that you can treat the - iterator like a pointer. - - Example: - \code - QValueList::Iterator it = list.begin(); - for( ; it != end(); ++it ) - it->show(); - \endcode -*/ - -/*! - \fn const T& QValueListConstIterator::operator*() const - Asterisk operator. Returns a reference to the current iterator item. -*/ - -/*! - \fn QValueListConstIterator& QValueListConstIterator::operator++() - Prefix ++ makes the succeeding item current and returns - an iterator pointing to the new current item. - The iterator can not check whether it reached the end of the list. Incrementing - the iterator as returned by end() causes undefined results. -*/ - -/*! - \fn QValueListConstIterator QValueListConstIterator::operator++(int) - Postfix ++ makes the succeeding item current and returns - an iterator pointing to the new current item. - The iterator can not check whether it reached the end of the list. Incrementing - the iterator as returned by end() causes undefined results. -*/ - -/*! - \fn QValueListConstIterator& QValueListConstIterator::operator--() - Prefix -- makes the previous item current and returns - an iterator pointing to the new current item. - The iterator can not check whether it reached the beginning of the list. Decrementing - the iterator as returned by begin() causes undefined results. -*/ - -/*! - \fn QValueListConstIterator QValueListConstIterator::operator--(int) - Postfix -- makes the previous item current and returns - an iterator pointing to the new current item. - The iterator can not check whether it reached the beginning of the list. Decrementing - the iterator as returned by begin() causes undefined results. -*/ - -/*! - \fn bool QValueListConstIterator::operator==( const QValueListConstIterator& it ) const - Compares both iterators and returns TRUE if they point to the same item. -*/ - -/*! - \fn bool QValueListConstIterator::operator!=( const QValueListConstIterator& it ) const - Compares both iterators and returns TRUE if they point to different items. -*/ diff --git a/qtools/qvaluelist.h b/qtools/qvaluelist.h deleted file mode 100644 index 8885bea..0000000 --- a/qtools/qvaluelist.h +++ /dev/null @@ -1,455 +0,0 @@ -/**************************************************************************** -** -** -** Definition of QValueList class -** -** Created : 990406 -** -** 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 QVALUELIST_H -#define QVALUELIST_H - -#ifndef QT_H -#include "qshared.h" -#include "qdatastream.h" -#endif // QT_H - -template -class Q_EXPORT QValueListNode -{ -public: - QValueListNode( const T& t ) : data( t ) { } - QValueListNode() { } -#if defined(Q_TEMPLATEDLL) - // Workaround MS bug in memory de/allocation in DLL vs. EXE - virtual ~QValueListNode() { } -#endif - - QValueListNode* next; - QValueListNode* prev; - T data; -}; - -template -class Q_EXPORT QValueListIterator -{ - public: - /** - * Typedefs - */ - typedef QValueListNode* NodePtr; - - /** - * Variables - */ - NodePtr node; - - /** - * Functions - */ - QValueListIterator() : node( 0 ) {} - QValueListIterator( NodePtr p ) : node( p ) {} - QValueListIterator( const QValueListIterator& it ) : node( it.node ) {} - QValueListIterator &operator=(const QValueListIterator &it) - { - node = it.node; - return *this; - } - - bool operator==( const QValueListIterator& it ) const { return node == it.node; } - bool operator!=( const QValueListIterator& it ) const { return node != it.node; } - const T& operator*() const { return node->data; } - T& operator*() { return node->data; } - - // Compilers are too dumb to understand this for QValueList - //T* operator->() const { return &(node->data); } - - QValueListIterator& operator++() { - node = node->next; - return *this; - } - - QValueListIterator operator++(int) { - QValueListIterator tmp = *this; - node = node->next; - return tmp; - } - - QValueListIterator& operator--() { - node = node->prev; - return *this; - } - - QValueListIterator operator--(int) { - QValueListIterator tmp = *this; - node = node->prev; - return tmp; - } -}; - -template -class Q_EXPORT QValueListConstIterator -{ - public: - /** - * Typedefs - */ - typedef QValueListNode* NodePtr; - - /** - * Variables - */ - NodePtr node; - - /** - * Functions - */ - QValueListConstIterator() : node( 0 ) {} - QValueListConstIterator( NodePtr p ) : node( p ) {} - QValueListConstIterator( const QValueListConstIterator& it ) : node( it.node ) {} - QValueListConstIterator( const QValueListIterator& it ) : node( it.node ) {} - QValueListConstIterator &operator=(const QValueListConstIterator &it) - { - node = it.node; - return *this; - } - - bool operator==( const QValueListConstIterator& it ) const { return node == it.node; } - bool operator!=( const QValueListConstIterator& it ) const { return node != it.node; } - const T& operator*() const { return node->data; } - - // Compilers are too dumb to understand this for QValueList - //const T* operator->() const { return &(node->data); } - - QValueListConstIterator& operator++() { - node = node->next; - return *this; - } - - QValueListConstIterator operator++(int) { - QValueListConstIterator tmp = *this; - node = node->next; - return tmp; - } - - QValueListConstIterator& operator--() { - node = node->prev; - return *this; - } - - QValueListConstIterator operator--(int) { - QValueListConstIterator tmp = *this; - node = node->prev; - return tmp; - } -}; - -template -class Q_EXPORT QValueListPrivate : public QShared -{ -public: - /** - * Typedefs - */ - typedef QValueListIterator Iterator; - typedef QValueListConstIterator ConstIterator; - typedef QValueListNode Node; - typedef QValueListNode* NodePtr; - - /** - * Functions - */ - QValueListPrivate() { node = new Node; node->next = node->prev = node; nodes = 0; } - QValueListPrivate( const QValueListPrivate& _p ) : QShared() { - node = new Node; node->next = node->prev = node; nodes = 0; - Iterator b( _p.node->next ); - Iterator e( _p.node ); - Iterator i( node ); - while( b != e ) - insert( i, *b++ ); - } - - void derefAndDelete() // ### hack to get around hp-cc brain damage - { - if ( deref() ) - delete this; - } - -#if defined(Q_TEMPLATEDLL) - // Workaround MS bug in memory de/allocation in DLL vs. EXE - virtual -#endif - ~QValueListPrivate() { - NodePtr p = node->next; - while( p != node ) { - NodePtr x = p->next; - delete p; - p = x; - } - delete node; - } - - Iterator insert( Iterator it, const T& x ) { - NodePtr p = new Node( x ); - p->next = it.node; - p->prev = it.node->prev; - it.node->prev->next = p; - it.node->prev = p; - nodes++; - return p; - } - - Iterator remove( Iterator it ) { - ASSERT ( it.node != node ); - NodePtr next = it.node->next; - NodePtr prev = it.node->prev; - prev->next = next; - next->prev = prev; - delete it.node; - nodes--; - return Iterator( next ); - } - - NodePtr find( NodePtr start, const T& x ) const { - ConstIterator first( start ); - ConstIterator last( node ); - while( first != last) { - if ( *first == x ) - return first.node; - ++first; - } - return last.node; - } - - int findIndex( NodePtr start, const T& x ) const { - ConstIterator first( start ); - ConstIterator last( node ); - int pos = 0; - while( first != last) { - if ( *first == x ) - return pos; - ++first; - ++pos; - } - return -1; - } - - uint contains( const T& x ) const { - uint result = 0; - Iterator first = Iterator( node->next ); - Iterator last = Iterator( node ); - while( first != last) { - if ( *first == x ) - ++result; - ++first; - } - return result; - } - - void remove( const T& x ) { - Iterator first = Iterator( node->next ); - Iterator last = Iterator( node ); - while( first != last) { - if ( *first == x ) - first = remove( first ); - else - ++first; - } - } - - NodePtr at( uint i ) const { - ASSERT( i <= nodes ); - NodePtr p = node->next; - for( uint x = 0; x < i; ++x ) - p = p->next; - return p; - } - - void clear() { - nodes = 0; - NodePtr p = node->next; - while( p != node ) { - NodePtr next = p->next; - delete p; - p = next; - } - node->next = node->prev = node; - } - - NodePtr node; - uint nodes; -}; - -template -class Q_EXPORT QValueList -{ -public: - /** - * Typedefs - */ - typedef QValueListIterator Iterator; - typedef QValueListConstIterator ConstIterator; - typedef T ValueType; - - /** - * API - */ - QValueList() { sh = new QValueListPrivate; } - QValueList( const QValueList& l ) { sh = l.sh; sh->ref(); } - ~QValueList() { sh->derefAndDelete(); } - - QValueList& operator= ( const QValueList& l ) - { - l.sh->ref(); - sh->derefAndDelete(); - sh = l.sh; - return *this; - } - - QValueList operator+ ( const QValueList& l ) const - { - QValueList l2( *this ); - for( ConstIterator it = l.begin(); it != l.end(); ++it ) - l2.append( *it ); - return l2; - } - - QValueList& operator+= ( const QValueList& l ) - { - for( ConstIterator it = l.begin(); it != l.end(); ++it ) - append( *it ); - return *this; - } - - bool operator== ( const QValueList& l ) const - { - if ( count() != l.count() ) - return FALSE; - ConstIterator it2 = begin(); - ConstIterator it = l.begin(); - for( ; it != l.end(); ++it, ++it2 ) - if ( !( *it == *it2 ) ) - return FALSE; - return TRUE; - } - - bool operator!= ( const QValueList& l ) const { return !( *this == l ); } - - Iterator begin() { detach(); return Iterator( sh->node->next ); } - ConstIterator begin() const { return ConstIterator( sh->node->next ); } - Iterator end() { detach(); return Iterator( sh->node ); } - ConstIterator end() const { return ConstIterator( sh->node ); } - Iterator fromLast() { detach(); return Iterator( sh->node->prev ); } - ConstIterator fromLast() const { return ConstIterator( sh->node->prev ); } - - bool isEmpty() const { return ( sh->nodes == 0 ); } - - Iterator insert( Iterator it, const T& x ) { detach(); return sh->insert( it, x ); } - - Iterator append( const T& x ) { detach(); return sh->insert( end(), x ); } - Iterator prepend( const T& x ) { detach(); return sh->insert( begin(), x ); } - - Iterator remove( Iterator it ) { detach(); return sh->remove( it ); } - void remove( const T& x ) { detach(); sh->remove( x ); } - - T& first() { detach(); return sh->node->next->data; } - const T& first() const { return sh->node->next->data; } - T& last() { detach(); return sh->node->prev->data; } - const T& last() const { return sh->node->prev->data; } - - T& operator[] ( uint i ) { detach(); return sh->at(i)->data; } - const T& operator[] ( uint i ) const { return sh->at(i)->data; } - Iterator at( uint i ) { detach(); return Iterator( sh->at(i) ); } - ConstIterator at( uint i ) const { return ConstIterator( sh->at(i) ); } - Iterator find ( const T& x ) { detach(); return Iterator( sh->find( sh->node->next, x) ); } - ConstIterator find ( const T& x ) const { return ConstIterator( sh->find( sh->node->next, x) ); } - Iterator find ( Iterator it, const T& x ) { detach(); return Iterator( sh->find( it.node, x ) ); } - ConstIterator find ( ConstIterator it, const T& x ) const { return ConstIterator( sh->find( it.node, x ) ); } - int findIndex( const T& x ) const { return sh->findIndex( sh->node->next, x) ; } - uint contains( const T& x ) const { return sh->contains( x ); } - - uint count() const { return sh->nodes; } - - void clear() { if ( sh->count == 1 ) sh->clear(); else { sh->deref(); sh = new QValueListPrivate; } } - - - QValueList& operator+= ( const T& x ) - { - append( x ); - return *this; - } - QValueList& operator<< ( const T& x ) - { - append( x ); - return *this; - } - - -protected: - /** - * Helpers - */ - void detach() { if ( sh->count > 1 ) { sh->deref(); sh = new QValueListPrivate( *sh ); } } - - /** - * Variables - */ - QValueListPrivate* sh; -}; - -#ifndef QT_NO_DATASTREAM -template -inline QDataStream& operator>>( QDataStream& s, QValueList& l ) -{ - l.clear(); - Q_UINT32 c; - s >> c; - for( Q_UINT32 i = 0; i < c; ++i ) - { - T t; - s >> t; - l.append( t ); - } - return s; -} - -template -inline QDataStream& operator<<( QDataStream& s, const QValueList& l ) -{ - s << (Q_UINT32)l.count(); - QValueListConstIterator it = l.begin(); - for( ; it != l.end(); ++it ) - s << *it; - return s; -} -#endif // QT_NO_DATASTREAM -#endif // QVALUELIST_H diff --git a/qtools/qvaluelist_p.h b/qtools/qvaluelist_p.h new file mode 100644 index 0000000..8885bea --- /dev/null +++ b/qtools/qvaluelist_p.h @@ -0,0 +1,455 @@ +/**************************************************************************** +** +** +** Definition of QValueList class +** +** Created : 990406 +** +** 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 QVALUELIST_H +#define QVALUELIST_H + +#ifndef QT_H +#include "qshared.h" +#include "qdatastream.h" +#endif // QT_H + +template +class Q_EXPORT QValueListNode +{ +public: + QValueListNode( const T& t ) : data( t ) { } + QValueListNode() { } +#if defined(Q_TEMPLATEDLL) + // Workaround MS bug in memory de/allocation in DLL vs. EXE + virtual ~QValueListNode() { } +#endif + + QValueListNode* next; + QValueListNode* prev; + T data; +}; + +template +class Q_EXPORT QValueListIterator +{ + public: + /** + * Typedefs + */ + typedef QValueListNode* NodePtr; + + /** + * Variables + */ + NodePtr node; + + /** + * Functions + */ + QValueListIterator() : node( 0 ) {} + QValueListIterator( NodePtr p ) : node( p ) {} + QValueListIterator( const QValueListIterator& it ) : node( it.node ) {} + QValueListIterator &operator=(const QValueListIterator &it) + { + node = it.node; + return *this; + } + + bool operator==( const QValueListIterator& it ) const { return node == it.node; } + bool operator!=( const QValueListIterator& it ) const { return node != it.node; } + const T& operator*() const { return node->data; } + T& operator*() { return node->data; } + + // Compilers are too dumb to understand this for QValueList + //T* operator->() const { return &(node->data); } + + QValueListIterator& operator++() { + node = node->next; + return *this; + } + + QValueListIterator operator++(int) { + QValueListIterator tmp = *this; + node = node->next; + return tmp; + } + + QValueListIterator& operator--() { + node = node->prev; + return *this; + } + + QValueListIterator operator--(int) { + QValueListIterator tmp = *this; + node = node->prev; + return tmp; + } +}; + +template +class Q_EXPORT QValueListConstIterator +{ + public: + /** + * Typedefs + */ + typedef QValueListNode* NodePtr; + + /** + * Variables + */ + NodePtr node; + + /** + * Functions + */ + QValueListConstIterator() : node( 0 ) {} + QValueListConstIterator( NodePtr p ) : node( p ) {} + QValueListConstIterator( const QValueListConstIterator& it ) : node( it.node ) {} + QValueListConstIterator( const QValueListIterator& it ) : node( it.node ) {} + QValueListConstIterator &operator=(const QValueListConstIterator &it) + { + node = it.node; + return *this; + } + + bool operator==( const QValueListConstIterator& it ) const { return node == it.node; } + bool operator!=( const QValueListConstIterator& it ) const { return node != it.node; } + const T& operator*() const { return node->data; } + + // Compilers are too dumb to understand this for QValueList + //const T* operator->() const { return &(node->data); } + + QValueListConstIterator& operator++() { + node = node->next; + return *this; + } + + QValueListConstIterator operator++(int) { + QValueListConstIterator tmp = *this; + node = node->next; + return tmp; + } + + QValueListConstIterator& operator--() { + node = node->prev; + return *this; + } + + QValueListConstIterator operator--(int) { + QValueListConstIterator tmp = *this; + node = node->prev; + return tmp; + } +}; + +template +class Q_EXPORT QValueListPrivate : public QShared +{ +public: + /** + * Typedefs + */ + typedef QValueListIterator Iterator; + typedef QValueListConstIterator ConstIterator; + typedef QValueListNode Node; + typedef QValueListNode* NodePtr; + + /** + * Functions + */ + QValueListPrivate() { node = new Node; node->next = node->prev = node; nodes = 0; } + QValueListPrivate( const QValueListPrivate& _p ) : QShared() { + node = new Node; node->next = node->prev = node; nodes = 0; + Iterator b( _p.node->next ); + Iterator e( _p.node ); + Iterator i( node ); + while( b != e ) + insert( i, *b++ ); + } + + void derefAndDelete() // ### hack to get around hp-cc brain damage + { + if ( deref() ) + delete this; + } + +#if defined(Q_TEMPLATEDLL) + // Workaround MS bug in memory de/allocation in DLL vs. EXE + virtual +#endif + ~QValueListPrivate() { + NodePtr p = node->next; + while( p != node ) { + NodePtr x = p->next; + delete p; + p = x; + } + delete node; + } + + Iterator insert( Iterator it, const T& x ) { + NodePtr p = new Node( x ); + p->next = it.node; + p->prev = it.node->prev; + it.node->prev->next = p; + it.node->prev = p; + nodes++; + return p; + } + + Iterator remove( Iterator it ) { + ASSERT ( it.node != node ); + NodePtr next = it.node->next; + NodePtr prev = it.node->prev; + prev->next = next; + next->prev = prev; + delete it.node; + nodes--; + return Iterator( next ); + } + + NodePtr find( NodePtr start, const T& x ) const { + ConstIterator first( start ); + ConstIterator last( node ); + while( first != last) { + if ( *first == x ) + return first.node; + ++first; + } + return last.node; + } + + int findIndex( NodePtr start, const T& x ) const { + ConstIterator first( start ); + ConstIterator last( node ); + int pos = 0; + while( first != last) { + if ( *first == x ) + return pos; + ++first; + ++pos; + } + return -1; + } + + uint contains( const T& x ) const { + uint result = 0; + Iterator first = Iterator( node->next ); + Iterator last = Iterator( node ); + while( first != last) { + if ( *first == x ) + ++result; + ++first; + } + return result; + } + + void remove( const T& x ) { + Iterator first = Iterator( node->next ); + Iterator last = Iterator( node ); + while( first != last) { + if ( *first == x ) + first = remove( first ); + else + ++first; + } + } + + NodePtr at( uint i ) const { + ASSERT( i <= nodes ); + NodePtr p = node->next; + for( uint x = 0; x < i; ++x ) + p = p->next; + return p; + } + + void clear() { + nodes = 0; + NodePtr p = node->next; + while( p != node ) { + NodePtr next = p->next; + delete p; + p = next; + } + node->next = node->prev = node; + } + + NodePtr node; + uint nodes; +}; + +template +class Q_EXPORT QValueList +{ +public: + /** + * Typedefs + */ + typedef QValueListIterator Iterator; + typedef QValueListConstIterator ConstIterator; + typedef T ValueType; + + /** + * API + */ + QValueList() { sh = new QValueListPrivate; } + QValueList( const QValueList& l ) { sh = l.sh; sh->ref(); } + ~QValueList() { sh->derefAndDelete(); } + + QValueList& operator= ( const QValueList& l ) + { + l.sh->ref(); + sh->derefAndDelete(); + sh = l.sh; + return *this; + } + + QValueList operator+ ( const QValueList& l ) const + { + QValueList l2( *this ); + for( ConstIterator it = l.begin(); it != l.end(); ++it ) + l2.append( *it ); + return l2; + } + + QValueList& operator+= ( const QValueList& l ) + { + for( ConstIterator it = l.begin(); it != l.end(); ++it ) + append( *it ); + return *this; + } + + bool operator== ( const QValueList& l ) const + { + if ( count() != l.count() ) + return FALSE; + ConstIterator it2 = begin(); + ConstIterator it = l.begin(); + for( ; it != l.end(); ++it, ++it2 ) + if ( !( *it == *it2 ) ) + return FALSE; + return TRUE; + } + + bool operator!= ( const QValueList& l ) const { return !( *this == l ); } + + Iterator begin() { detach(); return Iterator( sh->node->next ); } + ConstIterator begin() const { return ConstIterator( sh->node->next ); } + Iterator end() { detach(); return Iterator( sh->node ); } + ConstIterator end() const { return ConstIterator( sh->node ); } + Iterator fromLast() { detach(); return Iterator( sh->node->prev ); } + ConstIterator fromLast() const { return ConstIterator( sh->node->prev ); } + + bool isEmpty() const { return ( sh->nodes == 0 ); } + + Iterator insert( Iterator it, const T& x ) { detach(); return sh->insert( it, x ); } + + Iterator append( const T& x ) { detach(); return sh->insert( end(), x ); } + Iterator prepend( const T& x ) { detach(); return sh->insert( begin(), x ); } + + Iterator remove( Iterator it ) { detach(); return sh->remove( it ); } + void remove( const T& x ) { detach(); sh->remove( x ); } + + T& first() { detach(); return sh->node->next->data; } + const T& first() const { return sh->node->next->data; } + T& last() { detach(); return sh->node->prev->data; } + const T& last() const { return sh->node->prev->data; } + + T& operator[] ( uint i ) { detach(); return sh->at(i)->data; } + const T& operator[] ( uint i ) const { return sh->at(i)->data; } + Iterator at( uint i ) { detach(); return Iterator( sh->at(i) ); } + ConstIterator at( uint i ) const { return ConstIterator( sh->at(i) ); } + Iterator find ( const T& x ) { detach(); return Iterator( sh->find( sh->node->next, x) ); } + ConstIterator find ( const T& x ) const { return ConstIterator( sh->find( sh->node->next, x) ); } + Iterator find ( Iterator it, const T& x ) { detach(); return Iterator( sh->find( it.node, x ) ); } + ConstIterator find ( ConstIterator it, const T& x ) const { return ConstIterator( sh->find( it.node, x ) ); } + int findIndex( const T& x ) const { return sh->findIndex( sh->node->next, x) ; } + uint contains( const T& x ) const { return sh->contains( x ); } + + uint count() const { return sh->nodes; } + + void clear() { if ( sh->count == 1 ) sh->clear(); else { sh->deref(); sh = new QValueListPrivate; } } + + + QValueList& operator+= ( const T& x ) + { + append( x ); + return *this; + } + QValueList& operator<< ( const T& x ) + { + append( x ); + return *this; + } + + +protected: + /** + * Helpers + */ + void detach() { if ( sh->count > 1 ) { sh->deref(); sh = new QValueListPrivate( *sh ); } } + + /** + * Variables + */ + QValueListPrivate* sh; +}; + +#ifndef QT_NO_DATASTREAM +template +inline QDataStream& operator>>( QDataStream& s, QValueList& l ) +{ + l.clear(); + Q_UINT32 c; + s >> c; + for( Q_UINT32 i = 0; i < c; ++i ) + { + T t; + s >> t; + l.append( t ); + } + return s; +} + +template +inline QDataStream& operator<<( QDataStream& s, const QValueList& l ) +{ + s << (Q_UINT32)l.count(); + QValueListConstIterator it = l.begin(); + for( ; it != l.end(); ++it ) + s << *it; + return s; +} +#endif // QT_NO_DATASTREAM +#endif // QVALUELIST_H diff --git a/qtools/qvaluestack.h b/qtools/qvaluestack.h deleted file mode 100644 index fe4462a..0000000 --- a/qtools/qvaluestack.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** -** Definition of QValueStack class -** -** Created : 990925 -** -** 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 QVALUESTACK_H -#define QVALUESTACK_H - -#ifndef QT_H -#include "qvaluelist.h" -#endif // QT_H - - -template -class Q_EXPORT QValueStack : public QValueList -{ -public: - QValueStack() {} - ~QValueStack() {} - void push( const T& d ) { QValueList::append(d); } - T pop() - { - T elem( this->last() ); - if ( !this->isEmpty() ) - this->remove( this->fromLast() ); - return elem; - } - T& top() { return this->last(); } - const T& top() const { return this->last(); } -}; - -#endif diff --git a/qtools/qvaluestack_p.h b/qtools/qvaluestack_p.h new file mode 100644 index 0000000..5e10acb --- /dev/null +++ b/qtools/qvaluestack_p.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** +** Definition of QValueStack class +** +** Created : 990925 +** +** 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 QVALUESTACK_H +#define QVALUESTACK_H + +#ifndef QT_H +#include "qvaluelist_p.h" +#endif // QT_H + + +template +class Q_EXPORT QValueStack : public QValueList +{ +public: + QValueStack() {} + ~QValueStack() {} + void push( const T& d ) { QValueList::append(d); } + T pop() + { + T elem( this->last() ); + if ( !this->isEmpty() ) + this->remove( this->fromLast() ); + return elem; + } + T& top() { return this->last(); } + const T& top() const { return this->last(); } +}; + +#endif diff --git a/qtools/qxml.h b/qtools/qxml.h index b44e42c..94005bb 100644 --- a/qtools/qxml.h +++ b/qtools/qxml.h @@ -1,5 +1,5 @@ /**************************************************************************** -** +** ** ** Definition of QXmlSimpleReader and related classes. ** @@ -51,8 +51,8 @@ #include #include #include -#include -#include +#include +#include #endif // QT_H #ifndef QT_NO_XML diff --git a/src/configgen.py b/src/configgen.py index 063c1f4..1dcf3b5 100755 --- a/src/configgen.py +++ b/src/configgen.py @@ -683,8 +683,6 @@ def main(): print("#ifndef CONFIGVALUES_H") print("#define CONFIGVALUES_H") print("") - print("#include ") - print("#include ") print("#include ") print("#include \"containers.h\"") print("#include \"settings.h\"") diff --git a/src/context.cpp b/src/context.cpp index 8fbd674..572e0d3 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -247,21 +247,20 @@ class PropertyMapper }; public: - PropertyMapper() : m_map(63) { m_map.setAutoDelete(TRUE); } - /** Add a property to the map * @param[in] name The name of the property to add. * @param[in] handle The method to call when the property is accessed. */ void addProperty(const char *name,typename PropertyFunc::Handler handle) { - if (m_map.find(name)) + auto it = m_map.find(name); + if (it==m_map.end()) { err("Error: adding property '%s' more than once",name); } else { - m_map.insert(name,new PropertyFunc(handle)); + m_map.insert(std::make_pair(name,std::make_unique(handle))); } } @@ -275,16 +274,12 @@ class PropertyMapper { //printf("PropertyMapper::get(%s)\n",name); TemplateVariant result; - PropertyFuncIntf *func = m_map.find(name); - if (func) - { - result = (*func)(obj); - } - return result; + auto it = m_map.find(name); + return it!=m_map.end() ? (*it->second)(obj) : TemplateVariant(); } private: - QDict m_map; + std::unordered_map> m_map; }; @@ -295,15 +290,15 @@ class PropertyMapper class ConfigContext::Private { public: - Private() { m_cachedLists.setAutoDelete(TRUE); } + Private() { } virtual ~Private() { } TemplateVariant fetchList(const QCString &name,const StringVector &list) { - TemplateVariant *v = m_cachedLists.find(name); - if (v==0) + auto it = m_cachedLists.find(name.str()); + if (it==m_cachedLists.end()) { TemplateList *tlist = TemplateList::alloc(); - m_cachedLists.insert(name,new TemplateVariant(tlist)); + m_cachedLists.insert(std::make_pair(name.str(),TemplateVariant(tlist))); for (const auto &s : list) { tlist->append(s.c_str()); @@ -312,11 +307,11 @@ class ConfigContext::Private } else { - return *v; + return it->second; } } private: - QDict m_cachedLists; + std::unordered_map m_cachedLists; }; //%% } diff --git a/src/context.h b/src/context.h index 03e502a..9573643 100644 --- a/src/context.h +++ b/src/context.h @@ -18,7 +18,6 @@ #include "types.h" #include "template.h" -#include #include #include "classdef.h" #include "searchindex.h" diff --git a/src/definition.h b/src/definition.h index 6c66bc7..4c0c566 100644 --- a/src/definition.h +++ b/src/definition.h @@ -19,8 +19,6 @@ #define DEFINITION_H #include -#include -#include #include "types.h" #include "reflist.h" diff --git a/src/diagram.cpp b/src/diagram.cpp index 80c85c6..052c1f4 100644 --- a/src/diagram.cpp +++ b/src/diagram.cpp @@ -15,8 +15,6 @@ #include #include -#include -#include #include "ftextstream.h" #include diff --git a/src/docbookgen.cpp b/src/docbookgen.cpp index d9e79cb..8d390b6 100644 --- a/src/docbookgen.cpp +++ b/src/docbookgen.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include "docbookgen.h" #include "doxygen.h" diff --git a/src/docbookvisitor.h b/src/docbookvisitor.h index b56066f..bec7a12 100644 --- a/src/docbookvisitor.h +++ b/src/docbookvisitor.h @@ -18,8 +18,6 @@ #include "containers.h" #include "docvisitor.h" -#include -#include #include #include diff --git a/src/doctokenizer.h b/src/doctokenizer.h index 235b403..ec73e61 100644 --- a/src/doctokenizer.h +++ b/src/doctokenizer.h @@ -20,7 +20,6 @@ #define _DOCTOKENIZER_H #include -#include #include #include "htmlattrib.h" diff --git a/src/doctokenizer.l b/src/doctokenizer.l index 983b5fa..0c167ca 100644 --- a/src/doctokenizer.l +++ b/src/doctokenizer.l @@ -29,7 +29,6 @@ #include #include -#include #include #include "doctokenizer.h" diff --git a/src/doxygen.cpp b/src/doxygen.cpp index 34468be..f5a280b 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -19,15 +19,12 @@ #include #include #include -#include #include -#include #include #include #include #include #include -#include #include #include diff --git a/src/doxygen.h b/src/doxygen.h index 1f514b3..5c8ad1b 100644 --- a/src/doxygen.h +++ b/src/doxygen.h @@ -17,9 +17,6 @@ #define DOXYGEN_H #include -#include -#include -#include #include "containers.h" #include "ftextstream.h" diff --git a/src/fortranscanner.l b/src/fortranscanner.l index b3f1bae..74d6d03 100644 --- a/src/fortranscanner.l +++ b/src/fortranscanner.l @@ -56,11 +56,8 @@ #include #include -#include -#include #include #include -#include #include "fortranscanner.h" #include "entry.h" diff --git a/src/layout.h b/src/layout.h index 4a0ae8c..d319b69 100644 --- a/src/layout.h +++ b/src/layout.h @@ -21,7 +21,6 @@ #include #include -#include #include "types.h" class LayoutParser; diff --git a/src/memberdef.h b/src/memberdef.h index 39355db..7b27cff 100644 --- a/src/memberdef.h +++ b/src/memberdef.h @@ -21,7 +21,6 @@ #include #include -#include #include #include "types.h" diff --git a/src/membergroup.h b/src/membergroup.h index d9a392e..b258a04 100644 --- a/src/membergroup.h +++ b/src/membergroup.h @@ -22,7 +22,6 @@ #include #include -#include #include "types.h" #include "reflist.h" diff --git a/src/membername.h b/src/membername.h index 1a788af..2141d22 100644 --- a/src/membername.h +++ b/src/membername.h @@ -18,7 +18,6 @@ #ifndef MEMBERNAME_H #define MEMBERNAME_H -#include #include "memberdef.h" #include "linkedmap.h" diff --git a/src/perlmodgen.cpp b/src/perlmodgen.cpp index f3e11b9..20bd01b 100644 --- a/src/perlmodgen.cpp +++ b/src/perlmodgen.cpp @@ -21,7 +21,6 @@ #include #include -#include #include #include "perlmodgen.h" diff --git a/src/reflist.h b/src/reflist.h index 0ced63b..7f4473c 100644 --- a/src/reflist.h +++ b/src/reflist.h @@ -20,8 +20,7 @@ #include #include -#include -#include +#include #include "linkedmap.h" class Definition; diff --git a/src/scanner.l b/src/scanner.l index 66437bc..19381dd 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -37,7 +37,6 @@ #include #include -#include #include #include diff --git a/src/textdocvisitor.h b/src/textdocvisitor.h index c4ba3d7..e424529 100644 --- a/src/textdocvisitor.h +++ b/src/textdocvisitor.h @@ -1,13 +1,13 @@ /****************************************************************************** * - * + * * * * Copyright (C) 1997-2015 by Dimitri van Heesch. * * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software + * documentation under the terms of the GNU General Public License is hereby + * granted. No representations are made about the suitability of this software * for any purpose. It is provided "as is" without express or implied warranty. * See the GNU General Public License for more details. * @@ -21,7 +21,6 @@ #include "docvisitor.h" #include "docparser.h" -#include #include #include "ftextstream.h" @@ -31,11 +30,11 @@ class TextDocVisitor : public DocVisitor { public: TextDocVisitor(FTextStream &t) : DocVisitor(DocVisitor_Text), m_t(t) {} - + //-------------------------------------- // visitor functions for leaf nodes //-------------------------------------- - + void visit(DocWord *w) { filter(w->word()); } void visit(DocLinkedWord *w) { filter(w->word()); } void visit(DocWhiteSpace *) { m_t << " "; } @@ -57,7 +56,7 @@ class TextDocVisitor : public DocVisitor //-------------------------------------- // visitor functions for compound nodes //-------------------------------------- - + void visitPre(DocAutoList *) {} void visitPost(DocAutoList *) {} void visitPre(DocAutoListItem *) {} diff --git a/src/vhdljjparser.cpp b/src/vhdljjparser.cpp index 2d67ec6..b666f4c 100644 --- a/src/vhdljjparser.cpp +++ b/src/vhdljjparser.cpp @@ -12,7 +12,6 @@ #include #include -#include #include "containers.h" #include "vhdljjparser.h" #include "vhdldocgen.h" diff --git a/src/vhdljjparser.h b/src/vhdljjparser.h index 651221c..b074511 100755 --- a/src/vhdljjparser.h +++ b/src/vhdljjparser.h @@ -3,18 +3,16 @@ #include #include +#include +#include #include "parserintf.h" #include #include #include #include -#include -#include #include -#include -#include #include "types.h" #include "entry.h" #include "vhdldocgen.h" diff --git a/src/xmlgen.cpp b/src/xmlgen.cpp index e8bb9e7..d002295 100644 --- a/src/xmlgen.cpp +++ b/src/xmlgen.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include "xmlgen.h" #include "doxygen.h" @@ -59,55 +58,54 @@ //------------------ -/** Helper class mapping MemberList::ListType to a string representing */ -class XmlSectionMapper : public QIntDict +static std::map g_xmlSectionMap = { - public: - XmlSectionMapper() : QIntDict(47) - { - insert(MemberListType_pubTypes,"public-type"); - insert(MemberListType_pubMethods,"public-func"); - insert(MemberListType_pubAttribs,"public-attrib"); - insert(MemberListType_pubSlots,"public-slot"); - insert(MemberListType_signals,"signal"); - insert(MemberListType_dcopMethods,"dcop-func"); - insert(MemberListType_properties,"property"); - insert(MemberListType_events,"event"); - insert(MemberListType_interfaces,"interfaces"); - insert(MemberListType_services,"services"); - insert(MemberListType_pubStaticMethods,"public-static-func"); - insert(MemberListType_pubStaticAttribs,"public-static-attrib"); - insert(MemberListType_proTypes,"protected-type"); - insert(MemberListType_proMethods,"protected-func"); - insert(MemberListType_proAttribs,"protected-attrib"); - insert(MemberListType_proSlots,"protected-slot"); - insert(MemberListType_proStaticMethods,"protected-static-func"); - insert(MemberListType_proStaticAttribs,"protected-static-attrib"); - insert(MemberListType_pacTypes,"package-type"); - insert(MemberListType_pacMethods,"package-func"); - insert(MemberListType_pacAttribs,"package-attrib"); - insert(MemberListType_pacStaticMethods,"package-static-func"); - insert(MemberListType_pacStaticAttribs,"package-static-attrib"); - insert(MemberListType_priTypes,"private-type"); - insert(MemberListType_priMethods,"private-func"); - insert(MemberListType_priAttribs,"private-attrib"); - insert(MemberListType_priSlots,"private-slot"); - insert(MemberListType_priStaticMethods,"private-static-func"); - insert(MemberListType_priStaticAttribs,"private-static-attrib"); - insert(MemberListType_friends,"friend"); - insert(MemberListType_related,"related"); - insert(MemberListType_decDefineMembers,"define"); - insert(MemberListType_decProtoMembers,"prototype"); - insert(MemberListType_decTypedefMembers,"typedef"); - insert(MemberListType_decSequenceMembers,"sequence"); - insert(MemberListType_decDictionaryMembers,"dictionary"); - insert(MemberListType_decEnumMembers,"enum"); - insert(MemberListType_decFuncMembers,"func"); - insert(MemberListType_decVarMembers,"var"); - } + { MemberListType_pubTypes,"public-type" }, + { MemberListType_pubMethods,"public-func" }, + { MemberListType_pubAttribs,"public-attrib" }, + { MemberListType_pubSlots,"public-slot" }, + { MemberListType_signals,"signal" }, + { MemberListType_dcopMethods,"dcop-func" }, + { MemberListType_properties,"property" }, + { MemberListType_events,"event" }, + { MemberListType_interfaces,"interfaces" }, + { MemberListType_services,"services" }, + { MemberListType_pubStaticMethods,"public-static-func" }, + { MemberListType_pubStaticAttribs,"public-static-attrib" }, + { MemberListType_proTypes,"protected-type" }, + { MemberListType_proMethods,"protected-func" }, + { MemberListType_proAttribs,"protected-attrib" }, + { MemberListType_proSlots,"protected-slot" }, + { MemberListType_proStaticMethods,"protected-static-func" }, + { MemberListType_proStaticAttribs,"protected-static-attrib" }, + { MemberListType_pacTypes,"package-type" }, + { MemberListType_pacMethods,"package-func" }, + { MemberListType_pacAttribs,"package-attrib" }, + { MemberListType_pacStaticMethods,"package-static-func" }, + { MemberListType_pacStaticAttribs,"package-static-attrib" }, + { MemberListType_priTypes,"private-type" }, + { MemberListType_priMethods,"private-func" }, + { MemberListType_priAttribs,"private-attrib" }, + { MemberListType_priSlots,"private-slot" }, + { MemberListType_priStaticMethods,"private-static-func" }, + { MemberListType_priStaticAttribs,"private-static-attrib" }, + { MemberListType_friends,"friend" }, + { MemberListType_related,"related" }, + { MemberListType_decDefineMembers,"define" }, + { MemberListType_decProtoMembers,"prototype" }, + { MemberListType_decTypedefMembers,"typedef" }, + { MemberListType_decSequenceMembers,"sequence" }, + { MemberListType_decDictionaryMembers,"dictionary" }, + { MemberListType_decEnumMembers,"enum" }, + { MemberListType_decFuncMembers,"func" }, + { MemberListType_decVarMembers,"var" }, }; -static XmlSectionMapper g_xmlSectionMapper; +static const char *xmlSectionMapper(MemberListType ml) +{ + auto it = g_xmlSectionMap.find(ml); + return it!=g_xmlSectionMap.end() ? it->second.c_str() : ""; +} inline void writeXMLString(FTextStream &t,const char *s) @@ -1347,7 +1345,7 @@ static void generateXMLForClass(const ClassDef *cd,FTextStream &ti) { if ((ml->listType()&MemberListType_detailedLists)==0) { - generateXMLSection(cd,ti,t,ml.get(),g_xmlSectionMapper.find(ml->listType())); + generateXMLSection(cd,ti,t,ml.get(),xmlSectionMapper(ml->listType())); } } @@ -1444,7 +1442,7 @@ static void generateXMLForNamespace(const NamespaceDef *nd,FTextStream &ti) { if ((ml->listType()&MemberListType_declarationLists)!=0) { - generateXMLSection(nd,ti,t,ml.get(),g_xmlSectionMapper.find(ml->listType())); + generateXMLSection(nd,ti,t,ml.get(),xmlSectionMapper(ml->listType())); } } @@ -1558,7 +1556,7 @@ static void generateXMLForFile(FileDef *fd,FTextStream &ti) { if ((ml->listType()&MemberListType_declarationLists)!=0) { - generateXMLSection(fd,ti,t,ml.get(),g_xmlSectionMapper.find(ml->listType())); + generateXMLSection(fd,ti,t,ml.get(),xmlSectionMapper(ml->listType())); } } @@ -1631,7 +1629,7 @@ static void generateXMLForGroup(const GroupDef *gd,FTextStream &ti) { if ((ml->listType()&MemberListType_declarationLists)!=0) { - generateXMLSection(gd,ti,t,ml.get(),g_xmlSectionMapper.find(ml->listType())); + generateXMLSection(gd,ti,t,ml.get(),xmlSectionMapper(ml->listType())); } } -- cgit v0.12