[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
mjs
mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 05:54:34 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 00468a10e7eb86d76dc14ed75184b53577bf704f
Author: mjs <mjs at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Tue Jan 29 11:49:41 2002 +0000
Top level:
* borrowed-classes.txt: Stop borrowing QMap, QDict, QPtrDict and
QSortedList.
Added the usual bunch of new test cases, especially for QMap,
where we also do some glassbox testing and check Red/Black tree
invariant consistency.
* Tests/qt/qdict-test.chk:
* Tests/qt/qdict-test.cpp: (operator<<), (main):
* Tests/qt/qmap-test.chk:
* Tests/qt/qmap-test.cpp: (CheckRedBlackRulesAtNode), (CheckRedBlackRules),
(main):
* Tests/qt/qptrdict-test.chk:
* Tests/qt/qptrdict-test.cpp: (operator<<), (main):
* Tests/test.list:
WebCore:
Reimplement QDict, QMap, QPtrDict and QSortedList.
Reimplement QDict in terms of CFDictionary:
* src/kwq/qt/qdict.h:
* src/kwq/KWQDictImpl.h:
* src/kwq/KWQDictImpl.mm: (KWQDictImpl::KWQDictImpl), (KWQDictImpl::insert),
(KWQDictImpl::remove), (KWQDictImpl::find),
(KWQDictIteratorImpl::KWQDictIteratorImpl),
(KWQDictIteratorImpl::currentStringKey):
Reimplement QMap as a right-threaded red-black tree, splitting
the work between template classes that manipulate keys and values
and non-template base classes that handle all the pointer
manipulation:
* src/kwq/qt/qmap.h:
* src/kwq/KWQMapImpl.h:
* src/kwq/KWQMapImpl.mm: (KWQMapNodeImpl::KWQMapNodeImpl),
(KWQMapNodeImpl::left), (KWQMapNodeImpl::right), (KWQMapNodeImpl::predecessor),
(KWQMapNodeImpl::successor), (KWQMapIteratorImpl::KWQMapIteratorImpl),
(KWQMapIteratorImpl::incrementInternal), (KWQMapImpl::KWQMapImpl),
(KWQMapImpl::rotateRight), (KWQMapImpl::rotateLeft),
(KWQMapImpl::rebalanceAfterInsert), (KWQMapImpl::rebalanceAfterRemove),
(KWQMapImpl::findInternal), (KWQMapImpl::insertInternal),
(KWQMapImpl::removeInternal), (KWQMapImpl::swap), (KWQMapImpl::countInternal),
(KWQMapImpl::clearInternal), (KWQMapImpl::beginInternal),
(KWQMapImpl::endInternal):
Reimplement QPtrDict in terms of CFDictionary:
* src/kwq/qt/qptrdict.h:
* src/kwq/KWQPtrDictImpl.h:
* src/kwq/KWQPtrDictImpl.mm:
(KWQPtrDictImpl::KWQPtrDictPrivate::KWQPtrDictPrivate),
(KWQPtrDictImpl::KWQPtrDictPrivate::~KWQPtrDictPrivate),
(KWQPtrDictImpl::KWQPtrDictImpl), (KWQPtrDictImpl::~KWQPtrDictImpl),
(invokeDeleteFuncOnValue), (KWQPtrDictImpl::clear), (KWQPtrDictImpl::count),
(KWQPtrDictImpl::insert), (KWQPtrDictImpl::remove), (KWQPtrDictImpl::find),
(KWQPtrDictImpl::swap), (KWQPtrDictImpl::assign), (KWQPtrDictImpl::take),
(KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate::KWQPtrDictIteratorPrivate),
(KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate::~KWQPtrDictIteratorPrivate),
(KWQPtrDictIteratorImpl::KWQPtrDictIteratorImpl),
(KWQPtrDictIteratorImpl::~KWQPtrDictIteratorImpl),
(KWQPtrDictIteratorImpl::count), (KWQPtrDictIteratorImpl::current),
(KWQPtrDictIteratorImpl::currentKey), (KWQPtrDictIteratorImpl::toFirst),
(KWQPtrDictIteratorImpl::operator++):
Reimplement QSortedList:
* src/kwq/qt/qsortedlist.h:
* src/kwq/KWQArrayImpl.mm: Remove stray include.
* src/kwq/Makefile.am: Add new files to build.
* src/kwq/qt/_qdict.h, src/kwq/qt/_qgdict.h,
src/kwq/qt/_qptrdict.h: Avoid causing problems when the relevant
defines are not defined.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@556 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog-2002-12-03 b/WebCore/ChangeLog-2002-12-03
index 619a7b1..7f1361b 100644
--- a/WebCore/ChangeLog-2002-12-03
+++ b/WebCore/ChangeLog-2002-12-03
@@ -1,3 +1,65 @@
+2002-01-29 Maciej Stachowiak <mjs at apple.com>
+
+ Reimplement QDict, QMap, QPtrDict and QSortedList.
+
+ Reimplement QDict in terms of CFDictionary:
+
+ * src/kwq/qt/qdict.h:
+ * src/kwq/KWQDictImpl.h:
+ * src/kwq/KWQDictImpl.mm: (KWQDictImpl::KWQDictImpl), (KWQDictImpl::insert),
+ (KWQDictImpl::remove), (KWQDictImpl::find),
+ (KWQDictIteratorImpl::KWQDictIteratorImpl),
+ (KWQDictIteratorImpl::currentStringKey):
+
+ Reimplement QMap as a right-threaded red-black tree, splitting
+ the work between template classes that manipulate keys and values
+ and non-template base classes that handle all the pointer
+ manipulation:
+
+ * src/kwq/qt/qmap.h:
+ * src/kwq/KWQMapImpl.h:
+ * src/kwq/KWQMapImpl.mm: (KWQMapNodeImpl::KWQMapNodeImpl),
+ (KWQMapNodeImpl::left), (KWQMapNodeImpl::right), (KWQMapNodeImpl::predecessor),
+ (KWQMapNodeImpl::successor), (KWQMapIteratorImpl::KWQMapIteratorImpl),
+ (KWQMapIteratorImpl::incrementInternal), (KWQMapImpl::KWQMapImpl),
+ (KWQMapImpl::rotateRight), (KWQMapImpl::rotateLeft),
+ (KWQMapImpl::rebalanceAfterInsert), (KWQMapImpl::rebalanceAfterRemove),
+ (KWQMapImpl::findInternal), (KWQMapImpl::insertInternal),
+ (KWQMapImpl::removeInternal), (KWQMapImpl::swap), (KWQMapImpl::countInternal),
+ (KWQMapImpl::clearInternal), (KWQMapImpl::beginInternal),
+ (KWQMapImpl::endInternal):
+
+ Reimplement QPtrDict in terms of CFDictionary:
+
+ * src/kwq/qt/qptrdict.h:
+ * src/kwq/KWQPtrDictImpl.h:
+ * src/kwq/KWQPtrDictImpl.mm:
+ (KWQPtrDictImpl::KWQPtrDictPrivate::KWQPtrDictPrivate),
+ (KWQPtrDictImpl::KWQPtrDictPrivate::~KWQPtrDictPrivate),
+ (KWQPtrDictImpl::KWQPtrDictImpl), (KWQPtrDictImpl::~KWQPtrDictImpl),
+ (invokeDeleteFuncOnValue), (KWQPtrDictImpl::clear), (KWQPtrDictImpl::count),
+ (KWQPtrDictImpl::insert), (KWQPtrDictImpl::remove), (KWQPtrDictImpl::find),
+ (KWQPtrDictImpl::swap), (KWQPtrDictImpl::assign), (KWQPtrDictImpl::take),
+ (KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate::KWQPtrDictIteratorPrivate),
+ (KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate::~KWQPtrDictIteratorPrivate),
+ (KWQPtrDictIteratorImpl::KWQPtrDictIteratorImpl),
+ (KWQPtrDictIteratorImpl::~KWQPtrDictIteratorImpl),
+ (KWQPtrDictIteratorImpl::count), (KWQPtrDictIteratorImpl::current),
+ (KWQPtrDictIteratorImpl::currentKey), (KWQPtrDictIteratorImpl::toFirst),
+ (KWQPtrDictIteratorImpl::operator++):
+
+ Reimplement QSortedList:
+
+ * src/kwq/qt/qsortedlist.h:
+
+ * src/kwq/KWQArrayImpl.mm: Remove stray include.
+
+ * src/kwq/Makefile.am: Add new files to build.
+
+ * src/kwq/qt/_qdict.h, src/kwq/qt/_qgdict.h,
+ src/kwq/qt/_qptrdict.h: Avoid causing problems when the relevant
+ defines are not defined.
+
2002-01-22 Richard Williamson <rjw at apple.com>
Implemented KWQDesktopWidget to represent main screen. Used by javascript.
diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index 619a7b1..7f1361b 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,65 @@
+2002-01-29 Maciej Stachowiak <mjs at apple.com>
+
+ Reimplement QDict, QMap, QPtrDict and QSortedList.
+
+ Reimplement QDict in terms of CFDictionary:
+
+ * src/kwq/qt/qdict.h:
+ * src/kwq/KWQDictImpl.h:
+ * src/kwq/KWQDictImpl.mm: (KWQDictImpl::KWQDictImpl), (KWQDictImpl::insert),
+ (KWQDictImpl::remove), (KWQDictImpl::find),
+ (KWQDictIteratorImpl::KWQDictIteratorImpl),
+ (KWQDictIteratorImpl::currentStringKey):
+
+ Reimplement QMap as a right-threaded red-black tree, splitting
+ the work between template classes that manipulate keys and values
+ and non-template base classes that handle all the pointer
+ manipulation:
+
+ * src/kwq/qt/qmap.h:
+ * src/kwq/KWQMapImpl.h:
+ * src/kwq/KWQMapImpl.mm: (KWQMapNodeImpl::KWQMapNodeImpl),
+ (KWQMapNodeImpl::left), (KWQMapNodeImpl::right), (KWQMapNodeImpl::predecessor),
+ (KWQMapNodeImpl::successor), (KWQMapIteratorImpl::KWQMapIteratorImpl),
+ (KWQMapIteratorImpl::incrementInternal), (KWQMapImpl::KWQMapImpl),
+ (KWQMapImpl::rotateRight), (KWQMapImpl::rotateLeft),
+ (KWQMapImpl::rebalanceAfterInsert), (KWQMapImpl::rebalanceAfterRemove),
+ (KWQMapImpl::findInternal), (KWQMapImpl::insertInternal),
+ (KWQMapImpl::removeInternal), (KWQMapImpl::swap), (KWQMapImpl::countInternal),
+ (KWQMapImpl::clearInternal), (KWQMapImpl::beginInternal),
+ (KWQMapImpl::endInternal):
+
+ Reimplement QPtrDict in terms of CFDictionary:
+
+ * src/kwq/qt/qptrdict.h:
+ * src/kwq/KWQPtrDictImpl.h:
+ * src/kwq/KWQPtrDictImpl.mm:
+ (KWQPtrDictImpl::KWQPtrDictPrivate::KWQPtrDictPrivate),
+ (KWQPtrDictImpl::KWQPtrDictPrivate::~KWQPtrDictPrivate),
+ (KWQPtrDictImpl::KWQPtrDictImpl), (KWQPtrDictImpl::~KWQPtrDictImpl),
+ (invokeDeleteFuncOnValue), (KWQPtrDictImpl::clear), (KWQPtrDictImpl::count),
+ (KWQPtrDictImpl::insert), (KWQPtrDictImpl::remove), (KWQPtrDictImpl::find),
+ (KWQPtrDictImpl::swap), (KWQPtrDictImpl::assign), (KWQPtrDictImpl::take),
+ (KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate::KWQPtrDictIteratorPrivate),
+ (KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate::~KWQPtrDictIteratorPrivate),
+ (KWQPtrDictIteratorImpl::KWQPtrDictIteratorImpl),
+ (KWQPtrDictIteratorImpl::~KWQPtrDictIteratorImpl),
+ (KWQPtrDictIteratorImpl::count), (KWQPtrDictIteratorImpl::current),
+ (KWQPtrDictIteratorImpl::currentKey), (KWQPtrDictIteratorImpl::toFirst),
+ (KWQPtrDictIteratorImpl::operator++):
+
+ Reimplement QSortedList:
+
+ * src/kwq/qt/qsortedlist.h:
+
+ * src/kwq/KWQArrayImpl.mm: Remove stray include.
+
+ * src/kwq/Makefile.am: Add new files to build.
+
+ * src/kwq/qt/_qdict.h, src/kwq/qt/_qgdict.h,
+ src/kwq/qt/_qptrdict.h: Avoid causing problems when the relevant
+ defines are not defined.
+
2002-01-22 Richard Williamson <rjw at apple.com>
Implemented KWQDesktopWidget to represent main screen. Used by javascript.
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 619a7b1..7f1361b 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,65 @@
+2002-01-29 Maciej Stachowiak <mjs at apple.com>
+
+ Reimplement QDict, QMap, QPtrDict and QSortedList.
+
+ Reimplement QDict in terms of CFDictionary:
+
+ * src/kwq/qt/qdict.h:
+ * src/kwq/KWQDictImpl.h:
+ * src/kwq/KWQDictImpl.mm: (KWQDictImpl::KWQDictImpl), (KWQDictImpl::insert),
+ (KWQDictImpl::remove), (KWQDictImpl::find),
+ (KWQDictIteratorImpl::KWQDictIteratorImpl),
+ (KWQDictIteratorImpl::currentStringKey):
+
+ Reimplement QMap as a right-threaded red-black tree, splitting
+ the work between template classes that manipulate keys and values
+ and non-template base classes that handle all the pointer
+ manipulation:
+
+ * src/kwq/qt/qmap.h:
+ * src/kwq/KWQMapImpl.h:
+ * src/kwq/KWQMapImpl.mm: (KWQMapNodeImpl::KWQMapNodeImpl),
+ (KWQMapNodeImpl::left), (KWQMapNodeImpl::right), (KWQMapNodeImpl::predecessor),
+ (KWQMapNodeImpl::successor), (KWQMapIteratorImpl::KWQMapIteratorImpl),
+ (KWQMapIteratorImpl::incrementInternal), (KWQMapImpl::KWQMapImpl),
+ (KWQMapImpl::rotateRight), (KWQMapImpl::rotateLeft),
+ (KWQMapImpl::rebalanceAfterInsert), (KWQMapImpl::rebalanceAfterRemove),
+ (KWQMapImpl::findInternal), (KWQMapImpl::insertInternal),
+ (KWQMapImpl::removeInternal), (KWQMapImpl::swap), (KWQMapImpl::countInternal),
+ (KWQMapImpl::clearInternal), (KWQMapImpl::beginInternal),
+ (KWQMapImpl::endInternal):
+
+ Reimplement QPtrDict in terms of CFDictionary:
+
+ * src/kwq/qt/qptrdict.h:
+ * src/kwq/KWQPtrDictImpl.h:
+ * src/kwq/KWQPtrDictImpl.mm:
+ (KWQPtrDictImpl::KWQPtrDictPrivate::KWQPtrDictPrivate),
+ (KWQPtrDictImpl::KWQPtrDictPrivate::~KWQPtrDictPrivate),
+ (KWQPtrDictImpl::KWQPtrDictImpl), (KWQPtrDictImpl::~KWQPtrDictImpl),
+ (invokeDeleteFuncOnValue), (KWQPtrDictImpl::clear), (KWQPtrDictImpl::count),
+ (KWQPtrDictImpl::insert), (KWQPtrDictImpl::remove), (KWQPtrDictImpl::find),
+ (KWQPtrDictImpl::swap), (KWQPtrDictImpl::assign), (KWQPtrDictImpl::take),
+ (KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate::KWQPtrDictIteratorPrivate),
+ (KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate::~KWQPtrDictIteratorPrivate),
+ (KWQPtrDictIteratorImpl::KWQPtrDictIteratorImpl),
+ (KWQPtrDictIteratorImpl::~KWQPtrDictIteratorImpl),
+ (KWQPtrDictIteratorImpl::count), (KWQPtrDictIteratorImpl::current),
+ (KWQPtrDictIteratorImpl::currentKey), (KWQPtrDictIteratorImpl::toFirst),
+ (KWQPtrDictIteratorImpl::operator++):
+
+ Reimplement QSortedList:
+
+ * src/kwq/qt/qsortedlist.h:
+
+ * src/kwq/KWQArrayImpl.mm: Remove stray include.
+
+ * src/kwq/Makefile.am: Add new files to build.
+
+ * src/kwq/qt/_qdict.h, src/kwq/qt/_qgdict.h,
+ src/kwq/qt/_qptrdict.h: Avoid causing problems when the relevant
+ defines are not defined.
+
2002-01-22 Richard Williamson <rjw at apple.com>
Implemented KWQDesktopWidget to represent main screen. Used by javascript.
diff --git a/WebCore/kwq/KWQArrayImpl.mm b/WebCore/kwq/KWQArrayImpl.mm
index f477ce7..8d364a0 100644
--- a/WebCore/kwq/KWQArrayImpl.mm
+++ b/WebCore/kwq/KWQArrayImpl.mm
@@ -27,7 +27,6 @@
#ifndef USING_BORROWED_QARRAY
-#include <cstring>
#include <new>
#define MIN(a,b) (((a)<(b))?(a):(b))
diff --git a/WebCore/kwq/KWQDict.h b/WebCore/kwq/KWQDict.h
index 4234247..a3ee0f4 100644
--- a/WebCore/kwq/KWQDict.h
+++ b/WebCore/kwq/KWQDict.h
@@ -33,13 +33,18 @@
// USING_BORROWED_QDICT ========================================================
#ifdef USING_BORROWED_QDICT
+
#include <_qdict.h>
+
#else
#include <_qcollection.h>
-#include "qstring.h"
+#include <qstring.h>
+#include <KWQDictImpl.h>
+
+template<class T> class QDictIterator;
// class QDict =================================================================
@@ -53,25 +58,32 @@ public:
// constructors, copy constructors, and destructors ------------------------
- QDict(int size=17, bool caseSensitive=TRUE);
- QDict(const QDict<T> &);
- ~QDict();
+ QDict(int size=17, bool caseSensitive=TRUE) : impl(size, caseSensitive, QDict::deleteFunc) {}
+ QDict(const QDict<T> &d) : impl(d.impl) {}
+ virtual ~QDict() { impl.clear(del_item); }
// member functions --------------------------------------------------------
- void clear();
- void insert(const QString &, const T *);
- bool remove(const QString &);
- T *find(const QString &) const;
- uint count() const;
+ virtual void clear() { impl.clear(del_item); }
+ virtual uint count() const { return impl.count(); }
+ void insert(const QString &key, const T *value) { impl.insert(key,(void *)value);}
+ bool remove(const QString &key) { return impl.remove(key,del_item); }
+ T *find(const QString &key) const { return (T *)impl.find(key); }
// operators ---------------------------------------------------------------
- QDict<T> &operator=(const QDict<T> &);
+ QDict<T> &operator=(const QDict<T> &d) { impl.assign(d.impl,del_item); QCollection::operator=(d); return *this;}
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
+ private:
+ static void deleteFunc(void *item) {
+ delete (T *)item;
+ }
+
+ KWQDictImpl impl;
+ friend class QDictIterator<T>;
}; // class QDict ==============================================================
@@ -92,23 +104,25 @@ public:
QDictIterator() {}
#endif
- QDictIterator(const QDict<T> &);
- ~QDictIterator();
+ QDictIterator(const QDict<T> &d) : impl(d.impl) {}
+ ~QDictIterator() {}
// member functions --------------------------------------------------------
- uint count() const;
- T *current() const;
- T *toFirst();
+ uint count() const { return impl.count(); }
+ T *current() const { return (T *) impl.current(); }
+ QString currentKey() const { return impl.currentStringKey(); }
+ T *toFirst() { return (T *)impl.toFirst(); }
// operators ---------------------------------------------------------------
- T *operator++();
+ T *operator++() { return (T *)(++impl); }
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
private:
+ KWQDictIteratorImpl impl;
// add copy constructor
// this private declaration prevents copying
diff --git a/WebCore/src/kwq/kio/kprinter.h b/WebCore/kwq/KWQDictImpl.h
similarity index 68%
copy from WebCore/src/kwq/kio/kprinter.h
copy to WebCore/kwq/KWQDictImpl.h
index 4562554..dff4b2f 100644
--- a/WebCore/src/kwq/kio/kprinter.h
+++ b/WebCore/kwq/KWQDictImpl.h
@@ -23,30 +23,38 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KPRINTER_H_
-#define KPRINTER_H_
+#ifndef KWQ_DICT_IMPL_H
+#define KWQ_DICT_IMPL_H
-#ifdef HAVE_CONFIG_H
#include <config.h>
-#endif
-
-#include <qpaintdevice.h>
+#include <KWQDef.h>
#include <qstring.h>
-#include <qwidget.h>
-#include <qsize.h>
-
-// NOTE: I stuck this file here rather than create a whole new
-// kdeprint directory
-
-class KPrinter : public QPaintDevice {
-public:
- bool setup(QWidget *parent=0);
- bool newPage();
- void setDocName(const QString &);
- void setCreator(const QString &);
- void setFullPage(bool);
- QSize margins() const;
+
+#ifndef USING_BORROWED_QDICT
+
+#include <KWQPtrDictImpl.h>
+
+class KWQDictImpl : public KWQPtrDictImpl {
+ public:
+ KWQDictImpl(int size, bool caseSensitive, void (*deleteFunc)(void *));
+ KWQDictImpl(const KWQDictImpl &di);
+ // ~KWQDictImpl();
+
+ void insert(const QString &key, const void *value);
+ bool remove(const QString &key, bool deleteItems);
+ void *find(const QString &key) const;
};
+
+class KWQDictIteratorImpl : public KWQPtrDictIteratorImpl {
+ public:
+ KWQDictIteratorImpl(const KWQDictImpl &di);
+ // ~KWQDictIteratorImpl();
+
+ QString currentStringKey() const;
+};
+
+
#endif
+#endif
diff --git a/WebCore/kwq/KWQBuffer.mm b/WebCore/kwq/KWQDictImpl.mm
similarity index 59%
copy from WebCore/kwq/KWQBuffer.mm
copy to WebCore/kwq/KWQDictImpl.mm
index de9a4cb..c16cf33 100644
--- a/WebCore/kwq/KWQBuffer.mm
+++ b/WebCore/kwq/KWQDictImpl.mm
@@ -22,69 +22,51 @@
* (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 <kwqdebug.h>
-#include <qbuffer.h>
+#include <KWQDictImpl.h>
+#include <CoreFoundation/CoreFoundation.h>
-#ifndef USING_BORROWED_QBUFFER
+#ifndef USING_BORROWED_QDICT
-#include <qiodevice.h>
-
-QBuffer::QBuffer() : opened(false), pos(0)
+KWQDictImpl::KWQDictImpl(int size, bool caseSensitive, void (*deleteFunc)(void *)) :
+ KWQPtrDictImpl(size, deleteFunc, &kCFCopyStringDictionaryKeyCallBacks)
{
}
-QBuffer::~QBuffer()
+KWQDictImpl::KWQDictImpl(const KWQDictImpl &di) :
+ KWQPtrDictImpl(di)
{
}
-
-QByteArray QBuffer::buffer() const
+void KWQDictImpl::insert(const QString &key, const void *value)
{
- return ba;
-}
+ KWQPtrDictImpl::insert(key.getCFMutableString(), value);
-uint QBuffer::size() const
-{
- return ba.size();
}
-bool QBuffer::isOpen()
+bool KWQDictImpl::remove(const QString &key, bool deleteItem)
{
- return opened;
+ return KWQPtrDictImpl::remove(key.getCFMutableString(), deleteItem);
}
-bool QBuffer::open(int mode)
+void *KWQDictImpl::find(const QString &key) const
{
- if (mode == IO_WriteOnly) {
- opened = true;
- pos = 0;
- return true;
- } else {
- return false;
- }
+ return KWQPtrDictImpl::find(key.getCFMutableString());
}
-void QBuffer::close()
+KWQDictIteratorImpl::KWQDictIteratorImpl(const KWQDictImpl &di) :
+ KWQPtrDictIteratorImpl(di)
{
- opened = false;
}
-int QBuffer::writeBlock(const char *data, uint len)
+QString KWQDictIteratorImpl::currentStringKey() const
{
- // FIXME: could easily be optimized a lot - leave extra space in
- // buffer for amortized constant time growth
+ void *key = currentKey();
- if (pos+len > ba.size()) {
- if (!ba.resize(pos+len)) {
- return -1;
- }
+ if (key == NULL) {
+ return QString();
}
- memcpy(ba.data()+pos, data, len);
- pos += len;
-
- return len;
+ return QString::fromCFString((CFStringRef)key);
}
-
#endif
diff --git a/WebCore/kwq/KWQMap.h b/WebCore/kwq/KWQMap.h
index b21233b..4c8b0dc 100644
--- a/WebCore/kwq/KWQMap.h
+++ b/WebCore/kwq/KWQMap.h
@@ -36,143 +36,387 @@
#include <_qmap.h>
#else
+#include <iostream>
#include <KWQDef.h>
-// class QMapIterator ==========================================================
-
-template<class K, class T> class QMapIterator {
-public:
-
- // typedefs ----------------------------------------------------------------
- // enums -------------------------------------------------------------------
- // constants ---------------------------------------------------------------
- // static member functions -------------------------------------------------
-
- // constructors, copy constructors, and destructors ------------------------
-
- QMapIterator();
- QMapIterator(const QMapIterator<K,T>&);
+#include <KWQMapImpl.h>
-// add no-op destructor
-#ifdef _KWQ_PEDANTIC_
- ~QMapIterator() {}
-#endif
-
- // member functions --------------------------------------------------------
+template <class K, class V> class QMap;
+template <class K, class V> class QMapIterator;
+template <class K, class V> class QMapConstIterator;
- const K& key() const;
- const T& data() const;
- // operators ---------------------------------------------------------------
-
- QMapIterator<K,T> &operator=(const QMapIterator<K,T> &);
- bool operator==(const QMapIterator<K,T>&) const;
- bool operator!=(const QMapIterator<K,T>&) const;
- T& operator*();
- const T& operator*() const;
- QMapIterator<K,T>& operator++();
-
- // this is not declared in the code, although assignment of this type
- // is used in the code... i guess a pointer copy is what they want
- //
- //QMapIterator<K,T> &operator=(const QMapIterator<K,T> &);
- //
-
-// protected -------------------------------------------------------------------
-// private ---------------------------------------------------------------------
+template <class K, class V> class QMapNode : private KWQMapNodeImpl
+{
+ private:
+ QMapNode(K k, V v) :
+ key(k),
+ value(v)
+ {
+ }
+
+ // intentionally not defined
+ QMapNode(const QMapNode<K,V>&node);
+
+ static QMapNode<K,V> *copyTree(const QMapNode<K,V> *node,
+ QMapNode<K,V> *subtreePredecessor,
+ QMapNode<K,V> *subtreeSuccessor)
+ {
+ if (node == NULL) {
+ return NULL;
+ }
+
+ // FIXME: not exception-safe - use auto_ptr?
+ QMapNode<K,V> *copy = new QMapNode<K,V>(node->key, node->value);
+ copy->color = node->color;
+
+ if (node->prevIsChild) {
+ copy->prevIsChild = true;
+ copy->prev = copyTree((QMapNode<K,V> *)node->prev, subtreePredecessor, copy);
+ } else {
+ copy->prevIsChild = false;
+ copy->prev = subtreePredecessor;
+ }
+
+ if (node->nextIsChild) {
+ copy->nextIsChild = true;
+ copy->next = copyTree((QMapNode<K,V> *)node->next, copy, subtreeSuccessor);
+ } else {
+ copy->nextIsChild = false;
+ copy->next = subtreeSuccessor;
+ }
+
+ return copy;
+ }
+
+ ~QMapNode()
+ {
+ delete left();
+ delete right();
+ }
+
+ K key;
+ V value;
+
+ friend class QMap<K,V>;
+ friend class QMapIterator<K,V>;
+ friend class QMapConstIterator<K,V>;
+};
+// class QMapIterator ==========================================================
+template<class K, class V> class QMapIterator : private KWQMapIteratorImpl {
+public:
+ QMapIterator()
+ {
+ }
+
+ QMapIterator(const QMapIterator<K,V> &iter) : KWQMapIteratorImpl(iter)
+ {
+ }
+
+ ~QMapIterator()
+ {
+ }
+
+ const K& key() const
+ {
+ return ((QMapNode<K,V> *)node)->key;
+ }
+
+ const V& data() const
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ QMapIterator<K,V> &operator=(const QMapIterator<K,V> &iter)
+ {
+ node = iter.node;
+ return *this;
+ }
+
+ bool operator==(const QMapIterator<K,V>&iter) const
+ {
+ return node == iter.node;
+ }
+
+ bool operator!=(const QMapIterator<K,V>&iter) const
+ {
+ return node != iter.node;
+ }
+
+ V& operator*()
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ const V& operator*() const
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ QMapIterator<K,V>& operator++()
+ {
+ incrementInternal();
+ return *this;
+ }
+
+private:
+ QMapIterator(QMapNode<K,V> *n)
+ {
+ node = n;
+ }
+
+ friend class QMap<K,V>;
+ friend class QMapConstIterator<K,V>;
}; // class QMapIterator =======================================================
// class QMapConstIterator =====================================================
-template<class K, class T> class QMapConstIterator {
+template<class K, class V> class QMapConstIterator : private KWQMapIteratorImpl {
public:
-
- // typedefs ----------------------------------------------------------------
- // enums -------------------------------------------------------------------
- // constants ---------------------------------------------------------------
- // static member functions -------------------------------------------------
-
- // constructors, copy constructors, and destructors ------------------------
-
- QMapConstIterator();
- QMapConstIterator(const QMapConstIterator<K,T> &);
- QMapConstIterator(const QMapIterator<K,T> &);
-
- ~QMapConstIterator();
-
- // member functions --------------------------------------------------------
-
- const K& key() const;
- const T& data() const;
-
- // operators ---------------------------------------------------------------
-
- QMapConstIterator<K,T> &operator=(const QMapConstIterator<K,T> &);
- bool operator==(const QMapConstIterator<K,T> &) const;
- bool operator!=(const QMapConstIterator<K,T> &) const;
- const T &operator*() const;
- QMapConstIterator<K,T>& operator++();
-
- // this is not declared in the code, although assignment of this type
- // is used in the code... i guess a pointer copy is what they want
- //
- //QMapConstIterator<K,T> &operator=(const QMapConstIterator<K,T> &);
- //
-
-// protected -------------------------------------------------------------------
-// private ---------------------------------------------------------------------
-
+ QMapConstIterator() : KWQMapIteratorImpl()
+ {
+ }
+
+ QMapConstIterator(const QMapConstIterator<K,V> &citer) : KWQMapIteratorImpl(citer)
+ {
+ }
+
+ QMapConstIterator(const QMapIterator<K,V> &iter) : KWQMapIteratorImpl(iter)
+ {
+ }
+
+ ~QMapConstIterator()
+ {
+ }
+
+ const K& key() const
+ {
+ return ((QMapNode<K,V> *)node)->key;
+ }
+
+ const V& data() const
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ QMapConstIterator<K,V> &operator=(const QMapConstIterator<K,V> &citer)
+ {
+ node = citer.node;
+ return *this;
+ }
+
+ bool operator==(const QMapConstIterator<K,V> &citer) const
+ {
+ return node == citer.node;
+ }
+
+ bool operator!=(const QMapConstIterator<K,V> &citer) const
+ {
+ return node != citer.node;
+ }
+
+ const V &operator*() const
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ QMapConstIterator<K,V>& operator++()
+ {
+ incrementInternal();
+ return *this;
+ }
+
+private:
+ QMapConstIterator(QMapNode<K,V> *n)
+ {
+ node = n;
+ }
+
+ friend class QMap<K,V>;
}; // class QMapConstIterator ==================================================
+
// class QMap ==================================================================
-template <class K, class T> class QMap {
+template <class K, class V> class QMap : public KWQMapImpl {
public:
// typedefs ----------------------------------------------------------------
- typedef QMapIterator<K, T> Iterator;
- typedef QMapConstIterator< K, T> ConstIterator;
+ typedef QMapIterator<K,V> Iterator;
+ typedef QMapConstIterator<K,V> ConstIterator;
// enums -------------------------------------------------------------------
// constants ---------------------------------------------------------------
// static member functions -------------------------------------------------
// constructors, copy constructors, and destructors ------------------------
-
- QMap();
- QMap(const QMap<K,T>&);
- ~QMap();
-
- // member functions --------------------------------------------------------
- void clear();
- uint count() const;
- Iterator begin();
- Iterator end();
-
- ConstIterator begin() const;
- ConstIterator end() const;
+ QMap() :
+ KWQMapImpl(new QMapNode<K,V>(K(),V()), 0)
+ {
+ }
- Iterator insert(const K&, const T&);
- void remove(const K&);
+ QMap(const QMap<K,V>& m) :
+ KWQMapImpl(QMapNode<K,V>::copyTree((QMapNode<K,V> *)m.endInternal(), NULL, NULL), m.count())
+ {
+ }
- ConstIterator find (const K &) const;
+ virtual ~QMap()
+ {
+ clear();
+ delete endInternal();
+ }
+
+ // member functions --------------------------------------------------------
- // operators ---------------------------------------------------------------
+ void clear()
+ {
+ clearInternal();
+ }
+
+ uint count() const
+ {
+ return countInternal();
+ }
+
+ Iterator begin()
+ {
+ return Iterator((QMapNode<K,V> *)beginInternal());
+ }
+
+ Iterator end()
+ {
+ return Iterator((QMapNode<K,V> *)endInternal());
+ }
+
+ ConstIterator begin() const
+ {
+ return ConstIterator((QMapNode<K,V> *)beginInternal());
+ }
+
+ ConstIterator end() const
+ {
+ return ConstIterator((QMapNode<K,V> *)endInternal());
+ }
+
+ Iterator insert(const K& key, const V& value)
+ {
+ QMapNode<K,V> tmp(key,value);
+
+ return Iterator((QMapNode<K,V> *)insertInternal(&tmp, true));
+ }
+
+ void remove(const K& key)
+ {
+ QMapNode<K,V> tmp(key, V());
+ removeInternal(&tmp);
+ }
+
+ ConstIterator find (const K &key) const
+ {
+ QMapNode<K,V> tmp(key, V());
+ QMapNode<K,V> *result = (QMapNode<K,V> *)findInternal(&tmp);
+
+ if (result != NULL) {
+ return ConstIterator(result);
+ } else {
+ return ConstIterator(end());
+ }
+ }
- QMap<K,T>& operator=(const QMap<K,T>&);
- T& operator[](const K& k);
+ // operators ---------------------------------------------------------------
-// protected -------------------------------------------------------------------
-// private ---------------------------------------------------------------------
+ QMap<K,V>& operator=(const QMap<K,V>&map)
+ {
+ QMap<K,V> tmp(map);
+ swap(tmp);
+ return *this;
+ }
+
+ V& operator[](const K& key)
+ {
+ QMapNode<K,V> tmp(key, V());
+
+ return ((QMapNode<K,V> *)insertInternal(&tmp, false))->value;
+ }
+
+
+protected:
+ virtual void copyNode(KWQMapNodeImpl *isrc, KWQMapNodeImpl *idst)
+ {
+ QMapNode<K,V> *src = (QMapNode<K,V> *)isrc;
+ QMapNode<K,V> *dst = (QMapNode<K,V> *)idst;
+ dst->key = src->key;
+ dst->value = src->value;
+ }
+
+ virtual KWQMapNodeImpl *duplicateNode(KWQMapNodeImpl *isrc)
+ {
+ QMapNode<K,V> *src = (QMapNode<K,V> *)isrc;
+ return new QMapNode<K,V>(src->key, src->value);
+ }
+
+ virtual CompareResult compareNodes(KWQMapNodeImpl *ia, KWQMapNodeImpl *ib) const
+ {
+ QMapNode<K,V> *a = (QMapNode<K,V> *)ia;
+ QMapNode<K,V> *b = (QMapNode<K,V> *)ib;
+
+ if (a->key == b->key) {
+ return Equal;
+ } else if (a->key < b->key) {
+ return Less;
+ } else {
+ return Greater;
+ }
+ }
+
+ virtual void swapNodes(KWQMapNodeImpl *ia, KWQMapNodeImpl *ib)
+ {
+ QMapNode<K,V> *a = (QMapNode<K,V> *)ia;
+ QMapNode<K,V> *b = (QMapNode<K,V> *)ib;
+
+ K tmpKey = a->key;
+ V tmpValue = a->value;
+ a->key = b->key;
+ a->value = b->value;
+ b->key = tmpKey;
+ b->value = tmpValue;
+ }
+
+ virtual void deleteNode(KWQMapNodeImpl *inode)
+ {
+ delete (QMapNode<K,V> *)inode;
+ }
}; // class QMap ===============================================================
+
+#ifdef _KWQ_IOSTREAM_
+template<class K, class V>
+inline ostream &operator<<(ostream &stream, const QMap<K,V> &m)
+{
+ uint count = m.count();
+ stream << "QMap: [size: " << count << "; items: ";
+
+ QMapConstIterator<K,V> iter = m.begin();
+
+ for (unsigned int i = 0; i < count; i++) {
+ stream << "(" << iter.key() << "," << iter.data() << ")";
+ if (i + 1 < count) {
+ stream << ", ";
+ }
+ ++iter;
+ }
+
+ return stream << "]";
+}
+#endif
+
#endif // USING_BORROWED_QMAP
#endif
diff --git a/WebCore/kwq/KWQMapImpl.h b/WebCore/kwq/KWQMapImpl.h
new file mode 100644
index 0000000..7c1be09
--- /dev/null
+++ b/WebCore/kwq/KWQMapImpl.h
@@ -0,0 +1,124 @@
+/*
+ * 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_MAP_IMPL_H
+#define KWQ_MAP_IMPL_H
+
+#include <config.h>
+
+#include <new>
+#include <iostream>
+
+#ifndef USING_BORROWED_QMAP
+
+
+class KWQMapNodeImpl
+{
+protected:
+ typedef enum { Red = 0, Black = 1 } KWQMapNodeColor;
+
+ KWQMapNodeImpl();
+
+ KWQMapNodeImpl *left();
+ const KWQMapNodeImpl *left() const;
+ KWQMapNodeImpl *right();
+ const KWQMapNodeImpl *right() const;
+ KWQMapNodeImpl *predecessor();
+ const KWQMapNodeImpl *predecessor() const;
+ KWQMapNodeImpl *successor();
+ const KWQMapNodeImpl *successor() const;
+
+ KWQMapNodeImpl *prev;
+ KWQMapNodeImpl *next;
+ bool prevIsChild;
+ bool nextIsChild;
+ KWQMapNodeColor color;
+
+ friend class KWQMapImpl;
+ friend class KWQMapIteratorImpl;
+
+#ifdef QMAP_TESTING
+ friend bool CheckRedBlackRules(KWQMapImpl *impl);
+ friend bool CheckRedBlackRulesAtNode(KWQMapImpl *impl, KWQMapNodeImpl *node, int &black_height);
+#endif
+};
+
+class KWQMapIteratorImpl {
+protected:
+ KWQMapNodeImpl *node;
+
+ KWQMapIteratorImpl();
+ KWQMapIteratorImpl(const KWQMapIteratorImpl& iter);
+ void incrementInternal();
+};
+
+class KWQMapImpl {
+ private:
+ // disallow default construction, copy construction and assignment
+ KWQMapImpl();
+ KWQMapImpl(const KWQMapImpl &);
+ KWQMapImpl &operator=(const KWQMapImpl &);
+
+ protected:
+ typedef enum { Less = -1, Equal = 0, Greater = 1 } CompareResult;
+
+ KWQMapImpl(KWQMapNodeImpl *node, uint count);
+
+ KWQMapNodeImpl *findInternal(KWQMapNodeImpl *target) const;
+ KWQMapNodeImpl *insertInternal(KWQMapNodeImpl *nodeToInsert, bool replaceExisting);
+ void removeInternal(KWQMapNodeImpl *nodeToRemove);
+ uint countInternal() const;
+ void clearInternal();
+ void swap(KWQMapImpl &map);
+ KWQMapNodeImpl *beginInternal() const;
+ KWQMapNodeImpl *endInternal() const;
+
+ virtual CompareResult compareNodes(KWQMapNodeImpl *a, KWQMapNodeImpl *b) const = 0;
+ virtual void copyNode(KWQMapNodeImpl *src, KWQMapNodeImpl *dst) = 0;
+ virtual KWQMapNodeImpl *duplicateNode(KWQMapNodeImpl *src) = 0;
+ virtual void swapNodes(KWQMapNodeImpl *a, KWQMapNodeImpl *b) = 0;
+ virtual void deleteNode(KWQMapNodeImpl *node) = 0;
+
+ private:
+ // can't possibly have a bigger height than this in a balanced tree
+ static const int MAX_STACK = 64;
+
+ void rebalanceAfterInsert(KWQMapNodeImpl **nodes, bool *wentLeft, int height);
+ void rebalanceAfterRemove(KWQMapNodeImpl *nodeToRemove, KWQMapNodeImpl **nodes, bool *wentLeft, int height);
+ void rotateRight(KWQMapNodeImpl *node, KWQMapNodeImpl *parent, bool leftParent);
+ void rotateLeft(KWQMapNodeImpl *node, KWQMapNodeImpl *parent, bool leftParent);
+
+ KWQMapNodeImpl *guard;
+ uint numNodes;
+
+#ifdef QMAP_TESTING
+ friend bool CheckRedBlackRules(KWQMapImpl *impl);
+ friend bool CheckRedBlackRulesAtNode(KWQMapImpl *impl, KWQMapNodeImpl *node, int &black_height);
+#endif
+};
+
+#endif
+
+#endif
diff --git a/WebCore/kwq/KWQMapImpl.mm b/WebCore/kwq/KWQMapImpl.mm
new file mode 100644
index 0000000..fdea9a4
--- /dev/null
+++ b/WebCore/kwq/KWQMapImpl.mm
@@ -0,0 +1,556 @@
+/*
+ * 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 <KWQMapImpl.h>
+
+#ifndef USING_BORROWED_QMAP
+
+// KWQMapNodeImpl
+
+KWQMapNodeImpl::KWQMapNodeImpl() :
+ prev(NULL),
+ next(NULL),
+ prevIsChild(true),
+ nextIsChild(true),
+ color(Red)
+{
+}
+
+KWQMapNodeImpl *KWQMapNodeImpl::left()
+{
+ return prevIsChild ? prev : NULL;
+}
+
+const KWQMapNodeImpl *KWQMapNodeImpl::left() const
+{
+ return prevIsChild ? prev : NULL;
+}
+
+KWQMapNodeImpl *KWQMapNodeImpl::right()
+{
+ return nextIsChild ? next : NULL;
+}
+
+const KWQMapNodeImpl *KWQMapNodeImpl::right() const
+{
+ return nextIsChild ? next : NULL;
+}
+
+KWQMapNodeImpl *KWQMapNodeImpl::predecessor()
+{
+ if (!prevIsChild || prev == NULL) {
+ return prev;
+ }
+ KWQMapNodeImpl *pred = left();
+ while (pred->right() != NULL) {
+ pred = pred->right();
+ }
+ return pred;
+}
+
+const KWQMapNodeImpl *KWQMapNodeImpl::predecessor() const
+{
+ if (!prevIsChild || prev == NULL) {
+ return prev;
+ }
+ const KWQMapNodeImpl *pred = left();
+ while (pred->right() != NULL) {
+ pred = pred->right();
+ }
+ return pred;
+}
+
+KWQMapNodeImpl *KWQMapNodeImpl::successor()
+{
+ if (!nextIsChild || next == NULL) {
+ return next;
+ }
+ KWQMapNodeImpl *succ = right();
+ while (succ->left() != NULL) {
+ succ = succ->left();
+ }
+ return succ;
+}
+
+const KWQMapNodeImpl *KWQMapNodeImpl::successor() const
+{
+ if (!nextIsChild || next == NULL) {
+ return next;
+ }
+ const KWQMapNodeImpl *succ = right();
+ while (succ->left() != NULL) {
+ succ = succ->left();
+ }
+ return succ;
+}
+
+
+KWQMapIteratorImpl::KWQMapIteratorImpl() : node(NULL)
+{
+}
+
+KWQMapIteratorImpl::KWQMapIteratorImpl(const KWQMapIteratorImpl& iter) : node(iter.node)
+{
+}
+
+void KWQMapIteratorImpl::incrementInternal()
+{
+ node = node->successor();
+}
+
+
+// KWQMapImpl
+
+
+KWQMapImpl::KWQMapImpl(KWQMapNodeImpl *node, uint count) :
+ guard(node),
+ numNodes(count)
+{
+}
+
+void KWQMapImpl::rotateRight(KWQMapNodeImpl *node, KWQMapNodeImpl *parent, bool leftParent)
+{
+ KWQMapNodeImpl *rotationChild = node->left();
+
+ if (leftParent) {
+ parent->prev = rotationChild;
+ } else {
+ parent->next = rotationChild;
+ }
+
+ node->prev = rotationChild->next;
+ node->prevIsChild = rotationChild->nextIsChild;
+
+ rotationChild->next = node;
+ rotationChild->nextIsChild = true;
+
+ // fixup threads
+ if (!node->prevIsChild) {
+ node->prev = rotationChild;
+ }
+ }
+
+void KWQMapImpl::rotateLeft(KWQMapNodeImpl *node, KWQMapNodeImpl *parent, bool leftParent)
+{
+ KWQMapNodeImpl *rotationChild = node->right();
+
+ if (leftParent) {
+ parent->prev = rotationChild;
+ } else {
+ parent->next = rotationChild;
+ }
+
+ node->next = rotationChild->prev;
+ node->nextIsChild = rotationChild->prevIsChild;
+
+ rotationChild->prev = node;
+ rotationChild->prevIsChild = true;
+
+ // fixup threads
+ if (!node->nextIsChild) {
+ node->next = rotationChild;
+ }
+}
+
+void KWQMapImpl::rebalanceAfterInsert(KWQMapNodeImpl **nodes, bool *wentLeft, int height)
+{
+ nodes[height]->color = KWQMapNodeImpl::Red;
+
+ while (nodes[height] != guard->prev && nodes[height-1]->color == KWQMapNodeImpl::Red) {
+ if (wentLeft[height-2]) {
+ KWQMapNodeImpl *uncle = nodes[height-2]->right();
+ if (uncle != NULL && uncle->color == KWQMapNodeImpl::Red) {
+ nodes[height-1]->color = KWQMapNodeImpl::Black;
+ uncle->color = KWQMapNodeImpl::Black;
+ nodes[height-2]->color = KWQMapNodeImpl::Red;
+
+ // go up two levels
+ height = height - 2;
+ } else {
+ KWQMapNodeImpl *parent;
+ if (!wentLeft[height-1]) {
+ parent = nodes[height-1]->right();
+ rotateLeft(nodes[height-1], nodes[height-2], wentLeft[height-2]);
+ } else {
+ parent = nodes[height-1];
+ }
+ parent->color = KWQMapNodeImpl::Black;
+ nodes[height-2]->color = KWQMapNodeImpl::Red;
+ rotateRight(nodes[height-2], nodes[height-3], wentLeft[height-3]);
+ break;
+ }
+ } else {
+ // same as the other branch, but with left and right swapped
+
+ KWQMapNodeImpl *uncle = nodes[height-2]->left();
+
+ if (uncle != NULL && uncle->color == KWQMapNodeImpl::Red) {
+ nodes[height-1]->color = KWQMapNodeImpl::Black;
+ uncle->color = KWQMapNodeImpl::Black;
+ nodes[height-2]->color = KWQMapNodeImpl::Red;
+
+ // go up two levels
+ height = height - 2;
+ } else {
+ KWQMapNodeImpl *parent;
+ if (wentLeft[height-1]) {
+ parent = nodes[height-1]->left();
+ rotateRight(nodes[height-1], nodes[height-2], wentLeft[height-2]);
+ } else {
+ parent = nodes[height-1];
+ }
+ parent->color = KWQMapNodeImpl::Black;
+ nodes[height-2]->color = KWQMapNodeImpl::Red;
+ rotateLeft(nodes[height-2], nodes[height-3], wentLeft[height-3]);
+ break;
+ }
+ }
+ }
+
+ guard->prev->color = KWQMapNodeImpl::Black;
+}
+
+void KWQMapImpl::rebalanceAfterRemove(KWQMapNodeImpl *nodeToRemove, KWQMapNodeImpl **nodes, bool *wentLeft, int height)
+{
+ if (nodeToRemove->color == KWQMapNodeImpl::Black) {
+ while (nodes[height] != guard->prev && (nodes[height]==NULL || nodes[height]->color==KWQMapNodeImpl::Black)) {
+ if (wentLeft[height-1]) {
+ KWQMapNodeImpl *sibling = nodes[height-1]->right();
+ if (sibling != NULL && sibling->color == KWQMapNodeImpl::Red) {
+ sibling->color = KWQMapNodeImpl::Black;
+ nodes[height-1]->color = KWQMapNodeImpl::Red;
+ rotateLeft(nodes[height-1], nodes[height-2], wentLeft[height-2]);
+
+ nodes[height] = nodes[height-1];
+ wentLeft[height] = true;
+ nodes[height-1] = sibling;
+ height = height + 1;
+
+ sibling = nodes[height-1]->right();
+ }
+ if ((sibling->left() == NULL || sibling->left()->color == KWQMapNodeImpl::Black) &&
+ (sibling->right() == NULL || sibling->right()->color == KWQMapNodeImpl::Black)) {
+ sibling->color = KWQMapNodeImpl::Red;
+ height = height - 1;
+ } else {
+ if (sibling->right() == NULL || sibling->right()->color == KWQMapNodeImpl::Black) {
+ sibling->left()->color = KWQMapNodeImpl::Black;
+ sibling->color = KWQMapNodeImpl::Red;
+ rotateRight(sibling, nodes[height-1], !wentLeft[height-1]);
+ sibling = nodes[height-1]->right();
+ }
+
+ sibling->color = nodes[height-1]->color;
+ nodes[height-1]->color = KWQMapNodeImpl::Black;
+ sibling->right()->color = KWQMapNodeImpl::Black;
+ rotateLeft(nodes[height-1], nodes[height-2], wentLeft[height-2]);
+
+ nodes[height] = guard->prev;
+ }
+ } else {
+ // same as the other branch, but with left and right swapped
+
+ KWQMapNodeImpl *sibling = nodes[height-1]->left();
+ if (sibling != NULL && sibling->color == KWQMapNodeImpl::Red) {
+ sibling->color = KWQMapNodeImpl::Black;
+ nodes[height-1]->color = KWQMapNodeImpl::Red;
+ rotateRight(nodes[height-1], nodes[height-2], wentLeft[height-2]);
+
+ nodes[height] = nodes[height-1];
+ wentLeft[height] = false;
+ nodes[height-1] = sibling;
+ height = height + 1;
+
+ sibling = nodes[height-1]->left();
+ }
+ if ((sibling->right() == NULL || sibling->right()->color == KWQMapNodeImpl::Black) &&
+ (sibling->left() == NULL || sibling->left()->color == KWQMapNodeImpl::Black)) {
+ sibling->color = KWQMapNodeImpl::Red;
+ height = height - 1;
+ } else {
+ if (sibling->left() == NULL || sibling->left()->color == KWQMapNodeImpl::Black) {
+ sibling->right()->color = KWQMapNodeImpl::Black;
+ sibling->color = KWQMapNodeImpl::Red;
+ rotateLeft(sibling, nodes[height-1], !wentLeft[height-1]);
+ sibling = nodes[height-1]->left();
+ }
+
+ sibling->color = nodes[height-1]->color;
+ nodes[height-1]->color = KWQMapNodeImpl::Black;
+ sibling->left()->color = KWQMapNodeImpl::Black;
+ rotateRight(nodes[height-1], nodes[height-2], wentLeft[height-2]);
+
+ nodes[height] = guard->prev;
+ }
+ }
+ }
+
+ if (nodes[height] != NULL) {
+ nodes[height]->color = KWQMapNodeImpl::Black;
+ }
+ }
+}
+
+KWQMapNodeImpl *KWQMapImpl::findInternal(KWQMapNodeImpl *target) const
+{
+ KWQMapNodeImpl *node = guard->left();
+
+ while (node != NULL) {
+ CompareResult compare = compareNodes(target,node);
+
+ if (compare == Equal) {
+ break;
+ } else if (compare == Less) {
+ node = node->left();
+ } else if (compare == Greater) {
+ node = node->right();
+ }
+ }
+
+ return node;
+}
+
+KWQMapNodeImpl *KWQMapImpl::insertInternal(KWQMapNodeImpl *nodeToInsert, bool replaceExisting)
+{
+ KWQMapNodeImpl *nodeStack[MAX_STACK];
+ bool wentLeftStack[MAX_STACK];
+ int height = 0;
+
+ nodeStack[height] = guard;
+ wentLeftStack[height] = true;
+ height++;
+
+ KWQMapNodeImpl *node = guard->left();
+
+ while (node != NULL) {
+ CompareResult compare = compareNodes(nodeToInsert, node);
+ if (compare == Equal) {
+ break;
+ } else if (compare == Less) {
+ nodeStack[height] = node;
+ wentLeftStack[height] = true;
+ height++;
+ node = node->left();
+ } else {
+ nodeStack[height] = node;
+ wentLeftStack[height] = false;
+ height++;
+ node = node->right();
+ }
+ }
+
+ if (node != NULL) {
+ if (replaceExisting) {
+ copyNode(nodeToInsert, node);
+ }
+ return node;
+ }
+
+ node = duplicateNode(nodeToInsert);
+
+ nodeStack[height] = node;
+
+ if (wentLeftStack[height-1]) {
+ // arrange for threading
+ node->prev = nodeStack[height-1]->prev;
+ node->prevIsChild = false;
+ node->next = nodeStack[height-1];
+ node->nextIsChild = false;
+
+ // make it the child
+ nodeStack[height-1]->prev = node;
+ nodeStack[height-1]->prevIsChild = true;
+ } else {
+ // arrange for threading
+ node->next = nodeStack[height-1]->next;
+ node->nextIsChild = false;
+ node->prev = nodeStack[height-1];
+ node->prevIsChild = false;
+
+ // make it the child
+ nodeStack[height-1]->next = node;
+ nodeStack[height-1]->nextIsChild = true;
+ }
+
+ rebalanceAfterInsert(nodeStack, wentLeftStack, height);
+ numNodes++;
+
+ return node;
+}
+
+void KWQMapImpl::removeInternal(KWQMapNodeImpl *nodeToDelete)
+{
+ KWQMapNodeImpl *nodeStack[MAX_STACK];
+ bool wentLeftStack[MAX_STACK];
+ int height = 0;
+
+ nodeStack[height] = guard;
+ wentLeftStack[height] = true;
+ height++;
+
+ KWQMapNodeImpl *node = guard->left();
+
+ while (node != NULL) {
+ CompareResult compare = compareNodes(nodeToDelete, node);
+ if (compare == Equal) {
+ break;
+ } else if (compare == Less) {
+ nodeStack[height] = node;
+ wentLeftStack[height] = true;
+ height++;
+ node = node->left();
+ } else {
+ nodeStack[height] = node;
+ wentLeftStack[height] = false;
+ height++;
+ node = node->right();
+ }
+ }
+
+ if (node == NULL) {
+ return;
+ }
+
+ KWQMapNodeImpl *removalParent;
+ KWQMapNodeImpl *nodeToRemove;
+ bool removalWentLeft;
+
+ if (node->left() == NULL || node->right() == NULL) {
+ // If this node has at most one subtree, we can remove it directly
+ nodeToRemove = node;
+ removalParent = nodeStack[height-1];
+ removalWentLeft = wentLeftStack[height-1];
+ } else {
+ // Otherwise we find the immediate successor (leftmost
+ // node in the right subtree), which must have at most one
+ // subtree, swap it's contents with the node we found, and
+ // remove it.
+ nodeToRemove = node->right();
+ wentLeftStack[height] = false;
+ nodeStack[height] = node;
+ height++;
+
+ removalParent = node;
+ removalWentLeft = false;
+
+ while (nodeToRemove->left() != NULL) {
+ wentLeftStack[height] = true;
+ nodeStack[height] = nodeToRemove;
+ removalParent = nodeToRemove;
+ nodeToRemove = nodeToRemove->left();
+ removalWentLeft = true;
+ height++;
+ }
+
+ swapNodes(node,nodeToRemove);
+ }
+
+
+ // find replacement node
+ KWQMapNodeImpl *removalReplacement;
+
+ if (nodeToRemove->left() != NULL) {
+ removalReplacement = nodeToRemove->left();
+ // fixup threading
+ nodeToRemove->predecessor()->next = nodeToRemove->next;
+ } else if (nodeToRemove->right() != NULL) {
+ removalReplacement = nodeToRemove->right();
+ // fixup threading
+ nodeToRemove->successor()->prev = nodeToRemove->prev;
+ } else {
+ removalReplacement = NULL;
+ }
+
+ nodeStack[height] = removalReplacement;
+
+ // detach removal node
+ if (removalWentLeft) {
+ if (removalReplacement == NULL) {
+ removalParent->prev = nodeToRemove->prev;
+ removalParent->prevIsChild = nodeToRemove->prevIsChild;
+ } else {
+ removalParent->prev = removalReplacement;
+ }
+ } else {
+ if (removalReplacement == NULL) {
+ removalParent->next = nodeToRemove->next;
+ removalParent->nextIsChild = nodeToRemove->nextIsChild;
+ } else {
+ removalParent->next = removalReplacement;
+ }
+ }
+
+ // do red-black rebalancing
+ rebalanceAfterRemove(nodeToRemove, nodeStack, wentLeftStack, height);
+
+ // detach removal node's children
+ nodeToRemove->next = NULL;
+ nodeToRemove->prev = NULL;
+
+ numNodes--;
+ deleteNode(nodeToRemove);
+}
+
+void KWQMapImpl::swap(KWQMapImpl &map)
+{
+ KWQMapNodeImpl *tmp = guard;
+ guard = map.guard;
+ map.guard = tmp;
+
+ uint tmpNumNodes = numNodes;
+ numNodes = map.numNodes;
+ map.numNodes = tmpNumNodes;
+}
+
+uint KWQMapImpl::countInternal() const
+{
+ return numNodes;
+}
+
+void KWQMapImpl::clearInternal()
+{
+ deleteNode(guard->prev);
+ guard->prev = NULL;
+ numNodes = 0;
+}
+
+KWQMapNodeImpl *KWQMapImpl::beginInternal() const
+{
+ KWQMapNodeImpl *node;
+
+ node = guard;
+ while (node->left() != NULL) {
+ node = node->left();
+ }
+
+ return node;
+}
+
+KWQMapNodeImpl *KWQMapImpl::endInternal() const
+{
+ return guard;
+}
+
+#endif
diff --git a/WebCore/kwq/KWQPtrDict.h b/WebCore/kwq/KWQPtrDict.h
index 3f0c240..d32c71f 100644
--- a/WebCore/kwq/KWQPtrDict.h
+++ b/WebCore/kwq/KWQPtrDict.h
@@ -39,6 +39,10 @@
#include <KWQDef.h>
#include <_qcollection.h>
+#include <KWQPtrDictImpl.h>
+
+template <class T> class QPtrDictIterator;
+
// class QPtrDict ==============================================================
template <class T> class QPtrDict : public QCollection {
@@ -51,27 +55,34 @@ public:
// constructors, copy constructors, and destructors ------------------------
- QPtrDict(int size=17);
- QPtrDict(const QPtrDict<T> &);
- ~QPtrDict();
+ QPtrDict(int size=17) : impl(size, deleteFunc) {}
+ QPtrDict(const QPtrDict<T> &pd) : impl(pd.impl) {}
+ virtual ~QPtrDict() { impl.clear(del_item); }
// member functions --------------------------------------------------------
- void clear();
- uint count() const;
- T *take(void *);
+ virtual void clear() { impl.clear(del_item); }
+ virtual uint count() const { return impl.count(); }
- void insert(void *, const T *);
- void remove(void *);
+ T *take(void *key) { return (T *)impl.take(key); }
+ void insert(void *key, const T *value) { impl.insert(key, (void *)value); }
+ bool remove(void *key) { return impl.remove(key, del_item); }
// operators ---------------------------------------------------------------
- QPtrDict<T> &operator=(const QPtrDict<T> &);
- T *operator[](void *) const;
+ QPtrDict<T> &operator=(const QPtrDict<T> &pd) { impl.assign(pd.impl,del_item); QCollection::operator=(pd); return *this; }
+ T *operator[](void *key) const { return (T *)impl.find(key); }
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
+ private:
+ static void deleteFunc(void *item) {
+ delete (T *)item;
+ }
+
+ KWQPtrDictImpl impl;
+ friend class QPtrDictIterator<T>;
}; // class QPtrDict ===========================================================
@@ -92,22 +103,24 @@ public:
QPtrDictIterator() {}
#endif
- QPtrDictIterator(const QPtrDict<T> &);
+ QPtrDictIterator(const QPtrDict<T> &pd) : impl(pd.impl) {}
~QPtrDictIterator() {}
// member functions --------------------------------------------------------
- T *current() const;
- void *currentKey() const;
+ uint count() { return impl.count(); }
+ T *current() const { return (T *)impl.current(); }
+ void *currentKey() const { return impl.currentKey(); }
// operators ---------------------------------------------------------------
- T *operator++();
+ T *operator++() { return (T *)(++impl); }
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
private:
+ KWQPtrDictIteratorImpl impl;
// add copy constructor
// this private declaration prevents copying
diff --git a/WebCore/src/kwq/KWQKGlobal.mm b/WebCore/kwq/KWQPtrDictImpl.h
similarity index 54%
copy from WebCore/src/kwq/KWQKGlobal.mm
copy to WebCore/kwq/KWQPtrDictImpl.h
index 72a3056..9937488 100644
--- a/WebCore/src/kwq/KWQKGlobal.mm
+++ b/WebCore/kwq/KWQPtrDictImpl.h
@@ -22,79 +22,70 @@
* (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 <kwqdebug.h>
-#include <kglobal.h>
-#include <kconfig.h>
-#include <kcharsets.h>
+#ifndef KWQ_PTRDICT_IMPL_H
+#define KWQ_PTRDICT_IMPL_H
-#include <qdict.h>
+#include <config.h>
+#include <KWQDef.h>
+
+#ifndef USING_BORROWED_PTRQDICT
+
+#include <stddef.h>
#define Fixed MacFixed
#define Rect MacRect
#define Boolean MacBoolean
-#include <Cocoa/Cocoa.h>
+#include <CoreFoundation/CFDictionary.h>
#undef Fixed
#undef Rect
#undef Boolean
-KWQStaticStringDict *KGlobal::_stringDict = 0L;
-KInstance *KGlobal::_instance = 0L;
-KLocale *KGlobal::_locale = 0L;
-KCharsets *KGlobal::_charsets = 0L;
-
-class KWQStaticStringDict : public QDict<QString>
+class KWQPtrDictImpl
{
-public:
- KWQStaticStringDict() : QDict<QString>() { };
-};
+ public:
+ KWQPtrDictImpl(int size, void (*deleteFunc)(void *), const CFDictionaryKeyCallBacks *cfdkcb = NULL);
+ KWQPtrDictImpl(const KWQPtrDictImpl &pdi);
+ ~KWQPtrDictImpl();
+
+ void clear(bool deleteItems);
+ uint count() const;
-KInstance *KGlobal::instance()
-{
- _logNotYetImplemented();
- return 0L;
-}
+ void *take(void *key);
+ void insert(void *key, const void *value);
+ bool remove(void *key, bool deleteItem);
+ void *find(void *key) const;
+ KWQPtrDictImpl &assign(const KWQPtrDictImpl &pdi, bool deleteItems);
+ private:
+ void KWQPtrDictImpl::swap(KWQPtrDictImpl &di);
-KCharsets *KGlobal::charsets()
-{
- if (_charsets == 0L) {
- _charsets = new KCharsets();
- }
- return _charsets;
-}
+ class KWQPtrDictPrivate;
+
+ KWQPtrDictPrivate *d;
+ friend class KWQPtrDictIteratorImpl;
+};
-KLocale *KGlobal::locale()
-{
- _logNotYetImplemented();
- return 0L;
-}
+class KWQPtrDictIteratorImpl {
+ public:
+ KWQPtrDictIteratorImpl(const KWQPtrDictImpl &pdi);
+ ~KWQPtrDictIteratorImpl();
-KStandardDirs *KGlobal::dirs()
-{
- _logNotYetImplemented();
- return 0L;
-}
+ uint count() const;
+ void *current() const;
+ void *currentKey() const;
+ void *KWQPtrDictIteratorImpl::toFirst();
+
+ void *operator++();
+ private:
+ class KWQPtrDictIteratorPrivate;
+
+ KWQPtrDictIteratorPrivate *d;
+};
-KConfig *KGlobal::config()
-{
- _logNotYetImplemented();
- return new KConfig("foo");
-}
+#endif
-const QString &KGlobal::staticQString(const QString &str)
-{
- if (!_stringDict) {
- _stringDict = new KWQStaticStringDict;
- }
- QString *result = _stringDict->find(str);
- if (!result)
- {
- result = new QString(str);
- _stringDict->insert(str, result);
- }
- return *result;
-}
+#endif
diff --git a/WebCore/kwq/KWQPtrDictImpl.mm b/WebCore/kwq/KWQPtrDictImpl.mm
new file mode 100644
index 0000000..8995e52
--- /dev/null
+++ b/WebCore/kwq/KWQPtrDictImpl.mm
@@ -0,0 +1,236 @@
+/*
+ * 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 <KWQPtrDictImpl.h>
+
+#ifndef USING_BORROWED_QPTRDICT
+
+#include <new>
+
+class KWQPtrDictImpl::KWQPtrDictPrivate
+{
+public:
+ KWQPtrDictPrivate(int size, void (*deleteFunc)(void *), const CFDictionaryKeyCallBacks *cfdkcb);
+ KWQPtrDictPrivate(KWQPtrDictPrivate &dp);
+ ~KWQPtrDictPrivate();
+
+ CFMutableDictionaryRef cfdict;
+ void (*del)(void *);
+};
+
+KWQPtrDictImpl::KWQPtrDictPrivate::KWQPtrDictPrivate(int size, void (*deleteFunc)(void *), const CFDictionaryKeyCallBacks *cfdkcb) :
+ cfdict(CFDictionaryCreateMutable(NULL, 0, cfdkcb, NULL)),
+ del(deleteFunc)
+{
+ if (cfdict == NULL) {
+ throw bad_alloc();
+ }
+}
+
+KWQPtrDictImpl::KWQPtrDictPrivate::KWQPtrDictPrivate(KWQPtrDictPrivate &dp) :
+ cfdict(CFDictionaryCreateMutableCopy(NULL, 0, dp.cfdict)),
+ del(dp.del)
+{
+ if (cfdict == NULL) {
+ throw bad_alloc();
+ }
+}
+
+KWQPtrDictImpl::KWQPtrDictPrivate::~KWQPtrDictPrivate()
+{
+ CFRelease(cfdict);
+}
+
+KWQPtrDictImpl::KWQPtrDictImpl(int size, void (*deleteFunc)(void *), const CFDictionaryKeyCallBacks *cfdkcb) :
+ d(new KWQPtrDictPrivate(size, deleteFunc, cfdkcb))
+{
+}
+
+KWQPtrDictImpl::KWQPtrDictImpl(const KWQPtrDictImpl &di) :
+ d(new KWQPtrDictPrivate(*di.d))
+{
+}
+
+
+KWQPtrDictImpl::~KWQPtrDictImpl()
+{
+ delete d;
+}
+
+static void invokeDeleteFuncOnValue (const void *key, const void *value, void *deleteFunc)
+{
+ void (*del)(void *) = (void (*)(void *))deleteFunc;
+
+ del((void *)value);
+}
+
+void KWQPtrDictImpl::clear(bool deleteItems)
+{
+ if (deleteItems) {
+ CFDictionaryApplyFunction(d->cfdict, invokeDeleteFuncOnValue, d->del);
+ }
+
+ CFDictionaryRemoveAllValues(d->cfdict);
+}
+
+uint KWQPtrDictImpl::count() const
+{
+ return CFDictionaryGetCount(d->cfdict);
+}
+
+void KWQPtrDictImpl::insert(void *key, const void *value)
+{
+ CFDictionarySetValue(d->cfdict, key /* DIFF: key.getCFMutableString() */, value);
+
+}
+
+bool KWQPtrDictImpl::remove(void *key, bool deleteItem)
+{
+ void *value = (void *)CFDictionaryGetValue(d->cfdict, key /* DIFF: key.getCFMutableString() */);
+
+ if (value == nil) {
+ return false;
+ }
+
+ CFDictionaryRemoveValue(d->cfdict, key /* DIFF: key.getCFMutableString() */);
+
+ if (deleteItem) {
+ d->del(value);
+ }
+
+ return true;
+}
+
+void *KWQPtrDictImpl::find(void *key) const
+{
+ return (void *)CFDictionaryGetValue(d->cfdict, key /* key.getCFMutableString() */);
+}
+
+void KWQPtrDictImpl::swap(KWQPtrDictImpl &di)
+{
+ KWQPtrDictPrivate *tmp;
+
+ tmp = di.d;
+ di.d = d;
+ d = tmp;
+}
+
+KWQPtrDictImpl &KWQPtrDictImpl::assign(const KWQPtrDictImpl &di, bool deleteItems)
+{
+ KWQPtrDictImpl tmp(di);
+
+ if (deleteItems) {
+ clear(true);
+ }
+
+ swap(tmp);
+
+ return *this;
+}
+
+
+void *KWQPtrDictImpl::take(void *key)
+{
+ void *value = find(key);
+ remove(key, false);
+ return value;
+}
+
+
+
+
+
+class KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate
+{
+public:
+ KWQPtrDictIteratorPrivate(CFMutableDictionaryRef cfdict);
+ ~KWQPtrDictIteratorPrivate();
+ uint count;
+ uint pos;
+ void **keys;
+ void **values;
+};
+
+
+KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate::KWQPtrDictIteratorPrivate(CFMutableDictionaryRef cfdict) :
+ count(CFDictionaryGetCount(cfdict)),
+ pos(0),
+ keys(new void*[count]),
+ values(new void*[count])
+{
+ CFDictionaryGetKeysAndValues(cfdict, (const void **)keys, (const void **)values);
+}
+
+KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate::~KWQPtrDictIteratorPrivate()
+{
+ delete keys;
+ delete values;
+}
+
+
+KWQPtrDictIteratorImpl::KWQPtrDictIteratorImpl(const KWQPtrDictImpl &di) :
+ d(new KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate(di.d->cfdict))
+{
+}
+
+KWQPtrDictIteratorImpl::~KWQPtrDictIteratorImpl()
+{
+ delete d;
+}
+
+uint KWQPtrDictIteratorImpl::count() const
+{
+ return d->count;
+}
+
+void *KWQPtrDictIteratorImpl::current() const
+{
+ if (d->pos >= d->count) {
+ return NULL;
+ }
+ return d->values[d->pos];
+}
+
+void * /* DIFF: QString */ KWQPtrDictIteratorImpl::currentKey() const
+{
+ if (d->pos >= d->count) {
+ return NULL; /* DIFF: QString(); */
+ }
+ return d->keys[d->pos]; /* DIFF: QString::fromCFString((CFStringRef)d->keys[d->pos]); */
+}
+
+void *KWQPtrDictIteratorImpl::toFirst()
+{
+ d->pos = 0;
+ return current();
+}
+
+void *KWQPtrDictIteratorImpl::operator++()
+{
+ ++(d->pos);
+ return current();
+}
+
+#endif
diff --git a/WebCore/kwq/KWQSortedList.h b/WebCore/kwq/KWQSortedList.h
index bda8bb3..9a388e9 100644
--- a/WebCore/kwq/KWQSortedList.h
+++ b/WebCore/kwq/KWQSortedList.h
@@ -50,19 +50,32 @@ public:
// constructors, copy constructors, and destructors ------------------------
- QSortedList();
- QSortedList(const QSortedList<T> &);
- ~QSortedList();
+ QSortedList() : QList<T>() {}
+ QSortedList(const QSortedList<T> &sl) : QList<T>(sl) {}
+ ~QSortedList() {}
- // member functions --------------------------------------------------------
+ // Member functions --------------------------------------------------------
// operators ---------------------------------------------------------------
- QSortedList<T> &operator=(const QSortedList<T> &);
+ QSortedList<T> &operator=(const QSortedList<T> &sl) { QList<T>::operator=(sl); return *this; }
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
+ virtual int compareItems(void *a, void *b)
+ {
+ T *ta = (T *)a;
+ T *tb = (T *)b;
+ if (*ta == *tb) {
+ return 0;
+ } else if (*ta < *tb) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
+
}; // class QSortedList ========================================================
#endif // USING_BORROWED_QSORTEDLIST
diff --git a/WebCore/kwq/Makefile.am b/WebCore/kwq/Makefile.am
index a6a28e5..b61e499 100644
--- a/WebCore/kwq/Makefile.am
+++ b/WebCore/kwq/Makefile.am
@@ -27,6 +27,7 @@ libkwq_o_SOURCES = \
KWQCursor.mm \
KWQDCOPClient.mm \
KWQDateTime.mm \
+ KWQDictImpl.mm \
KWQDrawUtil.mm \
KWQEvent.mm \
KWQFont.mm \
@@ -36,6 +37,7 @@ libkwq_o_SOURCES = \
KWQFrame.mm \
KWQGuardedPtr.mm \
KWQPoint.mm \
+ KWQPtrDictImpl.mm \
KWQRect.mm \
KWQSize.mm \
KWQHBox.mm \
@@ -85,6 +87,7 @@ libkwq_o_SOURCES = \
KWQLabel.mm \
KWQLineEdit.mm \
KWQListBox.mm \
+ KWQMapImpl.mm \
KWQMovie.mm \
KWQNSTextField.mm \
KWQObject.mm \
diff --git a/WebCore/kwq/qt/_qdict.h b/WebCore/kwq/qt/_qdict.h
index 912aca3..0b430cd 100644
--- a/WebCore/kwq/qt/_qdict.h
+++ b/WebCore/kwq/qt/_qdict.h
@@ -40,9 +40,7 @@
// KWQ hacks ---------------------------------------------------------------
-#ifndef USING_BORROWED_QDICT
-#define USING_BORROWED_QDICT
-#endif
+#ifdef USING_BORROWED_QDICT
#include <KWQDef.h>
#include <iostream>
@@ -114,6 +112,7 @@ public:
type *operator+=(uint j) { return (type *)QGDictIterator::operator+=(j);}
};
+#if 0
#ifdef _KWQ_IOSTREAM_
template <class T>
ostream &operator<<(ostream &o, const QDict<T>&d)
@@ -135,5 +134,8 @@ ostream &operator<<(ostream &o, const QDict<T>&d)
return o;
}
#endif
-
+#endif
+
+#endif
+
#endif // QDICT_H
diff --git a/WebCore/kwq/qt/_qgdict.h b/WebCore/kwq/qt/_qgdict.h
index 25e2e17..88575b2 100644
--- a/WebCore/kwq/qt/_qgdict.h
+++ b/WebCore/kwq/qt/_qgdict.h
@@ -40,6 +40,8 @@
// KWQ hacks ---------------------------------------------------------------
+#include <config.h>
+
#ifndef USING_BORROWED_QDICT
#define USING_BORROWED_QDICT
#endif
@@ -235,5 +237,4 @@ inline void *QGDictIterator::getKeyPtr() const
return curNode ? ((QPtrBucket*)curNode)->getKey() : 0;
}
-
#endif // QGDICT_H
diff --git a/WebCore/kwq/qt/_qptrdict.h b/WebCore/kwq/qt/_qptrdict.h
index 87df229..fc3441e 100644
--- a/WebCore/kwq/qt/_qptrdict.h
+++ b/WebCore/kwq/qt/_qptrdict.h
@@ -40,9 +40,9 @@
// KWQ hacks ---------------------------------------------------------------
+#include <config.h>
+
#ifndef USING_BORROWED_QPTRDICT
-#define USING_BORROWED_QPTRDICT
-#endif
#include <KWQDef.h>
#include <iostream>
@@ -110,6 +110,7 @@ public:
type *operator+=(uint j) { return (type *)QGDictIterator::operator+=(j);}
};
+#if 0
#ifdef _KWQ_IOSTREAM_
template <class T>
ostream &operator<<(ostream &o, const QPtrDict<T>&d)
@@ -131,6 +132,8 @@ ostream &operator<<(ostream &o, const QPtrDict<T>&d)
return o;
}
#endif
+#endif
+#endif
#endif // QPTRDICT_H
diff --git a/WebCore/kwq/qt/qdict.h b/WebCore/kwq/qt/qdict.h
index 4234247..a3ee0f4 100644
--- a/WebCore/kwq/qt/qdict.h
+++ b/WebCore/kwq/qt/qdict.h
@@ -33,13 +33,18 @@
// USING_BORROWED_QDICT ========================================================
#ifdef USING_BORROWED_QDICT
+
#include <_qdict.h>
+
#else
#include <_qcollection.h>
-#include "qstring.h"
+#include <qstring.h>
+#include <KWQDictImpl.h>
+
+template<class T> class QDictIterator;
// class QDict =================================================================
@@ -53,25 +58,32 @@ public:
// constructors, copy constructors, and destructors ------------------------
- QDict(int size=17, bool caseSensitive=TRUE);
- QDict(const QDict<T> &);
- ~QDict();
+ QDict(int size=17, bool caseSensitive=TRUE) : impl(size, caseSensitive, QDict::deleteFunc) {}
+ QDict(const QDict<T> &d) : impl(d.impl) {}
+ virtual ~QDict() { impl.clear(del_item); }
// member functions --------------------------------------------------------
- void clear();
- void insert(const QString &, const T *);
- bool remove(const QString &);
- T *find(const QString &) const;
- uint count() const;
+ virtual void clear() { impl.clear(del_item); }
+ virtual uint count() const { return impl.count(); }
+ void insert(const QString &key, const T *value) { impl.insert(key,(void *)value);}
+ bool remove(const QString &key) { return impl.remove(key,del_item); }
+ T *find(const QString &key) const { return (T *)impl.find(key); }
// operators ---------------------------------------------------------------
- QDict<T> &operator=(const QDict<T> &);
+ QDict<T> &operator=(const QDict<T> &d) { impl.assign(d.impl,del_item); QCollection::operator=(d); return *this;}
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
+ private:
+ static void deleteFunc(void *item) {
+ delete (T *)item;
+ }
+
+ KWQDictImpl impl;
+ friend class QDictIterator<T>;
}; // class QDict ==============================================================
@@ -92,23 +104,25 @@ public:
QDictIterator() {}
#endif
- QDictIterator(const QDict<T> &);
- ~QDictIterator();
+ QDictIterator(const QDict<T> &d) : impl(d.impl) {}
+ ~QDictIterator() {}
// member functions --------------------------------------------------------
- uint count() const;
- T *current() const;
- T *toFirst();
+ uint count() const { return impl.count(); }
+ T *current() const { return (T *) impl.current(); }
+ QString currentKey() const { return impl.currentStringKey(); }
+ T *toFirst() { return (T *)impl.toFirst(); }
// operators ---------------------------------------------------------------
- T *operator++();
+ T *operator++() { return (T *)(++impl); }
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
private:
+ KWQDictIteratorImpl impl;
// add copy constructor
// this private declaration prevents copying
diff --git a/WebCore/kwq/qt/qmap.h b/WebCore/kwq/qt/qmap.h
index b21233b..4c8b0dc 100644
--- a/WebCore/kwq/qt/qmap.h
+++ b/WebCore/kwq/qt/qmap.h
@@ -36,143 +36,387 @@
#include <_qmap.h>
#else
+#include <iostream>
#include <KWQDef.h>
-// class QMapIterator ==========================================================
-
-template<class K, class T> class QMapIterator {
-public:
-
- // typedefs ----------------------------------------------------------------
- // enums -------------------------------------------------------------------
- // constants ---------------------------------------------------------------
- // static member functions -------------------------------------------------
-
- // constructors, copy constructors, and destructors ------------------------
-
- QMapIterator();
- QMapIterator(const QMapIterator<K,T>&);
+#include <KWQMapImpl.h>
-// add no-op destructor
-#ifdef _KWQ_PEDANTIC_
- ~QMapIterator() {}
-#endif
-
- // member functions --------------------------------------------------------
+template <class K, class V> class QMap;
+template <class K, class V> class QMapIterator;
+template <class K, class V> class QMapConstIterator;
- const K& key() const;
- const T& data() const;
- // operators ---------------------------------------------------------------
-
- QMapIterator<K,T> &operator=(const QMapIterator<K,T> &);
- bool operator==(const QMapIterator<K,T>&) const;
- bool operator!=(const QMapIterator<K,T>&) const;
- T& operator*();
- const T& operator*() const;
- QMapIterator<K,T>& operator++();
-
- // this is not declared in the code, although assignment of this type
- // is used in the code... i guess a pointer copy is what they want
- //
- //QMapIterator<K,T> &operator=(const QMapIterator<K,T> &);
- //
-
-// protected -------------------------------------------------------------------
-// private ---------------------------------------------------------------------
+template <class K, class V> class QMapNode : private KWQMapNodeImpl
+{
+ private:
+ QMapNode(K k, V v) :
+ key(k),
+ value(v)
+ {
+ }
+
+ // intentionally not defined
+ QMapNode(const QMapNode<K,V>&node);
+
+ static QMapNode<K,V> *copyTree(const QMapNode<K,V> *node,
+ QMapNode<K,V> *subtreePredecessor,
+ QMapNode<K,V> *subtreeSuccessor)
+ {
+ if (node == NULL) {
+ return NULL;
+ }
+
+ // FIXME: not exception-safe - use auto_ptr?
+ QMapNode<K,V> *copy = new QMapNode<K,V>(node->key, node->value);
+ copy->color = node->color;
+
+ if (node->prevIsChild) {
+ copy->prevIsChild = true;
+ copy->prev = copyTree((QMapNode<K,V> *)node->prev, subtreePredecessor, copy);
+ } else {
+ copy->prevIsChild = false;
+ copy->prev = subtreePredecessor;
+ }
+
+ if (node->nextIsChild) {
+ copy->nextIsChild = true;
+ copy->next = copyTree((QMapNode<K,V> *)node->next, copy, subtreeSuccessor);
+ } else {
+ copy->nextIsChild = false;
+ copy->next = subtreeSuccessor;
+ }
+
+ return copy;
+ }
+
+ ~QMapNode()
+ {
+ delete left();
+ delete right();
+ }
+
+ K key;
+ V value;
+
+ friend class QMap<K,V>;
+ friend class QMapIterator<K,V>;
+ friend class QMapConstIterator<K,V>;
+};
+// class QMapIterator ==========================================================
+template<class K, class V> class QMapIterator : private KWQMapIteratorImpl {
+public:
+ QMapIterator()
+ {
+ }
+
+ QMapIterator(const QMapIterator<K,V> &iter) : KWQMapIteratorImpl(iter)
+ {
+ }
+
+ ~QMapIterator()
+ {
+ }
+
+ const K& key() const
+ {
+ return ((QMapNode<K,V> *)node)->key;
+ }
+
+ const V& data() const
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ QMapIterator<K,V> &operator=(const QMapIterator<K,V> &iter)
+ {
+ node = iter.node;
+ return *this;
+ }
+
+ bool operator==(const QMapIterator<K,V>&iter) const
+ {
+ return node == iter.node;
+ }
+
+ bool operator!=(const QMapIterator<K,V>&iter) const
+ {
+ return node != iter.node;
+ }
+
+ V& operator*()
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ const V& operator*() const
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ QMapIterator<K,V>& operator++()
+ {
+ incrementInternal();
+ return *this;
+ }
+
+private:
+ QMapIterator(QMapNode<K,V> *n)
+ {
+ node = n;
+ }
+
+ friend class QMap<K,V>;
+ friend class QMapConstIterator<K,V>;
}; // class QMapIterator =======================================================
// class QMapConstIterator =====================================================
-template<class K, class T> class QMapConstIterator {
+template<class K, class V> class QMapConstIterator : private KWQMapIteratorImpl {
public:
-
- // typedefs ----------------------------------------------------------------
- // enums -------------------------------------------------------------------
- // constants ---------------------------------------------------------------
- // static member functions -------------------------------------------------
-
- // constructors, copy constructors, and destructors ------------------------
-
- QMapConstIterator();
- QMapConstIterator(const QMapConstIterator<K,T> &);
- QMapConstIterator(const QMapIterator<K,T> &);
-
- ~QMapConstIterator();
-
- // member functions --------------------------------------------------------
-
- const K& key() const;
- const T& data() const;
-
- // operators ---------------------------------------------------------------
-
- QMapConstIterator<K,T> &operator=(const QMapConstIterator<K,T> &);
- bool operator==(const QMapConstIterator<K,T> &) const;
- bool operator!=(const QMapConstIterator<K,T> &) const;
- const T &operator*() const;
- QMapConstIterator<K,T>& operator++();
-
- // this is not declared in the code, although assignment of this type
- // is used in the code... i guess a pointer copy is what they want
- //
- //QMapConstIterator<K,T> &operator=(const QMapConstIterator<K,T> &);
- //
-
-// protected -------------------------------------------------------------------
-// private ---------------------------------------------------------------------
-
+ QMapConstIterator() : KWQMapIteratorImpl()
+ {
+ }
+
+ QMapConstIterator(const QMapConstIterator<K,V> &citer) : KWQMapIteratorImpl(citer)
+ {
+ }
+
+ QMapConstIterator(const QMapIterator<K,V> &iter) : KWQMapIteratorImpl(iter)
+ {
+ }
+
+ ~QMapConstIterator()
+ {
+ }
+
+ const K& key() const
+ {
+ return ((QMapNode<K,V> *)node)->key;
+ }
+
+ const V& data() const
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ QMapConstIterator<K,V> &operator=(const QMapConstIterator<K,V> &citer)
+ {
+ node = citer.node;
+ return *this;
+ }
+
+ bool operator==(const QMapConstIterator<K,V> &citer) const
+ {
+ return node == citer.node;
+ }
+
+ bool operator!=(const QMapConstIterator<K,V> &citer) const
+ {
+ return node != citer.node;
+ }
+
+ const V &operator*() const
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ QMapConstIterator<K,V>& operator++()
+ {
+ incrementInternal();
+ return *this;
+ }
+
+private:
+ QMapConstIterator(QMapNode<K,V> *n)
+ {
+ node = n;
+ }
+
+ friend class QMap<K,V>;
}; // class QMapConstIterator ==================================================
+
// class QMap ==================================================================
-template <class K, class T> class QMap {
+template <class K, class V> class QMap : public KWQMapImpl {
public:
// typedefs ----------------------------------------------------------------
- typedef QMapIterator<K, T> Iterator;
- typedef QMapConstIterator< K, T> ConstIterator;
+ typedef QMapIterator<K,V> Iterator;
+ typedef QMapConstIterator<K,V> ConstIterator;
// enums -------------------------------------------------------------------
// constants ---------------------------------------------------------------
// static member functions -------------------------------------------------
// constructors, copy constructors, and destructors ------------------------
-
- QMap();
- QMap(const QMap<K,T>&);
- ~QMap();
-
- // member functions --------------------------------------------------------
- void clear();
- uint count() const;
- Iterator begin();
- Iterator end();
-
- ConstIterator begin() const;
- ConstIterator end() const;
+ QMap() :
+ KWQMapImpl(new QMapNode<K,V>(K(),V()), 0)
+ {
+ }
- Iterator insert(const K&, const T&);
- void remove(const K&);
+ QMap(const QMap<K,V>& m) :
+ KWQMapImpl(QMapNode<K,V>::copyTree((QMapNode<K,V> *)m.endInternal(), NULL, NULL), m.count())
+ {
+ }
- ConstIterator find (const K &) const;
+ virtual ~QMap()
+ {
+ clear();
+ delete endInternal();
+ }
+
+ // member functions --------------------------------------------------------
- // operators ---------------------------------------------------------------
+ void clear()
+ {
+ clearInternal();
+ }
+
+ uint count() const
+ {
+ return countInternal();
+ }
+
+ Iterator begin()
+ {
+ return Iterator((QMapNode<K,V> *)beginInternal());
+ }
+
+ Iterator end()
+ {
+ return Iterator((QMapNode<K,V> *)endInternal());
+ }
+
+ ConstIterator begin() const
+ {
+ return ConstIterator((QMapNode<K,V> *)beginInternal());
+ }
+
+ ConstIterator end() const
+ {
+ return ConstIterator((QMapNode<K,V> *)endInternal());
+ }
+
+ Iterator insert(const K& key, const V& value)
+ {
+ QMapNode<K,V> tmp(key,value);
+
+ return Iterator((QMapNode<K,V> *)insertInternal(&tmp, true));
+ }
+
+ void remove(const K& key)
+ {
+ QMapNode<K,V> tmp(key, V());
+ removeInternal(&tmp);
+ }
+
+ ConstIterator find (const K &key) const
+ {
+ QMapNode<K,V> tmp(key, V());
+ QMapNode<K,V> *result = (QMapNode<K,V> *)findInternal(&tmp);
+
+ if (result != NULL) {
+ return ConstIterator(result);
+ } else {
+ return ConstIterator(end());
+ }
+ }
- QMap<K,T>& operator=(const QMap<K,T>&);
- T& operator[](const K& k);
+ // operators ---------------------------------------------------------------
-// protected -------------------------------------------------------------------
-// private ---------------------------------------------------------------------
+ QMap<K,V>& operator=(const QMap<K,V>&map)
+ {
+ QMap<K,V> tmp(map);
+ swap(tmp);
+ return *this;
+ }
+
+ V& operator[](const K& key)
+ {
+ QMapNode<K,V> tmp(key, V());
+
+ return ((QMapNode<K,V> *)insertInternal(&tmp, false))->value;
+ }
+
+
+protected:
+ virtual void copyNode(KWQMapNodeImpl *isrc, KWQMapNodeImpl *idst)
+ {
+ QMapNode<K,V> *src = (QMapNode<K,V> *)isrc;
+ QMapNode<K,V> *dst = (QMapNode<K,V> *)idst;
+ dst->key = src->key;
+ dst->value = src->value;
+ }
+
+ virtual KWQMapNodeImpl *duplicateNode(KWQMapNodeImpl *isrc)
+ {
+ QMapNode<K,V> *src = (QMapNode<K,V> *)isrc;
+ return new QMapNode<K,V>(src->key, src->value);
+ }
+
+ virtual CompareResult compareNodes(KWQMapNodeImpl *ia, KWQMapNodeImpl *ib) const
+ {
+ QMapNode<K,V> *a = (QMapNode<K,V> *)ia;
+ QMapNode<K,V> *b = (QMapNode<K,V> *)ib;
+
+ if (a->key == b->key) {
+ return Equal;
+ } else if (a->key < b->key) {
+ return Less;
+ } else {
+ return Greater;
+ }
+ }
+
+ virtual void swapNodes(KWQMapNodeImpl *ia, KWQMapNodeImpl *ib)
+ {
+ QMapNode<K,V> *a = (QMapNode<K,V> *)ia;
+ QMapNode<K,V> *b = (QMapNode<K,V> *)ib;
+
+ K tmpKey = a->key;
+ V tmpValue = a->value;
+ a->key = b->key;
+ a->value = b->value;
+ b->key = tmpKey;
+ b->value = tmpValue;
+ }
+
+ virtual void deleteNode(KWQMapNodeImpl *inode)
+ {
+ delete (QMapNode<K,V> *)inode;
+ }
}; // class QMap ===============================================================
+
+#ifdef _KWQ_IOSTREAM_
+template<class K, class V>
+inline ostream &operator<<(ostream &stream, const QMap<K,V> &m)
+{
+ uint count = m.count();
+ stream << "QMap: [size: " << count << "; items: ";
+
+ QMapConstIterator<K,V> iter = m.begin();
+
+ for (unsigned int i = 0; i < count; i++) {
+ stream << "(" << iter.key() << "," << iter.data() << ")";
+ if (i + 1 < count) {
+ stream << ", ";
+ }
+ ++iter;
+ }
+
+ return stream << "]";
+}
+#endif
+
#endif // USING_BORROWED_QMAP
#endif
diff --git a/WebCore/kwq/qt/qptrdict.h b/WebCore/kwq/qt/qptrdict.h
index 3f0c240..d32c71f 100644
--- a/WebCore/kwq/qt/qptrdict.h
+++ b/WebCore/kwq/qt/qptrdict.h
@@ -39,6 +39,10 @@
#include <KWQDef.h>
#include <_qcollection.h>
+#include <KWQPtrDictImpl.h>
+
+template <class T> class QPtrDictIterator;
+
// class QPtrDict ==============================================================
template <class T> class QPtrDict : public QCollection {
@@ -51,27 +55,34 @@ public:
// constructors, copy constructors, and destructors ------------------------
- QPtrDict(int size=17);
- QPtrDict(const QPtrDict<T> &);
- ~QPtrDict();
+ QPtrDict(int size=17) : impl(size, deleteFunc) {}
+ QPtrDict(const QPtrDict<T> &pd) : impl(pd.impl) {}
+ virtual ~QPtrDict() { impl.clear(del_item); }
// member functions --------------------------------------------------------
- void clear();
- uint count() const;
- T *take(void *);
+ virtual void clear() { impl.clear(del_item); }
+ virtual uint count() const { return impl.count(); }
- void insert(void *, const T *);
- void remove(void *);
+ T *take(void *key) { return (T *)impl.take(key); }
+ void insert(void *key, const T *value) { impl.insert(key, (void *)value); }
+ bool remove(void *key) { return impl.remove(key, del_item); }
// operators ---------------------------------------------------------------
- QPtrDict<T> &operator=(const QPtrDict<T> &);
- T *operator[](void *) const;
+ QPtrDict<T> &operator=(const QPtrDict<T> &pd) { impl.assign(pd.impl,del_item); QCollection::operator=(pd); return *this; }
+ T *operator[](void *key) const { return (T *)impl.find(key); }
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
+ private:
+ static void deleteFunc(void *item) {
+ delete (T *)item;
+ }
+
+ KWQPtrDictImpl impl;
+ friend class QPtrDictIterator<T>;
}; // class QPtrDict ===========================================================
@@ -92,22 +103,24 @@ public:
QPtrDictIterator() {}
#endif
- QPtrDictIterator(const QPtrDict<T> &);
+ QPtrDictIterator(const QPtrDict<T> &pd) : impl(pd.impl) {}
~QPtrDictIterator() {}
// member functions --------------------------------------------------------
- T *current() const;
- void *currentKey() const;
+ uint count() { return impl.count(); }
+ T *current() const { return (T *)impl.current(); }
+ void *currentKey() const { return impl.currentKey(); }
// operators ---------------------------------------------------------------
- T *operator++();
+ T *operator++() { return (T *)(++impl); }
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
private:
+ KWQPtrDictIteratorImpl impl;
// add copy constructor
// this private declaration prevents copying
diff --git a/WebCore/kwq/qt/qsortedlist.h b/WebCore/kwq/qt/qsortedlist.h
index bda8bb3..9a388e9 100644
--- a/WebCore/kwq/qt/qsortedlist.h
+++ b/WebCore/kwq/qt/qsortedlist.h
@@ -50,19 +50,32 @@ public:
// constructors, copy constructors, and destructors ------------------------
- QSortedList();
- QSortedList(const QSortedList<T> &);
- ~QSortedList();
+ QSortedList() : QList<T>() {}
+ QSortedList(const QSortedList<T> &sl) : QList<T>(sl) {}
+ ~QSortedList() {}
- // member functions --------------------------------------------------------
+ // Member functions --------------------------------------------------------
// operators ---------------------------------------------------------------
- QSortedList<T> &operator=(const QSortedList<T> &);
+ QSortedList<T> &operator=(const QSortedList<T> &sl) { QList<T>::operator=(sl); return *this; }
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
+ virtual int compareItems(void *a, void *b)
+ {
+ T *ta = (T *)a;
+ T *tb = (T *)b;
+ if (*ta == *tb) {
+ return 0;
+ } else if (*ta < *tb) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
+
}; // class QSortedList ========================================================
#endif // USING_BORROWED_QSORTEDLIST
diff --git a/WebCore/src/kwq/KWQArrayImpl.mm b/WebCore/src/kwq/KWQArrayImpl.mm
index f477ce7..8d364a0 100644
--- a/WebCore/src/kwq/KWQArrayImpl.mm
+++ b/WebCore/src/kwq/KWQArrayImpl.mm
@@ -27,7 +27,6 @@
#ifndef USING_BORROWED_QARRAY
-#include <cstring>
#include <new>
#define MIN(a,b) (((a)<(b))?(a):(b))
diff --git a/WebCore/src/kwq/kio/kprinter.h b/WebCore/src/kwq/KWQDictImpl.h
similarity index 68%
copy from WebCore/src/kwq/kio/kprinter.h
copy to WebCore/src/kwq/KWQDictImpl.h
index 4562554..dff4b2f 100644
--- a/WebCore/src/kwq/kio/kprinter.h
+++ b/WebCore/src/kwq/KWQDictImpl.h
@@ -23,30 +23,38 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef KPRINTER_H_
-#define KPRINTER_H_
+#ifndef KWQ_DICT_IMPL_H
+#define KWQ_DICT_IMPL_H
-#ifdef HAVE_CONFIG_H
#include <config.h>
-#endif
-
-#include <qpaintdevice.h>
+#include <KWQDef.h>
#include <qstring.h>
-#include <qwidget.h>
-#include <qsize.h>
-
-// NOTE: I stuck this file here rather than create a whole new
-// kdeprint directory
-
-class KPrinter : public QPaintDevice {
-public:
- bool setup(QWidget *parent=0);
- bool newPage();
- void setDocName(const QString &);
- void setCreator(const QString &);
- void setFullPage(bool);
- QSize margins() const;
+
+#ifndef USING_BORROWED_QDICT
+
+#include <KWQPtrDictImpl.h>
+
+class KWQDictImpl : public KWQPtrDictImpl {
+ public:
+ KWQDictImpl(int size, bool caseSensitive, void (*deleteFunc)(void *));
+ KWQDictImpl(const KWQDictImpl &di);
+ // ~KWQDictImpl();
+
+ void insert(const QString &key, const void *value);
+ bool remove(const QString &key, bool deleteItems);
+ void *find(const QString &key) const;
};
+
+class KWQDictIteratorImpl : public KWQPtrDictIteratorImpl {
+ public:
+ KWQDictIteratorImpl(const KWQDictImpl &di);
+ // ~KWQDictIteratorImpl();
+
+ QString currentStringKey() const;
+};
+
+
#endif
+#endif
diff --git a/WebCore/kwq/KWQBuffer.mm b/WebCore/src/kwq/KWQDictImpl.mm
similarity index 59%
copy from WebCore/kwq/KWQBuffer.mm
copy to WebCore/src/kwq/KWQDictImpl.mm
index de9a4cb..c16cf33 100644
--- a/WebCore/kwq/KWQBuffer.mm
+++ b/WebCore/src/kwq/KWQDictImpl.mm
@@ -22,69 +22,51 @@
* (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 <kwqdebug.h>
-#include <qbuffer.h>
+#include <KWQDictImpl.h>
+#include <CoreFoundation/CoreFoundation.h>
-#ifndef USING_BORROWED_QBUFFER
+#ifndef USING_BORROWED_QDICT
-#include <qiodevice.h>
-
-QBuffer::QBuffer() : opened(false), pos(0)
+KWQDictImpl::KWQDictImpl(int size, bool caseSensitive, void (*deleteFunc)(void *)) :
+ KWQPtrDictImpl(size, deleteFunc, &kCFCopyStringDictionaryKeyCallBacks)
{
}
-QBuffer::~QBuffer()
+KWQDictImpl::KWQDictImpl(const KWQDictImpl &di) :
+ KWQPtrDictImpl(di)
{
}
-
-QByteArray QBuffer::buffer() const
+void KWQDictImpl::insert(const QString &key, const void *value)
{
- return ba;
-}
+ KWQPtrDictImpl::insert(key.getCFMutableString(), value);
-uint QBuffer::size() const
-{
- return ba.size();
}
-bool QBuffer::isOpen()
+bool KWQDictImpl::remove(const QString &key, bool deleteItem)
{
- return opened;
+ return KWQPtrDictImpl::remove(key.getCFMutableString(), deleteItem);
}
-bool QBuffer::open(int mode)
+void *KWQDictImpl::find(const QString &key) const
{
- if (mode == IO_WriteOnly) {
- opened = true;
- pos = 0;
- return true;
- } else {
- return false;
- }
+ return KWQPtrDictImpl::find(key.getCFMutableString());
}
-void QBuffer::close()
+KWQDictIteratorImpl::KWQDictIteratorImpl(const KWQDictImpl &di) :
+ KWQPtrDictIteratorImpl(di)
{
- opened = false;
}
-int QBuffer::writeBlock(const char *data, uint len)
+QString KWQDictIteratorImpl::currentStringKey() const
{
- // FIXME: could easily be optimized a lot - leave extra space in
- // buffer for amortized constant time growth
+ void *key = currentKey();
- if (pos+len > ba.size()) {
- if (!ba.resize(pos+len)) {
- return -1;
- }
+ if (key == NULL) {
+ return QString();
}
- memcpy(ba.data()+pos, data, len);
- pos += len;
-
- return len;
+ return QString::fromCFString((CFStringRef)key);
}
-
#endif
diff --git a/WebCore/src/kwq/KWQMapImpl.h b/WebCore/src/kwq/KWQMapImpl.h
new file mode 100644
index 0000000..7c1be09
--- /dev/null
+++ b/WebCore/src/kwq/KWQMapImpl.h
@@ -0,0 +1,124 @@
+/*
+ * 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_MAP_IMPL_H
+#define KWQ_MAP_IMPL_H
+
+#include <config.h>
+
+#include <new>
+#include <iostream>
+
+#ifndef USING_BORROWED_QMAP
+
+
+class KWQMapNodeImpl
+{
+protected:
+ typedef enum { Red = 0, Black = 1 } KWQMapNodeColor;
+
+ KWQMapNodeImpl();
+
+ KWQMapNodeImpl *left();
+ const KWQMapNodeImpl *left() const;
+ KWQMapNodeImpl *right();
+ const KWQMapNodeImpl *right() const;
+ KWQMapNodeImpl *predecessor();
+ const KWQMapNodeImpl *predecessor() const;
+ KWQMapNodeImpl *successor();
+ const KWQMapNodeImpl *successor() const;
+
+ KWQMapNodeImpl *prev;
+ KWQMapNodeImpl *next;
+ bool prevIsChild;
+ bool nextIsChild;
+ KWQMapNodeColor color;
+
+ friend class KWQMapImpl;
+ friend class KWQMapIteratorImpl;
+
+#ifdef QMAP_TESTING
+ friend bool CheckRedBlackRules(KWQMapImpl *impl);
+ friend bool CheckRedBlackRulesAtNode(KWQMapImpl *impl, KWQMapNodeImpl *node, int &black_height);
+#endif
+};
+
+class KWQMapIteratorImpl {
+protected:
+ KWQMapNodeImpl *node;
+
+ KWQMapIteratorImpl();
+ KWQMapIteratorImpl(const KWQMapIteratorImpl& iter);
+ void incrementInternal();
+};
+
+class KWQMapImpl {
+ private:
+ // disallow default construction, copy construction and assignment
+ KWQMapImpl();
+ KWQMapImpl(const KWQMapImpl &);
+ KWQMapImpl &operator=(const KWQMapImpl &);
+
+ protected:
+ typedef enum { Less = -1, Equal = 0, Greater = 1 } CompareResult;
+
+ KWQMapImpl(KWQMapNodeImpl *node, uint count);
+
+ KWQMapNodeImpl *findInternal(KWQMapNodeImpl *target) const;
+ KWQMapNodeImpl *insertInternal(KWQMapNodeImpl *nodeToInsert, bool replaceExisting);
+ void removeInternal(KWQMapNodeImpl *nodeToRemove);
+ uint countInternal() const;
+ void clearInternal();
+ void swap(KWQMapImpl &map);
+ KWQMapNodeImpl *beginInternal() const;
+ KWQMapNodeImpl *endInternal() const;
+
+ virtual CompareResult compareNodes(KWQMapNodeImpl *a, KWQMapNodeImpl *b) const = 0;
+ virtual void copyNode(KWQMapNodeImpl *src, KWQMapNodeImpl *dst) = 0;
+ virtual KWQMapNodeImpl *duplicateNode(KWQMapNodeImpl *src) = 0;
+ virtual void swapNodes(KWQMapNodeImpl *a, KWQMapNodeImpl *b) = 0;
+ virtual void deleteNode(KWQMapNodeImpl *node) = 0;
+
+ private:
+ // can't possibly have a bigger height than this in a balanced tree
+ static const int MAX_STACK = 64;
+
+ void rebalanceAfterInsert(KWQMapNodeImpl **nodes, bool *wentLeft, int height);
+ void rebalanceAfterRemove(KWQMapNodeImpl *nodeToRemove, KWQMapNodeImpl **nodes, bool *wentLeft, int height);
+ void rotateRight(KWQMapNodeImpl *node, KWQMapNodeImpl *parent, bool leftParent);
+ void rotateLeft(KWQMapNodeImpl *node, KWQMapNodeImpl *parent, bool leftParent);
+
+ KWQMapNodeImpl *guard;
+ uint numNodes;
+
+#ifdef QMAP_TESTING
+ friend bool CheckRedBlackRules(KWQMapImpl *impl);
+ friend bool CheckRedBlackRulesAtNode(KWQMapImpl *impl, KWQMapNodeImpl *node, int &black_height);
+#endif
+};
+
+#endif
+
+#endif
diff --git a/WebCore/src/kwq/KWQMapImpl.mm b/WebCore/src/kwq/KWQMapImpl.mm
new file mode 100644
index 0000000..fdea9a4
--- /dev/null
+++ b/WebCore/src/kwq/KWQMapImpl.mm
@@ -0,0 +1,556 @@
+/*
+ * 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 <KWQMapImpl.h>
+
+#ifndef USING_BORROWED_QMAP
+
+// KWQMapNodeImpl
+
+KWQMapNodeImpl::KWQMapNodeImpl() :
+ prev(NULL),
+ next(NULL),
+ prevIsChild(true),
+ nextIsChild(true),
+ color(Red)
+{
+}
+
+KWQMapNodeImpl *KWQMapNodeImpl::left()
+{
+ return prevIsChild ? prev : NULL;
+}
+
+const KWQMapNodeImpl *KWQMapNodeImpl::left() const
+{
+ return prevIsChild ? prev : NULL;
+}
+
+KWQMapNodeImpl *KWQMapNodeImpl::right()
+{
+ return nextIsChild ? next : NULL;
+}
+
+const KWQMapNodeImpl *KWQMapNodeImpl::right() const
+{
+ return nextIsChild ? next : NULL;
+}
+
+KWQMapNodeImpl *KWQMapNodeImpl::predecessor()
+{
+ if (!prevIsChild || prev == NULL) {
+ return prev;
+ }
+ KWQMapNodeImpl *pred = left();
+ while (pred->right() != NULL) {
+ pred = pred->right();
+ }
+ return pred;
+}
+
+const KWQMapNodeImpl *KWQMapNodeImpl::predecessor() const
+{
+ if (!prevIsChild || prev == NULL) {
+ return prev;
+ }
+ const KWQMapNodeImpl *pred = left();
+ while (pred->right() != NULL) {
+ pred = pred->right();
+ }
+ return pred;
+}
+
+KWQMapNodeImpl *KWQMapNodeImpl::successor()
+{
+ if (!nextIsChild || next == NULL) {
+ return next;
+ }
+ KWQMapNodeImpl *succ = right();
+ while (succ->left() != NULL) {
+ succ = succ->left();
+ }
+ return succ;
+}
+
+const KWQMapNodeImpl *KWQMapNodeImpl::successor() const
+{
+ if (!nextIsChild || next == NULL) {
+ return next;
+ }
+ const KWQMapNodeImpl *succ = right();
+ while (succ->left() != NULL) {
+ succ = succ->left();
+ }
+ return succ;
+}
+
+
+KWQMapIteratorImpl::KWQMapIteratorImpl() : node(NULL)
+{
+}
+
+KWQMapIteratorImpl::KWQMapIteratorImpl(const KWQMapIteratorImpl& iter) : node(iter.node)
+{
+}
+
+void KWQMapIteratorImpl::incrementInternal()
+{
+ node = node->successor();
+}
+
+
+// KWQMapImpl
+
+
+KWQMapImpl::KWQMapImpl(KWQMapNodeImpl *node, uint count) :
+ guard(node),
+ numNodes(count)
+{
+}
+
+void KWQMapImpl::rotateRight(KWQMapNodeImpl *node, KWQMapNodeImpl *parent, bool leftParent)
+{
+ KWQMapNodeImpl *rotationChild = node->left();
+
+ if (leftParent) {
+ parent->prev = rotationChild;
+ } else {
+ parent->next = rotationChild;
+ }
+
+ node->prev = rotationChild->next;
+ node->prevIsChild = rotationChild->nextIsChild;
+
+ rotationChild->next = node;
+ rotationChild->nextIsChild = true;
+
+ // fixup threads
+ if (!node->prevIsChild) {
+ node->prev = rotationChild;
+ }
+ }
+
+void KWQMapImpl::rotateLeft(KWQMapNodeImpl *node, KWQMapNodeImpl *parent, bool leftParent)
+{
+ KWQMapNodeImpl *rotationChild = node->right();
+
+ if (leftParent) {
+ parent->prev = rotationChild;
+ } else {
+ parent->next = rotationChild;
+ }
+
+ node->next = rotationChild->prev;
+ node->nextIsChild = rotationChild->prevIsChild;
+
+ rotationChild->prev = node;
+ rotationChild->prevIsChild = true;
+
+ // fixup threads
+ if (!node->nextIsChild) {
+ node->next = rotationChild;
+ }
+}
+
+void KWQMapImpl::rebalanceAfterInsert(KWQMapNodeImpl **nodes, bool *wentLeft, int height)
+{
+ nodes[height]->color = KWQMapNodeImpl::Red;
+
+ while (nodes[height] != guard->prev && nodes[height-1]->color == KWQMapNodeImpl::Red) {
+ if (wentLeft[height-2]) {
+ KWQMapNodeImpl *uncle = nodes[height-2]->right();
+ if (uncle != NULL && uncle->color == KWQMapNodeImpl::Red) {
+ nodes[height-1]->color = KWQMapNodeImpl::Black;
+ uncle->color = KWQMapNodeImpl::Black;
+ nodes[height-2]->color = KWQMapNodeImpl::Red;
+
+ // go up two levels
+ height = height - 2;
+ } else {
+ KWQMapNodeImpl *parent;
+ if (!wentLeft[height-1]) {
+ parent = nodes[height-1]->right();
+ rotateLeft(nodes[height-1], nodes[height-2], wentLeft[height-2]);
+ } else {
+ parent = nodes[height-1];
+ }
+ parent->color = KWQMapNodeImpl::Black;
+ nodes[height-2]->color = KWQMapNodeImpl::Red;
+ rotateRight(nodes[height-2], nodes[height-3], wentLeft[height-3]);
+ break;
+ }
+ } else {
+ // same as the other branch, but with left and right swapped
+
+ KWQMapNodeImpl *uncle = nodes[height-2]->left();
+
+ if (uncle != NULL && uncle->color == KWQMapNodeImpl::Red) {
+ nodes[height-1]->color = KWQMapNodeImpl::Black;
+ uncle->color = KWQMapNodeImpl::Black;
+ nodes[height-2]->color = KWQMapNodeImpl::Red;
+
+ // go up two levels
+ height = height - 2;
+ } else {
+ KWQMapNodeImpl *parent;
+ if (wentLeft[height-1]) {
+ parent = nodes[height-1]->left();
+ rotateRight(nodes[height-1], nodes[height-2], wentLeft[height-2]);
+ } else {
+ parent = nodes[height-1];
+ }
+ parent->color = KWQMapNodeImpl::Black;
+ nodes[height-2]->color = KWQMapNodeImpl::Red;
+ rotateLeft(nodes[height-2], nodes[height-3], wentLeft[height-3]);
+ break;
+ }
+ }
+ }
+
+ guard->prev->color = KWQMapNodeImpl::Black;
+}
+
+void KWQMapImpl::rebalanceAfterRemove(KWQMapNodeImpl *nodeToRemove, KWQMapNodeImpl **nodes, bool *wentLeft, int height)
+{
+ if (nodeToRemove->color == KWQMapNodeImpl::Black) {
+ while (nodes[height] != guard->prev && (nodes[height]==NULL || nodes[height]->color==KWQMapNodeImpl::Black)) {
+ if (wentLeft[height-1]) {
+ KWQMapNodeImpl *sibling = nodes[height-1]->right();
+ if (sibling != NULL && sibling->color == KWQMapNodeImpl::Red) {
+ sibling->color = KWQMapNodeImpl::Black;
+ nodes[height-1]->color = KWQMapNodeImpl::Red;
+ rotateLeft(nodes[height-1], nodes[height-2], wentLeft[height-2]);
+
+ nodes[height] = nodes[height-1];
+ wentLeft[height] = true;
+ nodes[height-1] = sibling;
+ height = height + 1;
+
+ sibling = nodes[height-1]->right();
+ }
+ if ((sibling->left() == NULL || sibling->left()->color == KWQMapNodeImpl::Black) &&
+ (sibling->right() == NULL || sibling->right()->color == KWQMapNodeImpl::Black)) {
+ sibling->color = KWQMapNodeImpl::Red;
+ height = height - 1;
+ } else {
+ if (sibling->right() == NULL || sibling->right()->color == KWQMapNodeImpl::Black) {
+ sibling->left()->color = KWQMapNodeImpl::Black;
+ sibling->color = KWQMapNodeImpl::Red;
+ rotateRight(sibling, nodes[height-1], !wentLeft[height-1]);
+ sibling = nodes[height-1]->right();
+ }
+
+ sibling->color = nodes[height-1]->color;
+ nodes[height-1]->color = KWQMapNodeImpl::Black;
+ sibling->right()->color = KWQMapNodeImpl::Black;
+ rotateLeft(nodes[height-1], nodes[height-2], wentLeft[height-2]);
+
+ nodes[height] = guard->prev;
+ }
+ } else {
+ // same as the other branch, but with left and right swapped
+
+ KWQMapNodeImpl *sibling = nodes[height-1]->left();
+ if (sibling != NULL && sibling->color == KWQMapNodeImpl::Red) {
+ sibling->color = KWQMapNodeImpl::Black;
+ nodes[height-1]->color = KWQMapNodeImpl::Red;
+ rotateRight(nodes[height-1], nodes[height-2], wentLeft[height-2]);
+
+ nodes[height] = nodes[height-1];
+ wentLeft[height] = false;
+ nodes[height-1] = sibling;
+ height = height + 1;
+
+ sibling = nodes[height-1]->left();
+ }
+ if ((sibling->right() == NULL || sibling->right()->color == KWQMapNodeImpl::Black) &&
+ (sibling->left() == NULL || sibling->left()->color == KWQMapNodeImpl::Black)) {
+ sibling->color = KWQMapNodeImpl::Red;
+ height = height - 1;
+ } else {
+ if (sibling->left() == NULL || sibling->left()->color == KWQMapNodeImpl::Black) {
+ sibling->right()->color = KWQMapNodeImpl::Black;
+ sibling->color = KWQMapNodeImpl::Red;
+ rotateLeft(sibling, nodes[height-1], !wentLeft[height-1]);
+ sibling = nodes[height-1]->left();
+ }
+
+ sibling->color = nodes[height-1]->color;
+ nodes[height-1]->color = KWQMapNodeImpl::Black;
+ sibling->left()->color = KWQMapNodeImpl::Black;
+ rotateRight(nodes[height-1], nodes[height-2], wentLeft[height-2]);
+
+ nodes[height] = guard->prev;
+ }
+ }
+ }
+
+ if (nodes[height] != NULL) {
+ nodes[height]->color = KWQMapNodeImpl::Black;
+ }
+ }
+}
+
+KWQMapNodeImpl *KWQMapImpl::findInternal(KWQMapNodeImpl *target) const
+{
+ KWQMapNodeImpl *node = guard->left();
+
+ while (node != NULL) {
+ CompareResult compare = compareNodes(target,node);
+
+ if (compare == Equal) {
+ break;
+ } else if (compare == Less) {
+ node = node->left();
+ } else if (compare == Greater) {
+ node = node->right();
+ }
+ }
+
+ return node;
+}
+
+KWQMapNodeImpl *KWQMapImpl::insertInternal(KWQMapNodeImpl *nodeToInsert, bool replaceExisting)
+{
+ KWQMapNodeImpl *nodeStack[MAX_STACK];
+ bool wentLeftStack[MAX_STACK];
+ int height = 0;
+
+ nodeStack[height] = guard;
+ wentLeftStack[height] = true;
+ height++;
+
+ KWQMapNodeImpl *node = guard->left();
+
+ while (node != NULL) {
+ CompareResult compare = compareNodes(nodeToInsert, node);
+ if (compare == Equal) {
+ break;
+ } else if (compare == Less) {
+ nodeStack[height] = node;
+ wentLeftStack[height] = true;
+ height++;
+ node = node->left();
+ } else {
+ nodeStack[height] = node;
+ wentLeftStack[height] = false;
+ height++;
+ node = node->right();
+ }
+ }
+
+ if (node != NULL) {
+ if (replaceExisting) {
+ copyNode(nodeToInsert, node);
+ }
+ return node;
+ }
+
+ node = duplicateNode(nodeToInsert);
+
+ nodeStack[height] = node;
+
+ if (wentLeftStack[height-1]) {
+ // arrange for threading
+ node->prev = nodeStack[height-1]->prev;
+ node->prevIsChild = false;
+ node->next = nodeStack[height-1];
+ node->nextIsChild = false;
+
+ // make it the child
+ nodeStack[height-1]->prev = node;
+ nodeStack[height-1]->prevIsChild = true;
+ } else {
+ // arrange for threading
+ node->next = nodeStack[height-1]->next;
+ node->nextIsChild = false;
+ node->prev = nodeStack[height-1];
+ node->prevIsChild = false;
+
+ // make it the child
+ nodeStack[height-1]->next = node;
+ nodeStack[height-1]->nextIsChild = true;
+ }
+
+ rebalanceAfterInsert(nodeStack, wentLeftStack, height);
+ numNodes++;
+
+ return node;
+}
+
+void KWQMapImpl::removeInternal(KWQMapNodeImpl *nodeToDelete)
+{
+ KWQMapNodeImpl *nodeStack[MAX_STACK];
+ bool wentLeftStack[MAX_STACK];
+ int height = 0;
+
+ nodeStack[height] = guard;
+ wentLeftStack[height] = true;
+ height++;
+
+ KWQMapNodeImpl *node = guard->left();
+
+ while (node != NULL) {
+ CompareResult compare = compareNodes(nodeToDelete, node);
+ if (compare == Equal) {
+ break;
+ } else if (compare == Less) {
+ nodeStack[height] = node;
+ wentLeftStack[height] = true;
+ height++;
+ node = node->left();
+ } else {
+ nodeStack[height] = node;
+ wentLeftStack[height] = false;
+ height++;
+ node = node->right();
+ }
+ }
+
+ if (node == NULL) {
+ return;
+ }
+
+ KWQMapNodeImpl *removalParent;
+ KWQMapNodeImpl *nodeToRemove;
+ bool removalWentLeft;
+
+ if (node->left() == NULL || node->right() == NULL) {
+ // If this node has at most one subtree, we can remove it directly
+ nodeToRemove = node;
+ removalParent = nodeStack[height-1];
+ removalWentLeft = wentLeftStack[height-1];
+ } else {
+ // Otherwise we find the immediate successor (leftmost
+ // node in the right subtree), which must have at most one
+ // subtree, swap it's contents with the node we found, and
+ // remove it.
+ nodeToRemove = node->right();
+ wentLeftStack[height] = false;
+ nodeStack[height] = node;
+ height++;
+
+ removalParent = node;
+ removalWentLeft = false;
+
+ while (nodeToRemove->left() != NULL) {
+ wentLeftStack[height] = true;
+ nodeStack[height] = nodeToRemove;
+ removalParent = nodeToRemove;
+ nodeToRemove = nodeToRemove->left();
+ removalWentLeft = true;
+ height++;
+ }
+
+ swapNodes(node,nodeToRemove);
+ }
+
+
+ // find replacement node
+ KWQMapNodeImpl *removalReplacement;
+
+ if (nodeToRemove->left() != NULL) {
+ removalReplacement = nodeToRemove->left();
+ // fixup threading
+ nodeToRemove->predecessor()->next = nodeToRemove->next;
+ } else if (nodeToRemove->right() != NULL) {
+ removalReplacement = nodeToRemove->right();
+ // fixup threading
+ nodeToRemove->successor()->prev = nodeToRemove->prev;
+ } else {
+ removalReplacement = NULL;
+ }
+
+ nodeStack[height] = removalReplacement;
+
+ // detach removal node
+ if (removalWentLeft) {
+ if (removalReplacement == NULL) {
+ removalParent->prev = nodeToRemove->prev;
+ removalParent->prevIsChild = nodeToRemove->prevIsChild;
+ } else {
+ removalParent->prev = removalReplacement;
+ }
+ } else {
+ if (removalReplacement == NULL) {
+ removalParent->next = nodeToRemove->next;
+ removalParent->nextIsChild = nodeToRemove->nextIsChild;
+ } else {
+ removalParent->next = removalReplacement;
+ }
+ }
+
+ // do red-black rebalancing
+ rebalanceAfterRemove(nodeToRemove, nodeStack, wentLeftStack, height);
+
+ // detach removal node's children
+ nodeToRemove->next = NULL;
+ nodeToRemove->prev = NULL;
+
+ numNodes--;
+ deleteNode(nodeToRemove);
+}
+
+void KWQMapImpl::swap(KWQMapImpl &map)
+{
+ KWQMapNodeImpl *tmp = guard;
+ guard = map.guard;
+ map.guard = tmp;
+
+ uint tmpNumNodes = numNodes;
+ numNodes = map.numNodes;
+ map.numNodes = tmpNumNodes;
+}
+
+uint KWQMapImpl::countInternal() const
+{
+ return numNodes;
+}
+
+void KWQMapImpl::clearInternal()
+{
+ deleteNode(guard->prev);
+ guard->prev = NULL;
+ numNodes = 0;
+}
+
+KWQMapNodeImpl *KWQMapImpl::beginInternal() const
+{
+ KWQMapNodeImpl *node;
+
+ node = guard;
+ while (node->left() != NULL) {
+ node = node->left();
+ }
+
+ return node;
+}
+
+KWQMapNodeImpl *KWQMapImpl::endInternal() const
+{
+ return guard;
+}
+
+#endif
diff --git a/WebCore/src/kwq/KWQKGlobal.mm b/WebCore/src/kwq/KWQPtrDictImpl.h
similarity index 54%
copy from WebCore/src/kwq/KWQKGlobal.mm
copy to WebCore/src/kwq/KWQPtrDictImpl.h
index 72a3056..9937488 100644
--- a/WebCore/src/kwq/KWQKGlobal.mm
+++ b/WebCore/src/kwq/KWQPtrDictImpl.h
@@ -22,79 +22,70 @@
* (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 <kwqdebug.h>
-#include <kglobal.h>
-#include <kconfig.h>
-#include <kcharsets.h>
+#ifndef KWQ_PTRDICT_IMPL_H
+#define KWQ_PTRDICT_IMPL_H
-#include <qdict.h>
+#include <config.h>
+#include <KWQDef.h>
+
+#ifndef USING_BORROWED_PTRQDICT
+
+#include <stddef.h>
#define Fixed MacFixed
#define Rect MacRect
#define Boolean MacBoolean
-#include <Cocoa/Cocoa.h>
+#include <CoreFoundation/CFDictionary.h>
#undef Fixed
#undef Rect
#undef Boolean
-KWQStaticStringDict *KGlobal::_stringDict = 0L;
-KInstance *KGlobal::_instance = 0L;
-KLocale *KGlobal::_locale = 0L;
-KCharsets *KGlobal::_charsets = 0L;
-
-class KWQStaticStringDict : public QDict<QString>
+class KWQPtrDictImpl
{
-public:
- KWQStaticStringDict() : QDict<QString>() { };
-};
+ public:
+ KWQPtrDictImpl(int size, void (*deleteFunc)(void *), const CFDictionaryKeyCallBacks *cfdkcb = NULL);
+ KWQPtrDictImpl(const KWQPtrDictImpl &pdi);
+ ~KWQPtrDictImpl();
+
+ void clear(bool deleteItems);
+ uint count() const;
-KInstance *KGlobal::instance()
-{
- _logNotYetImplemented();
- return 0L;
-}
+ void *take(void *key);
+ void insert(void *key, const void *value);
+ bool remove(void *key, bool deleteItem);
+ void *find(void *key) const;
+ KWQPtrDictImpl &assign(const KWQPtrDictImpl &pdi, bool deleteItems);
+ private:
+ void KWQPtrDictImpl::swap(KWQPtrDictImpl &di);
-KCharsets *KGlobal::charsets()
-{
- if (_charsets == 0L) {
- _charsets = new KCharsets();
- }
- return _charsets;
-}
+ class KWQPtrDictPrivate;
+
+ KWQPtrDictPrivate *d;
+ friend class KWQPtrDictIteratorImpl;
+};
-KLocale *KGlobal::locale()
-{
- _logNotYetImplemented();
- return 0L;
-}
+class KWQPtrDictIteratorImpl {
+ public:
+ KWQPtrDictIteratorImpl(const KWQPtrDictImpl &pdi);
+ ~KWQPtrDictIteratorImpl();
-KStandardDirs *KGlobal::dirs()
-{
- _logNotYetImplemented();
- return 0L;
-}
+ uint count() const;
+ void *current() const;
+ void *currentKey() const;
+ void *KWQPtrDictIteratorImpl::toFirst();
+
+ void *operator++();
+ private:
+ class KWQPtrDictIteratorPrivate;
+
+ KWQPtrDictIteratorPrivate *d;
+};
-KConfig *KGlobal::config()
-{
- _logNotYetImplemented();
- return new KConfig("foo");
-}
+#endif
-const QString &KGlobal::staticQString(const QString &str)
-{
- if (!_stringDict) {
- _stringDict = new KWQStaticStringDict;
- }
- QString *result = _stringDict->find(str);
- if (!result)
- {
- result = new QString(str);
- _stringDict->insert(str, result);
- }
- return *result;
-}
+#endif
diff --git a/WebCore/src/kwq/KWQPtrDictImpl.mm b/WebCore/src/kwq/KWQPtrDictImpl.mm
new file mode 100644
index 0000000..8995e52
--- /dev/null
+++ b/WebCore/src/kwq/KWQPtrDictImpl.mm
@@ -0,0 +1,236 @@
+/*
+ * 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 <KWQPtrDictImpl.h>
+
+#ifndef USING_BORROWED_QPTRDICT
+
+#include <new>
+
+class KWQPtrDictImpl::KWQPtrDictPrivate
+{
+public:
+ KWQPtrDictPrivate(int size, void (*deleteFunc)(void *), const CFDictionaryKeyCallBacks *cfdkcb);
+ KWQPtrDictPrivate(KWQPtrDictPrivate &dp);
+ ~KWQPtrDictPrivate();
+
+ CFMutableDictionaryRef cfdict;
+ void (*del)(void *);
+};
+
+KWQPtrDictImpl::KWQPtrDictPrivate::KWQPtrDictPrivate(int size, void (*deleteFunc)(void *), const CFDictionaryKeyCallBacks *cfdkcb) :
+ cfdict(CFDictionaryCreateMutable(NULL, 0, cfdkcb, NULL)),
+ del(deleteFunc)
+{
+ if (cfdict == NULL) {
+ throw bad_alloc();
+ }
+}
+
+KWQPtrDictImpl::KWQPtrDictPrivate::KWQPtrDictPrivate(KWQPtrDictPrivate &dp) :
+ cfdict(CFDictionaryCreateMutableCopy(NULL, 0, dp.cfdict)),
+ del(dp.del)
+{
+ if (cfdict == NULL) {
+ throw bad_alloc();
+ }
+}
+
+KWQPtrDictImpl::KWQPtrDictPrivate::~KWQPtrDictPrivate()
+{
+ CFRelease(cfdict);
+}
+
+KWQPtrDictImpl::KWQPtrDictImpl(int size, void (*deleteFunc)(void *), const CFDictionaryKeyCallBacks *cfdkcb) :
+ d(new KWQPtrDictPrivate(size, deleteFunc, cfdkcb))
+{
+}
+
+KWQPtrDictImpl::KWQPtrDictImpl(const KWQPtrDictImpl &di) :
+ d(new KWQPtrDictPrivate(*di.d))
+{
+}
+
+
+KWQPtrDictImpl::~KWQPtrDictImpl()
+{
+ delete d;
+}
+
+static void invokeDeleteFuncOnValue (const void *key, const void *value, void *deleteFunc)
+{
+ void (*del)(void *) = (void (*)(void *))deleteFunc;
+
+ del((void *)value);
+}
+
+void KWQPtrDictImpl::clear(bool deleteItems)
+{
+ if (deleteItems) {
+ CFDictionaryApplyFunction(d->cfdict, invokeDeleteFuncOnValue, d->del);
+ }
+
+ CFDictionaryRemoveAllValues(d->cfdict);
+}
+
+uint KWQPtrDictImpl::count() const
+{
+ return CFDictionaryGetCount(d->cfdict);
+}
+
+void KWQPtrDictImpl::insert(void *key, const void *value)
+{
+ CFDictionarySetValue(d->cfdict, key /* DIFF: key.getCFMutableString() */, value);
+
+}
+
+bool KWQPtrDictImpl::remove(void *key, bool deleteItem)
+{
+ void *value = (void *)CFDictionaryGetValue(d->cfdict, key /* DIFF: key.getCFMutableString() */);
+
+ if (value == nil) {
+ return false;
+ }
+
+ CFDictionaryRemoveValue(d->cfdict, key /* DIFF: key.getCFMutableString() */);
+
+ if (deleteItem) {
+ d->del(value);
+ }
+
+ return true;
+}
+
+void *KWQPtrDictImpl::find(void *key) const
+{
+ return (void *)CFDictionaryGetValue(d->cfdict, key /* key.getCFMutableString() */);
+}
+
+void KWQPtrDictImpl::swap(KWQPtrDictImpl &di)
+{
+ KWQPtrDictPrivate *tmp;
+
+ tmp = di.d;
+ di.d = d;
+ d = tmp;
+}
+
+KWQPtrDictImpl &KWQPtrDictImpl::assign(const KWQPtrDictImpl &di, bool deleteItems)
+{
+ KWQPtrDictImpl tmp(di);
+
+ if (deleteItems) {
+ clear(true);
+ }
+
+ swap(tmp);
+
+ return *this;
+}
+
+
+void *KWQPtrDictImpl::take(void *key)
+{
+ void *value = find(key);
+ remove(key, false);
+ return value;
+}
+
+
+
+
+
+class KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate
+{
+public:
+ KWQPtrDictIteratorPrivate(CFMutableDictionaryRef cfdict);
+ ~KWQPtrDictIteratorPrivate();
+ uint count;
+ uint pos;
+ void **keys;
+ void **values;
+};
+
+
+KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate::KWQPtrDictIteratorPrivate(CFMutableDictionaryRef cfdict) :
+ count(CFDictionaryGetCount(cfdict)),
+ pos(0),
+ keys(new void*[count]),
+ values(new void*[count])
+{
+ CFDictionaryGetKeysAndValues(cfdict, (const void **)keys, (const void **)values);
+}
+
+KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate::~KWQPtrDictIteratorPrivate()
+{
+ delete keys;
+ delete values;
+}
+
+
+KWQPtrDictIteratorImpl::KWQPtrDictIteratorImpl(const KWQPtrDictImpl &di) :
+ d(new KWQPtrDictIteratorImpl::KWQPtrDictIteratorPrivate(di.d->cfdict))
+{
+}
+
+KWQPtrDictIteratorImpl::~KWQPtrDictIteratorImpl()
+{
+ delete d;
+}
+
+uint KWQPtrDictIteratorImpl::count() const
+{
+ return d->count;
+}
+
+void *KWQPtrDictIteratorImpl::current() const
+{
+ if (d->pos >= d->count) {
+ return NULL;
+ }
+ return d->values[d->pos];
+}
+
+void * /* DIFF: QString */ KWQPtrDictIteratorImpl::currentKey() const
+{
+ if (d->pos >= d->count) {
+ return NULL; /* DIFF: QString(); */
+ }
+ return d->keys[d->pos]; /* DIFF: QString::fromCFString((CFStringRef)d->keys[d->pos]); */
+}
+
+void *KWQPtrDictIteratorImpl::toFirst()
+{
+ d->pos = 0;
+ return current();
+}
+
+void *KWQPtrDictIteratorImpl::operator++()
+{
+ ++(d->pos);
+ return current();
+}
+
+#endif
diff --git a/WebCore/src/kwq/Makefile.am b/WebCore/src/kwq/Makefile.am
index a6a28e5..b61e499 100644
--- a/WebCore/src/kwq/Makefile.am
+++ b/WebCore/src/kwq/Makefile.am
@@ -27,6 +27,7 @@ libkwq_o_SOURCES = \
KWQCursor.mm \
KWQDCOPClient.mm \
KWQDateTime.mm \
+ KWQDictImpl.mm \
KWQDrawUtil.mm \
KWQEvent.mm \
KWQFont.mm \
@@ -36,6 +37,7 @@ libkwq_o_SOURCES = \
KWQFrame.mm \
KWQGuardedPtr.mm \
KWQPoint.mm \
+ KWQPtrDictImpl.mm \
KWQRect.mm \
KWQSize.mm \
KWQHBox.mm \
@@ -85,6 +87,7 @@ libkwq_o_SOURCES = \
KWQLabel.mm \
KWQLineEdit.mm \
KWQListBox.mm \
+ KWQMapImpl.mm \
KWQMovie.mm \
KWQNSTextField.mm \
KWQObject.mm \
diff --git a/WebCore/src/kwq/qt/_qdict.h b/WebCore/src/kwq/qt/_qdict.h
index 912aca3..0b430cd 100644
--- a/WebCore/src/kwq/qt/_qdict.h
+++ b/WebCore/src/kwq/qt/_qdict.h
@@ -40,9 +40,7 @@
// KWQ hacks ---------------------------------------------------------------
-#ifndef USING_BORROWED_QDICT
-#define USING_BORROWED_QDICT
-#endif
+#ifdef USING_BORROWED_QDICT
#include <KWQDef.h>
#include <iostream>
@@ -114,6 +112,7 @@ public:
type *operator+=(uint j) { return (type *)QGDictIterator::operator+=(j);}
};
+#if 0
#ifdef _KWQ_IOSTREAM_
template <class T>
ostream &operator<<(ostream &o, const QDict<T>&d)
@@ -135,5 +134,8 @@ ostream &operator<<(ostream &o, const QDict<T>&d)
return o;
}
#endif
-
+#endif
+
+#endif
+
#endif // QDICT_H
diff --git a/WebCore/src/kwq/qt/_qgdict.h b/WebCore/src/kwq/qt/_qgdict.h
index 25e2e17..88575b2 100644
--- a/WebCore/src/kwq/qt/_qgdict.h
+++ b/WebCore/src/kwq/qt/_qgdict.h
@@ -40,6 +40,8 @@
// KWQ hacks ---------------------------------------------------------------
+#include <config.h>
+
#ifndef USING_BORROWED_QDICT
#define USING_BORROWED_QDICT
#endif
@@ -235,5 +237,4 @@ inline void *QGDictIterator::getKeyPtr() const
return curNode ? ((QPtrBucket*)curNode)->getKey() : 0;
}
-
#endif // QGDICT_H
diff --git a/WebCore/src/kwq/qt/_qptrdict.h b/WebCore/src/kwq/qt/_qptrdict.h
index 87df229..fc3441e 100644
--- a/WebCore/src/kwq/qt/_qptrdict.h
+++ b/WebCore/src/kwq/qt/_qptrdict.h
@@ -40,9 +40,9 @@
// KWQ hacks ---------------------------------------------------------------
+#include <config.h>
+
#ifndef USING_BORROWED_QPTRDICT
-#define USING_BORROWED_QPTRDICT
-#endif
#include <KWQDef.h>
#include <iostream>
@@ -110,6 +110,7 @@ public:
type *operator+=(uint j) { return (type *)QGDictIterator::operator+=(j);}
};
+#if 0
#ifdef _KWQ_IOSTREAM_
template <class T>
ostream &operator<<(ostream &o, const QPtrDict<T>&d)
@@ -131,6 +132,8 @@ ostream &operator<<(ostream &o, const QPtrDict<T>&d)
return o;
}
#endif
+#endif
+#endif
#endif // QPTRDICT_H
diff --git a/WebCore/src/kwq/qt/qdict.h b/WebCore/src/kwq/qt/qdict.h
index 4234247..a3ee0f4 100644
--- a/WebCore/src/kwq/qt/qdict.h
+++ b/WebCore/src/kwq/qt/qdict.h
@@ -33,13 +33,18 @@
// USING_BORROWED_QDICT ========================================================
#ifdef USING_BORROWED_QDICT
+
#include <_qdict.h>
+
#else
#include <_qcollection.h>
-#include "qstring.h"
+#include <qstring.h>
+#include <KWQDictImpl.h>
+
+template<class T> class QDictIterator;
// class QDict =================================================================
@@ -53,25 +58,32 @@ public:
// constructors, copy constructors, and destructors ------------------------
- QDict(int size=17, bool caseSensitive=TRUE);
- QDict(const QDict<T> &);
- ~QDict();
+ QDict(int size=17, bool caseSensitive=TRUE) : impl(size, caseSensitive, QDict::deleteFunc) {}
+ QDict(const QDict<T> &d) : impl(d.impl) {}
+ virtual ~QDict() { impl.clear(del_item); }
// member functions --------------------------------------------------------
- void clear();
- void insert(const QString &, const T *);
- bool remove(const QString &);
- T *find(const QString &) const;
- uint count() const;
+ virtual void clear() { impl.clear(del_item); }
+ virtual uint count() const { return impl.count(); }
+ void insert(const QString &key, const T *value) { impl.insert(key,(void *)value);}
+ bool remove(const QString &key) { return impl.remove(key,del_item); }
+ T *find(const QString &key) const { return (T *)impl.find(key); }
// operators ---------------------------------------------------------------
- QDict<T> &operator=(const QDict<T> &);
+ QDict<T> &operator=(const QDict<T> &d) { impl.assign(d.impl,del_item); QCollection::operator=(d); return *this;}
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
+ private:
+ static void deleteFunc(void *item) {
+ delete (T *)item;
+ }
+
+ KWQDictImpl impl;
+ friend class QDictIterator<T>;
}; // class QDict ==============================================================
@@ -92,23 +104,25 @@ public:
QDictIterator() {}
#endif
- QDictIterator(const QDict<T> &);
- ~QDictIterator();
+ QDictIterator(const QDict<T> &d) : impl(d.impl) {}
+ ~QDictIterator() {}
// member functions --------------------------------------------------------
- uint count() const;
- T *current() const;
- T *toFirst();
+ uint count() const { return impl.count(); }
+ T *current() const { return (T *) impl.current(); }
+ QString currentKey() const { return impl.currentStringKey(); }
+ T *toFirst() { return (T *)impl.toFirst(); }
// operators ---------------------------------------------------------------
- T *operator++();
+ T *operator++() { return (T *)(++impl); }
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
private:
+ KWQDictIteratorImpl impl;
// add copy constructor
// this private declaration prevents copying
diff --git a/WebCore/src/kwq/qt/qmap.h b/WebCore/src/kwq/qt/qmap.h
index b21233b..4c8b0dc 100644
--- a/WebCore/src/kwq/qt/qmap.h
+++ b/WebCore/src/kwq/qt/qmap.h
@@ -36,143 +36,387 @@
#include <_qmap.h>
#else
+#include <iostream>
#include <KWQDef.h>
-// class QMapIterator ==========================================================
-
-template<class K, class T> class QMapIterator {
-public:
-
- // typedefs ----------------------------------------------------------------
- // enums -------------------------------------------------------------------
- // constants ---------------------------------------------------------------
- // static member functions -------------------------------------------------
-
- // constructors, copy constructors, and destructors ------------------------
-
- QMapIterator();
- QMapIterator(const QMapIterator<K,T>&);
+#include <KWQMapImpl.h>
-// add no-op destructor
-#ifdef _KWQ_PEDANTIC_
- ~QMapIterator() {}
-#endif
-
- // member functions --------------------------------------------------------
+template <class K, class V> class QMap;
+template <class K, class V> class QMapIterator;
+template <class K, class V> class QMapConstIterator;
- const K& key() const;
- const T& data() const;
- // operators ---------------------------------------------------------------
-
- QMapIterator<K,T> &operator=(const QMapIterator<K,T> &);
- bool operator==(const QMapIterator<K,T>&) const;
- bool operator!=(const QMapIterator<K,T>&) const;
- T& operator*();
- const T& operator*() const;
- QMapIterator<K,T>& operator++();
-
- // this is not declared in the code, although assignment of this type
- // is used in the code... i guess a pointer copy is what they want
- //
- //QMapIterator<K,T> &operator=(const QMapIterator<K,T> &);
- //
-
-// protected -------------------------------------------------------------------
-// private ---------------------------------------------------------------------
+template <class K, class V> class QMapNode : private KWQMapNodeImpl
+{
+ private:
+ QMapNode(K k, V v) :
+ key(k),
+ value(v)
+ {
+ }
+
+ // intentionally not defined
+ QMapNode(const QMapNode<K,V>&node);
+
+ static QMapNode<K,V> *copyTree(const QMapNode<K,V> *node,
+ QMapNode<K,V> *subtreePredecessor,
+ QMapNode<K,V> *subtreeSuccessor)
+ {
+ if (node == NULL) {
+ return NULL;
+ }
+
+ // FIXME: not exception-safe - use auto_ptr?
+ QMapNode<K,V> *copy = new QMapNode<K,V>(node->key, node->value);
+ copy->color = node->color;
+
+ if (node->prevIsChild) {
+ copy->prevIsChild = true;
+ copy->prev = copyTree((QMapNode<K,V> *)node->prev, subtreePredecessor, copy);
+ } else {
+ copy->prevIsChild = false;
+ copy->prev = subtreePredecessor;
+ }
+
+ if (node->nextIsChild) {
+ copy->nextIsChild = true;
+ copy->next = copyTree((QMapNode<K,V> *)node->next, copy, subtreeSuccessor);
+ } else {
+ copy->nextIsChild = false;
+ copy->next = subtreeSuccessor;
+ }
+
+ return copy;
+ }
+
+ ~QMapNode()
+ {
+ delete left();
+ delete right();
+ }
+
+ K key;
+ V value;
+
+ friend class QMap<K,V>;
+ friend class QMapIterator<K,V>;
+ friend class QMapConstIterator<K,V>;
+};
+// class QMapIterator ==========================================================
+template<class K, class V> class QMapIterator : private KWQMapIteratorImpl {
+public:
+ QMapIterator()
+ {
+ }
+
+ QMapIterator(const QMapIterator<K,V> &iter) : KWQMapIteratorImpl(iter)
+ {
+ }
+
+ ~QMapIterator()
+ {
+ }
+
+ const K& key() const
+ {
+ return ((QMapNode<K,V> *)node)->key;
+ }
+
+ const V& data() const
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ QMapIterator<K,V> &operator=(const QMapIterator<K,V> &iter)
+ {
+ node = iter.node;
+ return *this;
+ }
+
+ bool operator==(const QMapIterator<K,V>&iter) const
+ {
+ return node == iter.node;
+ }
+
+ bool operator!=(const QMapIterator<K,V>&iter) const
+ {
+ return node != iter.node;
+ }
+
+ V& operator*()
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ const V& operator*() const
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ QMapIterator<K,V>& operator++()
+ {
+ incrementInternal();
+ return *this;
+ }
+
+private:
+ QMapIterator(QMapNode<K,V> *n)
+ {
+ node = n;
+ }
+
+ friend class QMap<K,V>;
+ friend class QMapConstIterator<K,V>;
}; // class QMapIterator =======================================================
// class QMapConstIterator =====================================================
-template<class K, class T> class QMapConstIterator {
+template<class K, class V> class QMapConstIterator : private KWQMapIteratorImpl {
public:
-
- // typedefs ----------------------------------------------------------------
- // enums -------------------------------------------------------------------
- // constants ---------------------------------------------------------------
- // static member functions -------------------------------------------------
-
- // constructors, copy constructors, and destructors ------------------------
-
- QMapConstIterator();
- QMapConstIterator(const QMapConstIterator<K,T> &);
- QMapConstIterator(const QMapIterator<K,T> &);
-
- ~QMapConstIterator();
-
- // member functions --------------------------------------------------------
-
- const K& key() const;
- const T& data() const;
-
- // operators ---------------------------------------------------------------
-
- QMapConstIterator<K,T> &operator=(const QMapConstIterator<K,T> &);
- bool operator==(const QMapConstIterator<K,T> &) const;
- bool operator!=(const QMapConstIterator<K,T> &) const;
- const T &operator*() const;
- QMapConstIterator<K,T>& operator++();
-
- // this is not declared in the code, although assignment of this type
- // is used in the code... i guess a pointer copy is what they want
- //
- //QMapConstIterator<K,T> &operator=(const QMapConstIterator<K,T> &);
- //
-
-// protected -------------------------------------------------------------------
-// private ---------------------------------------------------------------------
-
+ QMapConstIterator() : KWQMapIteratorImpl()
+ {
+ }
+
+ QMapConstIterator(const QMapConstIterator<K,V> &citer) : KWQMapIteratorImpl(citer)
+ {
+ }
+
+ QMapConstIterator(const QMapIterator<K,V> &iter) : KWQMapIteratorImpl(iter)
+ {
+ }
+
+ ~QMapConstIterator()
+ {
+ }
+
+ const K& key() const
+ {
+ return ((QMapNode<K,V> *)node)->key;
+ }
+
+ const V& data() const
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ QMapConstIterator<K,V> &operator=(const QMapConstIterator<K,V> &citer)
+ {
+ node = citer.node;
+ return *this;
+ }
+
+ bool operator==(const QMapConstIterator<K,V> &citer) const
+ {
+ return node == citer.node;
+ }
+
+ bool operator!=(const QMapConstIterator<K,V> &citer) const
+ {
+ return node != citer.node;
+ }
+
+ const V &operator*() const
+ {
+ return ((QMapNode<K,V> *)node)->value;
+ }
+
+ QMapConstIterator<K,V>& operator++()
+ {
+ incrementInternal();
+ return *this;
+ }
+
+private:
+ QMapConstIterator(QMapNode<K,V> *n)
+ {
+ node = n;
+ }
+
+ friend class QMap<K,V>;
}; // class QMapConstIterator ==================================================
+
// class QMap ==================================================================
-template <class K, class T> class QMap {
+template <class K, class V> class QMap : public KWQMapImpl {
public:
// typedefs ----------------------------------------------------------------
- typedef QMapIterator<K, T> Iterator;
- typedef QMapConstIterator< K, T> ConstIterator;
+ typedef QMapIterator<K,V> Iterator;
+ typedef QMapConstIterator<K,V> ConstIterator;
// enums -------------------------------------------------------------------
// constants ---------------------------------------------------------------
// static member functions -------------------------------------------------
// constructors, copy constructors, and destructors ------------------------
-
- QMap();
- QMap(const QMap<K,T>&);
- ~QMap();
-
- // member functions --------------------------------------------------------
- void clear();
- uint count() const;
- Iterator begin();
- Iterator end();
-
- ConstIterator begin() const;
- ConstIterator end() const;
+ QMap() :
+ KWQMapImpl(new QMapNode<K,V>(K(),V()), 0)
+ {
+ }
- Iterator insert(const K&, const T&);
- void remove(const K&);
+ QMap(const QMap<K,V>& m) :
+ KWQMapImpl(QMapNode<K,V>::copyTree((QMapNode<K,V> *)m.endInternal(), NULL, NULL), m.count())
+ {
+ }
- ConstIterator find (const K &) const;
+ virtual ~QMap()
+ {
+ clear();
+ delete endInternal();
+ }
+
+ // member functions --------------------------------------------------------
- // operators ---------------------------------------------------------------
+ void clear()
+ {
+ clearInternal();
+ }
+
+ uint count() const
+ {
+ return countInternal();
+ }
+
+ Iterator begin()
+ {
+ return Iterator((QMapNode<K,V> *)beginInternal());
+ }
+
+ Iterator end()
+ {
+ return Iterator((QMapNode<K,V> *)endInternal());
+ }
+
+ ConstIterator begin() const
+ {
+ return ConstIterator((QMapNode<K,V> *)beginInternal());
+ }
+
+ ConstIterator end() const
+ {
+ return ConstIterator((QMapNode<K,V> *)endInternal());
+ }
+
+ Iterator insert(const K& key, const V& value)
+ {
+ QMapNode<K,V> tmp(key,value);
+
+ return Iterator((QMapNode<K,V> *)insertInternal(&tmp, true));
+ }
+
+ void remove(const K& key)
+ {
+ QMapNode<K,V> tmp(key, V());
+ removeInternal(&tmp);
+ }
+
+ ConstIterator find (const K &key) const
+ {
+ QMapNode<K,V> tmp(key, V());
+ QMapNode<K,V> *result = (QMapNode<K,V> *)findInternal(&tmp);
+
+ if (result != NULL) {
+ return ConstIterator(result);
+ } else {
+ return ConstIterator(end());
+ }
+ }
- QMap<K,T>& operator=(const QMap<K,T>&);
- T& operator[](const K& k);
+ // operators ---------------------------------------------------------------
-// protected -------------------------------------------------------------------
-// private ---------------------------------------------------------------------
+ QMap<K,V>& operator=(const QMap<K,V>&map)
+ {
+ QMap<K,V> tmp(map);
+ swap(tmp);
+ return *this;
+ }
+
+ V& operator[](const K& key)
+ {
+ QMapNode<K,V> tmp(key, V());
+
+ return ((QMapNode<K,V> *)insertInternal(&tmp, false))->value;
+ }
+
+
+protected:
+ virtual void copyNode(KWQMapNodeImpl *isrc, KWQMapNodeImpl *idst)
+ {
+ QMapNode<K,V> *src = (QMapNode<K,V> *)isrc;
+ QMapNode<K,V> *dst = (QMapNode<K,V> *)idst;
+ dst->key = src->key;
+ dst->value = src->value;
+ }
+
+ virtual KWQMapNodeImpl *duplicateNode(KWQMapNodeImpl *isrc)
+ {
+ QMapNode<K,V> *src = (QMapNode<K,V> *)isrc;
+ return new QMapNode<K,V>(src->key, src->value);
+ }
+
+ virtual CompareResult compareNodes(KWQMapNodeImpl *ia, KWQMapNodeImpl *ib) const
+ {
+ QMapNode<K,V> *a = (QMapNode<K,V> *)ia;
+ QMapNode<K,V> *b = (QMapNode<K,V> *)ib;
+
+ if (a->key == b->key) {
+ return Equal;
+ } else if (a->key < b->key) {
+ return Less;
+ } else {
+ return Greater;
+ }
+ }
+
+ virtual void swapNodes(KWQMapNodeImpl *ia, KWQMapNodeImpl *ib)
+ {
+ QMapNode<K,V> *a = (QMapNode<K,V> *)ia;
+ QMapNode<K,V> *b = (QMapNode<K,V> *)ib;
+
+ K tmpKey = a->key;
+ V tmpValue = a->value;
+ a->key = b->key;
+ a->value = b->value;
+ b->key = tmpKey;
+ b->value = tmpValue;
+ }
+
+ virtual void deleteNode(KWQMapNodeImpl *inode)
+ {
+ delete (QMapNode<K,V> *)inode;
+ }
}; // class QMap ===============================================================
+
+#ifdef _KWQ_IOSTREAM_
+template<class K, class V>
+inline ostream &operator<<(ostream &stream, const QMap<K,V> &m)
+{
+ uint count = m.count();
+ stream << "QMap: [size: " << count << "; items: ";
+
+ QMapConstIterator<K,V> iter = m.begin();
+
+ for (unsigned int i = 0; i < count; i++) {
+ stream << "(" << iter.key() << "," << iter.data() << ")";
+ if (i + 1 < count) {
+ stream << ", ";
+ }
+ ++iter;
+ }
+
+ return stream << "]";
+}
+#endif
+
#endif // USING_BORROWED_QMAP
#endif
diff --git a/WebCore/src/kwq/qt/qptrdict.h b/WebCore/src/kwq/qt/qptrdict.h
index 3f0c240..d32c71f 100644
--- a/WebCore/src/kwq/qt/qptrdict.h
+++ b/WebCore/src/kwq/qt/qptrdict.h
@@ -39,6 +39,10 @@
#include <KWQDef.h>
#include <_qcollection.h>
+#include <KWQPtrDictImpl.h>
+
+template <class T> class QPtrDictIterator;
+
// class QPtrDict ==============================================================
template <class T> class QPtrDict : public QCollection {
@@ -51,27 +55,34 @@ public:
// constructors, copy constructors, and destructors ------------------------
- QPtrDict(int size=17);
- QPtrDict(const QPtrDict<T> &);
- ~QPtrDict();
+ QPtrDict(int size=17) : impl(size, deleteFunc) {}
+ QPtrDict(const QPtrDict<T> &pd) : impl(pd.impl) {}
+ virtual ~QPtrDict() { impl.clear(del_item); }
// member functions --------------------------------------------------------
- void clear();
- uint count() const;
- T *take(void *);
+ virtual void clear() { impl.clear(del_item); }
+ virtual uint count() const { return impl.count(); }
- void insert(void *, const T *);
- void remove(void *);
+ T *take(void *key) { return (T *)impl.take(key); }
+ void insert(void *key, const T *value) { impl.insert(key, (void *)value); }
+ bool remove(void *key) { return impl.remove(key, del_item); }
// operators ---------------------------------------------------------------
- QPtrDict<T> &operator=(const QPtrDict<T> &);
- T *operator[](void *) const;
+ QPtrDict<T> &operator=(const QPtrDict<T> &pd) { impl.assign(pd.impl,del_item); QCollection::operator=(pd); return *this; }
+ T *operator[](void *key) const { return (T *)impl.find(key); }
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
+ private:
+ static void deleteFunc(void *item) {
+ delete (T *)item;
+ }
+
+ KWQPtrDictImpl impl;
+ friend class QPtrDictIterator<T>;
}; // class QPtrDict ===========================================================
@@ -92,22 +103,24 @@ public:
QPtrDictIterator() {}
#endif
- QPtrDictIterator(const QPtrDict<T> &);
+ QPtrDictIterator(const QPtrDict<T> &pd) : impl(pd.impl) {}
~QPtrDictIterator() {}
// member functions --------------------------------------------------------
- T *current() const;
- void *currentKey() const;
+ uint count() { return impl.count(); }
+ T *current() const { return (T *)impl.current(); }
+ void *currentKey() const { return impl.currentKey(); }
// operators ---------------------------------------------------------------
- T *operator++();
+ T *operator++() { return (T *)(++impl); }
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
private:
+ KWQPtrDictIteratorImpl impl;
// add copy constructor
// this private declaration prevents copying
diff --git a/WebCore/src/kwq/qt/qsortedlist.h b/WebCore/src/kwq/qt/qsortedlist.h
index bda8bb3..9a388e9 100644
--- a/WebCore/src/kwq/qt/qsortedlist.h
+++ b/WebCore/src/kwq/qt/qsortedlist.h
@@ -50,19 +50,32 @@ public:
// constructors, copy constructors, and destructors ------------------------
- QSortedList();
- QSortedList(const QSortedList<T> &);
- ~QSortedList();
+ QSortedList() : QList<T>() {}
+ QSortedList(const QSortedList<T> &sl) : QList<T>(sl) {}
+ ~QSortedList() {}
- // member functions --------------------------------------------------------
+ // Member functions --------------------------------------------------------
// operators ---------------------------------------------------------------
- QSortedList<T> &operator=(const QSortedList<T> &);
+ QSortedList<T> &operator=(const QSortedList<T> &sl) { QList<T>::operator=(sl); return *this; }
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
+ virtual int compareItems(void *a, void *b)
+ {
+ T *ta = (T *)a;
+ T *tb = (T *)b;
+ if (*ta == *tb) {
+ return 0;
+ } else if (*ta < *tb) {
+ return -1;
+ } else {
+ return 1;
+ }
+ }
+
}; // class QSortedList ========================================================
#endif // USING_BORROWED_QSORTEDLIST
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list