Commit 20320915 authored by mjs's avatar mjs

* borrowed-classes.txt: Stopped borrowing QVector, QList,

	QCollection and QTL.

	Extended tests for QList, QSortedList (to test QList::sort more
	thoroughly) and QVector. Especially excercise autodeletion
	semantics and corner cases more thoroughly.

	* Tests/qt/qlist-test.chk:
	* Tests/qt/qlist-test.cpp: (operator<<), (main):
	* Tests/qt/qsortedlist-test.chk:
	* Tests/qt/qsortedlist-test.cpp: (main):
	* Tests/qt/qvector-test.chk:
	* Tests/qt/qvector-test.cpp: (operator<<), (printVectorNullTolerant), (main):

	* Tests/qt/qmap-test.cpp (CheckRedBlackRules): Tweak a bit to
	violate QMap's abstraction for glass-box testing.
WebCore:
	Reimplemented QList, QVector and QCollection from
	scratch. Implemented copy-on-write optimization for QMap.

	Minimally reimplement QCollection.

	* src/kwq/qt/qcollection.h:
	* src/kwq/KWQCollection.mm: (QCollection::QCollection), (QCollection::operator=),
	(QCollection::~QCollection), (QCollection::autoDelete),
	(QCollection::setAutoDelete):

	* src/kwq/qt/qdict.h, src/kwq/qt/qptrdict.h: Include
	qcollection.h, not _qcollection.h

	Reimplement QList as a doubly-linked list.

	* src/kwq/qt/qlist.h:
	* src/kwq/KWQListImpl.h:
	* src/kwq/KWQListImpl.mm: (KWQListImpl::KWQListPrivate::copyList),
	(KWQListImpl::KWQListPrivate::KWQListPrivate),
	(KWQListImpl::KWQListPrivate::~KWQListPrivate),
	(KWQListIteratorImpl::KWQListIteratorPrivate::KWQListIteratorPrivate),
	(KWQListImpl::KWQListImpl), (KWQListImpl::~KWQListImpl), (KWQListImpl::isEmpty),
	(KWQListImpl::count), (KWQListImpl::clear), (KWQListImpl::sort),
	(KWQListImpl::at), (KWQListImpl::insert), (KWQListImpl::remove),
	(KWQListImpl::removeFirst), (KWQListImpl::removeLast), (KWQListImpl::removeRef),
	(KWQListImpl::getLast), (KWQListImpl::current), (KWQListImpl::first),
	(KWQListImpl::last), (KWQListImpl::next), (KWQListImpl::prev),
	(KWQListImpl::take), (KWQListImpl::append), (KWQListImpl::prepend),
	(KWQListImpl::containsRef), (KWQListImpl::assign), (KWQListImpl::addIterator),
	(KWQListImpl::removeIterator), (KWQListIteratorImpl::KWQListIteratorImpl),
	(KWQListIteratorImpl::~KWQListIteratorImpl), (KWQListIteratorImpl::count),
	(KWQListIteratorImpl::toFirst), (KWQListIteratorImpl::toLast),
	(KWQListIteratorImpl::current), (KWQListIteratorImpl::operator--),
	(KWQListIteratorImpl::operator++), (KWQListIteratorImpl::operator=):

	Reimplement QVector in terms of CFArray.

	* src/kwq/qt/qvector.h:
	* src/kwq/KWQVectorImpl.h:
	* src/kwq/KWQVectorImpl.mm: (KWQVectorImpl::KWQVectorPrivate::KWQVectorPrivate),
	(KWQVectorImpl::KWQVectorPrivate::~KWQVectorPrivate),
	(KWQVectorImpl::KWQVectorImpl), (KWQVectorImpl::~KWQVectorImpl),
	(KWQVectorImpl::clear), (KWQVectorImpl::isEmpty), (KWQVectorImpl::count),
	(KWQVectorImpl::size), (KWQVectorImpl::remove), (KWQVectorImpl::resize),
	(KWQVectorImpl::insert), (KWQVectorImpl::at), (KWQVectorImpl::assign),
	(KWQVectorImpl::KWQVectorImpl::swap):

	Implemented copy-on-write optimization for QMap. This had the
	pleasant side effect of improving the separation between pointer
	manipulation and key/value manipulation.

	* src/kwq/qt/qmap.h:
	* src/kwq/KWQMapImpl.h:
	* src/kwq/KWQMapImpl.mm: (KWQMapImpl::KWQMapPrivate::KWQMapPrivate),
	(KWQMapImpl::KWQMapPrivate::~KWQMapPrivate), (KWQMapImpl::KWQMapImpl),
	(KWQMapImpl::~KWQMapImpl), (KWQMapImpl::copyOnWrite), (KWQMapImpl::copyTree),
	(KWQMapImpl::rebalanceAfterInsert), (KWQMapImpl::rebalanceAfterRemove),
	(KWQMapImpl::findInternal), (KWQMapImpl::insertInternal),
	(KWQMapImpl::removeInternal), (KWQMapImpl::swap), (KWQMapImpl::countInternal),
	(KWQMapImpl::clearInternal), (KWQMapImpl::beginInternal),
	(KWQMapImpl::endInternal):

	* src/kwq/Makefile.am: Add new files to build.

	* src/kdelibs/khtml/rendering/render_text.cpp
	(TextSlaveArray::findFirstMatching): Fix two places where the KDE
	code was depending on implementation details of QVector.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@612 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 78cf27d5
2002-02-12 Maciej Stachowiak <mjs@apple.com>
Reimplemented QList, QVector and QCollection from
scratch. Implemented copy-on-write optimization for QMap.
Minimally reimplement QCollection.
* src/kwq/qt/qcollection.h:
* src/kwq/KWQCollection.mm: (QCollection::QCollection), (QCollection::operator=),
(QCollection::~QCollection), (QCollection::autoDelete),
(QCollection::setAutoDelete):
* src/kwq/qt/qdict.h, src/kwq/qt/qptrdict.h: Include
qcollection.h, not _qcollection.h
Reimplement QList as a doubly-linked list.
* src/kwq/qt/qlist.h:
* src/kwq/KWQListImpl.h:
* src/kwq/KWQListImpl.mm: (KWQListImpl::KWQListPrivate::copyList),
(KWQListImpl::KWQListPrivate::KWQListPrivate),
(KWQListImpl::KWQListPrivate::~KWQListPrivate),
(KWQListIteratorImpl::KWQListIteratorPrivate::KWQListIteratorPrivate),
(KWQListImpl::KWQListImpl), (KWQListImpl::~KWQListImpl), (KWQListImpl::isEmpty),
(KWQListImpl::count), (KWQListImpl::clear), (KWQListImpl::sort),
(KWQListImpl::at), (KWQListImpl::insert), (KWQListImpl::remove),
(KWQListImpl::removeFirst), (KWQListImpl::removeLast), (KWQListImpl::removeRef),
(KWQListImpl::getLast), (KWQListImpl::current), (KWQListImpl::first),
(KWQListImpl::last), (KWQListImpl::next), (KWQListImpl::prev),
(KWQListImpl::take), (KWQListImpl::append), (KWQListImpl::prepend),
(KWQListImpl::containsRef), (KWQListImpl::assign), (KWQListImpl::addIterator),
(KWQListImpl::removeIterator), (KWQListIteratorImpl::KWQListIteratorImpl),
(KWQListIteratorImpl::~KWQListIteratorImpl), (KWQListIteratorImpl::count),
(KWQListIteratorImpl::toFirst), (KWQListIteratorImpl::toLast),
(KWQListIteratorImpl::current), (KWQListIteratorImpl::operator--),
(KWQListIteratorImpl::operator++), (KWQListIteratorImpl::operator=):
Reimplement QVector in terms of CFArray.
* src/kwq/qt/qvector.h:
* src/kwq/KWQVectorImpl.h:
* src/kwq/KWQVectorImpl.mm: (KWQVectorImpl::KWQVectorPrivate::KWQVectorPrivate),
(KWQVectorImpl::KWQVectorPrivate::~KWQVectorPrivate),
(KWQVectorImpl::KWQVectorImpl), (KWQVectorImpl::~KWQVectorImpl),
(KWQVectorImpl::clear), (KWQVectorImpl::isEmpty), (KWQVectorImpl::count),
(KWQVectorImpl::size), (KWQVectorImpl::remove), (KWQVectorImpl::resize),
(KWQVectorImpl::insert), (KWQVectorImpl::at), (KWQVectorImpl::assign),
(KWQVectorImpl::KWQVectorImpl::swap):
Implemented copy-on-write optimization for QMap. This had the
pleasant side effect of improving the separation between pointer
manipulation and key/value manipulation.
* src/kwq/qt/qmap.h:
* src/kwq/KWQMapImpl.h:
* src/kwq/KWQMapImpl.mm: (KWQMapImpl::KWQMapPrivate::KWQMapPrivate),
(KWQMapImpl::KWQMapPrivate::~KWQMapPrivate), (KWQMapImpl::KWQMapImpl),
(KWQMapImpl::~KWQMapImpl), (KWQMapImpl::copyOnWrite), (KWQMapImpl::copyTree),
(KWQMapImpl::rebalanceAfterInsert), (KWQMapImpl::rebalanceAfterRemove),
(KWQMapImpl::findInternal), (KWQMapImpl::insertInternal),
(KWQMapImpl::removeInternal), (KWQMapImpl::swap), (KWQMapImpl::countInternal),
(KWQMapImpl::clearInternal), (KWQMapImpl::beginInternal),
(KWQMapImpl::endInternal):
* src/kwq/Makefile.am: Add new files to build.
* src/kdelibs/khtml/rendering/render_text.cpp
(TextSlaveArray::findFirstMatching): Fix two places where the KDE
code was depending on implementation details of QVector.
2002-02-07 Richard Williamson <rjw@apple.com>
More changes to IFLocationChangeHandler API.
......
2002-02-12 Maciej Stachowiak <mjs@apple.com>
Reimplemented QList, QVector and QCollection from
scratch. Implemented copy-on-write optimization for QMap.
Minimally reimplement QCollection.
* src/kwq/qt/qcollection.h:
* src/kwq/KWQCollection.mm: (QCollection::QCollection), (QCollection::operator=),
(QCollection::~QCollection), (QCollection::autoDelete),
(QCollection::setAutoDelete):
* src/kwq/qt/qdict.h, src/kwq/qt/qptrdict.h: Include
qcollection.h, not _qcollection.h
Reimplement QList as a doubly-linked list.
* src/kwq/qt/qlist.h:
* src/kwq/KWQListImpl.h:
* src/kwq/KWQListImpl.mm: (KWQListImpl::KWQListPrivate::copyList),
(KWQListImpl::KWQListPrivate::KWQListPrivate),
(KWQListImpl::KWQListPrivate::~KWQListPrivate),
(KWQListIteratorImpl::KWQListIteratorPrivate::KWQListIteratorPrivate),
(KWQListImpl::KWQListImpl), (KWQListImpl::~KWQListImpl), (KWQListImpl::isEmpty),
(KWQListImpl::count), (KWQListImpl::clear), (KWQListImpl::sort),
(KWQListImpl::at), (KWQListImpl::insert), (KWQListImpl::remove),
(KWQListImpl::removeFirst), (KWQListImpl::removeLast), (KWQListImpl::removeRef),
(KWQListImpl::getLast), (KWQListImpl::current), (KWQListImpl::first),
(KWQListImpl::last), (KWQListImpl::next), (KWQListImpl::prev),
(KWQListImpl::take), (KWQListImpl::append), (KWQListImpl::prepend),
(KWQListImpl::containsRef), (KWQListImpl::assign), (KWQListImpl::addIterator),
(KWQListImpl::removeIterator), (KWQListIteratorImpl::KWQListIteratorImpl),
(KWQListIteratorImpl::~KWQListIteratorImpl), (KWQListIteratorImpl::count),
(KWQListIteratorImpl::toFirst), (KWQListIteratorImpl::toLast),
(KWQListIteratorImpl::current), (KWQListIteratorImpl::operator--),
(KWQListIteratorImpl::operator++), (KWQListIteratorImpl::operator=):
Reimplement QVector in terms of CFArray.
* src/kwq/qt/qvector.h:
* src/kwq/KWQVectorImpl.h:
* src/kwq/KWQVectorImpl.mm: (KWQVectorImpl::KWQVectorPrivate::KWQVectorPrivate),
(KWQVectorImpl::KWQVectorPrivate::~KWQVectorPrivate),
(KWQVectorImpl::KWQVectorImpl), (KWQVectorImpl::~KWQVectorImpl),
(KWQVectorImpl::clear), (KWQVectorImpl::isEmpty), (KWQVectorImpl::count),
(KWQVectorImpl::size), (KWQVectorImpl::remove), (KWQVectorImpl::resize),
(KWQVectorImpl::insert), (KWQVectorImpl::at), (KWQVectorImpl::assign),
(KWQVectorImpl::KWQVectorImpl::swap):
Implemented copy-on-write optimization for QMap. This had the
pleasant side effect of improving the separation between pointer
manipulation and key/value manipulation.
* src/kwq/qt/qmap.h:
* src/kwq/KWQMapImpl.h:
* src/kwq/KWQMapImpl.mm: (KWQMapImpl::KWQMapPrivate::KWQMapPrivate),
(KWQMapImpl::KWQMapPrivate::~KWQMapPrivate), (KWQMapImpl::KWQMapImpl),
(KWQMapImpl::~KWQMapImpl), (KWQMapImpl::copyOnWrite), (KWQMapImpl::copyTree),
(KWQMapImpl::rebalanceAfterInsert), (KWQMapImpl::rebalanceAfterRemove),
(KWQMapImpl::findInternal), (KWQMapImpl::insertInternal),
(KWQMapImpl::removeInternal), (KWQMapImpl::swap), (KWQMapImpl::countInternal),
(KWQMapImpl::clearInternal), (KWQMapImpl::beginInternal),
(KWQMapImpl::endInternal):
* src/kwq/Makefile.am: Add new files to build.
* src/kdelibs/khtml/rendering/render_text.cpp
(TextSlaveArray::findFirstMatching): Fix two places where the KDE
code was depending on implementation details of QVector.
2002-02-07 Richard Williamson <rjw@apple.com>
More changes to IFLocationChangeHandler API.
......
2002-02-12 Maciej Stachowiak <mjs@apple.com>
Reimplemented QList, QVector and QCollection from
scratch. Implemented copy-on-write optimization for QMap.
Minimally reimplement QCollection.
* src/kwq/qt/qcollection.h:
* src/kwq/KWQCollection.mm: (QCollection::QCollection), (QCollection::operator=),
(QCollection::~QCollection), (QCollection::autoDelete),
(QCollection::setAutoDelete):
* src/kwq/qt/qdict.h, src/kwq/qt/qptrdict.h: Include
qcollection.h, not _qcollection.h
Reimplement QList as a doubly-linked list.
* src/kwq/qt/qlist.h:
* src/kwq/KWQListImpl.h:
* src/kwq/KWQListImpl.mm: (KWQListImpl::KWQListPrivate::copyList),
(KWQListImpl::KWQListPrivate::KWQListPrivate),
(KWQListImpl::KWQListPrivate::~KWQListPrivate),
(KWQListIteratorImpl::KWQListIteratorPrivate::KWQListIteratorPrivate),
(KWQListImpl::KWQListImpl), (KWQListImpl::~KWQListImpl), (KWQListImpl::isEmpty),
(KWQListImpl::count), (KWQListImpl::clear), (KWQListImpl::sort),
(KWQListImpl::at), (KWQListImpl::insert), (KWQListImpl::remove),
(KWQListImpl::removeFirst), (KWQListImpl::removeLast), (KWQListImpl::removeRef),
(KWQListImpl::getLast), (KWQListImpl::current), (KWQListImpl::first),
(KWQListImpl::last), (KWQListImpl::next), (KWQListImpl::prev),
(KWQListImpl::take), (KWQListImpl::append), (KWQListImpl::prepend),
(KWQListImpl::containsRef), (KWQListImpl::assign), (KWQListImpl::addIterator),
(KWQListImpl::removeIterator), (KWQListIteratorImpl::KWQListIteratorImpl),
(KWQListIteratorImpl::~KWQListIteratorImpl), (KWQListIteratorImpl::count),
(KWQListIteratorImpl::toFirst), (KWQListIteratorImpl::toLast),
(KWQListIteratorImpl::current), (KWQListIteratorImpl::operator--),
(KWQListIteratorImpl::operator++), (KWQListIteratorImpl::operator=):
Reimplement QVector in terms of CFArray.
* src/kwq/qt/qvector.h:
* src/kwq/KWQVectorImpl.h:
* src/kwq/KWQVectorImpl.mm: (KWQVectorImpl::KWQVectorPrivate::KWQVectorPrivate),
(KWQVectorImpl::KWQVectorPrivate::~KWQVectorPrivate),
(KWQVectorImpl::KWQVectorImpl), (KWQVectorImpl::~KWQVectorImpl),
(KWQVectorImpl::clear), (KWQVectorImpl::isEmpty), (KWQVectorImpl::count),
(KWQVectorImpl::size), (KWQVectorImpl::remove), (KWQVectorImpl::resize),
(KWQVectorImpl::insert), (KWQVectorImpl::at), (KWQVectorImpl::assign),
(KWQVectorImpl::KWQVectorImpl::swap):
Implemented copy-on-write optimization for QMap. This had the
pleasant side effect of improving the separation between pointer
manipulation and key/value manipulation.
* src/kwq/qt/qmap.h:
* src/kwq/KWQMapImpl.h:
* src/kwq/KWQMapImpl.mm: (KWQMapImpl::KWQMapPrivate::KWQMapPrivate),
(KWQMapImpl::KWQMapPrivate::~KWQMapPrivate), (KWQMapImpl::KWQMapImpl),
(KWQMapImpl::~KWQMapImpl), (KWQMapImpl::copyOnWrite), (KWQMapImpl::copyTree),
(KWQMapImpl::rebalanceAfterInsert), (KWQMapImpl::rebalanceAfterRemove),
(KWQMapImpl::findInternal), (KWQMapImpl::insertInternal),
(KWQMapImpl::removeInternal), (KWQMapImpl::swap), (KWQMapImpl::countInternal),
(KWQMapImpl::clearInternal), (KWQMapImpl::beginInternal),
(KWQMapImpl::endInternal):
* src/kwq/Makefile.am: Add new files to build.
* src/kdelibs/khtml/rendering/render_text.cpp
(TextSlaveArray::findFirstMatching): Fix two places where the KDE
code was depending on implementation details of QVector.
2002-02-07 Richard Williamson <rjw@apple.com>
More changes to IFLocationChangeHandler API.
......
......@@ -265,7 +265,7 @@ int TextSlaveArray::findFirstMatching(Item d) const
if ( (*this)[mid] == 0 ) // null item greater
res = -1;
else
res = ((QGVector*)this)->compareItems( d, (*this)[mid] );
res = ((TextSlaveArray*)this)->compareItems( d, (*this)[mid] );
if ( res < 0 )
n2 = mid - 1;
else if ( res > 0 )
......@@ -278,7 +278,7 @@ int TextSlaveArray::findFirstMatching(Item d) const
/* if ( !found )
return -1; */
// search to first one equal or bigger
while ( found && (mid > 0) && !((QGVector*)this)->compareItems(d, (*this)[mid-1]) )
while ( found && (mid > 0) && !((TextSlaveArray*)this)->compareItems(d, (*this)[mid-1]) )
mid--;
return mid;
}
......
/****************************************************************************
** $Id$
**
** Definition of base class for all collection classes
**
** Created : 920629
**
** 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 QCOLLECTION_H
#define QCOLLECTION_H
#include <config.h>
#include <KWQDef.h>
#ifdef USING_BORROWED_QCOLLECTION
#include <_qcollection.h>
#else
class QCollection {
public:
typedef void *Item;
bool autoDelete();
void setAutoDelete(bool autoDelete);
protected:
QCollection();
QCollection(const QCollection &);
QCollection &operator=(const QCollection &);
virtual ~QCollection();
bool del_item; // default FALSE
};
#endif /* USING_BORROWED_QCOLLECTION */
#endif /* QCOLLECTION_H */
/*
* Copyright (C) 2001 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <qcollection.h>
#ifndef USING_BORROWED_QCOLLECTION
QCollection::QCollection() :
del_item(FALSE)
{
}
QCollection::QCollection(const QCollection &other) :
del_item(FALSE)
{
}
QCollection &QCollection::operator=(const QCollection &other)
{
return *this; // don't copy del_item
}
QCollection::~QCollection()
{
}
bool QCollection::autoDelete()
{
return del_item;
}
void QCollection::setAutoDelete(bool autoDelete)
{
del_item = autoDelete;
}
#endif
......@@ -39,7 +39,7 @@
#else
#include <_qcollection.h>
#include <qcollection.h>
#include <qstring.h>
#include <KWQDictImpl.h>
......
/*
* Copyright (C) 2001 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef KWQ_LIST_IMPL_H
#define KWQ_LIST_IMPL_H
#include <config.h>
#include <KWQDef.h>
#ifndef USING_BORROWED_QLIST
class KWQListIteratorImpl;
class KWQListImpl
{
public:
KWQListImpl(void (*deleteFunc)(void *));
KWQListImpl(const KWQListImpl &impl);
~KWQListImpl();
bool isEmpty() const;
uint count() const;
void clear(bool deleteItems);
void sort(int (*compareFunc)(void *a, void *b, void *data), void *data);
void *at(uint n);
bool insert(uint n, const void *item);
bool remove(bool deleteItem);
bool remove(uint n, bool deleteItem);
bool remove(const void *item, bool deleteItem, int (*compareFunc)(void *a, void *b, void *data), void *data);
bool removeFirst(bool deleteItem);
bool removeLast(bool deleteItem);
bool removeRef(const void *item, bool deleteItem);
void *getLast() const;
void *current() const;
void *first();
void *last();
void *next();
void *prev();
void *take(uint n);
void append(const void *item);
void prepend(const void *item);
uint containsRef(const void *item) const;
KWQListImpl &assign(const KWQListImpl &impl, bool deleteItems);
private:
void addIterator(KWQListIteratorImpl *iter) const;
void removeIterator(KWQListIteratorImpl *iter) const;
class KWQListPrivate;
KWQListPrivate *d;
friend class KWQListIteratorImpl;
};
class KWQListIteratorImpl {
public:
KWQListIteratorImpl();
KWQListIteratorImpl(const KWQListImpl &impl);
KWQListIteratorImpl(const KWQListIteratorImpl &impl);
~KWQListIteratorImpl();
uint count() const;
void *toFirst();
void *toLast();
void *current() const;
// operators ---------------------------------------------------------------
void *operator--();
void *operator++();
KWQListIteratorImpl &operator=(const KWQListIteratorImpl &impl);
private:
class KWQListIteratorPrivate;
KWQListIteratorPrivate *d;
friend class KWQListImpl;
};
#endif
#endif
/*
* Copyright (C) 2001 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <KWQListImpl.h>
#ifndef USING_BORROWED_QLIST
#include <cstddef>
#define Fixed MacFixed
#define Rect MacRect
#define Boolean MacBoolean
#include <CoreFoundation/CFArray.h>
#undef Fixed
#undef Rect
#undef Boolean
// KWQListNode
class KWQListNode
{
public:
KWQListNode() : data(NULL), next(NULL), prev(NULL) {}
void *data;
KWQListNode *next;
KWQListNode *prev;
};
// KWQListImpl::KWQListPrivate
class KWQListImpl::KWQListPrivate
{
public:
KWQListPrivate(void (*deleteFunc)(void *));
KWQListPrivate(KWQListPrivate &vp);
~KWQListPrivate();
static KWQListNode *copyList(KWQListNode *l);
KWQListNode *head;
// KWQListNode *tail;
KWQListNode *current;
uint count;
void (*deleteItem)(void *);
KWQListNode *iterators;
};
KWQListNode *KWQListImpl::KWQListPrivate::copyList(KWQListNode *l)
{
KWQListNode *node = l;
KWQListNode *head = NULL;
KWQListNode *last = NULL;
while (node != NULL) {
KWQListNode *copy = new KWQListNode;
copy->data = node->data;
if (last != NULL) {
last->next = copy;
copy->prev = last;
} else {
head = copy;
copy->prev = NULL;
}
copy->next = NULL;
last = copy;
node = node->next;
}
return head;
}
KWQListImpl::KWQListPrivate::KWQListPrivate(void (*deleteFunc)(void *)) :
head(NULL),
current(NULL),
count(0),
deleteItem(deleteFunc),
iterators(NULL)
{
}
KWQListImpl::KWQListPrivate::KWQListPrivate(KWQListPrivate &vp) :
head(copyList(vp.head)),
current(NULL),
count(vp.count),
deleteItem(vp.deleteItem),
iterators(NULL)
{
}
KWQListImpl::KWQListPrivate::~KWQListPrivate()
{
while (head != NULL) {
KWQListNode *tmp = head->next;
delete head;
head = tmp;
}
}
// KWQListIteratorImpl::KWQListIteratorPrivate
class KWQListIteratorImpl::KWQListIteratorPrivate
{
public:
KWQListIteratorPrivate();
KWQListIteratorPrivate(const KWQListImpl &list, KWQListNode *n);
const KWQListImpl *list;
KWQListNode *node;
};
KWQListIteratorImpl::KWQListIteratorPrivate::KWQListIteratorPrivate() :
list(NULL),
node(NULL)
{
}
KWQListIteratorImpl::KWQListIteratorPrivate::KWQListIteratorPrivate(const KWQListImpl &l, KWQListNode *n) :
list(&l),