Skip to content

Commit

Permalink
Reduced and improved functionality of QList
Browse files Browse the repository at this point in the history
- operations on current index and node (next(), prev(), last(), first()) have been removed.
- access to internal nodes has been removed.
- old QList has been renamed to QInternalList for use inside qtools only.
- added type safe compare, new, and delete operations (compareValues(), newValue(), deleteValue()).
- add compareValues also to QDict for consistency.
- changed doxygen's implementation to comply with the new QList and QDict interface.
  • Loading branch information
Dimitri van Heesch committed Dec 30, 2013
1 parent 744d1ca commit 6e51abf
Show file tree
Hide file tree
Showing 70 changed files with 1,087 additions and 962 deletions.
4 changes: 2 additions & 2 deletions qtools/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = NO
CLASS_DIAGRAMS = YES
MSCGEN_PATH =
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = YES
HAVE_DOT = NO
DOT_NUM_THREADS = 0
DOT_FONTNAME =
DOT_FONTSIZE = 10
Expand Down
20 changes: 17 additions & 3 deletions qtools/qdict.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

#else

template<class type> class Q_EXPORT QDict : public QGDict
template<class type> class Q_EXPORT QDict : private QGDict
{
public:
QDict(int size=17, bool caseSensitive=TRUE)
Expand All @@ -61,26 +61,40 @@ template<class type> class Q_EXPORT QDict : public QGDict
~QDict() { clear(); }
QDict<type> &operator=(const QDict<type> &d)
{ return (QDict<type>&)QGDict::operator=(d); }

// capacity
uint count() const { return QGDict::count(); }
uint size() const { return QGDict::size(); }
bool isEmpty() const { return QGDict::count() == 0; }

// modifiers
void insert( const QString &k, const type *d )
{ QGDict::look_string(k,(Item)d,1); }
void replace( const QString &k, const type *d )
{ QGDict::look_string(k,(Item)d,2); }
bool remove( const QString &k ) { return QGDict::remove_string(k); }
type *take( const QString &k ) { return (type *)QGDict::take_string(k); }
void clear() { QGDict::clear(); }
void resize( uint n ) { QGDict::resize(n); }

// search
type *find( const QString &k ) const
{ return (type *)((QGDict*)this)->QGDict::look_string(k,0,0); }
type *operator[]( const QString &k ) const
{ return (type *)((QGDict*)this)->QGDict::look_string(k,0,0); }

void clear() { QGDict::clear(); }
void resize( uint n ) { QGDict::resize(n); }
// operations
void statistics() const { QGDict::statistics(); }
private:
void deleteItem( Item d );

// new to be reimplemented methods
virtual int compareValues(const type *t1,const type *t2) const
{ return const_cast<QDict<type>*>(this)->QGDict::compareItems((QCollection::Item)t1,(QCollection::Item)t2); }

// reimplemented methods
virtual int compareItems(QCollection::Item i1,QCollection::Item i2)
{ return compareValues((const type*)i1,(const type*)i2); }
};

#if defined(Q_DELETING_VOID_UNDEFINED)
Expand Down
4 changes: 2 additions & 2 deletions qtools/qdir.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
#endif // QT_H

#ifndef QT_NO_DIR
typedef QList<QFileInfo> QFileInfoList;
typedef QListIterator<QFileInfo> QFileInfoListIterator;
typedef QInternalList<QFileInfo> QFileInfoList;
typedef QInternalListIterator<QFileInfo> QFileInfoListIterator;
class QStringList;


Expand Down
26 changes: 13 additions & 13 deletions qtools/qgcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
**********************************************************************/

#include "qgcache.h"
#include "qlist.h"
#include "qinternallist.h"
#include "qdict.h"
#include "qstring.h"

Expand Down Expand Up @@ -73,7 +73,7 @@ struct QCacheItem
QCList class (internal list of cache items)
*****************************************************************************/

class QCList : private QList<QCacheItem>
class QCList : private QInternalList<QCacheItem>
{
friend class QGCacheIterator;
friend class QCListIt;
Expand All @@ -88,13 +88,13 @@ friend class QCListIt;

void setAutoDelete( bool del ) { QCollection::setAutoDelete(del); }

bool removeFirst() { return QList<QCacheItem>::removeFirst(); }
bool removeLast() { return QList<QCacheItem>::removeLast(); }
bool removeFirst() { return QInternalList<QCacheItem>::removeFirst(); }
bool removeLast() { return QInternalList<QCacheItem>::removeLast(); }

QCacheItem *first() { return QList<QCacheItem>::first(); }
QCacheItem *last() { return QList<QCacheItem>::last(); }
QCacheItem *prev() { return QList<QCacheItem>::prev(); }
QCacheItem *next() { return QList<QCacheItem>::next(); }
QCacheItem *first() { return QInternalList<QCacheItem>::first(); }
QCacheItem *last() { return QInternalList<QCacheItem>::last(); }
QCacheItem *prev() { return QInternalList<QCacheItem>::prev(); }
QCacheItem *next() { return QInternalList<QCacheItem>::next(); }

#if defined(DEBUG)
int inserts; // variables for statistics
Expand Down Expand Up @@ -125,7 +125,7 @@ void QCList::insert( QCacheItem *ci )
item = next();
}
if ( item )
QList<QCacheItem>::insert( at(), ci );
QInternalList<QCacheItem>::insert( at(), ci );
else
append( ci );
#if defined(DEBUG)
Expand All @@ -136,7 +136,7 @@ void QCList::insert( QCacheItem *ci )

inline void QCList::insert( int i, QCacheItem *ci )
{
QList<QCacheItem>::insert( i, ci );
QInternalList<QCacheItem>::insert( i, ci );
#if defined(DEBUG)
ASSERT( ci->node == 0 );
#endif
Expand Down Expand Up @@ -166,11 +166,11 @@ inline void QCList::reference( QCacheItem *ci )
}


class QCListIt: public QListIterator<QCacheItem>
class QCListIt: public QInternalListIterator<QCacheItem>
{
public:
QCListIt( const QCList *p ): QListIterator<QCacheItem>( *p ) {}
QCListIt( const QCListIt *p ): QListIterator<QCacheItem>( *p ) {}
QCListIt( const QCList *p ): QInternalListIterator<QCacheItem>( *p ) {}
QCListIt( const QCListIt *p ): QInternalListIterator<QCacheItem>( *p ) {}
};


Expand Down
10 changes: 5 additions & 5 deletions qtools/qgdict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
**********************************************************************/

#include "qgdict.h"
#include "qlist.h"
#include "qinternallist.h"
#include "qstring.h"
#include "qdatastream.h"
#include <ctype.h>
Expand All @@ -63,14 +63,14 @@ static const int op_insert = 1;
static const int op_replace = 2;


class QGDItList : public QList<QGDictIterator>
class QGDItList : public QInternalList<QGDictIterator>
{
public:
QGDItList() : QList<QGDictIterator>() {}
QGDItList( const QGDItList &list ) : QList<QGDictIterator>(list) {}
QGDItList() : QInternalList<QGDictIterator>() {}
QGDItList( const QGDItList &list ) : QInternalList<QGDictIterator>(list) {}
~QGDItList() { clear(); }
QGDItList &operator=(const QGDItList &list)
{ return (QGDItList&)QList<QGDictIterator>::operator=(list); }
{ return (QGDItList&)QInternalList<QGDictIterator>::operator=(list); }
};


Expand Down
139 changes: 139 additions & 0 deletions qtools/qinternallist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/****************************************************************************
**
**
** Definition of QList template/macro class
**
** Created : 920701
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
** licenses may use this file in accordance with the Qt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/

#ifndef QINTERNALLIST_H
#define QINTERNALLIST_H

#ifndef QT_H
#include "qglist.h"
#endif // QT_H


template<class type> class Q_EXPORT QInternalList : public QGList
{
public:
QInternalList() {}
QInternalList( const QInternalList<type> &l ) : QGList(l) {}
~QInternalList() { clear(); }
QInternalList<type> &operator=(const QInternalList<type> &l)
{ return (QInternalList<type>&)QGList::operator=(l); }
bool operator==( const QInternalList<type> &list ) const
{ return QGList::operator==( list ); }
uint count() const { return QGList::count(); }
bool isEmpty() const { return QGList::count() == 0; }
bool insert( uint i, const type *d){ return QGList::insertAt(i,(QCollection::Item)d); }
void inSort( const type *d ) { QGList::inSort((QCollection::Item)d); }
void prepend( const type *d ) { QGList::insertAt(0,(QCollection::Item)d); }
void append( const type *d ) { QGList::append((QCollection::Item)d); }
bool remove( uint i ) { return QGList::removeAt(i); }
bool remove() { return QGList::remove((QCollection::Item)0); }
bool remove( const type *d ) { return QGList::remove((QCollection::Item)d); }
bool removeRef( const type *d ) { return QGList::removeRef((QCollection::Item)d); }
void removeNode( QLNode *n ) { QGList::removeNode(n); }
bool removeFirst() { return QGList::removeFirst(); }
bool removeLast() { return QGList::removeLast(); }
type *take( uint i ) { return (type *)QGList::takeAt(i); }
type *take() { return (type *)QGList::take(); }
type *takeNode( QLNode *n ) { return (type *)QGList::takeNode(n); }
void clear() { QGList::clear(); }
void sort() { QGList::sort(); }
int find( const type *d ) { return QGList::find((QCollection::Item)d); }
int findNext( const type *d ) { return QGList::find((QCollection::Item)d,FALSE); }
int findRef( const type *d ) { return QGList::findRef((QCollection::Item)d); }
int findNextRef( const type *d ){ return QGList::findRef((QCollection::Item)d,FALSE);}
uint contains( const type *d ) const { return QGList::contains((QCollection::Item)d); }
uint containsRef( const type *d ) const
{ return QGList::containsRef((QCollection::Item)d); }
type *at( uint i ) { return (type *)QGList::at(i); }
int at() const { return QGList::at(); }
type *current() const { return (type *)QGList::get(); }
QLNode *currentNode() const { return QGList::currentNode(); }
type *getFirst() const { return (type *)QGList::cfirst(); }
type *getLast() const { return (type *)QGList::clast(); }
type *first() { return (type *)QGList::first(); }
type *last() { return (type *)QGList::last(); }
type *next() { return (type *)QGList::next(); }
type *prev() { return (type *)QGList::prev(); }
void toVector( QGVector *vec )const{ QGList::toVector(vec); }
private:
void deleteItem( QCollection::Item d );
};

#if defined(Q_DELETING_VOID_UNDEFINED)
template<> inline void QInternalList<void>::deleteItem( QCollection::Item )
{
}
#endif

template<class type> inline void QInternalList<type>::deleteItem( QCollection::Item d )
{
if ( del_item ) delete (type *)d;
}


template<class type> class Q_EXPORT QInternalListIterator : public QGListIterator
{
public:
QInternalListIterator(const QInternalList<type> &l) :QGListIterator((QGList &)l) {}
~QInternalListIterator() {}
uint count() const { return list->count(); }
bool isEmpty() const { return list->count() == 0; }
bool atFirst() const { return QGListIterator::atFirst(); }
bool atLast() const { return QGListIterator::atLast(); }
type *toFirst() { return (type *)QGListIterator::toFirst(); }
type *toLast() { return (type *)QGListIterator::toLast(); }
operator type *() const { return (type *)QGListIterator::get(); }
type *operator*() { return (type *)QGListIterator::get(); }

// No good, since QList<char> (ie. QStrList fails...
//
// MSVC++ gives warning
// Sunpro C++ 4.1 gives error
// type *operator->() { return (type *)QGListIterator::get(); }

type *current() const { return (type *)QGListIterator::get(); }
type *operator()() { return (type *)QGListIterator::operator()();}
type *operator++() { return (type *)QGListIterator::operator++(); }
type *operator+=(uint j) { return (type *)QGListIterator::operator+=(j);}
type *operator--() { return (type *)QGListIterator::operator--(); }
type *operator-=(uint j) { return (type *)QGListIterator::operator-=(j);}
QInternalListIterator<type>& operator=(const QInternalListIterator<type>&it)
{ QGListIterator::operator=(it); return *this; }
};


#endif // QINTERNALLIST_H
Loading

0 comments on commit 6e51abf

Please sign in to comment.