From 367ff3fb9e3933f6704c98359cdd8d934ace941f Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 24 Aug 2024 20:52:58 +0900 Subject: Rename global classes nt* related files to equivalent tq* Signed-off-by: Michele Calgaro --- src/3rdparty/sqlite/config.h | 2 +- src/3rdparty/sqlite/trolltech.patch | 2 +- src/codecs/tqfontcodecs_p.h | 2 +- src/codecs/tqjpunicode.h | 2 +- src/codecs/tqtextcodecplugin.h | 2 +- src/dialogs/tqfiledialog.cpp | 4 +- src/inputmethod/ntqinputcontextplugin.h | 2 +- src/kernel/ntqaccessible.h | 2 +- src/kernel/ntqgif.h | 2 +- src/kernel/ntqgplugin.h | 130 --- src/kernel/ntqguardedptr.h | 144 --- src/kernel/ntqinputcontext.h | 2 +- src/kernel/ntqjpegio.h | 2 +- src/kernel/ntqnamespace.h | 2 +- src/kernel/ntqpolygonscanner.h | 2 +- src/kernel/ntqt.h | 18 +- src/kernel/qaccel.cpp | 2 +- src/kernel/qapplication.cpp | 2 +- src/kernel/qapplication_x11.cpp | 2 +- src/kernel/qdnd_x11.cpp | 2 +- src/kernel/qgplugin.cpp | 72 -- src/kernel/qguardedptr.cpp | 226 ----- src/kernel/qinputcontext_p.h | 2 +- src/kernel/qt_kernel.pri | 8 +- src/kernel/qt_pch.h | 2 +- src/kernel/qvariant.cpp | 2 +- src/kernel/tqcolor_p.cpp | 2 +- src/kernel/tqdropsite.h | 2 +- src/kernel/tqfontengine_p.h | 2 +- src/kernel/tqgplugin.cpp | 72 ++ src/kernel/tqgplugin.h | 130 +++ src/kernel/tqguardedptr.cpp | 226 +++++ src/kernel/tqguardedptr.h | 144 +++ src/kernel/tqimageformatplugin.h | 2 +- src/kernel/tqlocalfs.cpp | 2 +- src/kernel/tqobjectdefs.h | 2 +- src/kernel/tqsignal.cpp | 2 +- src/kernel/tqsimplerichtext.cpp | 2 +- src/kernel/tqsizepolicy.h | 2 +- src/kernel/tqt.h | 2 +- src/kernel/tqtextengine_p.h | 2 +- src/kernel/tqurloperator.cpp | 2 +- src/kernel/tqwidget.cpp | 2 +- src/libqt.map | 4 +- src/moc/moc.pro | 12 +- src/network/tqnetwork.h | 2 +- src/qt.pro | 4 +- src/sql/drivers/cache/tqsqlcachedresult.h | 2 +- src/sql/tqsql.h | 2 +- src/sql/tqsqldatabase.cpp | 2 +- src/sql/tqsqldriverplugin.h | 2 +- src/sql/tqsqlmanager_p.h | 2 +- src/styles/tqmotifplusstyle.cpp | 2 +- src/styles/tqsgistyle.h | 2 +- src/styles/tqstylefactory.cpp | 2 +- src/styles/tqstyleplugin.h | 2 +- src/table/tqtable.cpp | 2 +- src/table/tqtable.h | 2 +- src/tools/ntqgarray.h | 134 --- src/tools/ntqgcache.h | 131 --- src/tools/ntqgdict.h | 225 ----- src/tools/ntqgeneric.h | 46 - src/tools/ntqglist.h | 279 ----- src/tools/ntqglobal.h | 1085 -------------------- src/tools/ntqgvector.h | 124 --- src/tools/ntqshared.h | 2 +- src/tools/ntqtl.h | 2 +- src/tools/qcom_p.h | 2 +- src/tools/qgarray.cpp | 830 --------------- src/tools/qgcache.cpp | 866 ---------------- src/tools/qgdict.cpp | 1151 --------------------- src/tools/qglist.cpp | 1566 ----------------------------- src/tools/qglobal.cpp | 889 ---------------- src/tools/qgpluginmanager.cpp | 552 ---------- src/tools/qgpluginmanager_p.h | 110 -- src/tools/qgvector.cpp | 598 ----------- src/tools/qpluginmanager_p.h | 2 +- src/tools/qt_tools.pri | 29 +- src/tools/qwinexport.cpp | 2 +- src/tools/tqasciicache.h | 2 +- src/tools/tqasciidict.h | 2 +- src/tools/tqcache.h | 2 +- src/tools/tqdeepcopy.h | 2 +- src/tools/tqdict.h | 2 +- src/tools/tqdir.h | 2 +- src/tools/tqfile.cpp | 2 +- src/tools/tqfileinfo_unix.cpp | 2 +- src/tools/tqgarray.cpp | 830 +++++++++++++++ src/tools/tqgarray.h | 134 +++ src/tools/tqgcache.cpp | 866 ++++++++++++++++ src/tools/tqgcache.h | 131 +++ src/tools/tqgdict.cpp | 1151 +++++++++++++++++++++ src/tools/tqgdict.h | 225 +++++ src/tools/tqglist.cpp | 1566 +++++++++++++++++++++++++++++ src/tools/tqglist.h | 279 +++++ src/tools/tqglobal.cpp | 889 ++++++++++++++++ src/tools/tqglobal.h | 1085 ++++++++++++++++++++ src/tools/tqgpluginmanager.cpp | 552 ++++++++++ src/tools/tqgpluginmanager_p.h | 110 ++ src/tools/tqgvector.cpp | 598 +++++++++++ src/tools/tqgvector.h | 124 +++ src/tools/tqintcache.h | 2 +- src/tools/tqintdict.h | 2 +- src/tools/tqiodevice.h | 2 +- src/tools/tqmap.h | 2 +- src/tools/tqmemarray.h | 2 +- src/tools/tqmutex.h | 2 +- src/tools/tqpair.h | 2 +- src/tools/tqptrcollection.h | 2 +- src/tools/tqptrdict.h | 2 +- src/tools/tqptrlist.h | 2 +- src/tools/tqptrqueue.h | 2 +- src/tools/tqptrstack.h | 2 +- src/tools/tqptrvector.h | 2 +- src/tools/tqsemaphore.h | 2 +- src/tools/tqthreadstorage.h | 2 +- src/tools/tqwaitcondition.h | 2 +- src/widgets/ntqdockarea.h | 2 +- src/widgets/ntqrangecontrol.h | 2 +- src/widgets/qdockwindow.cpp | 2 +- src/widgets/qeffects.cpp | 2 +- src/widgets/qrangecontrol.cpp | 2 +- src/widgets/tqbutton.cpp | 2 +- src/widgets/tqdialogbuttons.cpp | 2 +- src/widgets/tqiconview.cpp | 2 +- src/widgets/tqlineedit.cpp | 2 +- src/widgets/tqlistbox.cpp | 4 +- src/widgets/tqmenubar.cpp | 2 +- src/widgets/tqmenudata.cpp | 2 +- src/widgets/tqmenudata.h | 2 +- src/widgets/tqpopupmenu.cpp | 2 +- src/widgets/tqpushbutton.cpp | 2 +- src/widgets/tqtextedit.cpp | 2 +- src/widgets/tqtoolbutton.cpp | 2 +- src/widgets/tqtooltip.cpp | 2 +- src/widgets/tqwidgetplugin.h | 2 +- src/workspace/tqworkspace.cpp | 2 +- 137 files changed, 9245 insertions(+), 9292 deletions(-) delete mode 100644 src/kernel/ntqgplugin.h delete mode 100644 src/kernel/ntqguardedptr.h delete mode 100644 src/kernel/qgplugin.cpp delete mode 100644 src/kernel/qguardedptr.cpp create mode 100644 src/kernel/tqgplugin.cpp create mode 100644 src/kernel/tqgplugin.h create mode 100644 src/kernel/tqguardedptr.cpp create mode 100644 src/kernel/tqguardedptr.h delete mode 100644 src/tools/ntqgarray.h delete mode 100644 src/tools/ntqgcache.h delete mode 100644 src/tools/ntqgdict.h delete mode 100644 src/tools/ntqgeneric.h delete mode 100644 src/tools/ntqglist.h delete mode 100644 src/tools/ntqglobal.h delete mode 100644 src/tools/ntqgvector.h delete mode 100644 src/tools/qgarray.cpp delete mode 100644 src/tools/qgcache.cpp delete mode 100644 src/tools/qgdict.cpp delete mode 100644 src/tools/qglist.cpp delete mode 100644 src/tools/qglobal.cpp delete mode 100644 src/tools/qgpluginmanager.cpp delete mode 100644 src/tools/qgpluginmanager_p.h delete mode 100644 src/tools/qgvector.cpp create mode 100644 src/tools/tqgarray.cpp create mode 100644 src/tools/tqgarray.h create mode 100644 src/tools/tqgcache.cpp create mode 100644 src/tools/tqgcache.h create mode 100644 src/tools/tqgdict.cpp create mode 100644 src/tools/tqgdict.h create mode 100644 src/tools/tqglist.cpp create mode 100644 src/tools/tqglist.h create mode 100644 src/tools/tqglobal.cpp create mode 100644 src/tools/tqglobal.h create mode 100644 src/tools/tqgpluginmanager.cpp create mode 100644 src/tools/tqgpluginmanager_p.h create mode 100644 src/tools/tqgvector.cpp create mode 100644 src/tools/tqgvector.h (limited to 'src') diff --git a/src/3rdparty/sqlite/config.h b/src/3rdparty/sqlite/config.h index 833636614..0a06d8eb6 100644 --- a/src/3rdparty/sqlite/config.h +++ b/src/3rdparty/sqlite/config.h @@ -1,4 +1,4 @@ -#include +#include #include #ifndef TQT_POINTER_SIZE diff --git a/src/3rdparty/sqlite/trolltech.patch b/src/3rdparty/sqlite/trolltech.patch index db15f9b6c..715155b46 100644 --- a/src/3rdparty/sqlite/trolltech.patch +++ b/src/3rdparty/sqlite/trolltech.patch @@ -3,7 +3,7 @@ diff -du ./config.h /home/harald/troll/qt-3.3/src/3rdparty/sqlite/config.h +++ /home/harald/troll/qt-3.3/src/3rdparty/sqlite/config.h 2004-01-08 14:29:23.000000000 +0100 @@ -1 +1,23 @@ -#define SQLITE_PTR_SZ 4 -+#include ++#include +#include + +#ifndef TQT_POINTER_SIZE diff --git a/src/codecs/tqfontcodecs_p.h b/src/codecs/tqfontcodecs_p.h index 4a8c1c602..423b7f1e3 100644 --- a/src/codecs/tqfontcodecs_p.h +++ b/src/codecs/tqfontcodecs_p.h @@ -51,7 +51,7 @@ // #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #include "tqtextcodec.h" #endif // QT_H diff --git a/src/codecs/tqjpunicode.h b/src/codecs/tqjpunicode.h index 2daa893b7..fc04af2b9 100644 --- a/src/codecs/tqjpunicode.h +++ b/src/codecs/tqjpunicode.h @@ -71,7 +71,7 @@ #define TQJPUNICODE_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H #ifndef TQT_NO_BIG_CODECS diff --git a/src/codecs/tqtextcodecplugin.h b/src/codecs/tqtextcodecplugin.h index 13a83733d..4ae572749 100644 --- a/src/codecs/tqtextcodecplugin.h +++ b/src/codecs/tqtextcodecplugin.h @@ -42,7 +42,7 @@ #define TQTEXTCODECPLUGIN_H #ifndef QT_H -#include "ntqgplugin.h" +#include "tqgplugin.h" #include "tqstringlist.h" #endif // QT_H diff --git a/src/dialogs/tqfiledialog.cpp b/src/dialogs/tqfiledialog.cpp index cf4eed715..4ae0469d6 100644 --- a/src/dialogs/tqfiledialog.cpp +++ b/src/dialogs/tqfiledialog.cpp @@ -65,7 +65,7 @@ #include "ntqcursor.h" #include "tqdragobject.h" #include "tqfile.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "tqhbox.h" #include "tqheader.h" #include "tqlabel.h" @@ -115,7 +115,7 @@ #ifdef TQ_WS_MAC #include "qt_mac.h" -extern TQString qt_mac_precomposeFileName(const TQString &); // qglobal.cpp +extern TQString qt_mac_precomposeFileName(const TQString &); // tqglobal.cpp #undef check #endif diff --git a/src/inputmethod/ntqinputcontextplugin.h b/src/inputmethod/ntqinputcontextplugin.h index ed1f2eaf4..a67d0b26a 100644 --- a/src/inputmethod/ntqinputcontextplugin.h +++ b/src/inputmethod/ntqinputcontextplugin.h @@ -39,7 +39,7 @@ #define TQINPUTCONTEXTPLUGIN_H #ifndef QT_H -#include "ntqgplugin.h" +#include "tqgplugin.h" #include "tqstringlist.h" #endif // QT_H diff --git a/src/kernel/ntqaccessible.h b/src/kernel/ntqaccessible.h index 4ea410f4c..25b12077e 100644 --- a/src/kernel/ntqaccessible.h +++ b/src/kernel/ntqaccessible.h @@ -43,7 +43,7 @@ #include "tqobject.h" #include #include "tqrect.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "tqmemarray.h" #endif // QT_H diff --git a/src/kernel/ntqgif.h b/src/kernel/ntqgif.h index f5fee77be..9d1658a0c 100644 --- a/src/kernel/ntqgif.h +++ b/src/kernel/ntqgif.h @@ -49,7 +49,7 @@ #define TQGIF_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H #ifndef QT_BUILTIN_GIF_READER diff --git a/src/kernel/ntqgplugin.h b/src/kernel/ntqgplugin.h deleted file mode 100644 index 88212515b..000000000 --- a/src/kernel/ntqgplugin.h +++ /dev/null @@ -1,130 +0,0 @@ -/**************************************************************************** -** -** ... -** -** Copyright (C) 2001-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQGPLUGIN_H -#define TQGPLUGIN_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. It exists for the convenience -// of a number of TQt sources files. This header file may change from -// version to version without notice, or even be removed. -// -// We mean it. -// -// - -#ifndef QT_H -#include "tqobject.h" -#endif // QT_H - -#ifndef TQT_NO_COMPONENT - -#ifndef TQ_EXTERN_C -#ifdef __cplusplus -#define TQ_EXTERN_C extern "C" -#else -#define TQ_EXTERN_C extern -#endif -#endif - -#ifndef TQ_EXPORT_PLUGIN -#if defined(TQT_THREAD_SUPPORT) -#define QT_THREADED_BUILD 1 -#define Q_PLUGIN_FLAGS_STRING "11" -#else -#define QT_THREADED_BUILD 0 -#define Q_PLUGIN_FLAGS_STRING "01" -#endif - -// this is duplicated at Q_UCM_VERIFICATION_DATA in qcom_p.h -// NOTE: if you change pattern, you MUST change the pattern in -// qcomlibrary.cpp as well. changing the pattern will break all -// backwards compatibility as well (no old plugins will be loaded). -#ifndef Q_PLUGIN_VERIFICATION_DATA -# define Q_PLUGIN_VERIFICATION_DATA \ - static const char *qt_ucm_verification_data = \ - "pattern=" "QT_UCM_VERIFICATION_DATA" "\n" \ - "version=" TQT_VERSION_STR "\n" \ - "flags=" Q_PLUGIN_FLAGS_STRING "\n" \ - "buildkey=" TQT_BUILD_KEY "\0"; -#endif // Q_PLUGIN_VERIFICATION_DATA - -#define Q_PLUGIN_INSTANTIATE( IMPLEMENTATION ) \ - { \ - IMPLEMENTATION *i = new IMPLEMENTATION; \ - return i->iface(); \ - } - -#if defined(TQ_WS_WIN) && defined(Q_CC_BOR) -# define Q_STDCALL __stdcall -#else -# define Q_STDCALL -#endif - -#define TQ_EXPORT_PLUGIN(PLUGIN) \ - Q_PLUGIN_VERIFICATION_DATA \ - TQ_EXTERN_C TQ_EXPORT \ - const char * Q_STDCALL qt_ucm_query_verification_data() \ - { return qt_ucm_verification_data; } \ - TQ_EXTERN_C TQ_EXPORT TQUnknownInterface* Q_STDCALL ucm_instantiate() \ - Q_PLUGIN_INSTANTIATE( PLUGIN ) -#endif - -struct TQUnknownInterface; - -class TQ_EXPORT TQGPlugin : public TQObject -{ - TQ_OBJECT -public: - TQGPlugin( TQUnknownInterface *i ); - ~TQGPlugin(); - - TQUnknownInterface* iface(); - void setIface( TQUnknownInterface *iface ); - -private: - TQGPlugin(); - TQUnknownInterface* _iface; -}; - -#endif // TQT_NO_COMPONENT - -#endif // TQGPLUGIN_H diff --git a/src/kernel/ntqguardedptr.h b/src/kernel/ntqguardedptr.h deleted file mode 100644 index 29ef8b8c7..000000000 --- a/src/kernel/ntqguardedptr.h +++ /dev/null @@ -1,144 +0,0 @@ -/**************************************************************************** -** -** Definition of TQGuardedPtr class -** -** Created : 990929 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQGUARDEDPTR_H -#define TQGUARDEDPTR_H - -#ifndef QT_H -#include "tqobject.h" -#endif // QT_H - -// ### 4.0: rename to something without Private in it. Not really internal. -class TQ_EXPORT TQGuardedPtrPrivate : public TQObject, public TQShared -{ - TQ_OBJECT -public: - TQGuardedPtrPrivate( TQObject* ); - ~TQGuardedPtrPrivate(); - - TQObject* object() const; - void reconnect( TQObject* ); - -private slots: - void objectDestroyed(); - -private: - TQObject* obj; -#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= - TQGuardedPtrPrivate( const TQGuardedPtrPrivate & ); - TQGuardedPtrPrivate &operator=( const TQGuardedPtrPrivate & ); -#endif -}; - -template -class TQGuardedPtr -{ -public: - TQGuardedPtr() : priv( new TQGuardedPtrPrivate( 0 ) ) {} - - TQGuardedPtr( T* o) { - priv = new TQGuardedPtrPrivate( (TQObject*)o ); - } - - TQGuardedPtr(const TQGuardedPtr &p) { - priv = p.priv; - ref(); - } - - ~TQGuardedPtr() { deref(); } - - TQGuardedPtr &operator=(const TQGuardedPtr &p) { - if ( priv != p.priv ) { - deref(); - priv = p.priv; - ref(); - } - return *this; - } - - TQGuardedPtr &operator=(T* o) { - if ( priv && priv->count == 1 ) { - priv->reconnect( (TQObject*)o ); - } else { - deref(); - priv = new TQGuardedPtrPrivate( (TQObject*)o ); - } - return *this; - } - - bool operator==( const TQGuardedPtr &p ) const { - return (T*)(*this) == (T*) p; - } - - bool operator!= ( const TQGuardedPtr& p ) const { - return !( *this == p ); - } - - bool isNull() const { return !priv || !priv->object(); } - - T* operator->() const { return (T*)(priv?priv->object():0); } - - T& operator*() const { return *((T*)(priv?priv->object():0)); } - - operator T*() const { return (T*)(priv?priv->object():0); } - -private: - - void ref() { if (priv) priv->ref(); } - - void deref() { - if ( priv && priv->deref() ) - delete priv; - } - - TQGuardedPtrPrivate* priv; -}; - - - - -inline TQObject* TQGuardedPtrPrivate::object() const -{ - return obj; -} - -#define Q_DEFINED_QGUARDEDPTR -#include "ntqwinexport.h" -#endif diff --git a/src/kernel/ntqinputcontext.h b/src/kernel/ntqinputcontext.h index 0ab8e728a..426aa796a 100644 --- a/src/kernel/ntqinputcontext.h +++ b/src/kernel/ntqinputcontext.h @@ -40,7 +40,7 @@ #ifndef QT_H #include "tqobject.h" -#include "ntqglobal.h" +#include "tqglobal.h" #include "tqevent.h" #include "tqstring.h" #include "tqptrlist.h" diff --git a/src/kernel/ntqjpegio.h b/src/kernel/ntqjpegio.h index bb27c5dc8..10ae8d7cf 100644 --- a/src/kernel/ntqjpegio.h +++ b/src/kernel/ntqjpegio.h @@ -41,7 +41,7 @@ #ifndef TQJPEGIO_H #define TQJPEGIO_H -#include "ntqglobal.h" +#include "tqglobal.h" #ifndef TQT_NO_IMAGEIO_JPEG diff --git a/src/kernel/ntqnamespace.h b/src/kernel/ntqnamespace.h index dd2cdedab..cace88141 100644 --- a/src/kernel/ntqnamespace.h +++ b/src/kernel/ntqnamespace.h @@ -42,7 +42,7 @@ #define TQNAMESPACE_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H diff --git a/src/kernel/ntqpolygonscanner.h b/src/kernel/ntqpolygonscanner.h index 3d281da7c..2ab2c8e37 100644 --- a/src/kernel/ntqpolygonscanner.h +++ b/src/kernel/ntqpolygonscanner.h @@ -42,7 +42,7 @@ #define TQPOLYGONSCANNER_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H class TQPointArray; diff --git a/src/kernel/ntqt.h b/src/kernel/ntqt.h index 875323a6d..52caddc35 100644 --- a/src/kernel/ntqt.h +++ b/src/kernel/ntqt.h @@ -15,14 +15,14 @@ #ifndef QT_H #define QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #include "ntqfeatures.h" #include "ntqshared.h" #include "tqptrcollection.h" -#include "ntqglist.h" +#include "tqglist.h" #include "tqobjectdefs.h" #include "ntqnamespace.h" -#include "ntqgarray.h" +#include "tqgarray.h" #include "tqmemarray.h" #include "tqcstring.h" #include "tqstring.h" @@ -30,7 +30,7 @@ #include "tqiodevice.h" #include "ntqkeysequence.h" #include "ntqwindowdefs.h" -#include "ntqgdict.h" +#include "tqgdict.h" #include "tqfont.h" #include "tqdatastream.h" #include "tqpair.h" @@ -86,17 +86,17 @@ #include "tqnetworkprotocol.h" #include #include -#include "ntqgcache.h" +#include "tqgcache.h" #include #include #include #include -#include "ntqgplugin.h" +#include "tqgplugin.h" #include #include "ntqrangecontrol.h" #include "tqbuttongroup.h" #include -#include "ntqgvector.h" +#include "tqgvector.h" #include "tqhbox.h" #include #include @@ -139,7 +139,7 @@ #include "tqmutex.h" #include #include -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include #include "tqsqlfield.h" #include @@ -281,7 +281,7 @@ #include "private/tqlayoutengine_p.h" #include "private/qcomlibrary_p.h" #include "private/qeffects_p.h" -#include "private/qgpluginmanager_p.h" +#include "private/tqgpluginmanager_p.h" #include "private/qinternal_p.h" #include "private/tqsqldriverinterface_p.h" #include "private/tqsqlmanager_p.h" diff --git a/src/kernel/qaccel.cpp b/src/kernel/qaccel.cpp index fabd7dcf4..e2f55f01e 100644 --- a/src/kernel/qaccel.cpp +++ b/src/kernel/qaccel.cpp @@ -47,7 +47,7 @@ #include "tqwidget.h" #include "tqptrlist.h" #include "tqwhatsthis.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "tqstatusbar.h" #include "ntqdockwindow.h" #include "tqsignalslotimp.h" diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp index d48805c3a..7abbbd56f 100644 --- a/src/kernel/qapplication.cpp +++ b/src/kernel/qapplication.cpp @@ -283,7 +283,7 @@ \headerfile ntqnamespace.h \headerfile ntqwindowdefs.h - \headerfile ntqglobal.h + \headerfile tqglobal.h */ /*! \enum TQt::HANDLE diff --git a/src/kernel/qapplication_x11.cpp b/src/kernel/qapplication_x11.cpp index 18a0eb7f0..f3252b296 100644 --- a/src/kernel/qapplication_x11.cpp +++ b/src/kernel/qapplication_x11.cpp @@ -81,7 +81,7 @@ #include "tqsessionmanager.h" #include "tqvaluelist.h" #include "tqdict.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "tqclipboard.h" #include "tqwhatsthis.h" // ######## dependency #include "tqsettings.h" diff --git a/src/kernel/qdnd_x11.cpp b/src/kernel/qdnd_x11.cpp index 5194ee878..c35bca0a4 100644 --- a/src/kernel/qdnd_x11.cpp +++ b/src/kernel/qdnd_x11.cpp @@ -48,7 +48,7 @@ #include "tqintdict.h" #include "tqdatetime.h" #include "tqdict.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "tqdragobject.h" #include "tqobjectlist.h" #include "ntqcursor.h" diff --git a/src/kernel/qgplugin.cpp b/src/kernel/qgplugin.cpp deleted file mode 100644 index ca5b4131f..000000000 --- a/src/kernel/qgplugin.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** ... -** -** Copyright (C) 2001-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqgplugin.h" - -#ifndef TQT_NO_COMPONENT - -#include - -TQGPlugin::TQGPlugin() - : _iface( 0 ) -{ -} - -TQGPlugin::TQGPlugin( TQUnknownInterface *i ) - : _iface( i ) -{ -} - -TQGPlugin::~TQGPlugin() -{ -} - -TQUnknownInterface* TQGPlugin::iface() -{ - Q_ASSERT( _iface ); - TQUnknownInterface *i; - _iface->queryInterface( IID_QUnknown, &i ); - return i; -} - -void TQGPlugin::setIface( TQUnknownInterface *iface ) -{ - _iface = iface; -} - -#endif // TQT_NO_COMPONENT diff --git a/src/kernel/qguardedptr.cpp b/src/kernel/qguardedptr.cpp deleted file mode 100644 index 5102d094b..000000000 --- a/src/kernel/qguardedptr.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQGuardedPtr class -** -** Created : 990929 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqguardedptr.h" - -/*! - \class TQGuardedPtr ntqguardedptr.h - \brief The TQGuardedPtr class is a template class that provides guarded pointers to TQObjects. - - \ingroup objectmodel - \mainclass - - A guarded pointer, \c{TQGuardedPtr}, behaves like a normal C++ - pointer \c{X*}, except that it is automatically set to 0 when - the referenced object is destroyed (unlike normal C++ pointers, - which become "dangling pointers" in such cases). \c X must be a - subclass of TQObject. - - Guarded pointers are useful whenever you need to store a pointer - to a TQObject that is owned by someone else and therefore might be - destroyed while you still hold a reference to it. You can safely - test the pointer for validity. - - Example: - \code - TQGuardedPtr label = new TQLabel( 0, "label" ); - label->setText( "I like guarded pointers" ); - - delete (TQLabel*) label; // simulate somebody destroying the label - - if ( label) - label->show(); - else - tqDebug("The label has been destroyed"); - \endcode - - The program will output \c{The label has been destroyed} rather - than dereferencing an invalid address in \c label->show(). - - The functions and operators available with a TQGuardedPtr are the - same as those available with a normal unguarded pointer, except - the pointer arithmetic operators (++, --, -, and +), which are - normally used only with arrays of objects. Use them like normal - pointers and you will not need to read this class documentation. - - For creating guarded pointers, you can construct or assign to them - from an X* or from another guarded pointer of the same type. You - can compare them with each other using operator==() and - operator!=(), or test for 0 with isNull(). And you can dereference - them using either the \c *x or the \c x->member notation. - - A guarded pointer will automatically cast to an X*, so you can - freely mix guarded and unguarded pointers. This means that if you - have a TQGuardedPtr, you can pass it to a function that - requires a TQWidget*. For this reason, it is of little value to - declare functions to take a TQGuardedPtr as a parameter; just use - normal pointers. Use a TQGuardedPtr when you are storing a pointer - over time. - - Note again that class \e X must inherit TQObject, or a compilation - or link error will result. -*/ - -/*! - \fn TQGuardedPtr::TQGuardedPtr() - - Constructs a 0 guarded pointer. - - \sa isNull() -*/ - -/*! - \fn TQGuardedPtr::TQGuardedPtr( T* p ) - - Constructs a guarded pointer that points to same object as \a p - points to. -*/ - -/*! - \fn TQGuardedPtr::TQGuardedPtr(const TQGuardedPtr &p) - - Copy one guarded pointer from another. The constructed guarded - pointer points to the same object that \a p points to (which may - be 0). -*/ - -/*! - \fn TQGuardedPtr::~TQGuardedPtr() - - Destroys the guarded pointer. Just like a normal pointer, - destroying a guarded pointer does \e not destroy the object being - pointed to. -*/ - -/*! - \fn TQGuardedPtr& TQGuardedPtr::operator=(const TQGuardedPtr &p) - - Assignment operator. This guarded pointer then points to the same - object as \a p points to. -*/ - -/*! - \overload TQGuardedPtr & TQGuardedPtr::operator=(T* p) - - Assignment operator. This guarded pointer then points to the same - object as \a p points to. -*/ - -/*! - \fn bool TQGuardedPtr::operator==( const TQGuardedPtr &p ) const - - Equality operator; implements traditional pointer semantics. - Returns TRUE if both \a p and this guarded pointer are 0, or if - both \a p and this pointer point to the same object; otherwise - returns FALSE. - - \sa operator!=() -*/ - -/*! - \fn bool TQGuardedPtr::operator!= ( const TQGuardedPtr& p ) const - - Inequality operator; implements pointer semantics, the negation of - operator==(). Returns TRUE if \a p and this guarded pointer are - not pointing to the same object; otherwise returns FALSE. -*/ - -/*! - \fn bool TQGuardedPtr::isNull() const - - Returns \c TRUE if the referenced object has been destroyed or if - there is no referenced object; otherwise returns FALSE. -*/ - -/*! - \fn T* TQGuardedPtr::operator->() const - - Overloaded arrow operator; implements pointer semantics. Just use - this operator as you would with a normal C++ pointer. -*/ - -/*! - \fn T& TQGuardedPtr::operator*() const - - Dereference operator; implements pointer semantics. Just use this - operator as you would with a normal C++ pointer. -*/ - -/*! - \fn TQGuardedPtr::operator T*() const - - Cast operator; implements pointer semantics. Because of this - function you can pass a TQGuardedPtr\ to a function where an X* - is required. -*/ - - -/* Internal classes */ - - -TQGuardedPtrPrivate::TQGuardedPtrPrivate( TQObject* o) - : TQObject(0, "_ptrpriv" ), obj( o ) -{ - if ( obj ) - connect( obj, TQ_SIGNAL( destroyed() ), this, TQ_SLOT( objectDestroyed() ) ); -} - - -TQGuardedPtrPrivate::~TQGuardedPtrPrivate() -{ -} - -void TQGuardedPtrPrivate::reconnect( TQObject *o ) -{ - if ( obj == o ) - return; - if ( obj ) - disconnect( obj, TQ_SIGNAL( destroyed() ), - this, TQ_SLOT( objectDestroyed() ) ); - obj = o; - if ( obj ) - connect( obj, TQ_SIGNAL( destroyed() ), - this, TQ_SLOT( objectDestroyed() ) ); -} - -void TQGuardedPtrPrivate::objectDestroyed() -{ - obj = 0; -} diff --git a/src/kernel/qinputcontext_p.h b/src/kernel/qinputcontext_p.h index 0e0f8da0c..37ba52b6c 100644 --- a/src/kernel/qinputcontext_p.h +++ b/src/kernel/qinputcontext_p.h @@ -52,7 +52,7 @@ // // -#include "ntqglobal.h" +#include "tqglobal.h" class TQKeyEvent; class TQWidget; diff --git a/src/kernel/qt_kernel.pri b/src/kernel/qt_kernel.pri index bd93c7c29..a31cab804 100644 --- a/src/kernel/qt_kernel.pri +++ b/src/kernel/qt_kernel.pri @@ -29,7 +29,7 @@ kernel { $$KERNEL_P/tqfontdata_p.h \ $$KERNEL_H/tqfontinfo.h \ $$KERNEL_H/tqfontmetrics.h \ - $$KERNEL_H/ntqguardedptr.h \ + $$KERNEL_H/tqguardedptr.h \ $$KERNEL_H/ntqgif.h \ $$KERNEL_H/tqiconset.h \ $$KERNEL_H/tqimage.h \ @@ -91,7 +91,7 @@ kernel { $$KERNEL_H/ntqvariant.h \ $$KERNEL_P/qrichtext_p.h \ $$KERNEL_P/qinternal_p.h \ - $$KERNEL_H/ntqgplugin.h \ + $$KERNEL_H/tqgplugin.h \ $$KERNEL_H/tqsimplerichtext.h \ $$KERNEL_CPP/qscriptengine_p.h \ $$KERNEL_CPP/tqtextengine_p.h \ @@ -213,7 +213,7 @@ kernel { $$KERNEL_CPP/qfocusdata.cpp \ $$KERNEL_CPP/tqfont.cpp \ $$KERNEL_CPP/tqfontdatabase.cpp \ - $$KERNEL_CPP/qguardedptr.cpp \ + $$KERNEL_CPP/tqguardedptr.cpp \ $$KERNEL_CPP/tqiconset.cpp \ $$KERNEL_CPP/tqimage.cpp \ $$KERNEL_CPP/tqimageformatplugin.cpp \ @@ -260,7 +260,7 @@ kernel { $$KERNEL_CPP/qrichtext.cpp \ $$KERNEL_CPP/qinternal.cpp \ $$KERNEL_CPP/qrichtext_p.cpp \ - $$KERNEL_CPP/qgplugin.cpp \ + $$KERNEL_CPP/tqgplugin.cpp \ $$KERNEL_CPP/tqsimplerichtext.cpp \ $$KERNEL_CPP/qscriptengine.cpp \ $$KERNEL_CPP/tqtextlayout.cpp \ diff --git a/src/kernel/qt_pch.h b/src/kernel/qt_pch.h index 908254769..611076c97 100644 --- a/src/kernel/qt_pch.h +++ b/src/kernel/qt_pch.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include // All moc genereated code has this include #include diff --git a/src/kernel/qvariant.cpp b/src/kernel/qvariant.cpp index ac3157676..884ef1ed5 100644 --- a/src/kernel/qvariant.cpp +++ b/src/kernel/qvariant.cpp @@ -475,7 +475,7 @@ void TQVariant::Private::clear() \value UInt an unsigned int Note that TQt's definition of bool depends on the compiler. - \c ntqglobal.h has the system-dependent definition of bool. + \c tqglobal.h has the system-dependent definition of bool. */ /*! diff --git a/src/kernel/tqcolor_p.cpp b/src/kernel/tqcolor_p.cpp index 0a91f5c90..d1462f43f 100644 --- a/src/kernel/tqcolor_p.cpp +++ b/src/kernel/tqcolor_p.cpp @@ -39,7 +39,7 @@ ** **********************************************************************/ -#include "ntqglobal.h" +#include "tqglobal.h" #if defined(Q_CC_BOR) // needed for qsort() because of a std namespace problem on Borland #include "qplatformdefs.h" diff --git a/src/kernel/tqdropsite.h b/src/kernel/tqdropsite.h index 3e95cdc3f..9ee72b4d8 100644 --- a/src/kernel/tqdropsite.h +++ b/src/kernel/tqdropsite.h @@ -41,7 +41,7 @@ #ifndef QT_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H #endif diff --git a/src/kernel/tqfontengine_p.h b/src/kernel/tqfontengine_p.h index 3dba677ca..559972746 100644 --- a/src/kernel/tqfontengine_p.h +++ b/src/kernel/tqfontengine_p.h @@ -38,7 +38,7 @@ #define TQFONTENGINE_P_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H #ifdef TQ_WS_WIN diff --git a/src/kernel/tqgplugin.cpp b/src/kernel/tqgplugin.cpp new file mode 100644 index 000000000..c0cfd8f47 --- /dev/null +++ b/src/kernel/tqgplugin.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** ... +** +** Copyright (C) 2001-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqgplugin.h" + +#ifndef TQT_NO_COMPONENT + +#include + +TQGPlugin::TQGPlugin() + : _iface( 0 ) +{ +} + +TQGPlugin::TQGPlugin( TQUnknownInterface *i ) + : _iface( i ) +{ +} + +TQGPlugin::~TQGPlugin() +{ +} + +TQUnknownInterface* TQGPlugin::iface() +{ + Q_ASSERT( _iface ); + TQUnknownInterface *i; + _iface->queryInterface( IID_QUnknown, &i ); + return i; +} + +void TQGPlugin::setIface( TQUnknownInterface *iface ) +{ + _iface = iface; +} + +#endif // TQT_NO_COMPONENT diff --git a/src/kernel/tqgplugin.h b/src/kernel/tqgplugin.h new file mode 100644 index 000000000..88212515b --- /dev/null +++ b/src/kernel/tqgplugin.h @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** ... +** +** Copyright (C) 2001-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQGPLUGIN_H +#define TQGPLUGIN_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. It exists for the convenience +// of a number of TQt sources files. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// +// + +#ifndef QT_H +#include "tqobject.h" +#endif // QT_H + +#ifndef TQT_NO_COMPONENT + +#ifndef TQ_EXTERN_C +#ifdef __cplusplus +#define TQ_EXTERN_C extern "C" +#else +#define TQ_EXTERN_C extern +#endif +#endif + +#ifndef TQ_EXPORT_PLUGIN +#if defined(TQT_THREAD_SUPPORT) +#define QT_THREADED_BUILD 1 +#define Q_PLUGIN_FLAGS_STRING "11" +#else +#define QT_THREADED_BUILD 0 +#define Q_PLUGIN_FLAGS_STRING "01" +#endif + +// this is duplicated at Q_UCM_VERIFICATION_DATA in qcom_p.h +// NOTE: if you change pattern, you MUST change the pattern in +// qcomlibrary.cpp as well. changing the pattern will break all +// backwards compatibility as well (no old plugins will be loaded). +#ifndef Q_PLUGIN_VERIFICATION_DATA +# define Q_PLUGIN_VERIFICATION_DATA \ + static const char *qt_ucm_verification_data = \ + "pattern=" "QT_UCM_VERIFICATION_DATA" "\n" \ + "version=" TQT_VERSION_STR "\n" \ + "flags=" Q_PLUGIN_FLAGS_STRING "\n" \ + "buildkey=" TQT_BUILD_KEY "\0"; +#endif // Q_PLUGIN_VERIFICATION_DATA + +#define Q_PLUGIN_INSTANTIATE( IMPLEMENTATION ) \ + { \ + IMPLEMENTATION *i = new IMPLEMENTATION; \ + return i->iface(); \ + } + +#if defined(TQ_WS_WIN) && defined(Q_CC_BOR) +# define Q_STDCALL __stdcall +#else +# define Q_STDCALL +#endif + +#define TQ_EXPORT_PLUGIN(PLUGIN) \ + Q_PLUGIN_VERIFICATION_DATA \ + TQ_EXTERN_C TQ_EXPORT \ + const char * Q_STDCALL qt_ucm_query_verification_data() \ + { return qt_ucm_verification_data; } \ + TQ_EXTERN_C TQ_EXPORT TQUnknownInterface* Q_STDCALL ucm_instantiate() \ + Q_PLUGIN_INSTANTIATE( PLUGIN ) +#endif + +struct TQUnknownInterface; + +class TQ_EXPORT TQGPlugin : public TQObject +{ + TQ_OBJECT +public: + TQGPlugin( TQUnknownInterface *i ); + ~TQGPlugin(); + + TQUnknownInterface* iface(); + void setIface( TQUnknownInterface *iface ); + +private: + TQGPlugin(); + TQUnknownInterface* _iface; +}; + +#endif // TQT_NO_COMPONENT + +#endif // TQGPLUGIN_H diff --git a/src/kernel/tqguardedptr.cpp b/src/kernel/tqguardedptr.cpp new file mode 100644 index 000000000..a08fe1aae --- /dev/null +++ b/src/kernel/tqguardedptr.cpp @@ -0,0 +1,226 @@ +/**************************************************************************** +** +** Implementation of TQGuardedPtr class +** +** Created : 990929 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqguardedptr.h" + +/*! + \class TQGuardedPtr tqguardedptr.h + \brief The TQGuardedPtr class is a template class that provides guarded pointers to TQObjects. + + \ingroup objectmodel + \mainclass + + A guarded pointer, \c{TQGuardedPtr}, behaves like a normal C++ + pointer \c{X*}, except that it is automatically set to 0 when + the referenced object is destroyed (unlike normal C++ pointers, + which become "dangling pointers" in such cases). \c X must be a + subclass of TQObject. + + Guarded pointers are useful whenever you need to store a pointer + to a TQObject that is owned by someone else and therefore might be + destroyed while you still hold a reference to it. You can safely + test the pointer for validity. + + Example: + \code + TQGuardedPtr label = new TQLabel( 0, "label" ); + label->setText( "I like guarded pointers" ); + + delete (TQLabel*) label; // simulate somebody destroying the label + + if ( label) + label->show(); + else + tqDebug("The label has been destroyed"); + \endcode + + The program will output \c{The label has been destroyed} rather + than dereferencing an invalid address in \c label->show(). + + The functions and operators available with a TQGuardedPtr are the + same as those available with a normal unguarded pointer, except + the pointer arithmetic operators (++, --, -, and +), which are + normally used only with arrays of objects. Use them like normal + pointers and you will not need to read this class documentation. + + For creating guarded pointers, you can construct or assign to them + from an X* or from another guarded pointer of the same type. You + can compare them with each other using operator==() and + operator!=(), or test for 0 with isNull(). And you can dereference + them using either the \c *x or the \c x->member notation. + + A guarded pointer will automatically cast to an X*, so you can + freely mix guarded and unguarded pointers. This means that if you + have a TQGuardedPtr, you can pass it to a function that + requires a TQWidget*. For this reason, it is of little value to + declare functions to take a TQGuardedPtr as a parameter; just use + normal pointers. Use a TQGuardedPtr when you are storing a pointer + over time. + + Note again that class \e X must inherit TQObject, or a compilation + or link error will result. +*/ + +/*! + \fn TQGuardedPtr::TQGuardedPtr() + + Constructs a 0 guarded pointer. + + \sa isNull() +*/ + +/*! + \fn TQGuardedPtr::TQGuardedPtr( T* p ) + + Constructs a guarded pointer that points to same object as \a p + points to. +*/ + +/*! + \fn TQGuardedPtr::TQGuardedPtr(const TQGuardedPtr &p) + + Copy one guarded pointer from another. The constructed guarded + pointer points to the same object that \a p points to (which may + be 0). +*/ + +/*! + \fn TQGuardedPtr::~TQGuardedPtr() + + Destroys the guarded pointer. Just like a normal pointer, + destroying a guarded pointer does \e not destroy the object being + pointed to. +*/ + +/*! + \fn TQGuardedPtr& TQGuardedPtr::operator=(const TQGuardedPtr &p) + + Assignment operator. This guarded pointer then points to the same + object as \a p points to. +*/ + +/*! + \overload TQGuardedPtr & TQGuardedPtr::operator=(T* p) + + Assignment operator. This guarded pointer then points to the same + object as \a p points to. +*/ + +/*! + \fn bool TQGuardedPtr::operator==( const TQGuardedPtr &p ) const + + Equality operator; implements traditional pointer semantics. + Returns TRUE if both \a p and this guarded pointer are 0, or if + both \a p and this pointer point to the same object; otherwise + returns FALSE. + + \sa operator!=() +*/ + +/*! + \fn bool TQGuardedPtr::operator!= ( const TQGuardedPtr& p ) const + + Inequality operator; implements pointer semantics, the negation of + operator==(). Returns TRUE if \a p and this guarded pointer are + not pointing to the same object; otherwise returns FALSE. +*/ + +/*! + \fn bool TQGuardedPtr::isNull() const + + Returns \c TRUE if the referenced object has been destroyed or if + there is no referenced object; otherwise returns FALSE. +*/ + +/*! + \fn T* TQGuardedPtr::operator->() const + + Overloaded arrow operator; implements pointer semantics. Just use + this operator as you would with a normal C++ pointer. +*/ + +/*! + \fn T& TQGuardedPtr::operator*() const + + Dereference operator; implements pointer semantics. Just use this + operator as you would with a normal C++ pointer. +*/ + +/*! + \fn TQGuardedPtr::operator T*() const + + Cast operator; implements pointer semantics. Because of this + function you can pass a TQGuardedPtr\ to a function where an X* + is required. +*/ + + +/* Internal classes */ + + +TQGuardedPtrPrivate::TQGuardedPtrPrivate( TQObject* o) + : TQObject(0, "_ptrpriv" ), obj( o ) +{ + if ( obj ) + connect( obj, TQ_SIGNAL( destroyed() ), this, TQ_SLOT( objectDestroyed() ) ); +} + + +TQGuardedPtrPrivate::~TQGuardedPtrPrivate() +{ +} + +void TQGuardedPtrPrivate::reconnect( TQObject *o ) +{ + if ( obj == o ) + return; + if ( obj ) + disconnect( obj, TQ_SIGNAL( destroyed() ), + this, TQ_SLOT( objectDestroyed() ) ); + obj = o; + if ( obj ) + connect( obj, TQ_SIGNAL( destroyed() ), + this, TQ_SLOT( objectDestroyed() ) ); +} + +void TQGuardedPtrPrivate::objectDestroyed() +{ + obj = 0; +} diff --git a/src/kernel/tqguardedptr.h b/src/kernel/tqguardedptr.h new file mode 100644 index 000000000..29ef8b8c7 --- /dev/null +++ b/src/kernel/tqguardedptr.h @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Definition of TQGuardedPtr class +** +** Created : 990929 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQGUARDEDPTR_H +#define TQGUARDEDPTR_H + +#ifndef QT_H +#include "tqobject.h" +#endif // QT_H + +// ### 4.0: rename to something without Private in it. Not really internal. +class TQ_EXPORT TQGuardedPtrPrivate : public TQObject, public TQShared +{ + TQ_OBJECT +public: + TQGuardedPtrPrivate( TQObject* ); + ~TQGuardedPtrPrivate(); + + TQObject* object() const; + void reconnect( TQObject* ); + +private slots: + void objectDestroyed(); + +private: + TQObject* obj; +#if defined(TQ_DISABLE_COPY) // Disabled copy constructor and operator= + TQGuardedPtrPrivate( const TQGuardedPtrPrivate & ); + TQGuardedPtrPrivate &operator=( const TQGuardedPtrPrivate & ); +#endif +}; + +template +class TQGuardedPtr +{ +public: + TQGuardedPtr() : priv( new TQGuardedPtrPrivate( 0 ) ) {} + + TQGuardedPtr( T* o) { + priv = new TQGuardedPtrPrivate( (TQObject*)o ); + } + + TQGuardedPtr(const TQGuardedPtr &p) { + priv = p.priv; + ref(); + } + + ~TQGuardedPtr() { deref(); } + + TQGuardedPtr &operator=(const TQGuardedPtr &p) { + if ( priv != p.priv ) { + deref(); + priv = p.priv; + ref(); + } + return *this; + } + + TQGuardedPtr &operator=(T* o) { + if ( priv && priv->count == 1 ) { + priv->reconnect( (TQObject*)o ); + } else { + deref(); + priv = new TQGuardedPtrPrivate( (TQObject*)o ); + } + return *this; + } + + bool operator==( const TQGuardedPtr &p ) const { + return (T*)(*this) == (T*) p; + } + + bool operator!= ( const TQGuardedPtr& p ) const { + return !( *this == p ); + } + + bool isNull() const { return !priv || !priv->object(); } + + T* operator->() const { return (T*)(priv?priv->object():0); } + + T& operator*() const { return *((T*)(priv?priv->object():0)); } + + operator T*() const { return (T*)(priv?priv->object():0); } + +private: + + void ref() { if (priv) priv->ref(); } + + void deref() { + if ( priv && priv->deref() ) + delete priv; + } + + TQGuardedPtrPrivate* priv; +}; + + + + +inline TQObject* TQGuardedPtrPrivate::object() const +{ + return obj; +} + +#define Q_DEFINED_QGUARDEDPTR +#include "ntqwinexport.h" +#endif diff --git a/src/kernel/tqimageformatplugin.h b/src/kernel/tqimageformatplugin.h index 6940f18b6..83dbad7f2 100644 --- a/src/kernel/tqimageformatplugin.h +++ b/src/kernel/tqimageformatplugin.h @@ -40,7 +40,7 @@ #define TQIMAGEFORMATPLUGIN_H #ifndef QT_H -#include "ntqgplugin.h" +#include "tqgplugin.h" #include "tqstringlist.h" #endif // QT_H diff --git a/src/kernel/tqlocalfs.cpp b/src/kernel/tqlocalfs.cpp index b6b525c8d..5adc77fb2 100644 --- a/src/kernel/tqlocalfs.cpp +++ b/src/kernel/tqlocalfs.cpp @@ -47,7 +47,7 @@ #include "tqurlinfo.h" #include "ntqapplication.h" #include "tqurloperator.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" //#define TQLOCALFS_DEBUG diff --git a/src/kernel/tqobjectdefs.h b/src/kernel/tqobjectdefs.h index ba5e12b88..422299850 100644 --- a/src/kernel/tqobjectdefs.h +++ b/src/kernel/tqobjectdefs.h @@ -42,7 +42,7 @@ #define TQOBJECTDEFS_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H diff --git a/src/kernel/tqsignal.cpp b/src/kernel/tqsignal.cpp index 22e325031..3be5bb960 100644 --- a/src/kernel/tqsignal.cpp +++ b/src/kernel/tqsignal.cpp @@ -40,7 +40,7 @@ #include "tqsignal.h" #include "ntqmetaobject.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" /*! \class TQSignal tqsignal.h diff --git a/src/kernel/tqsimplerichtext.cpp b/src/kernel/tqsimplerichtext.cpp index 2288a5692..eccf9190d 100644 --- a/src/kernel/tqsimplerichtext.cpp +++ b/src/kernel/tqsimplerichtext.cpp @@ -54,7 +54,7 @@ public: void adjustSize(TQPainter *p = 0); }; -// Pull this private function in from qglobal.cpp +// Pull this private function in from tqglobal.cpp extern unsigned int qt_int_sqrt( unsigned int n ); void TQSimpleRichTextData::adjustSize(TQPainter *p) { diff --git a/src/kernel/tqsizepolicy.h b/src/kernel/tqsizepolicy.h index 2c764d33b..f6fac3885 100644 --- a/src/kernel/tqsizepolicy.h +++ b/src/kernel/tqsizepolicy.h @@ -42,7 +42,7 @@ #define TQSIZEPOLICY_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H // Documentation is in qabstractlayout.cpp. diff --git a/src/kernel/tqt.h b/src/kernel/tqt.h index 723759d55..665f07b1a 100644 --- a/src/kernel/tqt.h +++ b/src/kernel/tqt.h @@ -22,7 +22,7 @@ Boston, MA 02110-1301, USA. #ifndef TQT_H #define TQT_H -#include +#include #define Qt TQt diff --git a/src/kernel/tqtextengine_p.h b/src/kernel/tqtextengine_p.h index 608bc06de..d1a467f2b 100644 --- a/src/kernel/tqtextengine_p.h +++ b/src/kernel/tqtextengine_p.h @@ -38,7 +38,7 @@ #define TQTEXTENGINE_P_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #include "tqstring.h" #include "ntqnamespace.h" #include diff --git a/src/kernel/tqurloperator.cpp b/src/kernel/tqurloperator.cpp index f7705bc2e..d8567e467 100644 --- a/src/kernel/tqurloperator.cpp +++ b/src/kernel/tqurloperator.cpp @@ -47,7 +47,7 @@ #include "tqmap.h" #include "tqdir.h" #include "tqptrdict.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" //#define TQURLOPERATOR_DEBUG diff --git a/src/kernel/tqwidget.cpp b/src/kernel/tqwidget.cpp index 0b27e2564..1e9a809cb 100644 --- a/src/kernel/tqwidget.cpp +++ b/src/kernel/tqwidget.cpp @@ -55,7 +55,7 @@ #include "ntqcleanuphandler.h" #include "tqstyle.h" #include "ntqmetaobject.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #if defined(TQT_THREAD_SUPPORT) #include "tqthread.h" #endif diff --git a/src/libqt.map b/src/libqt.map index 42e353c76..bc20283fb 100644 --- a/src/libqt.map +++ b/src/libqt.map @@ -2,7 +2,7 @@ global: extern "C++" { - QGuardedPtrPrivate::* + TQGuardedPtrPrivate::* }; local: extern "C++" @@ -19,7 +19,7 @@ TQHttpRequest::*; TQHttpResponseHeader::*; TQMainWindowLayout::*; - Q*Private::*; # collides with QGuardedPtrPrivate + Q*Private::*; # collides with TQGuardedPtrPrivate QPSPrinter*; Q*RegExpEngine::*; Q*SvgDevice::*; diff --git a/src/moc/moc.pro b/src/moc/moc.pro index e1b56f668..e26c4893f 100644 --- a/src/moc/moc.pro +++ b/src/moc/moc.pro @@ -20,11 +20,11 @@ SOURCES = ../tools/tqbuffer.cpp \ ../tools/tqfile.cpp \ ../tools/tqdir.cpp \ ../tools/tqfileinfo.cpp \ - ../tools/qgarray.cpp \ - ../tools/qgdict.cpp \ - ../tools/qglist.cpp \ - ../tools/qglobal.cpp \ - ../tools/qgvector.cpp \ + ../tools/tqgarray.cpp \ + ../tools/tqgdict.cpp \ + ../tools/tqglist.cpp \ + ../tools/tqglobal.cpp \ + ../tools/tqgvector.cpp \ ../tools/tqiodevice.cpp \ ../tools/tqregexp.cpp \ ../tools/tqstring.cpp \ @@ -34,7 +34,7 @@ SOURCES = ../tools/tqbuffer.cpp \ ../tools/tqtextstream.cpp \ ../tools/tqbitarray.cpp \ ../tools/tqmap.cpp \ - ../tools/qgcache.cpp \ + ../tools/tqgcache.cpp \ ../codecs/tqtextcodec.cpp \ ../codecs/tqutfcodec.cpp diff --git a/src/network/tqnetwork.h b/src/network/tqnetwork.h index 7f6de06d3..ec612b175 100644 --- a/src/network/tqnetwork.h +++ b/src/network/tqnetwork.h @@ -42,7 +42,7 @@ #define TQNETWORK_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H #if !defined( TQT_MODULE_NETWORK ) || defined( QT_LICENSE_PROFESSIONAL ) || defined( QT_INTERNAL_NETWORK ) diff --git a/src/qt.pro b/src/qt.pro index 01b74fe97..903d9b396 100644 --- a/src/qt.pro +++ b/src/qt.pro @@ -169,14 +169,14 @@ wince-* { CONFIG -= incremental message( ...removing plugin stuff... (not permanent) ) HEADERS -= $$TOOLS_CPP/qcomlibrary.h \ - $$KERNEL_CPP/ntqgplugin.h \ + $$KERNEL_CPP/tqgplugin.h \ $$KERNEL_CPP/tqimageformatplugin.h \ $$STYLES_CPP/tqstyleplugin.h \ $$CODECS_CPP/tqtextcodecplugin.h \ $$WIDGETS_CPP/tqwidgetplugin.h SOURCES -= $$TOOLS_CPP/qcomlibrary.cpp \ - $$KERNEL_CPP/qgplugin.cpp \ + $$KERNEL_CPP/tqgplugin.cpp \ $$KERNEL_CPP/tqimageformatplugin.cpp \ $$STYLES_CPP/tqstyleplugin.cpp \ $$CODECS_CPP/tqtextcodecplugin.cpp \ diff --git a/src/sql/drivers/cache/tqsqlcachedresult.h b/src/sql/drivers/cache/tqsqlcachedresult.h index 11aa63d99..f49ffea89 100644 --- a/src/sql/drivers/cache/tqsqlcachedresult.h +++ b/src/sql/drivers/cache/tqsqlcachedresult.h @@ -51,7 +51,7 @@ // // -#include +#include #include #include #include diff --git a/src/sql/tqsql.h b/src/sql/tqsql.h index 28a8204b2..845b1f890 100644 --- a/src/sql/tqsql.h +++ b/src/sql/tqsql.h @@ -42,7 +42,7 @@ #define TQSQL_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H #if !defined( TQT_MODULE_SQL ) || defined( QT_LICENSE_PROFESSIONAL ) diff --git a/src/sql/tqsqldatabase.cpp b/src/sql/tqsqldatabase.cpp index 301025914..4a7657248 100644 --- a/src/sql/tqsqldatabase.cpp +++ b/src/sql/tqsqldatabase.cpp @@ -82,7 +82,7 @@ #include #include #include "tqobject.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "ntqcleanuphandler.h" #include "tqdict.h" #include diff --git a/src/sql/tqsqldriverplugin.h b/src/sql/tqsqldriverplugin.h index 81c4958a8..bb72834af 100644 --- a/src/sql/tqsqldriverplugin.h +++ b/src/sql/tqsqldriverplugin.h @@ -42,7 +42,7 @@ #define TQSQLDRIVERPLUGIN_H #ifndef QT_H -#include "ntqgplugin.h" +#include "tqgplugin.h" #include "tqstringlist.h" #endif // QT_H diff --git a/src/sql/tqsqlmanager_p.h b/src/sql/tqsqlmanager_p.h index bb3010f2b..8b667d68e 100644 --- a/src/sql/tqsqlmanager_p.h +++ b/src/sql/tqsqlmanager_p.h @@ -54,7 +54,7 @@ // #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #include "tqstring.h" #include "tqstringlist.h" #include "tqsql.h" diff --git a/src/styles/tqmotifplusstyle.cpp b/src/styles/tqmotifplusstyle.cpp index eec496cda..d1c40292a 100644 --- a/src/styles/tqmotifplusstyle.cpp +++ b/src/styles/tqmotifplusstyle.cpp @@ -58,7 +58,7 @@ #include "tqscrollbar.h" #include "tqtabbar.h" #include "tqtoolbar.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "tqlayout.h" diff --git a/src/styles/tqsgistyle.h b/src/styles/tqsgistyle.h index d09ad4cf4..9a28713f1 100644 --- a/src/styles/tqsgistyle.h +++ b/src/styles/tqsgistyle.h @@ -43,7 +43,7 @@ #ifndef QT_H #include "tqmotifstyle.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "tqwidget.h" #endif // QT_H diff --git a/src/styles/tqstylefactory.cpp b/src/styles/tqstylefactory.cpp index f31c8e0f0..7a5706c64 100644 --- a/src/styles/tqstylefactory.cpp +++ b/src/styles/tqstylefactory.cpp @@ -62,7 +62,7 @@ #endif #if !defined( TQT_NO_STYLE_MAC ) && defined( TQ_WS_MAC ) -TQString p2qstring(const unsigned char *c); //qglobal.cpp +TQString p2qstring(const unsigned char *c); //tqglobal.cpp #include "qt_mac.h" #include "qmacstyle_mac.h" #endif diff --git a/src/styles/tqstyleplugin.h b/src/styles/tqstyleplugin.h index 13d83c453..e7e703d30 100644 --- a/src/styles/tqstyleplugin.h +++ b/src/styles/tqstyleplugin.h @@ -42,7 +42,7 @@ #define TQSTYLEPLUGIN_H #ifndef QT_H -#include "ntqgplugin.h" +#include "tqgplugin.h" #include "tqstringlist.h" #endif // QT_H diff --git a/src/table/tqtable.cpp b/src/table/tqtable.cpp index 220d9af7c..002fcc502 100644 --- a/src/table/tqtable.cpp +++ b/src/table/tqtable.cpp @@ -38,7 +38,7 @@ ** **********************************************************************/ -#include "ntqglobal.h" +#include "tqglobal.h" #if defined(Q_CC_BOR) // needed for qsort() because of a std namespace problem on Borland #include "qplatformdefs.h" diff --git a/src/table/tqtable.h b/src/table/tqtable.h index f952a4d78..51393ae76 100644 --- a/src/table/tqtable.h +++ b/src/table/tqtable.h @@ -48,7 +48,7 @@ #include "tqheader.h" #include "tqmemarray.h" #include "tqptrlist.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "ntqshared.h" #include "tqintdict.h" #include "tqstringlist.h" diff --git a/src/tools/ntqgarray.h b/src/tools/ntqgarray.h deleted file mode 100644 index 4d239dd66..000000000 --- a/src/tools/ntqgarray.h +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** Definition of TQGArray class -** -** Created : 930906 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQGARRAY_H -#define TQGARRAY_H - -#ifndef QT_H -#include "ntqshared.h" -#endif // QT_H - - -class TQ_EXPORT TQGArray // generic array -{ -friend class TQBuffer; -public: - // do not use this, even though this is public - // ### make protected or private in TQt 4.0 beta? - struct array_data : public TQShared { // shared array - array_data():data(0),len(0) -#ifdef QT_QGARRAY_SPEED_OPTIM - ,maxl(0) -#endif - {} - char *data; // actual array data - uint len; -#ifdef QT_QGARRAY_SPEED_OPTIM - uint maxl; -#endif - }; - TQGArray(); - enum Optimization { MemOptim, SpeedOptim }; -protected: - TQGArray( int, int ); // dummy; does not alloc - TQGArray( int size ); // allocate 'size' bytes - TQGArray( const TQGArray &a ); // shallow copy - virtual ~TQGArray(); - - TQGArray &operator=( const TQGArray &a ) { return assign( a ); } - - virtual void detach() { duplicate(*this); } - - // ### TQt 4.0: maybe provide two versions of data(), at(), etc. - char *data() const { return shd->data; } - uint nrefs() const { return shd->count; } - uint size() const { return shd->len; } - bool isEqual( const TQGArray &a ) const; - - bool resize( uint newsize, Optimization optim ); - bool resize( uint newsize ); - - bool fill( const char *d, int len, uint sz ); - - TQGArray &assign( const TQGArray &a ); - TQGArray &assign( const char *d, uint len ); - TQGArray &duplicate( const TQGArray &a ); - TQGArray &duplicate( const char *d, uint len ); - void store( const char *d, uint len ); - - array_data *sharedBlock() const { return shd; } - void setSharedBlock( array_data *p ) { shd=(array_data*)p; } - - TQGArray &setRawData( const char *d, uint len ); - void resetRawData( const char *d, uint len ); - - int find( const char *d, uint index, uint sz ) const; - int contains( const char *d, uint sz ) const; - - void sort( uint sz ); - int bsearch( const char *d, uint sz ) const; - - char *at( uint index ) const; - - bool setExpand( uint index, const char *d, uint sz ); - -protected: - virtual array_data *newData(); - virtual void deleteData( array_data *p ); - -private: - static void msg_index( uint ); - array_data *shd; -}; - - -inline char *TQGArray::at( uint index ) const -{ -#if defined(QT_CHECK_RANGE) - if ( index >= size() ) { - msg_index( index ); - index = 0; - } -#endif - return &shd->data[index]; -} - - -#endif // TQGARRAY_H diff --git a/src/tools/ntqgcache.h b/src/tools/ntqgcache.h deleted file mode 100644 index 9082af762..000000000 --- a/src/tools/ntqgcache.h +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** -** -** Definition of TQGCache and TQGCacheIterator classes -** -** Created : 950208 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQGCACHE_H -#define TQGCACHE_H - -#ifndef QT_H -#include "tqptrcollection.h" -#include "ntqglist.h" -#include "ntqgdict.h" -#endif // QT_H - - -class TQCList; // internal classes -class TQCListIt; -class TQCDict; - - -class TQ_EXPORT TQGCache : public TQPtrCollection // generic LRU cache -{ -friend class TQGCacheIterator; -protected: - enum KeyType { StringKey, AsciiKey, IntKey, PtrKey }; - // identical to TQGDict's, but PtrKey is not used at the moment - - TQGCache( int maxCost, uint size, KeyType kt, bool caseSensitive, - bool copyKeys ); - TQGCache( const TQGCache & ); // not allowed, calls fatal() - ~TQGCache(); - TQGCache &operator=( const TQGCache & ); // not allowed, calls fatal() - - uint count() const; - uint size() const; - int maxCost() const { return mCost; } - int totalCost() const { return tCost; } - void setMaxCost( int maxCost ); - void clear(); - - bool insert_string( const TQString &key, TQPtrCollection::Item, - int cost, int priority ); - bool insert_other( const char *key, TQPtrCollection::Item, - int cost, int priority ); - bool remove_string( const TQString &key ); - bool remove_other( const char *key ); - TQPtrCollection::Item take_string( const TQString &key ); - TQPtrCollection::Item take_other( const char *key ); - - TQPtrCollection::Item find_string( const TQString &key, bool ref=TRUE ) const; - TQPtrCollection::Item find_other( const char *key, bool ref=TRUE ) const; - - void statistics() const; - -private: - bool makeRoomFor( int cost, int priority = -1 ); - KeyType keytype; - TQCList *lruList; - TQCDict *dict; - int mCost; - int tCost; - bool copyk; -}; - - -class TQ_EXPORT TQGCacheIterator // generic cache iterator -{ -protected: - TQGCacheIterator( const TQGCache & ); - TQGCacheIterator( const TQGCacheIterator & ); - ~TQGCacheIterator(); - TQGCacheIterator &operator=( const TQGCacheIterator & ); - - uint count() const; - bool atFirst() const; - bool atLast() const; - TQPtrCollection::Item toFirst(); - TQPtrCollection::Item toLast(); - - TQPtrCollection::Item get() const; - TQString getKeyString() const; - const char *getKeyAscii() const; - long getKeyInt() const; - - TQPtrCollection::Item operator()(); - TQPtrCollection::Item operator++(); - TQPtrCollection::Item operator+=( uint ); - TQPtrCollection::Item operator--(); - TQPtrCollection::Item operator-=( uint ); - -protected: - TQCListIt *it; // iterator on cache list -}; - - -#endif // TQGCACHE_H diff --git a/src/tools/ntqgdict.h b/src/tools/ntqgdict.h deleted file mode 100644 index 9a941ecb7..000000000 --- a/src/tools/ntqgdict.h +++ /dev/null @@ -1,225 +0,0 @@ -/**************************************************************************** -** -** Definition of TQGDict and TQGDictIterator classes -** -** Created : 920529 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQGDICT_H -#define TQGDICT_H - -#ifndef QT_H -#include "tqptrcollection.h" -#include "tqstring.h" -#endif // QT_H - -class TQGDictIterator; -class TQGDItList; - - -class TQBaseBucket // internal dict node -{ -public: - TQPtrCollection::Item getData() { return data; } - TQPtrCollection::Item setData( TQPtrCollection::Item d ) { return data = d; } - TQBaseBucket *getNext() { return next; } - void setNext( TQBaseBucket *n) { next = n; } -protected: - TQBaseBucket( TQPtrCollection::Item d, TQBaseBucket *n ) : data(d), next(n) {} - TQPtrCollection::Item data; - TQBaseBucket *next; -}; - -class TQStringBucket : public TQBaseBucket -{ -public: - TQStringBucket( const TQString &k, TQPtrCollection::Item d, TQBaseBucket *n ) - : TQBaseBucket(d,n), key(k) {} - const TQString &getKey() const { return key; } -private: - TQString key; -}; - -class TQAsciiBucket : public TQBaseBucket -{ -public: - TQAsciiBucket( const char *k, TQPtrCollection::Item d, TQBaseBucket *n ) - : TQBaseBucket(d,n), key(k) {} - const char *getKey() const { return key; } -private: - const char *key; -}; - -class TQIntBucket : public TQBaseBucket -{ -public: - TQIntBucket( long k, TQPtrCollection::Item d, TQBaseBucket *n ) - : TQBaseBucket(d,n), key(k) {} - long getKey() const { return key; } -private: - long key; -}; - -class TQPtrBucket : public TQBaseBucket -{ -public: - TQPtrBucket( void *k, TQPtrCollection::Item d, TQBaseBucket *n ) - : TQBaseBucket(d,n), key(k) {} - void *getKey() const { return key; } -private: - void *key; -}; - - -class TQ_EXPORT TQGDict : public TQPtrCollection // generic dictionary class -{ -public: - uint count() const { return numItems; } - uint size() const { return vlen; } - TQPtrCollection::Item look_string( const TQString& key, TQPtrCollection::Item, - int ); - TQPtrCollection::Item look_ascii( const char *key, TQPtrCollection::Item, int ); - TQPtrCollection::Item look_int( long key, TQPtrCollection::Item, int ); - TQPtrCollection::Item look_ptr( void *key, TQPtrCollection::Item, int ); -#ifndef TQT_NO_DATASTREAM - TQDataStream &read( TQDataStream & ); - TQDataStream &write( TQDataStream & ) const; -#endif -protected: - enum KeyType { StringKey, AsciiKey, IntKey, PtrKey }; - - TQGDict( uint len, KeyType kt, bool cs, bool ck ); - TQGDict( const TQGDict & ); - ~TQGDict(); - - TQGDict &operator=( const TQGDict & ); - - bool remove_string( const TQString &key, TQPtrCollection::Item item=0 ); - bool remove_ascii( const char *key, TQPtrCollection::Item item=0 ); - bool remove_int( long key, TQPtrCollection::Item item=0 ); - bool remove_ptr( void *key, TQPtrCollection::Item item=0 ); - TQPtrCollection::Item take_string( const TQString &key ); - TQPtrCollection::Item take_ascii( const char *key ); - TQPtrCollection::Item take_int( long key ); - TQPtrCollection::Item take_ptr( void *key ); - - void clear(); - void resize( uint ); - - int hashKeyString( const TQString & ); - int hashKeyAscii( const char * ); - - void statistics() const; - -#ifndef TQT_NO_DATASTREAM - virtual TQDataStream &read( TQDataStream &, TQPtrCollection::Item & ); - virtual TQDataStream &write( TQDataStream &, TQPtrCollection::Item ) const; -#endif -private: - TQBaseBucket **vec; - uint vlen; - uint numItems; - uint keytype : 2; - uint cases : 1; - uint copyk : 1; - TQGDItList *iterators; - void unlink_common( int, TQBaseBucket *, TQBaseBucket * ); - TQStringBucket *unlink_string( const TQString &, - TQPtrCollection::Item item = 0 ); - TQAsciiBucket *unlink_ascii( const char *, TQPtrCollection::Item item = 0 ); - TQIntBucket *unlink_int( long, TQPtrCollection::Item item = 0 ); - TQPtrBucket *unlink_ptr( void *, TQPtrCollection::Item item = 0 ); - void init( uint, KeyType, bool, bool ); - friend class TQGDictIterator; -}; - - -class TQ_EXPORT TQGDictIterator // generic dictionary iterator -{ -friend class TQGDict; -public: - TQGDictIterator( const TQGDict & ); - TQGDictIterator( const TQGDictIterator & ); - TQGDictIterator &operator=( const TQGDictIterator & ); - ~TQGDictIterator(); - - TQPtrCollection::Item toFirst(); - - TQPtrCollection::Item get() const; - TQString getKeyString() const; - const char *getKeyAscii() const; - long getKeyInt() const; - void *getKeyPtr() const; - - TQPtrCollection::Item operator()(); - TQPtrCollection::Item operator++(); - TQPtrCollection::Item operator+=(uint); - -protected: - TQGDict *dict; - -private: - TQBaseBucket *curNode; - uint curIndex; -}; - -inline TQPtrCollection::Item TQGDictIterator::get() const -{ - return curNode ? curNode->getData() : 0; -} - -inline TQString TQGDictIterator::getKeyString() const -{ - return curNode ? ((TQStringBucket*)curNode)->getKey() : TQString::null; -} - -inline const char *TQGDictIterator::getKeyAscii() const -{ - return curNode ? ((TQAsciiBucket*)curNode)->getKey() : 0; -} - -inline long TQGDictIterator::getKeyInt() const -{ - return curNode ? ((TQIntBucket*)curNode)->getKey() : 0; -} - -inline void *TQGDictIterator::getKeyPtr() const -{ - return curNode ? ((TQPtrBucket*)curNode)->getKey() : 0; -} - - -#endif // TQGDICT_H diff --git a/src/tools/ntqgeneric.h b/src/tools/ntqgeneric.h deleted file mode 100644 index b82f18849..000000000 --- a/src/tools/ntqgeneric.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** -** -** Macros for pasting tokens; utilized by our generic classes -** -** Created : 920529 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQGENERIC_H -#define TQGENERIC_H - -#error "do not include ntqgeneric.h any more" - -#endif // TQGENERIC_H diff --git a/src/tools/ntqglist.h b/src/tools/ntqglist.h deleted file mode 100644 index 95a5786d3..000000000 --- a/src/tools/ntqglist.h +++ /dev/null @@ -1,279 +0,0 @@ -/**************************************************************************** -** -** Definition of TQGList and TQGListIterator classes -** -** Created : 920624 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQGLIST_H -#define TQGLIST_H - -#ifndef QT_H -#include "tqptrcollection.h" -#endif // QT_H - -class TQ_EXPORT TQLNode -{ -friend class TQGList; -friend class TQGListIterator; -friend class TQGListStdIterator; -public: - TQPtrCollection::Item getData() { return data; } -private: - TQPtrCollection::Item data; - TQLNode *prev; - TQLNode *next; - TQLNode( TQPtrCollection::Item d ) { data = d; } -}; - -class TQMutex; -class TQGListPrivate; -class TQGListIteratorList; // internal helper class - -class TQ_EXPORT TQGList : public TQPtrCollection // doubly linked generic list -{ -friend class TQGListIterator; -friend class TQGListIteratorList; -friend class TQGVector; // needed by TQGVector::toList -public: - uint count() const; // return number of nodes - -#ifndef TQT_NO_DATASTREAM - TQDataStream &read( TQDataStream & ); // read list from stream - TQDataStream &write( TQDataStream & ) const; // write list to stream -#endif -protected: - TQGList(); // create empty list - TQGList( const TQGList & ); // make copy of other list - virtual ~TQGList(); - - TQGList &operator=( const TQGList & ); // assign from other list - bool operator==( const TQGList& ) const; - - void inSort( TQPtrCollection::Item ); // add item sorted in list - void append( TQPtrCollection::Item ); // add item at end of list - bool insertAt( uint index, TQPtrCollection::Item ); // add item at i'th position - void relinkNode( TQLNode * ); // relink as first item - bool removeNode( TQLNode * ); // remove node - bool remove( TQPtrCollection::Item = 0 ); // remove item (0=current) - bool removeRef( TQPtrCollection::Item = 0 ); // remove item (0=current) - bool removeFirst(); // remove first item - bool removeLast(); // remove last item - bool removeAt( uint ); // remove item at i'th position - bool replaceAt( uint, TQPtrCollection::Item ); // replace item at position i with item - TQPtrCollection::Item takeNode( TQLNode * ); // take out node - TQPtrCollection::Item take(); // take out current item - TQPtrCollection::Item takeAt( uint index ); // take out item at i'th pos - TQPtrCollection::Item takeFirst(); // take out first item - TQPtrCollection::Item takeLast(); // take out last item - - void sort(); // sort all items; - void clear(); // remove all items - - int findRef( TQPtrCollection::Item, bool = TRUE ); // find exact item in list - int find( TQPtrCollection::Item, bool = TRUE ); // find equal item in list - - uint containsRef( TQPtrCollection::Item ) const; // get number of exact matches - uint contains( TQPtrCollection::Item ) const; // get number of equal matches - - TQPtrCollection::Item at( uint index ); // access item at i'th pos - int at() const; // get current index - TQLNode *currentNode() const; // get current node - - TQPtrCollection::Item get() const; // get current item - - TQPtrCollection::Item cfirst() const; // get ptr to first list item - TQPtrCollection::Item clast() const; // get ptr to last list item - TQPtrCollection::Item first(); // set first item in list curr - TQPtrCollection::Item last(); // set last item in list curr - TQPtrCollection::Item next(); // set next item in list curr - TQPtrCollection::Item prev(); // set prev item in list curr - - void toVector( TQGVector * ) const; // put items in vector - - virtual int compareItems( TQPtrCollection::Item, TQPtrCollection::Item ); - -#ifndef TQT_NO_DATASTREAM - virtual TQDataStream &read( TQDataStream &, TQPtrCollection::Item & ); - virtual TQDataStream &write( TQDataStream &, TQPtrCollection::Item ) const; -#endif - - TQLNode* begin() const { return firstNode; } - TQLNode* end() const { return 0; } - TQLNode* erase( TQLNode* it ); - -private: - void prepend( TQPtrCollection::Item ); // add item at start of list - - void heapSortPushDown( TQPtrCollection::Item* heap, int first, int last ); - - TQLNode *firstNode; // first node - TQLNode *lastNode; // last node - TQLNode *curNode; // current node - int curIndex; // current index - uint numNodes; // number of nodes - TQGListIteratorList *iterators; // list of iterators - - TQLNode *locate( uint ); // get node at i'th pos - TQLNode *unlink(); // unlink node - -#if defined(TQT_THREAD_SUPPORT) -// TQMutex* mutex; -#endif - -// TQGListPrivate* d; -}; - - -inline uint TQGList::count() const -{ - return numNodes; -} - -inline bool TQGList::removeFirst() -{ - first(); - return remove(); -} - -inline bool TQGList::removeLast() -{ - last(); - return remove(); -} - -inline int TQGList::at() const -{ - return curIndex; -} - -inline TQPtrCollection::Item TQGList::at( uint index ) -{ - TQLNode *n = locate( index ); - return n ? n->data : 0; -} - -inline TQLNode *TQGList::currentNode() const -{ - return curNode; -} - -inline TQPtrCollection::Item TQGList::get() const -{ - return curNode ? curNode->data : 0; -} - -inline TQPtrCollection::Item TQGList::cfirst() const -{ - return firstNode ? firstNode->data : 0; -} - -inline TQPtrCollection::Item TQGList::clast() const -{ - return lastNode ? lastNode->data : 0; -} - - -/***************************************************************************** - TQGList stream functions - *****************************************************************************/ - -#ifndef TQT_NO_DATASTREAM -TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQGList & ); -TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQGList & ); -#endif - -/***************************************************************************** - TQGListIterator class - *****************************************************************************/ - -class TQ_EXPORT TQGListIterator // TQGList iterator -{ -friend class TQGList; -friend class TQGListIteratorList; -protected: - TQGListIterator( const TQGList & ); - TQGListIterator( const TQGListIterator & ); - TQGListIterator &operator=( const TQGListIterator & ); - ~TQGListIterator(); - - bool atFirst() const; // test if at first item - bool atLast() const; // test if at last item - TQPtrCollection::Item toFirst(); // move to first item - TQPtrCollection::Item toLast(); // move to last item - - TQPtrCollection::Item get() const; // get current item - TQPtrCollection::Item operator()(); // get current and move to next - TQPtrCollection::Item operator++(); // move to next item (prefix) - TQPtrCollection::Item operator+=(uint); // move n positions forward - TQPtrCollection::Item operator--(); // move to prev item (prefix) - TQPtrCollection::Item operator-=(uint); // move n positions backward - -protected: - TQGList *list; // reference to list - -private: - TQLNode *curNode; // current node in list -}; - - -inline bool TQGListIterator::atFirst() const -{ - return curNode == list->firstNode; -} - -inline bool TQGListIterator::atLast() const -{ - return curNode == list->lastNode; -} - -inline TQPtrCollection::Item TQGListIterator::get() const -{ - return curNode ? curNode->data : 0; -} - -class TQ_EXPORT TQGListStdIterator -{ -public: - inline TQGListStdIterator( TQLNode* n ) : node( n ){} - inline operator TQLNode* () { return node; } -protected: - inline TQLNode *next() { return node->next; } - TQLNode *node; -}; - - -#endif // TQGLIST_H diff --git a/src/tools/ntqglobal.h b/src/tools/ntqglobal.h deleted file mode 100644 index 64115edf3..000000000 --- a/src/tools/ntqglobal.h +++ /dev/null @@ -1,1085 +0,0 @@ -/**************************************************************************** -** -** Global type declarations and definitions -** -** Created : 920529 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQGLOBAL_H -#define TQGLOBAL_H - -#define TQT_VERSION_STR "3.5.0" -/* - TQT_VERSION is (major << 16) + (minor << 8) + patch. - */ -#define TQT_VERSION 0x030500 - -/* - The operating system, must be one of: (Q_OS_x) - - MACX - Mac OS X - MAC9 - Mac OS 9 - DARWIN - Darwin OS (Without Mac OS X) - MSDOS - MS-DOS and Windows - OS2 - OS/2 - OS2EMX - XFree86 on OS/2 (not PM) - WIN32 - Win32 (Windows 95/98/ME and Windows NT/2000/XP) - CYGWIN - Cygwin - SOLARIS - Sun Solaris - HPUX - HP-UX - ULTRIX - DEC Ultrix - LINUX - Linux - FREEBSD - FreeBSD - NETBSD - NetBSD - OPENBSD - OpenBSD - BSDI - BSD/OS - IRIX - SGI Irix - OSF - HP Tru64 UNIX - SCO - SCO OpenServer 5 - UNIXWARE - UnixWare 7, Open UNIX 8 - AIX - AIX - HURD - GNU Hurd - DGUX - DG/UX - RELIANT - Reliant UNIX - DYNIX - DYNIX/ptx - TQNX - TQNX - TQNX6 - TQNX RTP 6.1 - LYNX - LynxOS - BSD4 - Any BSD 4.4 system - UNIX - Any UNIX BSD/SYSV system -*/ - -#if defined(__DARWIN_X11__) -# define Q_OS_DARWIN -#elif defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__)) -# define Q_OS_MACX -#elif defined(__MACOSX__) -# define Q_OS_MACX -#elif defined(macintosh) -# define Q_OS_MAC9 -#elif defined(__CYGWIN__) -# define Q_OS_CYGWIN -#elif defined(MSDOS) || defined(_MSDOS) -# define Q_OS_MSDOS -#elif defined(__OS2__) -# if defined(__EMX__) -# define Q_OS_OS2EMX -# else -# define Q_OS_OS2 -# endif -#elif !defined(SAG_COM) && (defined(WIN64) || defined(_WIN64) || defined(__WIN64__)) -# define Q_OS_WIN32 -# define Q_OS_WIN64 -#elif !defined(SAG_COM) && (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)) -# define Q_OS_WIN32 -#elif defined(__MWERKS__) && defined(__INTEL__) -# define Q_OS_WIN32 -#elif defined(__sun) || defined(sun) -# define Q_OS_SOLARIS -#elif defined(hpux) || defined(__hpux) -# define Q_OS_HPUX -#elif defined(__ultrix) || defined(ultrix) -# define Q_OS_ULTRIX -#elif defined(sinix) -# define Q_OS_RELIANT -#elif defined(__GNU__) -# define Q_OS_HURD -#elif defined(__linux__) || defined(__linux) || defined(__GNU__) || defined(__GLIBC__) -# define Q_OS_LINUX -#elif defined(__FreeBSD__) || defined(__DragonFly__) -# define Q_OS_FREEBSD -# define Q_OS_BSD4 -#elif defined(__NetBSD__) -# define Q_OS_NETBSD -# define Q_OS_BSD4 -#elif defined(__OpenBSD__) -# define Q_OS_OPENBSD -# define Q_OS_BSD4 -#elif defined(__bsdi__) -# define Q_OS_BSDI -# define Q_OS_BSD4 -#elif defined(__sgi) -# define Q_OS_IRIX -#elif defined(__osf__) -# define Q_OS_OSF -#elif defined(_AIX) -# define Q_OS_AIX -#elif defined(__Lynx__) -# define Q_OS_LYNX -#elif defined(__DGUX__) -# define Q_OS_DGUX -#elif defined(__QNXNTO__) -# define Q_OS_QNX6 -#elif defined(__QNX__) -# define Q_OS_QNX -#elif defined(_SEQUENT_) -# define Q_OS_DYNIX -#elif defined(_SCO_DS) /* SCO OpenServer 5 + GCC */ -# define Q_OS_SCO -#elif defined(__USLC__) /* all SCO platforms + UDK or OUDK */ -# define Q_OS_UNIXWARE -# define Q_OS_UNIXWARE7 -#elif defined(__svr4__) && defined(i386) /* Open UNIX 8 + GCC */ -# define Q_OS_UNIXWARE -# define Q_OS_UNIXWARE7 -#elif defined(__MAKEDEPEND__) -#else -# error "TQt has not been ported to this OS - talk to qt-bugs@trolltech.com" -#endif - -#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64) -# define Q_OS_WIN -#endif - -#if defined(Q_OS_MAC9) || defined(Q_OS_MACX) -# define Q_OS_MAC -#endif - -#if defined(Q_OS_MAC9) || defined(Q_OS_MSDOS) || defined(Q_OS_OS2) || defined(Q_OS_WIN) -# undef Q_OS_UNIX -#elif !defined(Q_OS_UNIX) -# define Q_OS_UNIX -#endif - -#if defined(Q_OS_MACX) -# ifdef MAC_OS_X_VERSION_MIN_REQUIRED -# undef MAC_OS_X_VERSION_MIN_REQUIRED -# endif -# define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_2 -# include -# if !defined(MAC_OS_X_VERSION_10_3) -# define MAC_OS_X_VERSION_10_3 MAC_OS_X_VERSION_10_2 + 1 -# endif -# if !defined(MAC_OS_X_VERSION_10_4) -# define MAC_OS_X_VERSION_10_4 MAC_OS_X_VERSION_10_3 + 1 -# endif -# if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) -# error "This version of Mac OS X is unsupported" -# endif -#endif - - -/* - The compiler, must be one of: (Q_CC_x) - - SYM - Symantec C++ for both PC and Macintosh - MPW - MPW C++ - MWERKS - Metrowerks CodeWarrior - MSVC - Microsoft Visual C/C++, Intel C++ for Windows - BOR - Borland/Turbo C++ - WAT - Watcom C++ - GNU - GNU C++ - COMEAU - Comeau C++ - EDG - Edison Design Group C++ - OC - CenterLine C++ - SUN - Sun WorkShop, Forte Developer, or Sun ONE Studio C++ - MIPS - MIPSpro C++ - DEC - DEC C++ - HP - HPUX C++ - HPACC - HPUX ANSI C++ - USLC - SCO OUDK, UDK, and UnixWare 2.X C++ - CDS - Reliant C++ - KAI - KAI C++ - INTEL - Intel C++ for Linux, Intel C++ for Windows - HIGHC - MetaWare High C/C++ - PGI - Portland Group C++ - GHS - Green Hills Optimizing C++ Compilers - - Should be sorted most to least authoritative. -*/ - -/* Symantec C++ is now Digital Mars */ -#if defined(__DMC__) || defined(__SC__) -# define Q_CC_SYM -/* "explicit" semantics implemented in 8.1e but keyword recognized since 7.5 */ -# if defined(__SC__) && __SC__ < 0x750 -# define Q_NO_EXPLICIT_KEYWORD -# endif -# define Q_NO_USING_KEYWORD -# if !defined(_CPPUNWIND) -# define Q_NO_EXCEPTIONS -# endif - -#elif defined(applec) -# define Q_CC_MPW -# define Q_NO_BOOL_TYPE -# define Q_NO_EXPLICIT_KEYWORD -# define Q_NO_USING_KEYWORD - -#elif defined(__MWERKS__) -# define Q_CC_MWERKS -/* "explicit" recognized since 4.0d1 */ -# define TQMAC_PASCAL pascal - -#elif defined(_MSC_VER) -# define Q_CC_MSVC -/* proper support of bool for _MSC_VER >= 1100 */ -# define Q_CANNOT_DELETE_CONSTANT -# define TQ_INLINE_TEMPLATES inline -/* Visual C++.Net issues for _MSC_VER >= 1300 */ -# if _MSC_VER >= 1300 -# define Q_CC_MSVC_NET -# if _MSC_VER < 1310 || (defined(Q_OS_WIN64) && defined(_M_IA64)) -# define TQ_TYPENAME -# endif -# endif -/* Intel C++ disguising as Visual C++: the `using' keyword avoids warnings */ -# if defined(__INTEL_COMPILER) -# define Q_CC_INTEL -# if !defined(__EXCEPTIONS) -# define Q_NO_EXCEPTIONS -# endif -# else -# define Q_NO_USING_KEYWORD /* ### check "using" status */ -# endif - -#elif defined(__BORLANDC__) || defined(__TURBOC__) -# define Q_CC_BOR -# if __BORLANDC__ < 0x502 -# define Q_NO_BOOL_TYPE -# define Q_NO_EXPLICIT_KEYWORD -# endif -# define Q_NO_USING_KEYWORD /* ### check "using" status */ - -#elif defined(__WATCOMC__) -# define Q_CC_WAT -# if defined(Q_OS_QNX4) -/* compiler flags */ -# define TQ_TYPENAME -# define Q_NO_BOOL_TYPE -# define Q_CANNOT_DELETE_CONSTANT -# define mutable -/* ??? */ -# define Q_BROKEN_TEMPLATE_SPECIALIZATION -/* no template classes in TQVariant */ -# define TQT_NO_TEMPLATE_VARIANT -/* Wcc does not fill in functions needed by valuelists, maps, and - valuestacks implicitly */ -# define TQ_FULL_TEMPLATE_INSTANTIATION -/* can we just compare the structures? */ -# define TQ_FULL_TEMPLATE_INSTANTIATION_MEMCMP -/* these are not useful to our customers */ -# define TQT_NO_SQL -# endif - -#elif defined(__GNUC__) -# define Q_CC_GNU -# define Q_C_CALLBACKS -# if __GNUC__ == 2 && __GNUC_MINOR__ <= 7 -# define TQ_FULL_TEMPLATE_INSTANTIATION -# endif -/* GCC 2.95 knows "using" but does not support it correctly */ -# if __GNUC__ == 2 && __GNUC_MINOR__ <= 95 -# define Q_NO_USING_KEYWORD -# endif -/* GCC 3.1 and GCC 3.2 wrongly define _SB_CTYPE_MACROS on HP-UX */ -# if defined(Q_OS_HPUX) && __GNUC__ == 3 && __GNUC_MINOR__ >= 1 -# define Q_WRONG_SB_CTYPE_MACROS -# endif - -/* ARM gcc pads structs to 32 bits, even when they contain a single - char, or short. We tell gcc to pack TQChars to 16 bits, to avoid - TQString bloat. However, gcc 3.4 doesn't allow us to create references to - members of a packed struct. (Pointers are OK, because then you - supposedly know what you are doing.) */ -# if (defined(__arm__) || defined(__ARMEL__)) && !defined(__ARM_EABI__) && !defined(QT_MOC_CPP) -# define TQ_PACKED __attribute__ ((packed)) -# if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3 -# define Q_NO_PACKED_REFERENCE -# endif -# endif -# if !defined(__EXCEPTIONS) -# define Q_NO_EXCEPTIONS -# endif - -/* IBM compiler versions are a bit messy. There are actually two products: - the C product, and the C++ product. The C++ compiler is always packaged - with the latest version of the C compiler. Version numbers do not always - match. This little table (I'm not sure it's accurate) should be helpful: - - C++ product C product - - C Set 3.1 C Compiler 3.0 - ... ... - C++ Compiler 3.6.6 C Compiler 4.3 - ... ... - Visual Age C++ 4.0 ... - ... ... - Visual Age C++ 5.0 C Compiler 5.0 - ... ... - Visual Age C++ 6.0 C Compiler 6.0 - - Now: - __xlC__ is the version of the C compiler in hexadecimal notation - is only an approximation of the C++ compiler version - __IBMCPP__ is the version of the C++ compiler in decimal notation - but it is not defined on older compilers like C Set 3.1 */ -#elif defined(__xlC__) -# define Q_CC_XLC -# define TQ_FULL_TEMPLATE_INSTANTIATION -# if __xlC__ < 0x400 -# define Q_NO_BOOL_TYPE -# define Q_NO_EXPLICIT_KEYWORD -# define Q_NO_USING_KEYWORD -# define TQ_TYPENAME -# define TQ_INLINE_TEMPLATES inline -# define Q_BROKEN_TEMPLATE_SPECIALIZATION -# define Q_CANNOT_DELETE_CONSTANT -# endif - -/* Older versions of DEC C++ do not define __EDG__ or __EDG - observed - on DEC C++ V5.5-004. New versions do define __EDG__ - observed on - Compaq C++ V6.3-002. - This compiler is different enough from other EDG compilers to handle - it separately anyway. */ -#elif defined(__DECCXX) || defined(__DECC) -# define Q_CC_DEC -/* Compaq C++ V6 compilers are EDG-based but I'm not sure about older - DEC C++ V5 compilers. */ -# if defined(__EDG__) -# define Q_CC_EDG -# endif -/* Compaq have disabled EDG's _BOOL macro and use _BOOL_EXISTS instead - - observed on Compaq C++ V6.3-002. - In any case versions prior to Compaq C++ V6.0-005 do not have bool. */ -# if !defined(_BOOL_EXISTS) -# define Q_NO_BOOL_TYPE -# endif -/* Spurious (?) error messages observed on Compaq C++ V6.5-014. */ -# define Q_NO_USING_KEYWORD -/* Apply to all versions prior to Compaq C++ V6.0-000 - observed on - DEC C++ V5.5-004. */ -# if __DECCXX_VER < 60060000 -# define TQ_TYPENAME -# define Q_BROKEN_TEMPLATE_SPECIALIZATION -# define Q_CANNOT_DELETE_CONSTANT -# endif -/* avoid undefined symbol problems with out-of-line template members */ -# define TQ_INLINE_TEMPLATES inline - -/* Compilers with EDG front end are similar. To detect them we test: - __EDG documented by SGI, observed on MIPSpro 7.3.1.1 and KAI C++ 4.0b - __EDG__ documented in EDG online docs, observed on Compaq C++ V6.3-002 */ -#elif defined(__EDG) || defined(__EDG__) -# define Q_CC_EDG -/* From the EDG documentation (does not seem to apply to Compaq C++): - _BOOL - Defined in C++ mode when bool is a keyword. The name of this - predefined macro is specified by a configuration flag. _BOOL - is the default. - __BOOL_DEFINED - Defined in Microsoft C++ mode when bool is a keyword. */ -# if !defined(_BOOL) && !defined(__BOOL_DEFINED) -# define Q_NO_BOOL_TYPE -# endif - -/* The Comeau compiler is based on EDG and does define __EDG__ */ -# if defined(__COMO__) -# define Q_CC_COMEAU -# define Q_C_CALLBACKS - -/* The `using' keyword was introduced to avoid KAI C++ warnings - but it's now causing KAI C++ errors instead. The standard is - unclear about the use of this keyword, and in practice every - compiler is using its own set of rules. Forget it. */ -# elif defined(__KCC) -# define Q_CC_KAI -# if !defined(_EXCEPTIONS) -# define Q_NO_EXCEPTIONS -# endif -# define Q_NO_USING_KEYWORD - -/* Using the `using' keyword avoids Intel C++ for Linux warnings */ -# elif defined(__INTEL_COMPILER) -# define Q_CC_INTEL -# if !defined(__EXCEPTIONS) -# define Q_NO_EXCEPTIONS -# endif - -/* The Portland Group compiler is based on EDG and does define __EDG__ */ -# elif defined(__PGI) -# define Q_CC_PGI -# if !defined(__EXCEPTIONS) -# define Q_NO_EXCEPTIONS -# endif - -/* Never tested! */ -# elif defined(__ghs) -# define Q_CC_GHS - -/* The UnixWare 7 UDK compiler is based on EDG and does define __EDG__ */ -# elif defined(__USLC__) && defined(__SCO_VERSION__) -# define Q_CC_USLC -/* The latest UDK 7.1.1b does not need this, but previous versions do */ -# if !defined(__SCO_VERSION__) || (__SCO_VERSION__ < 302200010) -# define TQ_INLINE_TEMPLATES inline -# endif -# define Q_NO_USING_KEYWORD /* ### check "using" status */ - -/* Never tested! */ -# elif defined(CENTERLINE_CLPP) || defined(OBJECTCENTER) -# define Q_CC_OC -# define Q_NO_USING_KEYWORD - -/* CDS++ defines __EDG__ although this is not documented in the Reliant - documentation. It also follows conventions like _BOOL and this documented */ -# elif defined(sinix) -# define Q_CC_CDS -# define Q_NO_USING_KEYWORD -# if defined(__cplusplus) && (__cplusplus < 2) /* Cfront C++ mode */ -# define Q_NO_EXCEPTIONS -# endif - -/* The MIPSpro compiler in o32 mode is based on EDG but disables features - such as template specialization nevertheless */ -# elif defined(__sgi) -# define Q_CC_MIPS -# if defined(_MIPS_SIM) && (_MIPS_SIM == _ABIO32) /* o32 ABI */ -# define TQ_TYPENAME -# define Q_BROKEN_TEMPLATE_SPECIALIZATION -# define Q_NO_EXPLICIT_KEYWORD -# define TQ_INLINE_TEMPLATES inline -# elif defined(_COMPILER_VERSION) && (_COMPILER_VERSION < 730) /* 7.2 */ -# define TQ_TYPENAME -# define Q_BROKEN_TEMPLATE_SPECIALIZATION -# endif -# define Q_NO_USING_KEYWORD /* ### check "using" status */ -# if defined(_COMPILER_VERSION) && (_COMPILER_VERSION >= 740) -# pragma set woff 3624,3625, 3649 /* turn off some harmless warnings */ -# endif -# endif - -/* The older UnixWare 2.X compiler? */ -#elif defined(__USLC__) -# define Q_CC_USLC -# define TQ_TYPENAME -# define Q_NO_BOOL_TYPE -# define Q_NO_EXPLICIT_KEYWORD -# define Q_NO_USING_KEYWORD -# define TQ_INLINE_TEMPLATES inline - -/* Never tested! */ -#elif defined(__HIGHC__) -# define Q_CC_HIGHC - -#elif defined(__SUNPRO_CC) || defined(__SUNPRO_C) -# define Q_CC_SUN -/* 5.0 compiler or better - 'bool' is enabled by default but can be disabled using -features=nobool - in which case _BOOL is not defined - this is the default in 4.2 compatibility mode triggered by -compat=4 */ -# if __SUNPRO_CC >= 0x500 -# if !defined(_BOOL) -# define Q_NO_BOOL_TYPE -# endif -# if defined(__SUNPRO_CC_COMPAT) && (__SUNPRO_CC_COMPAT <= 4) -# define Q_NO_USING_KEYWORD -# endif -# define Q_C_CALLBACKS -/* 4.2 compiler or older */ -# else -# define Q_NO_BOOL_TYPE -# define Q_NO_EXPLICIT_KEYWORD -# define Q_NO_USING_KEYWORD -# endif - -/* CDS++ does not seem to define __EDG__ or __EDG according to Reliant - documentation but nevertheless uses EDG conventions like _BOOL */ -#elif defined(sinix) -# define Q_CC_EDG -# define Q_CC_CDS -# if !defined(_BOOL) -# define Q_NO_BOOL_TYPE -# endif -# define Q_BROKEN_TEMPLATE_SPECIALIZATION - -#elif defined(Q_OS_HPUX) -/* __HP_aCC was not defined in first aCC releases */ -# if defined(__HP_aCC) || __cplusplus >= 199707L -# define Q_CC_HPACC -# else -# define Q_CC_HP -# define Q_NO_BOOL_TYPE -# define TQ_FULL_TEMPLATE_INSTANTIATION -# define Q_BROKEN_TEMPLATE_SPECIALIZATION -# define Q_NO_EXPLICIT_KEYWORD -# endif -# define Q_NO_USING_KEYWORD /* ### check "using" status */ - -#else -# error "TQt has not been tested with this compiler - talk to qt-bugs@trolltech.com" -#endif - -#ifndef TQ_PACKED -# define TQ_PACKED -#endif - - -/* - The window system, must be one of: (TQ_WS_x) - - MACX - Mac OS X - MAC9 - Mac OS 9 - WIN32 - Windows - X11 - X Window System - PM - unsupported - WIN16 - unsupported -*/ - -#if defined(Q_OS_MAC9) -# define TQ_WS_MAC9 -#elif defined(Q_OS_MSDOS) -# define TQ_WS_WIN16 -# error "TQt requires Win32 and does not work with Windows 3.x" -#elif defined(_WIN32_X11_) -# define TQ_WS_X11 -#elif defined(Q_OS_WIN32) -# define TQ_WS_WIN32 -# if defined(Q_OS_WIN64) -# define TQ_WS_WIN64 -# endif -#elif defined(Q_OS_OS2) -# define TQ_WS_PM -# error "TQt does not work with OS/2 Presentation Manager or Workplace Shell" -#elif defined(Q_OS_UNIX) -# if defined(Q_OS_MACX) -# define TQ_WS_MACX -# else -# define TQ_WS_X11 -# endif -#endif -#if defined(Q_OS_MAC) && !defined(TQMAC_PASCAL) -# define TQMAC_PASCAL -#endif - -#if defined(TQ_WS_WIN16) || defined(TQ_WS_WIN32) -# define TQ_WS_WIN -#endif - -#if (defined(TQ_WS_MAC9) || defined(TQ_WS_MACX)) && !defined(TQ_WS_X11) -# define TQ_WS_MAC -#endif - - -/* - Some classes do not permit copies to be made of an object. - These classes contains a private copy constructor and operator= - to disable copying (the compiler gives an error message). - Undefine TQ_DISABLE_COPY to turn off this checking. -*/ - -#define TQ_DISABLE_COPY - -#if defined(__cplusplus) - - -// -// Useful type definitions for TQt -// - -#if defined(Q_NO_BOOL_TYPE) -#if defined(Q_CC_HP) -// bool is an unsupported reserved keyword in later versions -#define bool int -#else -typedef int bool; -#endif -#endif - -typedef unsigned char uchar; -typedef unsigned short ushort; -typedef unsigned uint; -typedef unsigned long ulong; -typedef char *pchar; -typedef uchar *puchar; -typedef const char *pcchar; - - -// -// Constant bool values -// - -#ifndef TRUE -const bool FALSE = 0; -const bool TRUE = !0; -#endif -#if defined(__WATCOMC__) -# if defined(Q_OS_QNX4) -const bool false = FALSE; -const bool true = TRUE; -# endif -#endif - -// -// Proper for-scoping -// ### turn on in 4.0 - -#if 0 && defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) -# define for if(0){}else for -#endif - -// -// Use the "explicit" keyword on platforms that support it. -// - -#if !defined(Q_NO_EXPLICIT_KEYWORD) -# define Q_EXPLICIT explicit -#else -# define Q_EXPLICIT -#endif - - -// -// Utility macros and inline functions -// - -#define TQMAX(a, b) ((b) < (a) ? (a) : (b)) -#define TQMIN(a, b) ((a) < (b) ? (a) : (b)) -#define TQABS(a) ((a) >= 0 ? (a) : -(a)) - -inline int tqRound( double d ) -{ - return d >= 0.0 ? int(d + 0.5) : int( d - ((int)d-1) + 0.5 ) + ((int)d-1); -} - - -// -// Size-dependent types (architechture-dependent byte order) -// - -typedef signed char TQ_INT8; // 8 bit signed -typedef unsigned char TQ_UINT8; // 8 bit unsigned -typedef short TQ_INT16; // 16 bit signed -typedef unsigned short TQ_UINT16; // 16 bit unsigned -typedef int TQ_INT32; // 32 bit signed -typedef unsigned int TQ_UINT32; // 32 bit unsigned -#if defined(Q_OS_WIN64) -typedef __int64 TQ_LONG; // word up to 64 bit signed -typedef unsigned __int64 TQ_ULONG; // word up to 64 bit unsigned -#else -typedef long TQ_LONG; // word up to 64 bit signed -typedef unsigned long TQ_ULONG; // word up to 64 bit unsigned -#endif -#if defined(Q_OS_WIN) && !defined(Q_CC_GNU) -# define TQ_INT64_C(c) c ## i64 // signed 64 bit constant -# define TQ_UINT64_C(c) c ## ui64 // unsigned 64 bit constant -typedef __int64 TQ_INT64; // 64 bit signed -typedef unsigned __int64 TQ_UINT64; // 64 bit unsigned -#else -# define TQ_INT64_C(c) c ## LL // signed 64 bit constant -# define TQ_UINT64_C(c) c ## ULL // unsigned 64 bit constant -typedef long long TQ_INT64; // 64 bit signed -typedef unsigned long long TQ_UINT64; // 64 bit unsigned -#endif -typedef TQ_INT64 TQ_LLONG; // signed long long -typedef TQ_UINT64 TQ_ULLONG; // unsigned long long - -#if defined(Q_OS_MACX) && !defined(QT_LARGEFILE_SUPPORT) -# define QT_LARGEFILE_SUPPORT 64 -#endif -#if defined(QT_LARGEFILE_SUPPORT) - typedef TQ_ULLONG TQtOffset; -#else - typedef TQ_ULONG TQtOffset; -#endif - - -// -// Data stream functions is provided by many classes (defined in tqdatastream.h) -// - -class TQCString; -class TQDataStream; -class TQString; - -// -// Feature subsetting -// -// Note that disabling some features will produce a libtqt that is not -// compatible with other libtqt builds. Such modifications are only -// supported on TQt/Embedded where reducing the library size is important -// and where the application-suite is often a fixed set. -// - -#if !defined(QT_MOC) -#if defined(TQCONFIG_LOCAL) -#include "qconfig-local.h" -#elif defined(TQCONFIG_MINIMAL) -#include "qconfig-minimal.h" -#elif defined(TQCONFIG_SMALL) -#include "qconfig-small.h" -#elif defined(TQCONFIG_MEDIUM) -#include "qconfig-medium.h" -#elif defined(TQCONFIG_LARGE) -#include "qconfig-large.h" -#else // everything... -#include "ntqconfig.h" -#endif -#endif - - -#ifndef TQT_BUILD_KEY -#define TQT_BUILD_KEY "unspecified" -#endif - -// prune to local config -#include "ntqmodules.h" -#ifndef TQT_MODULE_DIALOGS -# define TQT_NO_DIALOG -#endif -#ifndef TQT_MODULE_INPUTMETHOD -# define TQT_NO_IM -#endif -#ifndef TQT_MODULE_WORKSPACE -# define TQT_NO_WORKSPACE -#endif -#ifndef TQT_MODULE_NETWORK -#define TQT_NO_NETWORK -#endif -#ifndef TQT_MODULE_CANVAS -# define TQT_NO_CANVAS -#endif -#ifndef TQT_MODULE_TABLE -#define TQT_NO_TABLE -#endif -#ifndef TQT_MODULE_XML -# define TQT_NO_XML -#endif -#ifndef TQT_MODULE_OPENGL -# define TQT_NO_OPENGL -#endif -#if !defined(TQT_MODULE_SQL) -# define TQT_NO_SQL -#endif - -#if defined(TQ_WS_MAC9) -//No need for menu merging -# ifndef TQMAC_QMENUBAR_NO_MERGE -# define TQMAC_QMENUBAR_NO_MERGE -# endif -//Mac9 does not use quartz -# ifndef TQMAC_NO_QUARTZ -# define TQMAC_NO_QUARTZ -# endif -# ifndef TQMAC_QMENUBAR_NO_EVENT -# define TQMAC_QMENUBAR_NO_EVENT -# endif -#endif -#if defined(TQ_WS_MACX) //for no nobody uses quartz, just putting in first level hooks -# ifndef TQMAC_NO_QUARTZ -# define TQMAC_NO_QUARTZ -# endif -# ifndef TQMAC_QMENUBAR_NO_EVENT -# define TQMAC_QMENUBAR_NO_EVENT -# endif -#endif - -#ifndef QT_H -#include "ntqfeatures.h" -#endif /* QT_H */ - - -// -// Create TQt DLL if QT_DLL is defined (Windows only) -// or QT_SHARED is defined (Kylix only) -// - -#if defined(Q_OS_WIN) -# if defined(QT_NODLL) -# undef QT_MAKEDLL -# undef QT_DLL -# elif defined(QT_MAKEDLL) /* create a TQt DLL library */ -# if defined(QT_DLL) -# undef QT_DLL -# endif -# define TQ_EXPORT __declspec(dllexport) -# define Q_TEMPLATEDLL -# define Q_TEMPLATE_EXTERN -# undef TQ_DISABLE_COPY /* avoid unresolved externals */ -# elif defined(QT_DLL) /* use a TQt DLL library */ -# define TQ_EXPORT __declspec(dllimport) -# define Q_TEMPLATEDLL -# ifndef Q_TEMPLATE_EXTERN -# if defined(Q_CC_MSVC_NET) -# define Q_TEMPLATE_EXTERN extern -# else -# define Q_TEMPLATE_EXTERN -# endif -# endif -# undef TQ_DISABLE_COPY /* avoid unresolved externals */ -# endif -#elif defined(Q_OS_LINUX) && defined(Q_CC_BOR) -# if defined(QT_SHARED) /* create a TQt shared library */ -# define TQ_EXPORT __declspec(dllexport) -# define Q_TEMPLATEDLL -# define Q_TEMPLATE_EXTERN -# undef TQ_DISABLE_COPY /* avoid unresolved externals */ -# else -# define Q_TEMPLATEDLL -# define Q_TEMPLATE_EXTERN -# undef TQ_DISABLE_COPY /* avoid unresolved externals */ -# endif -#elif defined(Q_CC_GNU) && __GNUC__ - 0 >= 4 -# define TQ_EXPORT __attribute__((visibility("default"))) -# undef QT_MAKEDLL /* ignore these for other platforms */ -# undef QT_DLL -#else -# undef QT_MAKEDLL /* ignore these for other platforms */ -# undef QT_DLL -#endif - -#ifndef TQ_EXPORT -# define TQ_EXPORT -#endif - - -// -// Some platform specific stuff -// - -#if defined(TQ_WS_WIN) -extern TQ_EXPORT bool qt_winunicode; -#endif - - -// -// System information -// - -TQ_EXPORT const char *tqVersion(); -TQ_EXPORT bool tqSysInfo( int *wordSize, bool *bigEndian ); -TQ_EXPORT bool tqSharedBuild(); -#if defined(Q_OS_MAC) -int qMacVersion(); -#elif defined(TQ_WS_WIN) -TQ_EXPORT int qWinVersion(); -#if defined(UNICODE) -#define QT_WA( uni, ansi ) if ( qt_winunicode ) { uni } else { ansi } -#define QT_WA_INLINE( uni, ansi ) ( qt_winunicode ? uni : ansi ) -#else -#define QT_WA( uni, ansi ) ansi -#define QT_WA_INLINE( uni, ansi ) ansi -#endif -#endif - -#ifdef Q_OS_TEMP -#ifdef QT_WA -#undef QT_WA -#undef QT_WA_INLINE -#endif -#define QT_WA( uni, ansi ) uni -#define QT_WA_INLINE( uni, ansi ) ( uni ) -#endif - -#ifndef TQ_INLINE_TEMPLATES -# define TQ_INLINE_TEMPLATES -#endif - -#ifndef TQ_TYPENAME -# define TQ_TYPENAME typename -#endif - -// -// Use to avoid "unused parameter" warnings -// -#define Q_UNUSED(x) (void)x; - -// -// Debugging and error handling -// - -#if !defined(TQT_NO_CHECK) -# define QT_CHECK_STATE // check state of objects etc. -# define QT_CHECK_RANGE // check range of indexes etc. -# define QT_CHECK_NULL // check null pointers -# define QT_CHECK_MATH // check math functions -#endif - -#if !defined(TQT_NO_DEBUG) && !defined(QT_DEBUG) -# define QT_DEBUG // display debug messages -# if !defined(TQT_NO_COMPAT) // compatibility with TQt 2 -# if !defined(NO_DEBUG) && !defined(DEBUG) -# if !defined(Q_OS_MACX) // clash with MacOS X headers -# define DEBUG -# endif -# endif -# endif -#endif - - -TQ_EXPORT void tqDebug( const TQString& ); // print debug message -TQ_EXPORT void tqDebug( const TQCString& ); // print debug message -TQ_EXPORT void tqDebug( const char *, ... ) // print debug message -#if defined(Q_CC_GNU) && !defined(__INSURE__) - __attribute__ ((format (printf, 1, 2))) -#endif -; - -TQ_EXPORT void tqWarning( const TQString& ); // print warning message -TQ_EXPORT void tqWarning( const TQCString& ); // print warning message -TQ_EXPORT void tqWarning( const char *, ... ) // print warning message -#if defined(Q_CC_GNU) && !defined(__INSURE__) - __attribute__ ((format (printf, 1, 2))) -#endif -; - -TQ_EXPORT void tqFatal( const TQString& ); // print fatal message and exit -TQ_EXPORT void tqFatal( const TQCString& ); // print fatal message and exit -TQ_EXPORT void tqFatal( const char *, ... ) // print fatal message and exit -#if defined(Q_CC_GNU) - __attribute__ ((format (printf, 1, 2))) -#endif -; - -TQ_EXPORT void tqSystemWarning( const char *, int code = -1 ); - - -#if !defined(Q_ASSERT) -# if defined(QT_CHECK_STATE) -# if defined(QT_FATAL_ASSERT) -# define Q_ASSERT(x) ((x) ? (void)0 : tqFatal("ASSERT: \"%s\" in %s (%d)",#x,__FILE__,__LINE__)) -# else -# define Q_ASSERT(x) ((x) ? (void)0 : tqWarning("ASSERT: \"%s\" in %s (%d)",#x,__FILE__,__LINE__)) -# endif -# else -# define Q_ASSERT(x) -# endif -#endif - -#if !defined(TQT_NO_COMPAT) // compatibility with TQt 2 -# if !defined(ASSERT) -# if !defined(Q_OS_TEMP) -# define ASSERT(x) Q_ASSERT(x) -# endif -# endif -#endif // TQT_NO_COMPAT - - -TQ_EXPORT bool tqt_check_pointer( bool c, const char *, int ); - -#if defined(QT_CHECK_NULL) -# define TQ_CHECK_PTR(p) (tqt_check_pointer((p)==0,__FILE__,__LINE__)) -#else -# define TQ_CHECK_PTR(p) -#endif - -enum TQtMsgType { TQtDebugMsg, TQtWarningMsg, TQtFatalMsg }; - -typedef void (*TQtMsgHandler)(TQtMsgType, const char *); -TQ_EXPORT TQtMsgHandler qInstallMsgHandler( TQtMsgHandler ); - -#if !defined(TQT_NO_COMPAT) // compatibility with TQt 2 -typedef TQtMsgHandler msg_handler; -#endif // TQT_NO_COMPAT - -TQ_EXPORT void tqSuppressObsoleteWarnings( bool = TRUE ); - -TQ_EXPORT void tqObsolete( const char *obj, const char *oldfunc, - const char *newfunc ); -TQ_EXPORT void tqObsolete( const char *obj, const char *oldfunc ); -TQ_EXPORT void tqObsolete( const char *message ); - - -// -// Install paths from configure -// - -TQ_EXPORT const char *tqInstallPath(); -TQ_EXPORT const char *tqInstallPathDocs(); -TQ_EXPORT const char *tqInstallPathHeaders(); -TQ_EXPORT const char *tqInstallPathLibs(); -TQ_EXPORT const char *tqInstallPathBins(); -TQ_EXPORT const char *tqInstallPathPlugins(); -TQ_EXPORT const char *tqInstallPathData(); -TQ_EXPORT const char *tqInstallPathTranslations(); -TQ_EXPORT const char *tqInstallPathSysconf(); -TQ_EXPORT const char *tqInstallPathShare(); - -#endif /* __cplusplus */ - -/* - compilers which follow outdated template instantiation rules - require a class to have a comparison operator to exist when - a TQValueList of this type is instantiated. It's not actually - used in the list, though. Hence the dummy implementation. - Just in case other code relies on it we better trigger a warning - mandating a real implementation. -*/ -#ifdef TQ_FULL_TEMPLATE_INSTANTIATION -# define TQ_DUMMY_COMPARISON_OPERATOR(C) \ - bool operator==( const C& ) const { \ - tqWarning( #C"::operator==( const "#C"& ) got called." ); \ - return FALSE; \ - } -#else -# define TQ_DUMMY_COMPARISON_OPERATOR(C) -#endif - -#endif /* TQGLOBAL_H */ - -/* - Avoid some particularly useless warnings from some stupid compilers. - To get ALL C++ compiler warnings, define QT_CC_WARNINGS or comment out - the line "#define TQT_NO_WARNINGS" -*/ - -#if !defined(QT_CC_WARNINGS) -# define TQT_NO_WARNINGS -#endif -#if defined(TQT_NO_WARNINGS) -# if defined(Q_CC_MSVC) -# pragma warning(disable: 4244) // 'conversion' conversion from 'type1' to 'type2', possible loss of data -# pragma warning(disable: 4275) // non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' -# pragma warning(disable: 4514) // unreferenced inline/local function has been removed -# pragma warning(disable: 4800) // 'type' : forcing value to bool 'true' or 'false' (performance warning) -# pragma warning(disable: 4097) // typedef-name 'identifier1' used as synonym for class-name 'identifier2' -# pragma warning(disable: 4706) // assignment within conditional expression -# pragma warning(disable: 4786) // truncating debug info after 255 characters -# pragma warning(disable: 4660) // template-class specialization 'identifier' is already instantiated -# pragma warning(disable: 4355) // 'this' : used in base member initializer list -# pragma warning(disable: 4231) // nonstandard extension used : 'extern' before template explicit instantiation -# pragma warning(disable: 4710) // function not inlined -# elif defined(Q_CC_BOR) -# pragma option -w-inl -# pragma option -w-aus -# pragma warn -inl -# pragma warn -pia -# pragma warn -ccc -# pragma warn -rch -# pragma warn -sig -# endif -#endif - diff --git a/src/tools/ntqgvector.h b/src/tools/ntqgvector.h deleted file mode 100644 index d1e8385df..000000000 --- a/src/tools/ntqgvector.h +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** Definition of TQGVector class -** -** Created : 930907 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQGVECTOR_H -#define TQGVECTOR_H - -#ifndef QT_H -#include "tqptrcollection.h" -#endif // QT_H - - -class TQ_EXPORT TQGVector : public TQPtrCollection // generic vector -{ -friend class TQGList; // needed by TQGList::toVector -public: -#ifndef TQT_NO_DATASTREAM - TQDataStream &read( TQDataStream & ); // read vector from stream - TQDataStream &write( TQDataStream & ) const; // write vector to stream -#endif - virtual int compareItems( Item, Item ); - -protected: - TQGVector(); // create empty vector - TQGVector( uint size ); // create vector with nullptrs - TQGVector( const TQGVector &v ); // make copy of other vector - ~TQGVector(); - - TQGVector &operator=( const TQGVector &v ); // assign from other vector - bool operator==( const TQGVector &v ) const; - - Item *data() const { return vec; } - uint size() const { return len; } - uint count() const { return numItems; } - - bool insert( uint index, Item ); // insert item at index - bool remove( uint index ); // remove item - Item take( uint index ); // take out item - - void clear(); // clear vector - bool resize( uint newsize ); // resize vector - - bool fill( Item, int flen ); // resize and fill vector - - void sort(); // sort vector - int bsearch( Item ) const; // binary search (when sorted) - - int findRef( Item, uint index ) const; // find exact item in vector - int find( Item, uint index ) const; // find equal item in vector - uint containsRef( Item ) const; // get number of exact matches - uint contains( Item ) const; // get number of equal matches - - Item at( uint index ) const // return indexed item - { -#if defined(QT_CHECK_RANGE) - if ( index >= len ) - warningIndexRange( index ); -#endif - return vec[index]; - } - - bool insertExpand( uint index, Item ); // insert, expand if necessary - - void toList( TQGList * ) const; // put items in list - -#ifndef TQT_NO_DATASTREAM - virtual TQDataStream &read( TQDataStream &, Item & ); - virtual TQDataStream &write( TQDataStream &, Item ) const; -#endif -private: - Item *vec; - uint len; - uint numItems; - - static void warningIndexRange( uint ); -}; - - -/***************************************************************************** - TQGVector stream functions - *****************************************************************************/ - -#ifndef TQT_NO_DATASTREAM -TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQGVector & ); -TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQGVector & ); -#endif - -#endif // TQGVECTOR_H diff --git a/src/tools/ntqshared.h b/src/tools/ntqshared.h index fbd4dd457..62dcc8e35 100644 --- a/src/tools/ntqshared.h +++ b/src/tools/ntqshared.h @@ -42,7 +42,7 @@ #define TQSHARED_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H struct TQ_EXPORT TQShared diff --git a/src/tools/ntqtl.h b/src/tools/ntqtl.h index 712129746..df5a7cdb6 100644 --- a/src/tools/ntqtl.h +++ b/src/tools/ntqtl.h @@ -42,7 +42,7 @@ #define TQTL_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #include "tqtextstream.h" #include "tqstring.h" #endif // QT_H diff --git a/src/tools/qcom_p.h b/src/tools/qcom_p.h index e0c31a67d..623c920dc 100644 --- a/src/tools/qcom_p.h +++ b/src/tools/qcom_p.h @@ -289,7 +289,7 @@ public: \ #endif #endif -// this is duplicated at Q_PLUGIN_VERIFICATION_DATA in ntqgplugin.h +// this is duplicated at Q_PLUGIN_VERIFICATION_DATA in tqgplugin.h // NOTE: if you change pattern, you MUST change the pattern in // qcomlibrary.cpp as well. changing the pattern will break all // backwards compatibility as well (no old plugins will be loaded). diff --git a/src/tools/qgarray.cpp b/src/tools/qgarray.cpp deleted file mode 100644 index 1470d100e..000000000 --- a/src/tools/qgarray.cpp +++ /dev/null @@ -1,830 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQGArray class -** -** Created : 930906 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqglobal.h" -#if defined(Q_CC_BOR) - // needed for qsort() because of a std namespace problem on Borland -# include "qplatformdefs.h" -#elif defined(TQ_WS_WIN) - // needed for bsearch on some platforms -# include "qt_windows.h" -#endif - -#define TQGARRAY_CPP -#include "ntqgarray.h" -#include -#include - -#ifdef TQT_THREAD_SUPPORT -# include -#endif // TQT_THREAD_SUPPORT - -/* - If USE_MALLOC isn't defined, we use new[] and delete[] to allocate - memory. The documentation for TQMemArray::assign() explicitly - mentions that the array is freed using free(), so don't mess around - with USE_MALLOC unless you know what you're doing. -*/ -#define USE_MALLOC - -#undef NEW -#undef DELETE - -#if defined(USE_MALLOC) -#define NEW(type,size) ((type*)malloc(size*sizeof(type))) -#define DELETE(array) (free((char*)array)) -#else -#define NEW(type,size) (new type[size]) -#define DELETE(array) (delete[] array) -#define DONT_USE_REALLOC // comment to use realloc() -#endif - -/*! - \class TQShared ntqshared.h - \reentrant - \ingroup shared - \brief The TQShared class is used internally for implementing shared classes. - - \internal - - It only contains a reference count and member functions to increment and - decrement it. - - Shared classes normally have internal classes that inherit TQShared and - add the shared data. - - \sa \link shclass.html Shared Classes\endlink -*/ - -/*! - \class TQGArray ntqgarray.h - \reentrant - \ingroup shared - \ingroup collection - \brief The TQGArray class is an internal class for implementing the TQMemArray class. - - \internal - - TQGArray is a strictly internal class that acts as base class for the - TQMemArray template array. - - It contains an array of bytes and has no notion of an array element. -*/ - - -/*! - Constructs a null array. -*/ - -TQGArray::TQGArray() -{ - shd = newData(); - TQ_CHECK_PTR( shd ); -} - -/*! - Dummy constructor; does not allocate any data. - - This constructor does not initialize any array data so subclasses - must do it. The intention is to make the code more efficient. -*/ - -TQGArray::TQGArray( int, int ) -{ -} - -/*! - Constructs an array with room for \a size bytes. -*/ - -TQGArray::TQGArray( int size ) -{ - if ( size < 0 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQGArray: Cannot allocate array with negative length" ); -#endif - size = 0; - } - shd = newData(); - TQ_CHECK_PTR( shd ); - if ( size == 0 ) // zero length - return; - shd->data = NEW(char,size); - TQ_CHECK_PTR( shd->data ); - shd->len = -#ifdef QT_QGARRAY_SPEED_OPTIM - shd->maxl = -#endif - size; -} - -/*! - Constructs a shallow copy of \a a. -*/ - -TQGArray::TQGArray( const TQGArray &a ) -{ - shd = a.shd; - shd->ref(); -} - -/*! - Dereferences the array data and deletes it if this was the last - reference. -*/ - -TQGArray::~TQGArray() -{ - if ( shd && shd->deref() ) { // delete when last reference - if ( shd->data ) // is lost - DELETE(shd->data); - deleteData( shd ); - shd = 0; - } -} - - -/*! - \fn TQGArray &TQGArray::operator=( const TQGArray &a ) - - Assigns a shallow copy of \a a to this array and returns a reference to - this array. Equivalent to assign(). -*/ - -/*! - \fn void TQGArray::detach() - - Detaches this array from shared array data. -*/ - -/*! - \fn char *TQGArray::data() const - - Returns a pointer to the actual array data. -*/ - -/*! - \fn uint TQGArray::nrefs() const - - Returns the reference count. -*/ - -/*! - \fn uint TQGArray::size() const - - Returns the size of the array, in bytes. -*/ - - -/*! - Returns TRUE if this array is equal to \a a, otherwise FALSE. - The comparison is bitwise, of course. -*/ - -bool TQGArray::isEqual( const TQGArray &a ) const -{ - if ( size() != a.size() ) // different size - return FALSE; - if ( data() == a.data() ) // has same data - return TRUE; - return (size() ? memcmp( data(), a.data(), size() ) : 0) == 0; -} - - -/*! - Resizes the array to \a newsize bytes. \a optim is either - \c MemOptim (the default) or \c SpeedOptim. - - Note: \c SpeedOptim is only available if TQt is built in a - particular configuration. By default, \c SpeedOptim is not available - for general use. -*/ -bool TQGArray::resize( uint newsize, Optimization optim ) -{ -#ifndef QT_QGARRAY_SPEED_OPTIM - Q_UNUSED(optim); -#endif - - if ( newsize == shd->len -#ifdef QT_QGARRAY_SPEED_OPTIM - && newsize == shd->maxl -#endif - ) // nothing to do - return TRUE; - if ( newsize == 0 ) { // remove array - if ( shd->data ) - DELETE(shd->data); - shd->data = 0; - shd->len = 0; -#ifdef QT_QGARRAY_SPEED_OPTIM - shd->maxl = 0; -#endif - return TRUE; - } - - uint newmaxl = newsize; -#ifdef QT_QGARRAY_SPEED_OPTIM - if ( optim == SpeedOptim ) { - if ( newsize <= shd->maxl && - ( newsize * 4 > shd->maxl || shd->maxl <= 4 ) ) { - shd->len = newsize; - return TRUE; - } - newmaxl = 4; - while ( newmaxl < newsize ) - newmaxl *= 2; - // try to spare some memory - if ( newmaxl >= 1024 * 1024 && newsize <= newmaxl - (newmaxl >> 2) ) - newmaxl -= newmaxl >> 2; - } - shd->maxl = newmaxl; -#endif - - if ( shd->data ) { // existing data -#if defined(DONT_USE_REALLOC) - char *newdata = NEW(char,newsize); // manual realloc - memcpy( newdata, shd->data, TQMIN(shd->len,newmaxl) ); - DELETE(shd->data); - shd->data = newdata; -#else - shd->data = (char *)realloc( shd->data, newmaxl ); -#endif - } else { - shd->data = NEW(char,newmaxl); - } - if ( !shd->data ) // no memory - return FALSE; - shd->len = newsize; - return TRUE; -} - -/*!\overload -*/ -bool TQGArray::resize( uint newsize ) -{ - return resize( newsize, MemOptim ); -} - - -/*! - Fills the array with the repeated occurrences of \a d, which is - \a sz bytes long. - If \a len is specified as different from -1, then the array will be - resized to \a len*sz before it is filled. - - Returns TRUE if successful, or FALSE if the memory cannot be allocated - (only when \a len != -1). - - \sa resize() -*/ - -bool TQGArray::fill( const char *d, int len, uint sz ) -{ - if ( len < 0 ) - len = shd->len/sz; // default: use array length - else if ( !resize( len*sz ) ) - return FALSE; - if ( sz == 1 ) // 8 bit elements - memset( data(), *d, len ); - else if ( sz == 4 ) { // 32 bit elements - TQ_INT32 *x = (TQ_INT32*)data(); - TQ_INT32 v = *((TQ_INT32*)d); - while ( len-- ) - *x++ = v; - } else if ( sz == 2 ) { // 16 bit elements - TQ_INT16 *x = (TQ_INT16*)data(); - TQ_INT16 v = *((TQ_INT16*)d); - while ( len-- ) - *x++ = v; - } else { // any other size elements - char *x = data(); - while ( len-- ) { // more complicated - memcpy( x, d, sz ); - x += sz; - } - } - return TRUE; -} - -/*! - \overload - Shallow copy. Dereference the current array and references the data - contained in \a a instead. Returns a reference to this array. - \sa operator=() -*/ - -TQGArray &TQGArray::assign( const TQGArray &a ) -{ - a.shd->ref(); // avoid 'a = a' - if ( shd->deref() ) { // delete when last reference - if ( shd->data ) // is lost - DELETE(shd->data); - deleteData( shd ); - } - shd = a.shd; - return *this; -} - -/*! - Shallow copy. Dereference the current array and references the - array data \a d, which contains \a len bytes. - Returns a reference to this array. - - Do not delete \a d later, because TQGArray takes care of that. -*/ - -TQGArray &TQGArray::assign( const char *d, uint len ) -{ - if ( shd->count > 1 ) { // disconnect this - shd->count--; - shd = newData(); - TQ_CHECK_PTR( shd ); - } else { - if ( shd->data ) - DELETE(shd->data); - } - shd->data = (char *)d; - shd->len = -#ifdef QT_QGARRAY_SPEED_OPTIM - shd->maxl = -#endif - len; - return *this; -} - -/*! - Deep copy. Dereference the current array and obtains a copy of the data - contained in \a a instead. Returns a reference to this array. - \sa assign(), operator=() -*/ - -TQGArray &TQGArray::duplicate( const TQGArray &a ) -{ - if ( a.shd == shd ) { // a.duplicate(a) ! - if ( shd->count > 1 ) { - shd->count--; - array_data *n = newData(); - TQ_CHECK_PTR( n ); - if ( (n->len=shd->len) ) { - n->data = NEW(char,n->len); - TQ_CHECK_PTR( n->data ); - if ( n->data ) - memcpy( n->data, shd->data, n->len ); - } else { - n->data = 0; - } - shd = n; - } - return *this; - } - char *oldptr = 0; - if ( shd->count > 1 ) { // disconnect this - shd->count--; - shd = newData(); - TQ_CHECK_PTR( shd ); - } else { // delete after copy was made - oldptr = shd->data; - } - if ( a.shd->len ) { // duplicate data - shd->data = NEW(char,a.shd->len); - TQ_CHECK_PTR( shd->data ); - if ( shd->data ) - memcpy( shd->data, a.shd->data, a.shd->len ); - } else { - shd->data = 0; - } - shd->len = -#ifdef QT_QGARRAY_SPEED_OPTIM - shd->maxl = -#endif - a.shd->len; - if ( oldptr ) - DELETE(oldptr); - return *this; -} - -/*! - \overload - Deep copy. Dereferences the current array and obtains a copy of - \a len characters from array data \a d instead. Returns a reference - to this array. - \sa assign(), operator=() -*/ - -TQGArray &TQGArray::duplicate( const char *d, uint len ) -{ - char *data; - if ( d == 0 || len == 0 ) { - data = 0; - len = 0; - } else { - if ( shd->count == 1 && shd->len == len ) { - if ( shd->data != d ) // avoid self-assignment - memcpy( shd->data, d, len ); // use same buffer - return *this; - } - data = NEW(char,len); - TQ_CHECK_PTR( data ); - memcpy( data, d, len ); - } - if ( shd->count > 1 ) { // detach - shd->count--; - shd = newData(); - TQ_CHECK_PTR( shd ); - } else { // just a single reference - if ( shd->data ) - DELETE(shd->data); - } - shd->data = data; - shd->len = -#ifdef QT_QGARRAY_SPEED_OPTIM - shd->maxl = -#endif - len; - return *this; -} - -/*! - Resizes this array to \a len bytes and copies the \a len bytes at - address \a d into it. - - \warning This function disregards the reference count mechanism. If - other TQGArrays reference the same data as this, all will be updated. -*/ - -void TQGArray::store( const char *d, uint len ) -{ // store, but not deref - resize( len ); - memcpy( shd->data, d, len ); -} - - -/*! - \fn array_data *TQGArray::sharedBlock() const - - Returns a pointer to the shared array block. - - \warning - - Do not use this function. Using it is begging for trouble. We dare - not remove it, for fear of breaking code, but we \e strongly - discourage new use of it. -*/ - -/*! - \fn void TQGArray::setSharedBlock( array_data *p ) - - Sets the shared array block to \a p. - - \warning - - Do not use this function. Using it is begging for trouble. We dare - not remove it, for fear of breaking code, but we \e strongly - discourage new use of it. -*/ - - -/*! - Sets raw data and returns a reference to the array. - - Dereferences the current array and sets the new array data to \a d and - the new array size to \a len. Do not attempt to resize or re-assign the - array data when raw data has been set. - Call resetRawData(d,len) to reset the array. - - Setting raw data is useful because it sets TQMemArray data without - allocating memory or copying data. - - Example of intended use: - \code - static uchar bindata[] = { 231, 1, 44, ... }; - TQByteArray a; - a.setRawData( bindata, sizeof(bindata) ); // a points to bindata - TQDataStream s( a, IO_ReadOnly ); // open on a's data - s >> ; // read raw bindata - s.close(); - a.resetRawData( bindata, sizeof(bindata) ); // finished - \endcode - - Example of misuse (do not do this): - \code - static uchar bindata[] = { 231, 1, 44, ... }; - TQByteArray a, b; - a.setRawData( bindata, sizeof(bindata) ); // a points to bindata - a.resize( 8 ); // will crash - b = a; // will crash - a[2] = 123; // might crash - // forget to resetRawData - will crash - \endcode - - \warning If you do not call resetRawData(), TQGArray will attempt to - deallocate or reallocate the raw data, which might not be too good. - Be careful. -*/ - -TQGArray &TQGArray::setRawData( const char *d, uint len ) -{ - duplicate( 0, 0 ); // set null data - shd->data = (char *)d; - shd->len = len; - return *this; -} - -/*! - Resets raw data. - - The arguments must be the data, \a d, and length \a len, that were - passed to setRawData(). This is for consistency checking. -*/ - -void TQGArray::resetRawData( const char *d, uint len ) -{ - if ( d != shd->data || len != shd->len ) { -#if defined(QT_CHECK_STATE) - tqWarning( "TQGArray::resetRawData: Inconsistent arguments" ); -#endif - return; - } - shd->data = 0; - shd->len = 0; -} - - -/*! - Finds the first occurrence of \a d in the array from position \a index, - where \a sz is the size of the \a d element. - - Note that \a index is given in units of \a sz, not bytes. - - This function only compares whole cells, not bytes. -*/ - -int TQGArray::find( const char *d, uint index, uint sz ) const -{ - index *= sz; - if ( index >= shd->len ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQGArray::find: Index %d out of range", index/sz ); -#endif - return -1; - } - uint i; - uint ii; - switch ( sz ) { - case 1: { // 8 bit elements - char *x = data() + index; - char v = *d; - for ( i=index; ilen; i++ ) { - if ( *x++ == v ) - break; - } - ii = i; - } - break; - case 2: { // 16 bit elements - TQ_INT16 *x = (TQ_INT16*)(data() + index); - TQ_INT16 v = *((TQ_INT16*)d); - for ( i=index; ilen; i+=2 ) { - if ( *x++ == v ) - break; - } - ii = i/2; - } - break; - case 4: { // 32 bit elements - TQ_INT32 *x = (TQ_INT32*)(data() + index); - TQ_INT32 v = *((TQ_INT32*)d); - for ( i=index; ilen; i+=4 ) { - if ( *x++ == v ) - break; - } - ii = i/4; - } - break; - default: { // any size elements - for ( i=index; ilen; i+=sz ) { - if ( memcmp( d, &shd->data[i], sz ) == 0 ) - break; - } - ii = i/sz; - } - break; - } - return ilen ? (int)ii : -1; -} - -/*! - Returns the number of occurrences of \a d in the array, where \a sz is - the size of the \a d element. - - This function only compares whole cells, not bytes. -*/ - -int TQGArray::contains( const char *d, uint sz ) const -{ - uint i = shd->len; - int count = 0; - switch ( sz ) { - case 1: { // 8 bit elements - char *x = data(); - char v = *d; - while ( i-- ) { - if ( *x++ == v ) - count++; - } - } - break; - case 2: { // 16 bit elements - TQ_INT16 *x = (TQ_INT16*)data(); - TQ_INT16 v = *((TQ_INT16*)d); - i /= 2; - while ( i-- ) { - if ( *x++ == v ) - count++; - } - } - break; - case 4: { // 32 bit elements - TQ_INT32 *x = (TQ_INT32*)data(); - TQ_INT32 v = *((TQ_INT32*)d); - i /= 4; - while ( i-- ) { - if ( *x++ == v ) - count++; - } - } - break; - default: { // any size elements - for ( i=0; ilen; i+=sz ) { - if ( memcmp(d, &shd->data[i], sz) == 0 ) - count++; - } - } - break; - } - return count; -} - -static int cmp_item_size = 0; - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -#ifdef Q_OS_TEMP -static int __cdecl cmp_arr( const void *n1, const void *n2 ) -#else -static int cmp_arr( const void *n1, const void *n2 ) -#endif -{ - return ( n1 && n2 ) ? memcmp( n1, n2, cmp_item_size ) - : ( n1 ? 1 : ( n2 ? -1 : 0 ) ); - // ### TQt 3.0: Add a virtual compareItems() method and call that instead -} - -#if defined(Q_C_CALLBACKS) -} -#endif - -/*! - Sorts the first \a sz items of the array. -*/ - -void TQGArray::sort( uint sz ) -{ - int numItems = size() / sz; - if ( numItems < 2 ) - return; - -#ifdef TQT_THREAD_SUPPORT - TQMutexLocker locker( tqt_global_mutexpool ? - tqt_global_mutexpool->get( &cmp_item_size ) : 0 ); -#endif // TQT_THREAD_SUPPORT - - cmp_item_size = sz; - qsort( shd->data, numItems, sz, cmp_arr ); -} - -/*! - Binary search; assumes that \a d is a sorted array of size \a sz. -*/ - -int TQGArray::bsearch( const char *d, uint sz ) const -{ - int numItems = size() / sz; - if ( !numItems ) - return -1; - -#ifdef TQT_THREAD_SUPPORT - TQMutexLocker locker( tqt_global_mutexpool ? - tqt_global_mutexpool->get( &cmp_item_size ) : 0 ); -#endif // TQT_THREAD_SUPPORT - - cmp_item_size = sz; - char* r = (char*)::bsearch( d, shd->data, numItems, sz, cmp_arr ); - if ( !r ) - return -1; - while( (r >= shd->data + sz) && (cmp_arr( r - sz, d ) == 0) ) - r -= sz; // search to first of equal elements; bsearch is undef - return (int)(( r - shd->data ) / sz); -} - - -/*! - \fn char *TQGArray::at( uint index ) const - - Returns a pointer to the byte at offset \a index in the array. -*/ - -/*! - Expand the array if necessary, and copies (the first part of) its - contents from the \a index * \a sz bytes at \a d. - - Returns TRUE if the operation succeeds, FALSE if it runs out of - memory. - - \warning This function disregards the reference count mechanism. If - other TQGArrays reference the same data as this, all will be changed. -*/ - -bool TQGArray::setExpand( uint index, const char *d, uint sz ) -{ - index *= sz; - if ( index >= shd->len ) { - if ( !resize( index+sz ) ) // no memory - return FALSE; - } - memcpy( data() + index, d, sz ); - return TRUE; -} - - -/*! - Prints a warning message if at() or [] is given a bad index. -*/ - -void TQGArray::msg_index( uint index ) -{ -#if defined(QT_CHECK_RANGE) - tqWarning( "TQGArray::at: Absolute index %d out of range", index ); -#else - Q_UNUSED( index ) -#endif -} - - -/*! - Returns a new shared array block. -*/ - -TQGArray::array_data * TQGArray::newData() -{ - return new array_data; -} - - -/*! - Deletes the shared array block \a p. -*/ - -void TQGArray::deleteData( array_data *p ) -{ - delete p; -} diff --git a/src/tools/qgcache.cpp b/src/tools/qgcache.cpp deleted file mode 100644 index 95f75534e..000000000 --- a/src/tools/qgcache.cpp +++ /dev/null @@ -1,866 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQGCache and TQGCacheIterator classes -** -** Created : 950208 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqgcache.h" -#include "tqptrlist.h" -#include "tqdict.h" -#include "tqstring.h" - -/*! - \class TQGCache ntqgcache.h - \reentrant - \ingroup shared - \ingroup collection - \brief The TQGCache class is an internal class for implementing TQCache - template classes. - - \internal - - TQGCache is a strictly internal class that acts as a base class for the - \link collection.html collection classes\endlink TQCache and TQIntCache. -*/ - - -/***************************************************************************** - TQGCacheItem class (internal cache item) - *****************************************************************************/ - -struct TQCacheItem -{ - TQCacheItem( void *k, TQPtrCollection::Item d, int c, short p ) - : priority(p), skipPriority(p), cost(c), key(k), data(d), node(0) {} - short priority; - short skipPriority; - int cost; - void *key; - TQPtrCollection::Item data; - TQLNode *node; -}; - - -/***************************************************************************** - TQCList class (internal list of cache items) - *****************************************************************************/ - -class TQCList : private TQPtrList -{ -friend class TQGCacheIterator; -friend class TQCListIt; -public: - TQCList() {} - ~TQCList(); - - void insert( TQCacheItem * ); // insert according to priority - void insert( int, TQCacheItem * ); - void take( TQCacheItem * ); - void reference( TQCacheItem * ); - - void setAutoDelete( bool del ) { TQPtrCollection::setAutoDelete(del); } - - bool removeFirst() { return TQPtrList::removeFirst(); } - bool removeLast() { return TQPtrList::removeLast(); } - - TQCacheItem *first() { return TQPtrList::first(); } - TQCacheItem *last() { return TQPtrList::last(); } - TQCacheItem *prev() { return TQPtrList::prev(); } - TQCacheItem *next() { return TQPtrList::next(); } - -#if defined(QT_DEBUG) - int inserts; // variables for statistics - int insertCosts; - int insertMisses; - int finds; - int hits; - int hitCosts; - int dumps; - int dumpCosts; -#endif -}; - - -TQCList::~TQCList() -{ -#if defined(QT_DEBUG) - Q_ASSERT( count() == 0 ); -#endif -} - - -void TQCList::insert( TQCacheItem *ci ) -{ - TQCacheItem *item = first(); - while( item && item->skipPriority > ci->priority ) { - item->skipPriority--; - item = next(); - } - if ( item ) - TQPtrList::insert( at(), ci ); - else - append( ci ); -#if defined(QT_DEBUG) - Q_ASSERT( ci->node == 0 ); -#endif - ci->node = currentNode(); -} - -inline void TQCList::insert( int i, TQCacheItem *ci ) -{ - TQPtrList::insert( i, ci ); -#if defined(QT_DEBUG) - Q_ASSERT( ci->node == 0 ); -#endif - ci->node = currentNode(); -} - - -void TQCList::take( TQCacheItem *ci ) -{ - if ( ci ) { -#if defined(QT_DEBUG) - Q_ASSERT( ci->node != 0 ); -#endif - takeNode( ci->node ); - ci->node = 0; - } -} - - -inline void TQCList::reference( TQCacheItem *ci ) -{ -#if defined(QT_DEBUG) - Q_ASSERT( ci != 0 && ci->node != 0 ); -#endif - ci->skipPriority = ci->priority; - relinkNode( ci->node ); // relink as first item -} - - -class TQCListIt: public TQPtrListIterator -{ -public: - TQCListIt( const TQCList *p ): TQPtrListIterator( *p ) {} - TQCListIt( const TQCListIt *p ): TQPtrListIterator( *p ) {} -}; - - -/***************************************************************************** - TQCDict class (internal dictionary of cache items) - *****************************************************************************/ - -// -// Since we need to decide if the dictionary should use an int or const -// char * key (the "bool trivial" argument in the constructor below) -// we cannot use the macro/template dict, but inherit directly from TQGDict. -// - -class TQCDict : public TQGDict -{ -public: - TQCDict( uint size, uint kt, bool caseSensitive, bool copyKeys ) - : TQGDict( size, (KeyType)kt, caseSensitive, copyKeys ) {} - ~TQCDict(); - - void clear() { TQGDict::clear(); } - - TQCacheItem *find_string(const TQString &key) const - { return (TQCacheItem*)((TQCDict*)this)->look_string(key, 0, 0); } - TQCacheItem *find_ascii(const char *key) const - { return (TQCacheItem*)((TQCDict*)this)->look_ascii(key, 0, 0); } - TQCacheItem *find_int(long key) const - { return (TQCacheItem*)((TQCDict*)this)->look_int(key, 0, 0); } - - TQCacheItem *take_string(const TQString &key) - { return (TQCacheItem*)TQGDict::take_string(key); } - TQCacheItem *take_ascii(const char *key) - { return (TQCacheItem*)TQGDict::take_ascii(key); } - TQCacheItem *take_int(long key) - { return (TQCacheItem*)TQGDict::take_int(key); } - - bool insert_string( const TQString &key, const TQCacheItem *ci ) - { return TQGDict::look_string(key,(Item)ci,1)!=0;} - bool insert_ascii( const char *key, const TQCacheItem *ci ) - { return TQGDict::look_ascii(key,(Item)ci,1)!=0;} - bool insert_int( long key, const TQCacheItem *ci ) - { return TQGDict::look_int(key,(Item)ci,1)!=0;} - - bool remove_string( TQCacheItem *item ) - { return TQGDict::remove_string(*((TQString*)(item->key)),item); } - bool remove_ascii( TQCacheItem *item ) - { return TQGDict::remove_ascii((const char *)item->key,item); } - bool remove_int( TQCacheItem *item ) - { return TQGDict::remove_int((long)item->key,item);} - - void statistics() { TQGDict::statistics(); } - -private: - void deleteItem( void *item ) - { if ( del_item ) { TQCacheItem *d = (TQCacheItem*)item; delete d; } } -}; - -inline TQCDict::~TQCDict() -{ - clear(); -} - -/***************************************************************************** - TQGDict member functions - *****************************************************************************/ - -/*! - Constructs a cache. - The maximum cost of the cache is given by \a maxCost and the size by \a - size. The key type is \a kt which may be \c StringKey, \c AsciiKey, - \c IntKey or \c PtrKey. The case-sensitivity of lookups is set with - \a caseSensitive. Keys are copied if \a copyKeys is TRUE. -*/ - -TQGCache::TQGCache( int maxCost, uint size, KeyType kt, bool caseSensitive, - bool copyKeys ) -{ - keytype = kt; - lruList = new TQCList; - TQ_CHECK_PTR( lruList ); - lruList->setAutoDelete( TRUE ); - copyk = ((keytype == AsciiKey) && copyKeys); - dict = new TQCDict( size, kt, caseSensitive, FALSE ); - TQ_CHECK_PTR( dict ); - mCost = maxCost; - tCost = 0; -#if defined(QT_DEBUG) - lruList->inserts = 0; - lruList->insertCosts = 0; - lruList->insertMisses = 0; - lruList->finds = 0; - lruList->hits = 0; - lruList->hitCosts = 0; - lruList->dumps = 0; - lruList->dumpCosts = 0; -#endif -} - -/*! - Cannot copy a cache. -*/ - -TQGCache::TQGCache( const TQGCache & ) - : TQPtrCollection() -{ -#if defined(QT_CHECK_NULL) - tqFatal( "TQGCache::TQGCache(TQGCache &): Cannot copy a cache" ); -#endif -} - -/*! - Removes all items from the cache and destroys it. -*/ - -TQGCache::~TQGCache() -{ - clear(); - delete dict; - delete lruList; -} - -/*! - Cannot assign a cache. -*/ - -TQGCache &TQGCache::operator=( const TQGCache & ) -{ -#if defined(QT_CHECK_NULL) - tqFatal( "TQGCache::operator=: Cannot copy a cache" ); -#endif - return *this; -} - - -/*! - Returns the number of items in the cache. -*/ - -uint TQGCache::count() const -{ - return dict->count(); -} - -/*! - Returns the size of the hash array. -*/ - -uint TQGCache::size() const -{ - return dict->size(); -} - -/*! - \fn int TQGCache::maxCost() const - - Returns the maximum cache cost. -*/ - -/*! - \fn int TQGCache::totalCost() const - - Returns the total cache cost. -*/ - -/*! - Sets the maximum cache cost to \a maxCost. -*/ - -void TQGCache::setMaxCost( int maxCost ) -{ - if ( maxCost < tCost ) { - if ( !makeRoomFor(tCost - maxCost) ) // remove excess cost - return; - } - mCost = maxCost; -} - - -/*! - Inserts an item with data \a data into the cache using key \a key. - The item has cost \a cost and priority \a priority. - - \warning If this function returns FALSE, you must delete \a data - yourself. Additionally, be very careful about using \a data after - calling this function, as any other insertions into the cache, from - anywhere in the application, or within TQt itself, could cause the - data to be discarded from the cache, and the pointer to become - invalid. -*/ - -bool TQGCache::insert_string( const TQString &key, TQPtrCollection::Item data, - int cost, int priority) -{ - if ( tCost + cost > mCost ) { - if ( !makeRoomFor(tCost + cost - mCost, priority) ) { -#if defined(QT_DEBUG) - lruList->insertMisses++; -#endif - return FALSE; - } - } -#if defined(QT_DEBUG) - Q_ASSERT( keytype == StringKey ); - lruList->inserts++; - lruList->insertCosts += cost; -#endif - if ( priority < -32768 ) - priority = -32768; - else if ( priority > 32767 ) - priority = 32677; - TQCacheItem *ci = new TQCacheItem( new TQString(key), newItem(data), - cost, (short)priority ); - TQ_CHECK_PTR( ci ); - lruList->insert( 0, ci ); - dict->insert_string( key, ci ); - tCost += cost; - return TRUE; -} - -bool TQGCache::insert_other( const char *key, TQPtrCollection::Item data, - int cost, int priority) -{ - if ( tCost + cost > mCost ) { - if ( !makeRoomFor(tCost + cost - mCost, priority) ) { -#if defined(QT_DEBUG) - lruList->insertMisses++; -#endif - return FALSE; - } - } -#if defined(QT_DEBUG) - Q_ASSERT( keytype != StringKey ); - lruList->inserts++; - lruList->insertCosts += cost; -#endif - if ( keytype == AsciiKey && copyk ) - key = tqstrdup( key ); - if ( priority < -32768 ) - priority = -32768; - else if ( priority > 32767 ) - priority = 32677; - TQCacheItem *ci = new TQCacheItem( (void*)key, newItem(data), cost, - (short)priority ); - TQ_CHECK_PTR( ci ); - lruList->insert( 0, ci ); - if ( keytype == AsciiKey ) - dict->insert_ascii( key, ci ); - else - dict->insert_int( (long)key, ci ); - tCost += cost; - return TRUE; -} - - -/*! - Removes the item with key \a key from the cache. Returns TRUE if the - item was removed; otherwise returns FALSE. -*/ - -bool TQGCache::remove_string( const TQString &key ) -{ - Item d = take_string( key ); - if ( d ) - deleteItem( d ); - return d != 0; -} - -bool TQGCache::remove_other( const char *key ) -{ - Item d = take_other( key ); - if ( d ) - deleteItem( d ); - return d != 0; -} - - -/*! - Takes the item with key \a key out of the cache. The item is not - deleted. If no item has this \a key 0 is returned. -*/ - -TQPtrCollection::Item TQGCache::take_string( const TQString &key ) -{ - TQCacheItem *ci = dict->take_string( key ); // take from dict - Item d; - if ( ci ) { - d = ci->data; - tCost -= ci->cost; - lruList->take( ci ); // take from list - delete (TQString*)ci->key; - delete ci; - } else { - d = 0; - } - return d; -} - -/*! - Takes the item with key \a key out of the cache. The item is not - deleted. If no item has this \a key 0 is returned. -*/ - -TQPtrCollection::Item TQGCache::take_other( const char *key ) -{ - TQCacheItem *ci; - if ( keytype == AsciiKey ) - ci = dict->take_ascii( key ); - else - ci = dict->take_int( (long)key ); - Item d; - if ( ci ) { - d = ci->data; - tCost -= ci->cost; - lruList->take( ci ); // take from list - if ( copyk ) - delete [] (char *)ci->key; - delete ci; - } else { - d = 0; - } - return d; -} - - -/*! - Clears the cache. -*/ - -void TQGCache::clear() -{ - TQCacheItem *ci; - while ( (ci = lruList->first()) ) { - switch ( keytype ) { - case StringKey: - dict->remove_string( ci ); - delete (TQString*)ci->key; - break; - case AsciiKey: - dict->remove_ascii( ci ); - if ( copyk ) - delete [] (char*)ci->key; - break; - case IntKey: - dict->remove_int( ci ); - break; - case PtrKey: // unused - break; - } - deleteItem( ci->data ); // delete data - lruList->removeFirst(); // remove from list - } - tCost = 0; -} - - -/*! - Finds an item for \a key in the cache and adds a reference if \a ref is TRUE. -*/ - -TQPtrCollection::Item TQGCache::find_string( const TQString &key, bool ref ) const -{ - TQCacheItem *ci = dict->find_string( key ); -#if defined(QT_DEBUG) - lruList->finds++; -#endif - if ( ci ) { -#if defined(QT_DEBUG) - lruList->hits++; - lruList->hitCosts += ci->cost; -#endif - if ( ref ) - lruList->reference( ci ); - return ci->data; - } - return 0; -} - - -/*! - Finds an item for \a key in the cache and adds a reference if \a ref is TRUE. -*/ - -TQPtrCollection::Item TQGCache::find_other( const char *key, bool ref ) const -{ - TQCacheItem *ci = keytype == AsciiKey ? dict->find_ascii(key) - : dict->find_int((long)key); -#if defined(QT_DEBUG) - lruList->finds++; -#endif - if ( ci ) { -#if defined(QT_DEBUG) - lruList->hits++; - lruList->hitCosts += ci->cost; -#endif - if ( ref ) - lruList->reference( ci ); - return ci->data; - } - return 0; -} - - -/*! - Allocates cache space for one or more items. -*/ - -bool TQGCache::makeRoomFor( int cost, int priority ) -{ - if ( cost > mCost ) // cannot make room for more - return FALSE; // than maximum cost - if ( priority == -1 ) - priority = 32767; - TQCacheItem *ci = lruList->last(); - int cntCost = 0; - int dumps = 0; // number of items to dump - while ( cntCost < cost && ci && ci->skipPriority <= priority ) { - cntCost += ci->cost; - ci = lruList->prev(); - dumps++; - } - if ( cntCost < cost ) // can enough cost be dumped? - return FALSE; // no -#if defined(QT_DEBUG) - Q_ASSERT( dumps > 0 ); -#endif - while ( dumps-- ) { - ci = lruList->last(); -#if defined(QT_DEBUG) - lruList->dumps++; - lruList->dumpCosts += ci->cost; -#endif - switch ( keytype ) { - case StringKey: - dict->remove_string( ci ); - delete (TQString*)ci->key; - break; - case AsciiKey: - dict->remove_ascii( ci ); - if ( copyk ) - delete [] (char *)ci->key; - break; - case IntKey: - dict->remove_int( ci ); - break; - case PtrKey: // unused - break; - } - deleteItem( ci->data ); // delete data - lruList->removeLast(); // remove from list - } - tCost -= cntCost; - return TRUE; -} - - -/*! - Outputs debug statistics. -*/ - -void TQGCache::statistics() const -{ -#if defined(QT_DEBUG) - TQString line; - line.fill( '*', 80 ); - tqDebug( "%s", line.ascii() ); - tqDebug( "CACHE STATISTICS:" ); - tqDebug( "cache contains %d item%s, with a total cost of %d", - count(), count() != 1 ? "s" : "", tCost ); - tqDebug( "maximum cost is %d, cache is %d%% full.", - mCost, (200*tCost + mCost) / (mCost*2) ); - tqDebug( "find() has been called %d time%s", - lruList->finds, lruList->finds != 1 ? "s" : "" ); - tqDebug( "%d of these were hits, items found had a total cost of %d.", - lruList->hits,lruList->hitCosts ); - tqDebug( "%d item%s %s been inserted with a total cost of %d.", - lruList->inserts,lruList->inserts != 1 ? "s" : "", - lruList->inserts != 1 ? "have" : "has", lruList->insertCosts ); - tqDebug( "%d item%s %s too large or had too low priority to be inserted.", - lruList->insertMisses, lruList->insertMisses != 1 ? "s" : "", - lruList->insertMisses != 1 ? "were" : "was" ); - tqDebug( "%d item%s %s been thrown away with a total cost of %d.", - lruList->dumps, lruList->dumps != 1 ? "s" : "", - lruList->dumps != 1 ? "have" : "has", lruList->dumpCosts ); - tqDebug( "Statistics from internal dictionary class:" ); - dict->statistics(); - tqDebug( "%s", line.ascii() ); -#endif -} - - -/***************************************************************************** - TQGCacheIterator member functions - *****************************************************************************/ - -/*! - \class TQGCacheIterator ntqgcache.h - \reentrant - \ingroup shared - \ingroup collection - \brief The TQGCacheIterator class is an internal class for implementing TQCacheIterator and - TQIntCacheIterator. - - \internal - - TQGCacheIterator is a strictly internal class that does the heavy work for - TQCacheIterator and TQIntCacheIterator. -*/ - -/*! - Constructs an iterator that operates on the cache \a c. -*/ - -TQGCacheIterator::TQGCacheIterator( const TQGCache &c ) -{ - it = new TQCListIt( c.lruList ); -#if defined(QT_DEBUG) - Q_ASSERT( it != 0 ); -#endif -} - -/*! - Constructs an iterator that operates on the same cache as \a ci. -*/ - -TQGCacheIterator::TQGCacheIterator( const TQGCacheIterator &ci ) -{ - it = new TQCListIt( ci.it ); -#if defined(QT_DEBUG) - Q_ASSERT( it != 0 ); -#endif -} - -/*! - Destroys the iterator. -*/ - -TQGCacheIterator::~TQGCacheIterator() -{ - delete it; -} - -/*! - Assigns the iterator \a ci to this cache iterator. -*/ - -TQGCacheIterator &TQGCacheIterator::operator=( const TQGCacheIterator &ci ) -{ - *it = *ci.it; - return *this; -} - -/*! - Returns the number of items in the cache. -*/ - -uint TQGCacheIterator::count() const -{ - return it->count(); -} - -/*! - Returns TRUE if the iterator points to the first item. -*/ - -bool TQGCacheIterator::atFirst() const -{ - return it->atFirst(); -} - -/*! - Returns TRUE if the iterator points to the last item. -*/ - -bool TQGCacheIterator::atLast() const -{ - return it->atLast(); -} - -/*! - Sets the list iterator to point to the first item in the cache. -*/ - -TQPtrCollection::Item TQGCacheIterator::toFirst() -{ - TQCacheItem *item = it->toFirst(); - return item ? item->data : 0; -} - -/*! - Sets the list iterator to point to the last item in the cache. -*/ - -TQPtrCollection::Item TQGCacheIterator::toLast() -{ - TQCacheItem *item = it->toLast(); - return item ? item->data : 0; -} - -/*! - Returns the current item. -*/ - -TQPtrCollection::Item TQGCacheIterator::get() const -{ - TQCacheItem *item = it->current(); - return item ? item->data : 0; -} - -/*! - Returns the key of the current item. -*/ - -TQString TQGCacheIterator::getKeyString() const -{ - TQCacheItem *item = it->current(); - return item ? *((TQString*)item->key) : TQString::null; -} - -/*! - Returns the key of the current item, as a \0-terminated C string. -*/ - -const char *TQGCacheIterator::getKeyAscii() const -{ - TQCacheItem *item = it->current(); - return item ? (const char *)item->key : 0; -} - -/*! - Returns the key of the current item, as a long. -*/ - -long TQGCacheIterator::getKeyInt() const -{ - TQCacheItem *item = it->current(); - return item ? (long)item->key : 0; -} - -/*! - Moves to the next item (postfix). -*/ - -TQPtrCollection::Item TQGCacheIterator::operator()() -{ - TQCacheItem *item = it->operator()(); - return item ? item->data : 0; -} - -/*! - Moves to the next item (prefix). -*/ - -TQPtrCollection::Item TQGCacheIterator::operator++() -{ - TQCacheItem *item = it->operator++(); - return item ? item->data : 0; -} - -/*! - Moves \a jump positions forward. -*/ - -TQPtrCollection::Item TQGCacheIterator::operator+=( uint jump ) -{ - TQCacheItem *item = it->operator+=(jump); - return item ? item->data : 0; -} - -/*! - Moves to the previous item (prefix). -*/ - -TQPtrCollection::Item TQGCacheIterator::operator--() -{ - TQCacheItem *item = it->operator--(); - return item ? item->data : 0; -} - -/*! - Moves \a jump positions backward. -*/ - -TQPtrCollection::Item TQGCacheIterator::operator-=( uint jump ) -{ - TQCacheItem *item = it->operator-=(jump); - return item ? item->data : 0; -} diff --git a/src/tools/qgdict.cpp b/src/tools/qgdict.cpp deleted file mode 100644 index dd35d64e3..000000000 --- a/src/tools/qgdict.cpp +++ /dev/null @@ -1,1151 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQGDict and TQGDictIterator classes -** -** Created : 920529 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqgdict.h" -#include "tqptrlist.h" -#include "tqstring.h" -#include "tqdatastream.h" -#include - -/*! - \class TQGDict - \reentrant - \ingroup collection - \brief The TQGDict class is an internal class for implementing TQDict template classes. - - \internal - - TQGDict is a strictly internal class that acts as a base class for the - \link collection.html collection classes\endlink TQDict and TQIntDict. - - TQGDict has some virtual functions that can be reimplemented to customize - the subclasses. - \list - \i read() reads a collection/dictionary item from a TQDataStream. - \i write() writes a collection/dictionary item to a TQDataStream. - \endlist - Normally, you do not have to reimplement any of these functions. -*/ - -static const int op_find = 0; -static const int op_insert = 1; -static const int op_replace = 2; - - -class TQGDItList : public TQPtrList -{ -public: - TQGDItList() : TQPtrList() {} - TQGDItList( const TQGDItList &list ) : TQPtrList(list) {} - ~TQGDItList() { clear(); } - TQGDItList &operator=(const TQGDItList &list) - { return (TQGDItList&)TQPtrList::operator=(list); } -}; - - -/***************************************************************************** - Default implementation of special and virtual functions - *****************************************************************************/ - -/*! - Returns the hash key for \a key, when key is a string. -*/ - -int TQGDict::hashKeyString( const TQString &key ) -{ -#if defined(QT_CHECK_NULL) - if ( key.isNull() ) - tqWarning( "TQGDict::hashKeyString: Invalid null key" ); -#endif - int i; - uint h=0; - uint g; - const TQChar *p = key.unicode(); - if ( cases ) { // case sensitive - for ( i=0; i<(int)key.length(); i++ ) { - h = (h<<4) + p[i].cell(); - if ( (g = h & 0xf0000000) ) - h ^= g >> 24; - h &= ~g; - } - } else { // case insensitive - for ( i=0; i<(int)key.length(); i++ ) { - h = (h<<4) + p[i].lower().cell(); - if ( (g = h & 0xf0000000) ) - h ^= g >> 24; - h &= ~g; - } - } - int index = h; - if ( index < 0 ) // adjust index to table size - index = -index; - return index; -} - -/*! - Returns the hash key for \a key, which is a C string. -*/ - -int TQGDict::hashKeyAscii( const char *key ) -{ -#if defined(QT_CHECK_NULL) - if ( key == 0 ) - tqWarning( "TQGDict::hashAsciiKey: Invalid null key" ); -#endif - const char *k = key; - uint h=0; - uint g; - if ( cases ) { // case sensitive - while ( *k ) { - h = (h<<4) + *k++; - if ( (g = h & 0xf0000000) ) - h ^= g >> 24; - h &= ~g; - } - } else { // case insensitive - while ( *k ) { - h = (h<<4) + tolower((uchar) *k); - if ( (g = h & 0xf0000000) ) - h ^= g >> 24; - h &= ~g; - k++; - } - } - int index = h; - if ( index < 0 ) // adjust index to table size - index = -index; - return index; -} - -#ifndef TQT_NO_DATASTREAM - -/*! - \overload - Reads a collection/dictionary item from the stream \a s and returns a - reference to the stream. - - The default implementation sets \a item to 0. - - \sa write() -*/ - -TQDataStream& TQGDict::read( TQDataStream &s, TQPtrCollection::Item &item ) -{ - item = 0; - return s; -} - -/*! - \overload - Writes a collection/dictionary item to the stream \a s and returns a - reference to the stream. - - \sa read() -*/ - -TQDataStream& TQGDict::write( TQDataStream &s, TQPtrCollection::Item ) const -{ - return s; -} -#endif //TQT_NO_DATASTREAM - -/***************************************************************************** - TQGDict member functions - *****************************************************************************/ - -/*! - Constructs a dictionary. - - \a len is the initial size of the dictionary. - The key type is \a kt which may be \c StringKey, \c AsciiKey, - \c IntKey or \c PtrKey. The case-sensitivity of lookups is set with - \a caseSensitive. Keys are copied if \a copyKeys is TRUE. -*/ - -TQGDict::TQGDict( uint len, KeyType kt, bool caseSensitive, bool copyKeys ) -{ - init( len, kt, caseSensitive, copyKeys ); -} - - -void TQGDict::init( uint len, KeyType kt, bool caseSensitive, bool copyKeys ) -{ - vlen = len ? len : 17; - vec = new TQBaseBucket *[ vlen ]; - - TQ_CHECK_PTR( vec ); - memset( (char*)vec, 0, vlen*sizeof(TQBaseBucket*) ); - numItems = 0; - iterators = 0; - // The caseSensitive and copyKey options don't make sense for - // all dict types. - switch ( (keytype = (uint)kt) ) { - case StringKey: - cases = caseSensitive; - copyk = FALSE; - break; - case AsciiKey: - cases = caseSensitive; - copyk = copyKeys; - break; - default: - cases = FALSE; - copyk = FALSE; - break; - } -} - - -/*! - Constructs a copy of \a dict. -*/ - -TQGDict::TQGDict( const TQGDict & dict ) - : TQPtrCollection( dict ) -{ - init( dict.vlen, (KeyType)dict.keytype, dict.cases, dict.copyk ); - TQGDictIterator it( dict ); - while ( it.get() ) { // copy from other dict - switch ( keytype ) { - case StringKey: - look_string( it.getKeyString(), it.get(), op_insert ); - break; - case AsciiKey: - look_ascii( it.getKeyAscii(), it.get(), op_insert ); - break; - case IntKey: - look_int( it.getKeyInt(), it.get(), op_insert ); - break; - case PtrKey: - look_ptr( it.getKeyPtr(), it.get(), op_insert ); - break; - } - ++it; - } -} - - -/*! - Removes all items from the dictionary and destroys it. -*/ - -TQGDict::~TQGDict() -{ - clear(); // delete everything - delete [] vec; - if ( !iterators ) // no iterators for this dict - return; - TQGDictIterator *i = iterators->first(); - while ( i ) { // notify all iterators that - i->dict = 0; // this dict is deleted - i = iterators->next(); - } - delete iterators; -} - - -/*! - Assigns \a dict to this dictionary. -*/ - -TQGDict &TQGDict::operator=( const TQGDict &dict ) -{ - if ( &dict == this ) - return *this; - clear(); - TQGDictIterator it( dict ); - while ( it.get() ) { // copy from other dict - switch ( keytype ) { - case StringKey: - look_string( it.getKeyString(), it.get(), op_insert ); - break; - case AsciiKey: - look_ascii( it.getKeyAscii(), it.get(), op_insert ); - break; - case IntKey: - look_int( it.getKeyInt(), it.get(), op_insert ); - break; - case PtrKey: - look_ptr( it.getKeyPtr(), it.get(), op_insert ); - break; - } - ++it; - } - return *this; -} - -/*! - \fn uint TQGDict::count() const - - Returns the number of items in the dictionary. -*/ - -/*! - \fn uint TQGDict::size() const - - Returns the size of the hash array. -*/ - -/*! - The do-it-all function; \a op is one of op_find, op_insert, op_replace. - The key is \a key and the item is \a d. -*/ - -TQPtrCollection::Item TQGDict::look_string( const TQString &key, TQPtrCollection::Item d, - int op ) -{ - TQStringBucket *n = 0; - int index = hashKeyString(key) % vlen; - if ( op == op_find ) { // find - if ( cases ) { - n = (TQStringBucket*)vec[index]; - while( n != 0 ) { - if ( key == n->getKey() ) - return n->getData(); // item found - n = (TQStringBucket*)n->getNext(); - } - } else { - TQString k = key.lower(); - n = (TQStringBucket*)vec[index]; - while( n != 0 ) { - if ( k == n->getKey().lower() ) - return n->getData(); // item found - n = (TQStringBucket*)n->getNext(); - } - } - return 0; // not found - } - if ( op == op_replace ) { // replace - if ( vec[index] != 0 ) // maybe something there - remove_string( key ); - } - // op_insert or op_replace - n = new TQStringBucket(key,newItem(d),vec[index]); - TQ_CHECK_PTR( n ); -#if defined(QT_CHECK_NULL) - if ( n->getData() == 0 ) - tqWarning( "TQDict: Cannot insert null item" ); -#endif - vec[index] = n; - numItems++; - return n->getData(); -} - -TQPtrCollection::Item TQGDict::look_ascii( const char *key, TQPtrCollection::Item d, int op ) -{ - TQAsciiBucket *n; - int index = hashKeyAscii(key) % vlen; - if ( op == op_find ) { // find - if ( cases ) { - for ( n=(TQAsciiBucket*)vec[index]; n; - n=(TQAsciiBucket*)n->getNext() ) { - if ( qstrcmp(n->getKey(),key) == 0 ) - return n->getData(); // item found - } - } else { - for ( n=(TQAsciiBucket*)vec[index]; n; - n=(TQAsciiBucket*)n->getNext() ) { - if ( tqstricmp(n->getKey(),key) == 0 ) - return n->getData(); // item found - } - } - return 0; // not found - } - if ( op == op_replace ) { // replace - if ( vec[index] != 0 ) // maybe something there - remove_ascii( key ); - } - // op_insert or op_replace - n = new TQAsciiBucket(copyk ? tqstrdup(key) : key,newItem(d),vec[index]); - TQ_CHECK_PTR( n ); -#if defined(QT_CHECK_NULL) - if ( n->getData() == 0 ) - tqWarning( "TQAsciiDict: Cannot insert null item" ); -#endif - vec[index] = n; - numItems++; - return n->getData(); -} - -TQPtrCollection::Item TQGDict::look_int( long key, TQPtrCollection::Item d, int op ) -{ - TQIntBucket *n; - int index = (int)((ulong)key % vlen); // simple hash - if ( op == op_find ) { // find - for ( n=(TQIntBucket*)vec[index]; n; - n=(TQIntBucket*)n->getNext() ) { - if ( n->getKey() == key ) - return n->getData(); // item found - } - return 0; // not found - } - if ( op == op_replace ) { // replace - if ( vec[index] != 0 ) // maybe something there - remove_int( key ); - } - // op_insert or op_replace - n = new TQIntBucket(key,newItem(d),vec[index]); - TQ_CHECK_PTR( n ); -#if defined(QT_CHECK_NULL) - if ( n->getData() == 0 ) - tqWarning( "TQIntDict: Cannot insert null item" ); -#endif - vec[index] = n; - numItems++; - return n->getData(); -} - -TQPtrCollection::Item TQGDict::look_ptr( void *key, TQPtrCollection::Item d, int op ) -{ - TQPtrBucket *n; - int index = (int)((ulong)key % vlen); // simple hash - if ( op == op_find ) { // find - for ( n=(TQPtrBucket*)vec[index]; n; - n=(TQPtrBucket*)n->getNext() ) { - if ( n->getKey() == key ) - return n->getData(); // item found - } - return 0; // not found - } - if ( op == op_replace ) { // replace - if ( vec[index] != 0 ) // maybe something there - remove_ptr( key ); - } - // op_insert or op_replace - n = new TQPtrBucket(key,newItem(d),vec[index]); - TQ_CHECK_PTR( n ); -#if defined(QT_CHECK_NULL) - if ( n->getData() == 0 ) - tqWarning( "TQPtrDict: Cannot insert null item" ); -#endif - vec[index] = n; - numItems++; - return n->getData(); -} - - -/*! - Changes the size of the hashtable to \a newsize. - The contents of the dictionary are preserved, - but all iterators on the dictionary become invalid. -*/ -void TQGDict::resize( uint newsize ) -{ - // Save old information - TQBaseBucket **old_vec = vec; - uint old_vlen = vlen; - bool old_copyk = copyk; - - vec = new TQBaseBucket *[vlen = newsize]; - TQ_CHECK_PTR( vec ); - memset( (char*)vec, 0, vlen*sizeof(TQBaseBucket*) ); - numItems = 0; - copyk = FALSE; - - // Reinsert every item from vec, deleting vec as we go - for ( uint index = 0; index < old_vlen; index++ ) { - switch ( keytype ) { - case StringKey: - { - TQStringBucket *n=(TQStringBucket *)old_vec[index]; - while ( n ) { - look_string( n->getKey(), n->getData(), op_insert ); - TQStringBucket *t=(TQStringBucket *)n->getNext(); - delete n; - n = t; - } - } - break; - case AsciiKey: - { - TQAsciiBucket *n=(TQAsciiBucket *)old_vec[index]; - while ( n ) { - look_ascii( n->getKey(), n->getData(), op_insert ); - TQAsciiBucket *t=(TQAsciiBucket *)n->getNext(); - delete n; - n = t; - } - } - break; - case IntKey: - { - TQIntBucket *n=(TQIntBucket *)old_vec[index]; - while ( n ) { - look_int( n->getKey(), n->getData(), op_insert ); - TQIntBucket *t=(TQIntBucket *)n->getNext(); - delete n; - n = t; - } - } - break; - case PtrKey: - { - TQPtrBucket *n=(TQPtrBucket *)old_vec[index]; - while ( n ) { - look_ptr( n->getKey(), n->getData(), op_insert ); - TQPtrBucket *t=(TQPtrBucket *)n->getNext(); - delete n; - n = t; - } - } - break; - } - } - delete [] old_vec; - - // Restore state - copyk = old_copyk; - - // Invalidate all iterators, since order is lost - if ( iterators && iterators->count() ) { - TQGDictIterator *i = iterators->first(); - while ( i ) { - i->toFirst(); - i = iterators->next(); - } - } -} - -/*! - Unlinks the bucket with the specified key (and specified data pointer, - if it is set). -*/ - -void TQGDict::unlink_common( int index, TQBaseBucket *node, TQBaseBucket *prev ) -{ - if ( iterators && iterators->count() ) { // update iterators - TQGDictIterator *i = iterators->first(); - while ( i ) { // invalidate all iterators - if ( i->curNode == node ) // referring to pending node - i->operator++(); - i = iterators->next(); - } - } - if ( prev ) // unlink node - prev->setNext( node->getNext() ); - else - vec[index] = node->getNext(); - numItems--; -} - -TQStringBucket *TQGDict::unlink_string( const TQString &key, TQPtrCollection::Item d ) -{ - if ( numItems == 0 ) // nothing in dictionary - return 0; - TQStringBucket *n; - TQStringBucket *prev = 0; - int index = hashKeyString(key) % vlen; - if ( cases ) { - for ( n=(TQStringBucket*)vec[index]; n; - n=(TQStringBucket*)n->getNext() ) { - bool found = (key == n->getKey()); - if ( found && d ) - found = (n->getData() == d); - if ( found ) { - unlink_common(index,n,prev); - return n; - } - prev = n; - } - } else { - TQString k = key.lower(); - for ( n=(TQStringBucket*)vec[index]; n; - n=(TQStringBucket*)n->getNext() ) { - bool found = (k == n->getKey().lower()); - if ( found && d ) - found = (n->getData() == d); - if ( found ) { - unlink_common(index,n,prev); - return n; - } - prev = n; - } - } - return 0; -} - -TQAsciiBucket *TQGDict::unlink_ascii( const char *key, TQPtrCollection::Item d ) -{ - if ( numItems == 0 ) // nothing in dictionary - return 0; - TQAsciiBucket *n; - TQAsciiBucket *prev = 0; - int index = hashKeyAscii(key) % vlen; - for ( n=(TQAsciiBucket *)vec[index]; n; n=(TQAsciiBucket *)n->getNext() ) { - bool found = (cases ? qstrcmp(n->getKey(),key) - : tqstricmp(n->getKey(),key)) == 0; - if ( found && d ) - found = (n->getData() == d); - if ( found ) { - unlink_common(index,n,prev); - return n; - } - prev = n; - } - return 0; -} - -TQIntBucket *TQGDict::unlink_int( long key, TQPtrCollection::Item d ) -{ - if ( numItems == 0 ) // nothing in dictionary - return 0; - TQIntBucket *n; - TQIntBucket *prev = 0; - int index = (int)((ulong)key % vlen); - for ( n=(TQIntBucket *)vec[index]; n; n=(TQIntBucket *)n->getNext() ) { - bool found = (n->getKey() == key); - if ( found && d ) - found = (n->getData() == d); - if ( found ) { - unlink_common(index,n,prev); - return n; - } - prev = n; - } - return 0; -} - -TQPtrBucket *TQGDict::unlink_ptr( void *key, TQPtrCollection::Item d ) -{ - if ( numItems == 0 ) // nothing in dictionary - return 0; - TQPtrBucket *n; - TQPtrBucket *prev = 0; - int index = (int)((ulong)key % vlen); - for ( n=(TQPtrBucket *)vec[index]; n; n=(TQPtrBucket *)n->getNext() ) { - bool found = (n->getKey() == key); - if ( found && d ) - found = (n->getData() == d); - if ( found ) { - unlink_common(index,n,prev); - return n; - } - prev = n; - } - return 0; -} - - -/*! - Removes the item with the specified \a key. If \a item is not null, - the remove will match the \a item as well (used to remove an - item when several items have the same key). -*/ - -bool TQGDict::remove_string( const TQString &key, TQPtrCollection::Item item ) -{ - TQStringBucket *n = unlink_string( key, item ); - if ( n ) { - deleteItem( n->getData() ); - delete n; - return TRUE; - } else { - return FALSE; - } -} - -bool TQGDict::remove_ascii( const char *key, TQPtrCollection::Item item ) -{ - TQAsciiBucket *n = unlink_ascii( key, item ); - if ( n ) { - if ( copyk ) - delete [] (char *)n->getKey(); - deleteItem( n->getData() ); - delete n; - } - return n != 0; -} - -bool TQGDict::remove_int( long key, TQPtrCollection::Item item ) -{ - TQIntBucket *n = unlink_int( key, item ); - if ( n ) { - deleteItem( n->getData() ); - delete n; - } - return n != 0; -} - -bool TQGDict::remove_ptr( void *key, TQPtrCollection::Item item ) -{ - TQPtrBucket *n = unlink_ptr( key, item ); - if ( n ) { - deleteItem( n->getData() ); - delete n; - } - return n != 0; -} - -TQPtrCollection::Item TQGDict::take_string( const TQString &key ) -{ - TQStringBucket *n = unlink_string( key ); - Item d; - if ( n ) { - d = n->getData(); - delete n; - } else { - d = 0; - } - return d; -} - -TQPtrCollection::Item TQGDict::take_ascii( const char *key ) -{ - TQAsciiBucket *n = unlink_ascii( key ); - Item d; - if ( n ) { - if ( copyk ) - delete [] (char *)n->getKey(); - d = n->getData(); - delete n; - } else { - d = 0; - } - return d; -} - -TQPtrCollection::Item TQGDict::take_int( long key ) -{ - TQIntBucket *n = unlink_int( key ); - Item d; - if ( n ) { - d = n->getData(); - delete n; - } else { - d = 0; - } - return d; -} - -TQPtrCollection::Item TQGDict::take_ptr( void *key ) -{ - TQPtrBucket *n = unlink_ptr( key ); - Item d; - if ( n ) { - d = n->getData(); - delete n; - } else { - d = 0; - } - return d; -} - -/*! - Removes all items from the dictionary. -*/ -void TQGDict::clear() -{ - if ( !numItems ) - return; - numItems = 0; // disable remove() function - for ( uint j=0; jgetNext(); - deleteItem( n->getData() ); - delete n; - n = next; - } - } - break; - case AsciiKey: - { - TQAsciiBucket *n=(TQAsciiBucket *)vec[j]; - while ( n ) { - TQAsciiBucket *next = (TQAsciiBucket*)n->getNext(); - if ( copyk ) - delete [] (char *)n->getKey(); - deleteItem( n->getData() ); - delete n; - n = next; - } - } - break; - case IntKey: - { - TQIntBucket *n=(TQIntBucket *)vec[j]; - while ( n ) { - TQIntBucket *next = (TQIntBucket*)n->getNext(); - deleteItem( n->getData() ); - delete n; - n = next; - } - } - break; - case PtrKey: - { - TQPtrBucket *n=(TQPtrBucket *)vec[j]; - while ( n ) { - TQPtrBucket *next = (TQPtrBucket*)n->getNext(); - deleteItem( n->getData() ); - delete n; - n = next; - } - } - break; - } - vec[j] = 0; // detach list of buckets - } - } - if ( iterators && iterators->count() ) { // invalidate all iterators - TQGDictIterator *i = iterators->first(); - while ( i ) { - i->curNode = 0; - i = iterators->next(); - } - } -} - -/*! - Outputs debug statistics. -*/ -void TQGDict::statistics() const -{ -#if defined(QT_DEBUG) - TQString line; - line.fill( '-', 60 ); - double real, ideal; - tqDebug( "%s", line.ascii() ); - tqDebug( "DICTIONARY STATISTICS:" ); - if ( count() == 0 ) { - tqDebug( "Empty!" ); - tqDebug( "%s", line.ascii() ); - return; - } - real = 0.0; - ideal = (float)count()/(2.0*size())*(count()+2.0*size()-1); - uint i = 0; - while ( igetNext(); - } - real = real + (double)b * ((double)b+1.0)/2.0; - char buf[80], *pbuf; - if ( b > 78 ) - b = 78; - pbuf = buf; - while ( b-- ) - *pbuf++ = '*'; - *pbuf = '\0'; - tqDebug( "%s", buf ); - i++; - } - tqDebug( "Array size = %d", size() ); - tqDebug( "# items = %d", count() ); - tqDebug( "Real dist = %g", real ); - tqDebug( "Rand dist = %g", ideal ); - tqDebug( "Real/Rand = %g", real/ideal ); - tqDebug( "%s", line.ascii() ); -#endif // QT_DEBUG -} - - -/***************************************************************************** - TQGDict stream functions - *****************************************************************************/ -#ifndef TQT_NO_DATASTREAM -TQDataStream &operator>>( TQDataStream &s, TQGDict &dict ) -{ - return dict.read( s ); -} - -TQDataStream &operator<<( TQDataStream &s, const TQGDict &dict ) -{ - return dict.write( s ); -} - -#if defined(Q_CC_DEC) && defined(__alpha) && (__DECCXX_VER-0 >= 50190001) -#pragma message disable narrowptr -#endif - -/*! - Reads a dictionary from the stream \a s. -*/ - -TQDataStream &TQGDict::read( TQDataStream &s ) -{ - uint num; - s >> num; // read number of items - clear(); // clear dict - while ( num-- ) { // read all items - Item d; - switch ( keytype ) { - case StringKey: - { - TQString k; - s >> k; - read( s, d ); - look_string( k, d, op_insert ); - } - break; - case AsciiKey: - { - char *k; - s >> k; - read( s, d ); - look_ascii( k, d, op_insert ); - if ( copyk ) - delete [] k; - } - break; - case IntKey: - { - TQ_UINT32 k; - s >> k; - read( s, d ); - look_int( k, d, op_insert ); - } - break; - case PtrKey: - { - TQ_UINT32 k; - s >> k; - read( s, d ); - // ### cannot insert 0 - this renders the thing - // useless since all pointers are written as 0, - // but hey, serializing pointers? can it be done - // at all, ever? - if ( k ) - look_ptr( (void *)k, d, op_insert ); - } - break; - } - } - return s; -} - -/*! - Writes the dictionary to the stream \a s. -*/ - -TQDataStream& TQGDict::write( TQDataStream &s ) const -{ - s << count(); // write number of items - uint i = 0; - while ( igetKey(); - break; - case AsciiKey: - s << ((TQAsciiBucket*)n)->getKey(); - break; - case IntKey: - s << (TQ_UINT32)((TQIntBucket*)n)->getKey(); - break; - case PtrKey: - s << (TQ_UINT32)0; // ### cannot serialize a pointer - break; - } - write( s, n->getData() ); // write data - n = n->getNext(); - } - i++; - } - return s; -} -#endif //TQT_NO_DATASTREAM - -/***************************************************************************** - TQGDictIterator member functions - *****************************************************************************/ - -/*! - \class TQGDictIterator ntqgdict.h - \reentrant - \ingroup collection - \brief The TQGDictIterator class is an internal class for implementing TQDictIterator and TQIntDictIterator. - - \internal - - TQGDictIterator is a strictly internal class that does the heavy work for - TQDictIterator and TQIntDictIterator. -*/ - -/*! - Constructs an iterator that operates on the dictionary \a d. -*/ - -TQGDictIterator::TQGDictIterator( const TQGDict &d ) -{ - dict = (TQGDict *)&d; // get reference to dict - toFirst(); // set to first noe - if ( !dict->iterators ) { - dict->iterators = new TQGDItList; // create iterator list - TQ_CHECK_PTR( dict->iterators ); - } - dict->iterators->append( this ); // attach iterator to dict -} - -/*! - Constructs a copy of the iterator \a it. -*/ - -TQGDictIterator::TQGDictIterator( const TQGDictIterator &it ) -{ - dict = it.dict; - curNode = it.curNode; - curIndex = it.curIndex; - if ( dict ) - dict->iterators->append( this ); // attach iterator to dict -} - -/*! - Assigns a copy of the iterator \a it and returns a reference to this - iterator. -*/ - -TQGDictIterator &TQGDictIterator::operator=( const TQGDictIterator &it ) -{ - if ( dict ) // detach from old dict - dict->iterators->removeRef( this ); - dict = it.dict; - curNode = it.curNode; - curIndex = it.curIndex; - if ( dict ) - dict->iterators->append( this ); // attach to new list - return *this; -} - -/*! - Destroys the iterator. -*/ - -TQGDictIterator::~TQGDictIterator() -{ - if ( dict ) // detach iterator from dict - dict->iterators->removeRef( this ); -} - - -/*! - Sets the iterator to point to the first item in the dictionary. -*/ - -TQPtrCollection::Item TQGDictIterator::toFirst() -{ - if ( !dict ) { -#if defined(QT_CHECK_NULL) - tqWarning( "TQGDictIterator::toFirst: Dictionary has been deleted" ); -#endif - return 0; - } - if ( dict->count() == 0 ) { // empty dictionary - curNode = 0; - return 0; - } - uint i = 0; - TQBaseBucket **v = dict->vec; - while ( !(*v++) ) - i++; - curNode = dict->vec[i]; - curIndex = i; - return curNode->getData(); -} - - -/*! - Moves to the next item (postfix). -*/ - -TQPtrCollection::Item TQGDictIterator::operator()() -{ - if ( !dict ) { -#if defined(QT_CHECK_NULL) - tqWarning( "TQGDictIterator::operator(): Dictionary has been deleted" ); -#endif - return 0; - } - if ( !curNode ) - return 0; - TQPtrCollection::Item d = curNode->getData(); - this->operator++(); - return d; -} - -/*! - Moves to the next item (prefix). -*/ - -TQPtrCollection::Item TQGDictIterator::operator++() -{ - if ( !dict ) { -#if defined(QT_CHECK_NULL) - tqWarning( "TQGDictIterator::operator++: Dictionary has been deleted" ); -#endif - return 0; - } - if ( !curNode ) - return 0; - curNode = curNode->getNext(); - if ( !curNode ) { // no next bucket - uint i = curIndex + 1; // look from next vec element - TQBaseBucket **v = &dict->vec[i]; - while ( i < dict->size() && !(*v++) ) - i++; - if ( i == dict->size() ) { // nothing found - curNode = 0; - return 0; - } - curNode = dict->vec[i]; - curIndex = i; - } - return curNode->getData(); -} - -/*! - Moves \a jumps positions forward. -*/ - -TQPtrCollection::Item TQGDictIterator::operator+=( uint jumps ) -{ - while ( curNode && jumps-- ) - operator++(); - return curNode ? curNode->getData() : 0; -} diff --git a/src/tools/qglist.cpp b/src/tools/qglist.cpp deleted file mode 100644 index 7ffa66d4d..000000000 --- a/src/tools/qglist.cpp +++ /dev/null @@ -1,1566 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQGList and TQGListIterator classes -** -** Created : 920624 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqglist.h" -#include "ntqgvector.h" -#include "tqdatastream.h" -#include "tqvaluelist.h" - -#if defined(TQT_THREAD_SUPPORT) - #include "tqmutex.h" -#endif // defined(TQT_THREAD_SUPPORT) - -/*! - \class TQLNode ntqglist.h - \reentrant - \ingroup collection - \brief The TQLNode class is an internal class for the TQPtrList template collection. - - \internal - - TQLNode is a doubly-linked list node. It has three pointers: - \list 1 - \i Pointer to the previous node. - \i Pointer to the next node. - \i Pointer to the actual data. - \endlist - - It might sometimes be practical to have direct access to the list nodes - in a TQPtrList, but it is seldom required. - - Be very careful if you want to access the list nodes. The heap can - easily get corrupted if you make a mistake. - - \sa TQPtrList::currentNode(), TQPtrList::removeNode(), TQPtrList::takeNode() -*/ - -/*! - \fn TQPtrCollection::Item TQLNode::getData() - Returns a pointer (\c void*) to the actual data in the list node. -*/ - - -/*! - \class TQGList ntqglist.h - \reentrant - \ingroup collection - \brief The TQGList class is an internal class for implementing TQt collection classes. - - \internal - - TQGList is a strictly internal class that acts as a base class for - several collection classes; TQPtrList, TQPtrQueue and TQPtrStack. - - TQGList has some virtual functions that can be reimplemented to - customize the subclasses, namely compareItems(), read() and - write. Normally, you do not have to reimplement any of these - functions. If you still want to reimplement them, see the TQStrList - class (tqstrlist.h) for an example. -*/ - - -/* Internal helper class for TQGList. Contains some optimization for - the typically case where only one iterators is activre on the list. - */ -class TQGListIteratorList -{ -public: - TQGListIteratorList() - : list(0), iterator(0) { - } - ~TQGListIteratorList() { - notifyClear( TRUE ); - delete list; - } - - void add( TQGListIterator* i ) { - if ( !iterator ) { - iterator = i; - } else if ( list ) { - list->push_front( i ); - } else { - list = new TQValueList; - list->push_front( i ); - } - } - - void remove( TQGListIterator* i ) { - if ( iterator == i ) { - iterator = 0; - } else if ( list ) { - list->remove( i ); - if ( list->isEmpty() ) { - delete list; - list = 0; - } - } - } - - void notifyClear( bool zeroList ) { - if ( iterator ) { - if ( zeroList ) - iterator->list = 0; - iterator->curNode = 0; - } - if ( list ) { - for ( TQValueList::Iterator i = list->begin(); i != list->end(); ++i ) { - if ( zeroList ) - (*i)->list = 0; - (*i)->curNode = 0; - } - } - } - - void notifyRemove( TQLNode* n, TQLNode* curNode ) { - if ( iterator ) { - if ( iterator->curNode == n ) - iterator->curNode = curNode; - } - if ( list ) { - for ( TQValueList::Iterator i = list->begin(); i != list->end(); ++i ) { - if ( (*i)->curNode == n ) - (*i)->curNode = curNode; - } - } - } - -private: - TQValueList* list; - TQGListIterator* iterator; -}; - - - -/***************************************************************************** - Default implementation of virtual functions - *****************************************************************************/ - -/*! - Documented as TQPtrList::compareItems(). - - Compares \a item1 with \a item2. -*/ -int TQGList::compareItems( TQPtrCollection::Item item1, TQPtrCollection::Item item2 ) -{ - return item1 != item2; // compare pointers -} - -#ifndef TQT_NO_DATASTREAM -/*! - \overload - Reads a collection/list item from the stream \a s and returns a reference - to the stream. - - The default implementation sets \a item to 0. - - \sa write() -*/ - -TQDataStream &TQGList::read( TQDataStream &s, TQPtrCollection::Item &item ) -{ - item = 0; - return s; -} - -/*! - \overload - Writes a collection/list item to the stream \a s and - returns a reference to the stream. - - The default implementation does nothing. - - \sa read() -*/ - -TQDataStream &TQGList::write( TQDataStream &s, TQPtrCollection::Item ) const -{ - return s; -} -#endif // TQT_NO_DATASTREAM - -/***************************************************************************** - TQGList member functions - *****************************************************************************/ - -/*! - Constructs an empty list. -*/ - -TQGList::TQGList() -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex = new TQMutex(true); -#endif - firstNode = lastNode = curNode = 0; // initialize list - numNodes = 0; - curIndex = -1; - iterators = 0; // initialize iterator list -} - -/*! - Constructs a copy of \a list. -*/ - -TQGList::TQGList( const TQGList & list ) - : TQPtrCollection( list ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex = new TQMutex(true); -#endif - firstNode = lastNode = curNode = 0; // initialize list - numNodes = 0; - curIndex = -1; - iterators = 0; // initialize iterator list - TQLNode *n = list.firstNode; - while ( n ) { // copy all items from list - append( n->data ); - n = n->next; - } -} - -/*! - Removes all items from the list and destroys the list. -*/ - -TQGList::~TQGList() -{ - clear(); - delete iterators; - // Workaround for GCC 2.7.* bug. Compiler constructs 'static' TQGList - // instances twice on the same address and therefore tries to destruct - // twice on the same address! This is insane but let's try not to crash - // here. - iterators = 0; -#if defined(TQT_THREAD_SUPPORT) - //delete mutex; -#endif -} - - -/*! - Assigns \a list to this list. -*/ - -TQGList& TQGList::operator=( const TQGList &list ) -{ - if ( &list == this ) - return *this; - - clear(); - if ( list.count() > 0 ) { - TQLNode *n = list.firstNode; - while ( n ) { // copy all items from list - append( n->data ); - n = n->next; - } - curNode = firstNode; - curIndex = 0; - } - return *this; -} - -/*! - Compares this list with \a list. Returns TRUE if the lists - contain the same data, otherwise FALSE. -*/ - -bool TQGList::operator==( const TQGList &list ) const -{ - if ( count() != list.count() ) { - return FALSE; - } - - if ( count() == 0 ) { - return TRUE; - } - - TQLNode *n1 = firstNode; - TQLNode *n2 = list.firstNode; - while ( n1 && n2 ) { - // should be mutable - if ( ( (TQGList*)this )->compareItems( n1->data, n2->data ) != 0 ) - return FALSE; - n1 = n1->next; - n2 = n2->next; - } - - return TRUE; -} - -/*! - \fn uint TQGList::count() const - - Returns the number of items in the list. -*/ - - -/*! - Returns the node at position \a index. Sets this node to current. -*/ - -TQLNode *TQGList::locate( uint index ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - if ( index == (uint)curIndex ) { // current node ? -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return curNode; - } - if ( !curNode && firstNode ) { // set current node - curNode = firstNode; - curIndex = 0; - } - TQLNode *node; - int distance = index - curIndex; // node distance to cur node - bool forward; // direction to traverse - - if ( index >= numNodes ) { -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return 0; - } - - if ( distance < 0 ) { - distance = -distance; - } - if ( (uint)distance < index && (uint)distance < numNodes - index ) { - node = curNode; // start from current node - forward = index > (uint)curIndex; - } else if ( index < numNodes - index ) { // start from first node - node = firstNode; - distance = index; - forward = TRUE; - } else { // start from last node - node = lastNode; - distance = numNodes - index - 1; - if ( distance < 0 ) - distance = 0; - forward = FALSE; - } - if ( forward ) { // now run through nodes - while ( distance-- ) { - node = node->next; - } - } else { - while ( distance-- ) { - node = node->prev; - } - } - curIndex = index; // must update index -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return curNode = node; -} - - -/*! - Inserts item \a d at its sorted position in the list. -*/ - -void TQGList::inSort( TQPtrCollection::Item d ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - int index = 0; - TQLNode *n = firstNode; - while ( n && compareItems(n->data,d) < 0 ){ // find position in list - n = n->next; - index++; - } - insertAt( index, d ); -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif -} - - -/*! - Inserts item \a d at the start of the list. -*/ - -void TQGList::prepend( TQPtrCollection::Item d ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - TQLNode *n = new TQLNode( newItem(d) ); - TQ_CHECK_PTR( n ); - n->prev = 0; - if ( (n->next = firstNode) ) // list is not empty - firstNode->prev = n; - else // initialize list - lastNode = n; - firstNode = curNode = n; // curNode affected - numNodes++; - curIndex = 0; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif -} - - -/*! - Inserts item \a d at the end of the list. -*/ - -void TQGList::append( TQPtrCollection::Item d ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - TQLNode *n = new TQLNode( newItem(d) ); - TQ_CHECK_PTR( n ); - n->next = 0; - if ( (n->prev = lastNode) ) { // list is not empty - lastNode->next = n; - } - else { // initialize list - firstNode = n; - } - lastNode = curNode = n; // curNode affected - curIndex = numNodes; - numNodes++; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif -} - - -/*! - Inserts item \a d at position \a index in the list. -*/ - -bool TQGList::insertAt( uint index, TQPtrCollection::Item d ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - if ( index == 0 ) { - prepend( d ); -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return TRUE; - } - else if ( index == numNodes ) { - append( d ); -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return TRUE; - } - TQLNode *nextNode = locate( index ); - if ( !nextNode ) { -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return FALSE; - } - TQLNode *prevNode = nextNode->prev; - TQLNode *n = new TQLNode( newItem(d) ); - TQ_CHECK_PTR( n ); - nextNode->prev = n; - Q_ASSERT( (!((curIndex > 0) && (!prevNode))) ); - prevNode->next = n; - n->prev = prevNode; // link new node into list - n->next = nextNode; - curNode = n; // curIndex set by locate() - numNodes++; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return TRUE; -} - - -/*! - Relinks node \a n and makes it the first node in the list. -*/ - -void TQGList::relinkNode( TQLNode *n ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - if ( n == firstNode ) { // already first -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return; - } - curNode = n; - unlink(); - n->prev = 0; - if ( (n->next = firstNode) ) { // list is not empty - firstNode->prev = n; - } - else { // initialize list - lastNode = n; - } - firstNode = curNode = n; // curNode affected - numNodes++; - curIndex = 0; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif -} - - -/*! - Unlinks the current list node and returns a pointer to this node. -*/ - -TQLNode *TQGList::unlink() -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - if ( curNode == 0 ) { // null current node -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return 0; - } - TQLNode *n = curNode; // unlink this node - if ( n == firstNode ) { // removing first node ? - if ( (firstNode = n->next) ) { - firstNode->prev = 0; - } else { - lastNode = curNode = 0; // list becomes empty - curIndex = -1; - } - } else { - if ( n == lastNode ) { // removing last node ? - lastNode = n->prev; - lastNode->next = 0; - } else { // neither last nor first node - n->prev->next = n->next; - n->next->prev = n->prev; - } - } - - if ( n->next ) { // change current node - curNode = n->next; - } else if ( n->prev ) { - curNode = n->prev; - curIndex--; - } - - if ( iterators ) { - iterators->notifyRemove( n, curNode ); - } - numNodes--; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return n; -} - - -/*! - Removes the node \a n from the list. -*/ - -bool TQGList::removeNode( TQLNode *n ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif -#if defined(QT_CHECK_NULL) - if ( n == 0 || (n->prev && n->prev->next != n) || - (n->next && n->next->prev != n) ) { - tqWarning( "TQGList::removeNode: Corrupted node" ); - return FALSE; - } -#endif - curNode = n; - unlink(); // unlink node - deleteItem( n->data ); // deallocate this node - delete n; - curNode = firstNode; - curIndex = curNode ? 0 : -1; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return TRUE; -} - -/*! - Removes the item \a d from the list. Uses compareItems() to find the item. - - If \a d is 0, removes the current item. -*/ - -bool TQGList::remove( TQPtrCollection::Item d ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - if ( d && find(d) == -1 ) { -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return FALSE; - } - TQLNode *n = unlink(); - if ( !n ) { -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return FALSE; - } - deleteItem( n->data ); - delete n; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return TRUE; -} - -/*! - Removes the item \a d from the list. -*/ - -bool TQGList::removeRef( TQPtrCollection::Item d ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - if ( findRef(d) == -1 ) { -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return FALSE; - } - TQLNode *n = unlink(); - if ( !n ) { -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return FALSE; - } - deleteItem( n->data ); - delete n; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return TRUE; -} - -/*! - \fn bool TQGList::removeFirst() - - Removes the first item in the list. -*/ - -/*! - \fn bool TQGList::removeLast() - - Removes the last item in the list. -*/ - -/*! - Removes the item at position \a index from the list. -*/ - -bool TQGList::removeAt( uint index ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - if ( !locate(index) ) { -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return FALSE; - } - TQLNode *n = unlink(); - if ( !n ) { -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return FALSE; - } - deleteItem( n->data ); - delete n; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return TRUE; -} - - -/*! - Replaces the item at index \a index with \a d. -*/ -bool TQGList::replaceAt( uint index, TQPtrCollection::Item d ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - TQLNode *n = locate( index ); - if ( !n ) { -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return FALSE; - } - if ( n->data != d ) { - deleteItem( n->data ); - n->data = newItem( d ); - } -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return TRUE; -} - - - -/*! - Takes the node \a n out of the list. -*/ - -TQPtrCollection::Item TQGList::takeNode( TQLNode *n ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif -#if defined(QT_CHECK_NULL) - if ( n == 0 || (n->prev && n->prev->next != n) || - (n->next && n->next->prev != n) ) { - tqWarning( "TQGList::takeNode: Corrupted node" ); -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return 0; - } -#endif - curNode = n; - unlink(); // unlink node - Item d = n->data; - delete n; // delete the node, not data - curNode = firstNode; - curIndex = curNode ? 0 : -1; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return d; -} - -/*! - Takes the current item out of the list. -*/ - -TQPtrCollection::Item TQGList::take() -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - TQLNode *n = unlink(); // unlink node - Item d = n ? n->data : 0; - delete n; // delete node, keep contents -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return d; -} - -/*! - Takes the item at position \a index out of the list. -*/ - -TQPtrCollection::Item TQGList::takeAt( uint index ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - if ( !locate(index) ) { -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return 0; - } - TQLNode *n = unlink(); // unlink node - Item d = n ? n->data : 0; - delete n; // delete node, keep contents -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return d; -} - -/*! - Takes the first item out of the list. -*/ - -TQPtrCollection::Item TQGList::takeFirst() -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - first(); - TQLNode *n = unlink(); // unlink node - Item d = n ? n->data : 0; - delete n; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return d; -} - -/*! - Takes the last item out of the list. -*/ - -TQPtrCollection::Item TQGList::takeLast() -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - last(); - TQLNode *n = unlink(); // unlink node - Item d = n ? n->data : 0; - delete n; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return d; -} - - -/*! - Removes all items from the list. -*/ - -void TQGList::clear() -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - TQLNode *n = firstNode; - - firstNode = lastNode = curNode = 0; // initialize list - numNodes = 0; - curIndex = -1; - - if ( iterators ) { - iterators->notifyClear( FALSE ); - } - - TQLNode *prevNode; - while ( n ) { // for all nodes ... - deleteItem( n->data ); // deallocate data - prevNode = n; - n = n->next; - delete prevNode; // deallocate node - } -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif -} - - -/*! - Finds item \a d in the list. If \a fromStart is TRUE the search - begins at the first node; otherwise it begins at the current node. -*/ - -int TQGList::findRef( TQPtrCollection::Item d, bool fromStart ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - TQLNode *n; - int index; - if ( fromStart ) { // start from first node - n = firstNode; - index = 0; - } else { // start from current node - n = curNode; - index = curIndex; - } - while ( n && n->data != d ) { // find exact match - n = n->next; - index++; - } - curNode = n; - curIndex = n ? index : -1; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return curIndex; // return position of item -} - -/*! - Finds item \a d in the list using compareItems(). If \a fromStart is - TRUE the search begins at the first node; otherwise it begins at the - current node. -*/ - -int TQGList::find( TQPtrCollection::Item d, bool fromStart ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - TQLNode *n; - int index; - if ( fromStart ) { // start from first node - n = firstNode; - index = 0; - } else { // start from current node - n = curNode; - index = curIndex; - } - while ( n && compareItems(n->data,d) ){ // find equal match - n = n->next; - index++; - } - curNode = n; - curIndex = n ? index : -1; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return curIndex; // return position of item -} - - -/*! - Counts the number item \a d occurs in the list. -*/ - -uint TQGList::containsRef( TQPtrCollection::Item d ) const -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - TQLNode *n = firstNode; - uint count = 0; - while ( n ) { // for all nodes... - if ( n->data == d ) // count # exact matches - count++; - n = n->next; - } -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return count; -} - -/*! - Counts the number of times item \a d occurs in the list. Uses - compareItems(). -*/ - -uint TQGList::contains( TQPtrCollection::Item d ) const -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - TQLNode *n = firstNode; - uint count = 0; - TQGList *that = (TQGList*)this; // mutable for compareItems() - while ( n ) { // for all nodes... - if ( !that->compareItems(n->data,d) ) // count # equal matches - count++; - n = n->next; - } -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return count; -} - - -/*! - \overload TQPtrCollection::Item TQGList::at( uint index ) - - Sets the item at position \a index to the current item. -*/ - -/*! - \fn int TQGList::at() const - - Returns the current index. -*/ - -/*! - \fn TQLNode *TQGList::currentNode() const - - Returns the current node. -*/ - -/*! - \fn TQPtrCollection::Item TQGList::get() const - - Returns the current item. -*/ - -/*! - \fn TQPtrCollection::Item TQGList::cfirst() const - - Returns the first item in the list. -*/ - -/*! - \fn TQPtrCollection::Item TQGList::clast() const - - Returns the last item in the list. -*/ - - -/*! - Returns the first list item. Sets this to current. -*/ - -TQPtrCollection::Item TQGList::first() -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - if ( firstNode ) { - curIndex = 0; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return (curNode=firstNode)->data; - } -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return 0; -} - -/*! - Returns the last list item. Sets this to current. -*/ - -TQPtrCollection::Item TQGList::last() -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - if ( lastNode ) { - curIndex = numNodes-1; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return (curNode=lastNode)->data; - } -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return 0; -} - -/*! - Returns the next list item (after current). Sets this to current. -*/ - -TQPtrCollection::Item TQGList::next() -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - if ( curNode ) { - if ( curNode->next ) { - curIndex++; - curNode = curNode->next; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return curNode->data; - } - curIndex = -1; - curNode = 0; - } -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return 0; -} - -/*! - Returns the previous list item (before current). Sets this to current. -*/ - -TQPtrCollection::Item TQGList::prev() -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - if ( curNode ) { - if ( curNode->prev ) { - curIndex--; - curNode = curNode->prev; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return curNode->data; - } - curIndex = -1; - curNode = 0; - } -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return 0; -} - - -/*! - Converts the list to a vector, \a vector. -*/ - -void TQGList::toVector( TQGVector *vector ) const -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - vector->clear(); - if ( !vector->resize( count() ) ) { -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return; - } - TQLNode *n = firstNode; - uint i = 0; - while ( n ) { - vector->insert( i, n->data ); - n = n->next; - i++; - } -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif -} - -void TQGList::heapSortPushDown( TQPtrCollection::Item* heap, int first, int last ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - int r = first; - while( r <= last/2 ) { - // Node r has only one child ? - if ( last == 2*r ) { - // Need for swapping ? - if ( compareItems( heap[r], heap[ 2*r ] ) > 0 ) { - TQPtrCollection::Item tmp = heap[r]; - heap[ r ] = heap[ 2*r ]; - heap[ 2*r ] = tmp; - } - // That's it ... - r = last; - } else { - // Node has two children - if ( compareItems( heap[r], heap[ 2*r ] ) > 0 && - compareItems( heap[ 2*r ], heap[ 2*r+1 ] ) <= 0 ) { - // Swap with left child - TQPtrCollection::Item tmp = heap[r]; - heap[ r ] = heap[ 2*r ]; - heap[ 2*r ] = tmp; - r *= 2; - } else if ( compareItems( heap[r], heap[ 2*r+1 ] ) > 0 && - compareItems( heap[ 2*r+1 ], heap[ 2*r ] ) < 0 ) { - // Swap with right child - TQPtrCollection::Item tmp = heap[r]; - heap[ r ] = heap[ 2*r+1 ]; - heap[ 2*r+1 ] = tmp; - r = 2*r+1; - } else { - // We are done - r = last; - } - } - } -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif -} - - -/*! Sorts the list by the result of the virtual compareItems() function. - - The Heap-Sort algorithm is used for sorting. It sorts n items with - O(n*log n) compares. This is the asymptotic optimal solution of the - sorting problem. -*/ - -void TQGList::sort() -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - uint n = count(); - if ( n < 2 ) { -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return; - } - - // Create the heap - TQPtrCollection::Item* realheap = new TQPtrCollection::Item[ n ]; - // Wow, what a fake. But I want the heap to be indexed as 1...n - TQPtrCollection::Item* heap = realheap - 1; - int size = 0; - TQLNode* insert = firstNode; - for( ; insert != 0; insert = insert->next ) { - heap[++size] = insert->data; - int i = size; - while( i > 1 && compareItems( heap[i], heap[ i / 2 ] ) < 0 ) { - TQPtrCollection::Item tmp = heap[ i ]; - heap[ i ] = heap[ i/2 ]; - heap[ i/2 ] = tmp; - i /= 2; - } - } - - insert = firstNode; - // Now do the sorting - for ( int i = n; i > 0; i-- ) { - insert->data = heap[1]; - insert = insert->next; - if ( i > 1 ) { - heap[1] = heap[i]; - heapSortPushDown( heap, 1, i - 1 ); - } - } - - delete [] realheap; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif -} - - -/***************************************************************************** - TQGList stream functions - *****************************************************************************/ - -#ifndef TQT_NO_DATASTREAM -TQDataStream &operator>>( TQDataStream &s, TQGList &list ) -{ // read list - return list.read( s ); -} - -TQDataStream &operator<<( TQDataStream &s, const TQGList &list ) -{ // write list - return list.write( s ); -} - -/*! - Reads a list from the stream \a s. -*/ - -TQDataStream &TQGList::read( TQDataStream &s ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - uint num; - s >> num; // read number of items - clear(); // clear list - while ( num-- ) { // read all items - Item d; - read( s, d ); - TQ_CHECK_PTR( d ); - if ( !d ) // no memory - break; - TQLNode *n = new TQLNode( d ); - TQ_CHECK_PTR( n ); - if ( !n ) // no memory - break; - n->next = 0; - if ( (n->prev = lastNode) ) // list is not empty - lastNode->next = n; - else // initialize list - firstNode = n; - lastNode = n; - numNodes++; - } - curNode = firstNode; - curIndex = curNode ? 0 : -1; -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return s; -} - -/*! - Writes the list to the stream \a s. -*/ - -TQDataStream &TQGList::write( TQDataStream &s ) const -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - s << count(); // write number of items - TQLNode *n = firstNode; - while ( n ) { // write all items - write( s, n->data ); - n = n->next; - } -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return s; -} - -#endif // TQT_NO_DATASTREAM - - - -/*! \internal - */ -TQLNode* TQGList::erase( TQLNode* it ) -{ -#if defined(TQT_THREAD_SUPPORT) - //mutex->lock(); -#endif - TQLNode* n = it; - it = it->next; - removeNode( n ); -#if defined(TQT_THREAD_SUPPORT) - //mutex->unlock(); -#endif - return it; -} - - -/***************************************************************************** - TQGListIterator member functions - *****************************************************************************/ - -/*! - \class TQGListIterator ntqglist.h - \reentrant - \ingroup collection - \brief The TQGListIterator class is an internal class for implementing TQPtrListIterator. - - \internal - - TQGListIterator is a strictly internal class that does the heavy work for - TQPtrListIterator. -*/ - -/*! - \internal - Constructs an iterator that operates on the list \a l. -*/ - -TQGListIterator::TQGListIterator( const TQGList &l ) -{ - list = (TQGList *)&l; // get reference to list - curNode = list->firstNode; // set to first node - if ( !list->iterators ) { - list->iterators = new TQGListIteratorList; // create iterator list - TQ_CHECK_PTR( list->iterators ); - } - list->iterators->add( this ); // attach iterator to list -} - -/*! - \internal - Constructs a copy of the iterator \a it. -*/ - -TQGListIterator::TQGListIterator( const TQGListIterator &it ) -{ - list = it.list; - curNode = it.curNode; - if ( list ) - list->iterators->add( this ); // attach iterator to list -} - -/*! - \internal - Assigns a copy of the iterator \a it and returns a reference to this - iterator. -*/ - -TQGListIterator &TQGListIterator::operator=( const TQGListIterator &it ) -{ - if ( list ) // detach from old list - list->iterators->remove( this ); - list = it.list; - curNode = it.curNode; - if ( list ) - list->iterators->add( this ); // attach to new list - return *this; -} - -/*! - \internal - Destroys the iterator. -*/ - -TQGListIterator::~TQGListIterator() -{ - if ( list ) // detach iterator from list - list->iterators->remove(this); -} - - -/*! - \fn bool TQGListIterator::atFirst() const - \internal - Returns TRUE if the iterator points to the first item, otherwise FALSE. -*/ - -/*! - \fn bool TQGListIterator::atLast() const - \internal - Returns TRUE if the iterator points to the last item, otherwise FALSE. -*/ - - -/*! - \internal - Sets the list iterator to point to the first item in the list. -*/ - -TQPtrCollection::Item TQGListIterator::toFirst() -{ - if ( !list ) { -#if defined(QT_CHECK_NULL) - tqWarning( "TQGListIterator::toFirst: List has been deleted" ); -#endif - return 0; - } - return list->firstNode ? (curNode = list->firstNode)->getData() : 0; -} - -/*! - \internal - Sets the list iterator to point to the last item in the list. -*/ - -TQPtrCollection::Item TQGListIterator::toLast() -{ - if ( !list ) { -#if defined(QT_CHECK_NULL) - tqWarning( "TQGListIterator::toLast: List has been deleted" ); -#endif - return 0; - } - return list->lastNode ? (curNode = list->lastNode)->getData() : 0; -} - - -/*! - \fn TQPtrCollection::Item TQGListIterator::get() const - \internal - Returns the iterator item. -*/ - - -/*! - \internal - Moves to the next item (postfix). -*/ - -TQPtrCollection::Item TQGListIterator::operator()() -{ - if ( !curNode ) - return 0; - TQPtrCollection::Item d = curNode->getData(); - curNode = curNode->next; - return d; -} - -/*! - \internal - Moves to the next item (prefix). -*/ - -TQPtrCollection::Item TQGListIterator::operator++() -{ - if ( !curNode ) - return 0; - curNode = curNode->next; - return curNode ? curNode->getData() : 0; -} - -/*! - \internal - Moves \a jumps positions forward. -*/ - -TQPtrCollection::Item TQGListIterator::operator+=( uint jumps ) -{ - while ( curNode && jumps-- ) - curNode = curNode->next; - return curNode ? curNode->getData() : 0; -} - -/*! - \internal - Moves to the previous item (prefix). -*/ - -TQPtrCollection::Item TQGListIterator::operator--() -{ - if ( !curNode ) - return 0; - curNode = curNode->prev; - return curNode ? curNode->getData() : 0; -} - -/*! - \internal - Moves \a jumps positions backward. -*/ - -TQPtrCollection::Item TQGListIterator::operator-=( uint jumps ) -{ - while ( curNode && jumps-- ) - curNode = curNode->prev; - return curNode ? curNode->getData() : 0; -} diff --git a/src/tools/qglobal.cpp b/src/tools/qglobal.cpp deleted file mode 100644 index 5e9f38a8a..000000000 --- a/src/tools/qglobal.cpp +++ /dev/null @@ -1,889 +0,0 @@ -/**************************************************************************** -** -** Global functions -** -** Created : 920604 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "qplatformdefs.h" - -#include "tqasciidict.h" -#include -#include -#include -#include -#include -#include - -#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) && !defined(Q_OS_TEMP) -#include -#endif - - -/*! - \relates TQApplication - - Returns the TQt version number as a string, for example, "2.3.0" or - "3.0.5". - - The \c TQT_VERSION define has the numeric value in the form: - 0xmmiibb (m = major, i = minor, b = bugfix). For example, TQt - 3.0.5's \c TQT_VERSION is 0x030005. -*/ - -const char *tqVersion() -{ - return TQT_VERSION_STR; -} - -bool tqSharedBuild() -{ -#ifdef QT_SHARED - return TRUE; -#else - return FALSE; -#endif -} - -/***************************************************************************** - System detection routines - *****************************************************************************/ - -static bool si_alreadyDone = FALSE; -static int si_wordSize; -static bool si_bigEndian; - -/*! - \relates TQApplication - - Obtains information about the system. - - The system's word size in bits (typically 32) is returned in \a - *wordSize. The \a *bigEndian is set to TRUE if this is a big-endian - machine, or to FALSE if this is a little-endian machine. - - In debug mode, this function calls tqFatal() with a message if the - computer is truly weird (i.e. different endianness for 16 bit and - 32 bit integers); in release mode it returns FALSE. -*/ - -bool tqSysInfo( int *wordSize, bool *bigEndian ) -{ -#if defined(QT_CHECK_NULL) - Q_ASSERT( wordSize != 0 ); - Q_ASSERT( bigEndian != 0 ); -#endif - - if ( si_alreadyDone ) { // run it only once - *wordSize = si_wordSize; - *bigEndian = si_bigEndian; - return TRUE; - } - - si_wordSize = 0; - TQ_ULONG n = (TQ_ULONG)(~0); - while ( n ) { // detect word size - si_wordSize++; - n /= 2; - } - *wordSize = si_wordSize; - - if ( *wordSize != 64 && - *wordSize != 32 && - *wordSize != 16 ) { // word size: 16, 32 or 64 -#if defined(QT_CHECK_RANGE) - tqFatal( "qSysInfo: Unsupported system word size %d", *wordSize ); -#endif - return FALSE; - } - if ( sizeof(TQ_INT8) != 1 || sizeof(TQ_INT16) != 2 || sizeof(TQ_INT32) != 4 || - sizeof(TQ_ULONG)*8 != si_wordSize || sizeof(float) != 4 || sizeof(double) != 8 ) { -#if defined(QT_CHECK_RANGE) - tqFatal( "qSysInfo: Unsupported system data type size" ); -#endif - return FALSE; - } - - bool be16, be32; // determine byte ordering - short ns = 0x1234; - int nl = 0x12345678; - - unsigned char *p = (unsigned char *)(&ns); // 16-bit integer - be16 = *p == 0x12; - - p = (unsigned char *)(&nl); // 32-bit integer - if ( p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78 ) - be32 = TRUE; - else - if ( p[0] == 0x78 && p[1] == 0x56 && p[2] == 0x34 && p[3] == 0x12 ) - be32 = FALSE; - else - be32 = !be16; - - if ( be16 != be32 ) { // strange machine! -#if defined(QT_CHECK_RANGE) - tqFatal( "qSysInfo: Inconsistent system byte order" ); -#endif - return FALSE; - } - - *bigEndian = si_bigEndian = be32; - si_alreadyDone = TRUE; - return TRUE; -} - -#if defined(Q_OS_MAC) - -#include "qt_mac.h" - -// This function has descended from Apple Source Code (FSpLocationFromFullPath), -// but changes have been made. [Creates a minimal alias from the full pathname] -OSErr qt_mac_create_fsspec(const TQString &file, FSSpec *spec) -{ - FSRef fref; - TQCString utfs = file.utf8(); - OSErr ret = FSPathMakeRef((const UInt8 *)utfs.data(), &fref, NULL); - if(ret == noErr) - ret = FSGetCatalogInfo(&fref, kFSCatInfoNone, NULL, NULL, spec, NULL); - return ret; -} - -CFStringRef tqstring2cfstring(const TQString &str) -{ - return CFStringCreateWithCharacters(0, (UniChar *)str.unicode(), str.length()); -} - -TQString cfstring2qstring(CFStringRef str) -{ - if(!str) - return TQString(); - - CFIndex length = CFStringGetLength(str); - if(const UniChar *chars = CFStringGetCharactersPtr(str)) - return TQString((TQChar *)chars, length); - UniChar *buffer = (UniChar*)malloc(length * sizeof(UniChar)); - CFStringGetCharacters(str, CFRangeMake(0, length), buffer); - TQString ret((TQChar *)buffer, length); - free(buffer); - return ret; -} - -unsigned char *p_str(const TQString &s) -{ - CFStringRef cfstr = tqstring2cfstring(s); - uchar *p = (uchar*)malloc(256); - CFStringGetPascalString(cfstr, p, 256, CFStringGetSystemEncoding()); - CFRelease(cfstr); - return p; -} - -TQString p2qstring(const unsigned char *c) { - CFStringRef cfstr = CFStringCreateWithPascalString(0, c, CFStringGetSystemEncoding()); - TQString str = cfstring2qstring(cfstr); - CFRelease(cfstr); - return str; -} - -int qMacVersion() -{ - static int macver = TQt::MV_Unknown; - static bool first = TRUE; - if(first) { - first = FALSE; - long gestalt_version; - if(Gestalt(gestaltSystemVersion, &gestalt_version) == noErr) { - macver = ((gestalt_version & 0x00f0) >> 4) + 2; - - } - } - return macver; -} -TQt::MacintoshVersion qt_macver = (TQt::MacintoshVersion)qMacVersion(); - -// HFS+ filesystems use decomposing unicode for certain layers in unicode -// In general these don't look great as a user visible string. -// Therefore it is a good idea to normalize them ourselves. -// These technotes on Apple's website: -// http://developer.apple.com/qa/qa2001/qa1235.html -// http://developer.apple.com/qa/qa2001/qa1173.html -TQString qt_mac_precomposeFileName(const TQString &str) -{ - if (str.isEmpty()) - return str; - int strLength = str.length(); - CFMutableStringRef cfmstr = CFStringCreateMutable(0, strLength); - CFStringAppendCharacters(cfmstr, (UniChar *)str.unicode(), strLength); - CFStringNormalize(cfmstr, kCFStringNormalizationFormC); - TQString newStr = cfstring2qstring(cfmstr); - CFRelease(cfmstr); - return newStr; -} -#elif defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN) || defined(Q_OS_TEMP) -bool qt_winunicode; -# ifdef Q_OS_TEMP - DWORD qt_cever = 0; -# endif // Q_OS_TEMP - -#include "qt_windows.h" - -int qWinVersion() -{ -#ifndef VER_PLATFORM_WIN32s -#define VER_PLATFORM_WIN32s 0 -#endif -#ifndef VER_PLATFORM_WIN32_WINDOWS -#define VER_PLATFORM_WIN32_WINDOWS 1 -#endif -#ifndef VER_PLATFORM_WIN32_NT -#define VER_PLATFORM_WIN32_NT 2 -#endif -#ifndef VER_PLATFORM_WIN32_CE -#define VER_PLATFORM_WIN32_CE 3 -#endif - - static int winver = TQt::WV_NT; - static int t=0; - if ( !t ) { - t=1; -#ifndef Q_OS_TEMP - OSVERSIONINFOA osver; - osver.dwOSVersionInfoSize = sizeof(osver); - GetVersionExA( &osver ); -#else - OSVERSIONINFOW osver; - osver.dwOSVersionInfoSize = sizeof(osver); - GetVersionEx( &osver ); - qt_cever = osver.dwMajorVersion * 100; - qt_cever += osver.dwMinorVersion * 10; -#endif - switch ( osver.dwPlatformId ) { - case VER_PLATFORM_WIN32s: - winver = TQt::WV_32s; - break; - case VER_PLATFORM_WIN32_WINDOWS: - // We treat Windows Me (minor 90) the same as Windows 98 - if ( osver.dwMinorVersion == 90 ) - winver = TQt::WV_Me; - else if ( osver.dwMinorVersion == 10 ) - winver = TQt::WV_98; - else - winver = TQt::WV_95; - break; - case VER_PLATFORM_WIN32_CE: -#ifdef Q_OS_TEMP - if ( qt_cever >= 400 ) - winver = TQt::WV_CENET; - else -#endif - winver = TQt::WV_CE; - break; - default: // VER_PLATFORM_WIN32_NT - if ( osver.dwMajorVersion < 5 ) { - winver = TQt::WV_NT; - } else if (osver.dwMajorVersion == 6) { - winver = TQt::WV_VISTA; - } else if ( osver.dwMinorVersion == 0 ) { - winver = TQt::WV_2000; - } else if ( osver.dwMinorVersion == 1 ) { - winver = TQt::WV_XP; - } else if ( osver.dwMinorVersion == 2 ) { - winver = TQt::WV_2003; - } else { - tqWarning("Untested Windows version detected!"); - winver = TQt::WV_NT_based; - } - } - } - -#if defined(UNICODE) - if ( winver & TQt::WV_NT_based ) - qt_winunicode = TRUE; - else -#endif - qt_winunicode = FALSE; - - return winver; -} - -TQt::WindowsVersion qt_winver = (TQt::WindowsVersion)qWinVersion(); -#endif - - -/***************************************************************************** - Debug output routines - *****************************************************************************/ - -/*! - \fn void tqDebug( const char *msg, ... ) - - \relates TQApplication - - Prints a debug message \a msg, or calls the message handler (if it - has been installed). - - This function takes a format string and a list of arguments, - similar to the C printf() function. - - Example: - \code - tqDebug( "my window handle = %x", myWidget->id() ); - \endcode - - Under X11, the text is printed to stderr. Under Windows, the text - is sent to the debugger. - - \warning The internal buffer is limited to 8196 bytes (including - the '\0'-terminator). - - \warning Passing (const char *)0 as argument to tqDebug might lead - to crashes on certain platforms due to the platforms printf implementation. - - \sa tqWarning(), tqFatal(), qInstallMsgHandler(), - \link debug.html Debugging\endlink -*/ - -/*! - \fn void tqWarning( const char *msg, ... ) - - \relates TQApplication - - Prints a warning message \a msg, or calls the message handler (if - it has been installed). - - This function takes a format string and a list of arguments, - similar to the C printf() function. - - Example: - \code - void f( int c ) - { - if ( c > 200 ) - tqWarning( "f: bad argument, c == %d", c ); - } - \endcode - - Under X11, the text is printed to stderr. Under Windows, the text - is sent to the debugger. - - \warning The internal buffer is limited to 8196 bytes (including - the '\0'-terminator). - - \warning Passing (const char *)0 as argument to tqWarning might lead - to crashes on certain platforms due to the platforms printf implementation. - - \sa tqDebug(), tqFatal(), qInstallMsgHandler(), - \link debug.html Debugging\endlink -*/ - -/*! - \fn void tqFatal( const char *msg, ... ) - - \relates TQApplication - - Prints a fatal error message \a msg and exits, or calls the - message handler (if it has been installed). - - This function takes a format string and a list of arguments, - similar to the C printf() function. - - Example: - \code - int divide( int a, int b ) - { - if ( b == 0 ) // program error - tqFatal( "divide: cannot divide by zero" ); - return a/b; - } - \endcode - - Under X11, the text is printed to stderr. Under Windows, the text - is sent to the debugger. - - \warning The internal buffer is limited to 8196 bytes (including - the '\0'-terminator). - - \warning Passing (const char *)0 as argument to tqFatal might lead - to crashes on certain platforms due to the platforms printf implementation. - - \sa tqDebug(), tqWarning(), qInstallMsgHandler(), - \link debug.html Debugging\endlink -*/ - - -static TQtMsgHandler handler = 0; // pointer to debug handler -static const int QT_BUFFER_LENGTH = 8196; // internal buffer length - - -#ifdef Q_CC_MWERKS - -#include "qt_mac.h" - -extern bool tqt_is_gui_used; -static void mac_default_handler( const char *msg ) -{ - if ( tqt_is_gui_used ) { - const unsigned char *p = p_str(msg); - DebugStr(p); - free((void*)p); - } else { - fprintf( stderr, msg ); - } -} - -#endif - -void handle_buffer(const char *buf, TQtMsgType msgType) -{ - if ( handler ) { - (*handler)( msgType, buf ); - } else if (msgType == TQtFatalMsg) { -#if defined(Q_CC_MWERKS) - mac_default_handler(buf); -#else - fprintf( stderr, "%s\n", buf ); // add newline -#endif -#if defined(Q_OS_UNIX) && defined(QT_DEBUG) - abort(); // trap; generates core dump -#elif defined(Q_OS_TEMP) && defined(QT_DEBUG) - TQString fstr; - fstr.sprintf( "%s:%s %s %s\n", __FILE__, __LINE__, TQT_VERSION_STR, buf ); - OutputDebugString( fstr.ucs2() ); -#elif defined(_CRT_ERROR) && defined(_DEBUG) - _CrtDbgReport( _CRT_ERROR, __FILE__, __LINE__, TQT_VERSION_STR, buf ); -#else - exit( 1 ); // goodbye cruel world -#endif - } else { -#if defined(Q_CC_MWERKS) - mac_default_handler(buf); -#elif defined(Q_OS_TEMP) - TQString fstr( buf ); - OutputDebugString( (fstr + "\n").ucs2() ); -#else - fprintf( stderr, "%s\n", buf ); // add newline -#endif - } -} - -void tqDebug( const TQString &msg ) -{ - char buf[QT_BUFFER_LENGTH]; - strcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").local8Bit() ); - int len = strlen(buf); - strncpy( &buf[len], msg.local8Bit(), QT_BUFFER_LENGTH - len - 1 ); - len += msg.length(); - if (len >= QT_BUFFER_LENGTH) { - len = QT_BUFFER_LENGTH - 1; - } - buf[len] = '\0'; - handle_buffer(buf, TQtDebugMsg); -} - -void tqDebug( const char *msg, ... ) -{ - char buf[QT_BUFFER_LENGTH]; - strcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").local8Bit() ); - int len = strlen(buf); - va_list ap; - va_start( ap, msg ); // use variable arg list -#if defined(QT_VSNPRINTF) - QT_VSNPRINTF( &buf[len], QT_BUFFER_LENGTH-len, msg, ap ); -#else - vsprintf( &buf[len], msg, ap ); -#endif - va_end( ap ); - handle_buffer(buf, TQtDebugMsg); -} - -void tqDebug( const TQCString &s ) -{ - tqDebug("%s", s.data()); -} - -void tqWarning( const TQString &msg ) -{ - char buf[QT_BUFFER_LENGTH]; - strcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").local8Bit() ); - int len = strlen(buf); - strncpy( &buf[len], msg.local8Bit(), QT_BUFFER_LENGTH - len - 1 ); - len += msg.length(); - if (len >= QT_BUFFER_LENGTH) { - len = QT_BUFFER_LENGTH - 1; - } - buf[len] = '\0'; - handle_buffer(buf, TQtWarningMsg); -} - -void tqWarning( const char *msg, ... ) -{ - char buf[QT_BUFFER_LENGTH]; - strcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").local8Bit() ); - int len = strlen(buf); - va_list ap; - va_start( ap, msg ); // use variable arg list -#if defined(QT_VSNPRINTF) - QT_VSNPRINTF( &buf[len], QT_BUFFER_LENGTH-len, msg, ap ); -#else - vsprintf( &buf[len], msg, ap ); -#endif - va_end( ap ); - handle_buffer(buf, TQtWarningMsg); -} - -void tqWarning( const TQCString &s ) -{ - tqWarning("%s", s.data()); -} - -void tqFatal( const TQString &msg ) -{ - char buf[QT_BUFFER_LENGTH]; - strcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").local8Bit() ); - int len = strlen(buf); - strncpy( &buf[len], msg.local8Bit(), QT_BUFFER_LENGTH - len - 1 ); - len += msg.length(); - if (len >= QT_BUFFER_LENGTH) { - len = QT_BUFFER_LENGTH - 1; - } - buf[len] = '\0'; - handle_buffer(buf, TQtFatalMsg); -} - -void tqFatal( const char *msg, ... ) -{ - char buf[QT_BUFFER_LENGTH]; - strcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").local8Bit() ); - int len = strlen(buf); - va_list ap; - va_start( ap, msg ); // use variable arg list -#if defined(QT_VSNPRINTF) - QT_VSNPRINTF( &buf[len], QT_BUFFER_LENGTH-len, msg, ap ); -#else - vsprintf( &buf[len], msg, ap ); -#endif - va_end( ap ); - handle_buffer(buf, TQtFatalMsg); -} - -void tqFatal( const TQCString &s ) -{ - tqWarning("%s", s.data()); -} - -/*! - \relates TQApplication - - Prints the message \a msg and uses \a code to get a system specific - error message. When \a code is -1 (the default), the system's last - error code will be used if possible. Use this method to handle - failures in platform specific API calls. - - This function does nothing when TQt is built with \c TQT_NO_DEBUG - defined. -*/ -void tqSystemWarning( const char* msg, int code ) -{ -#ifndef TQT_NO_DEBUG -#if defined(Q_OS_WIN32) - if ( code == -1 ) - code = GetLastError(); - - if ( !code ) - return; - - unsigned short *string; - QT_WA( { - FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - code, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&string, - 0, - NULL ); - - tqWarning( "%s\n\tError code %d - %s", msg, code, TQString::fromUcs2(string).latin1() ); - }, { - FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - code, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (char*)&string, - 0, - NULL ); - - tqWarning( "%s\n\tError code %d - %s", msg, code, (const char*)string ); - } ); - LocalFree( (HLOCAL)string ); -#else - if ( code != -1 ) - tqWarning( "%s\n\tError code %d - %s", msg, code, strerror( code ) ); - else - tqWarning( "%s", msg ); -#endif -#else - Q_UNUSED( msg ); - Q_UNUSED( code ); -#endif -} - -/*! - \fn void Q_ASSERT( bool test ) - - \relates TQApplication - - Prints a warning message containing the source code file name and - line number if \a test is FALSE. - - This is really a macro defined in \c ntqglobal.h. - - Q_ASSERT is useful for testing pre- and post-conditions. - - Example: - \code - // - // File: div.cpp - // - - #include - - int divide( int a, int b ) - { - Q_ASSERT( b != 0 ); // this is line 9 - return a/b; - } - \endcode - - If \c b is zero, the Q_ASSERT statement will output the following - message using the tqWarning() function: - \code - ASSERT: "b != 0" in div.cpp (9) - \endcode - - \sa tqWarning(), \link debug.html Debugging\endlink -*/ - - -/*! - \fn void TQ_CHECK_PTR( void *p ) - - \relates TQApplication - - If \a p is 0, prints a warning message containing the source code file - name and line number, saying that the program ran out of memory. - - This is really a macro defined in \c ntqglobal.h. - - Example: - \code - int *a; - - TQ_CHECK_PTR( a = new int[80] ); // WRONG! - - a = new (nothrow) int[80]; // Right - TQ_CHECK_PTR( a ); - \endcode - - \sa tqWarning(), \link debug.html Debugging\endlink -*/ - - -// -// The TQ_CHECK_PTR macro calls this function to check if an allocation went ok. -// -bool tqt_check_pointer( bool c, const char *n, int l ) -{ - if ( c ) - tqWarning( "In file %s, line %d: Out of memory", n, l ); - return TRUE; -} - - -static bool firstObsoleteWarning(const char *obj, const char *oldfunc ) -{ - static TQAsciiDict *obsoleteDict = 0; - if ( !obsoleteDict ) { // first time func is called - obsoleteDict = new TQAsciiDict; -#if defined(QT_DEBUG) - tqDebug( - "You are using obsolete functions in the TQt library. Call the function\n" - "qSuppressObsoleteWarnings() to suppress obsolete warnings.\n" - ); -#endif - } - TQCString s( obj ); - s += "::"; - s += oldfunc; - if ( obsoleteDict->find(s.data()) == 0 ) { - obsoleteDict->insert( s.data(), (int*)1 ); // anything different from 0 - return TRUE; - } - return FALSE; -} - -static bool suppressObsolete = FALSE; - -void tqSuppressObsoleteWarnings( bool suppress ) -{ - suppressObsolete = suppress; -} - -void tqObsolete( const char *obj, const char *oldfunc, const char *newfunc ) -{ - if ( suppressObsolete ) - return; - if ( !firstObsoleteWarning(obj, oldfunc) ) - return; - if ( obj ) - tqDebug( "%s::%s: This function is obsolete, use %s instead.", - obj, oldfunc, newfunc ); - else - tqDebug( "%s: This function is obsolete, use %s instead.", - oldfunc, newfunc ); -} - -void tqObsolete( const char *obj, const char *oldfunc ) -{ - if ( suppressObsolete ) - return; - if ( !firstObsoleteWarning(obj, oldfunc) ) - return; - if ( obj ) - tqDebug( "%s::%s: This function is obsolete.", obj, oldfunc ); - else - tqDebug( "%s: This function is obsolete.", oldfunc ); -} - -void tqObsolete( const char *message ) -{ - if ( suppressObsolete ) - return; - if ( !firstObsoleteWarning( "TQt", message) ) - return; - tqDebug( "%s", message ); -} - - -/*! - \relates TQApplication - - Installs a TQt message handler \a h. Returns a pointer to the - message handler previously defined. - - The message handler is a function that prints out debug messages, - warnings and fatal error messages. The TQt library (debug version) - contains hundreds of warning messages that are printed when - internal errors (usually invalid function arguments) occur. If you - implement your own message handler, you get total control of these - messages. - - The default message handler prints the message to the standard - output under X11 or to the debugger under Windows. If it is a - fatal message, the application aborts immediately. - - Only one message handler can be defined, since this is usually - done on an application-wide basis to control debug output. - - To restore the message handler, call \c qInstallMsgHandler(0). - - Example: - \code - #include - #include - #include - - void myMessageOutput( TQtMsgType type, const char *msg ) - { - switch ( type ) { - case TQtDebugMsg: - fprintf( stderr, "Debug: %s\n", msg ); - break; - case TQtWarningMsg: - fprintf( stderr, "Warning: %s\n", msg ); - break; - case TQtFatalMsg: - fprintf( stderr, "Fatal: %s\n", msg ); - abort(); // deliberately core dump - } - } - - int main( int argc, char **argv ) - { - qInstallMsgHandler( myMessageOutput ); - TQApplication a( argc, argv ); - ... - return a.exec(); - } - \endcode - - \sa tqDebug(), tqWarning(), tqFatal(), \link debug.html Debugging\endlink -*/ - -TQtMsgHandler qInstallMsgHandler( TQtMsgHandler h ) -{ - TQtMsgHandler old = handler; - handler = h; - return old; -} - - -/* - Dijkstra's bisection algorithm to find the square root as an integer. - Deliberately not exported as part of the TQt API, but used in - tqsimplerichtext.cpp -*/ -unsigned int qt_int_sqrt( unsigned int n ) -{ - // n must be in the range 0...UINT_MAX/2-1 - if ( n >= ( UINT_MAX>>2 ) ) { - unsigned int r = 2 * qt_int_sqrt( n / 4 ); - unsigned int r2 = r + 1; - return ( n >= r2 * r2 ) ? r2 : r; - } - uint h, p= 0, q= 1, r= n; - while ( q <= n ) - q <<= 2; - while ( q != 1 ) { - q >>= 2; - h= p + q; - p >>= 1; - if ( r >= h ) { - p += q; - r -= h; - } - } - return p; -} - diff --git a/src/tools/qgpluginmanager.cpp b/src/tools/qgpluginmanager.cpp deleted file mode 100644 index b2b5bf63d..000000000 --- a/src/tools/qgpluginmanager.cpp +++ /dev/null @@ -1,552 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQGPluginManager class -** -** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "qgpluginmanager_p.h" -#ifndef TQT_NO_COMPONENT -#include "qcomlibrary_p.h" -#include "tqmap.h" -#include "tqdir.h" - -/* - The following co-occurrence code is borrowed from TQt Linguist. - - How similar are two texts? The approach used here relies on - co-occurrence matrices and is very efficient. - - Let's see with an example: how similar are "here" and "hither"? The - co-occurrence matrix M for "here" is M[h,e] = 1, M[e,r] = 1, - M[r,e] = 1 and 0 elsewhere; the matrix N for "hither" is N[h,i] = 1, - N[i,t] = 1, ..., N[h,e] = 1, N[e,r] = 1 and 0 elsewhere. The union - U of both matrices is the matrix U[i,j] = max { M[i,j], N[i,j] }, - and the intersection V is V[i,j] = min { M[i,j], N[i,j] }. The score - for a pair of texts is - - score = (sum of V[i,j] over all i, j) / (sum of U[i,j] over all i, j), - - a formula suggested by Arnt Gulbrandsen. Here we have - - score = 2 / 6, - - or one third. - - The implementation differs from this in a few details. Most - importantly, repetitions are ignored; for input "xxx", M[x,x] equals - 1, not 2. -*/ - -/* - Every character is assigned to one of 20 buckets so that the - co-occurrence matrix requires only 20 * 20 = 400 bits, not - 256 * 256 = 65536 bits or even more if we want the whole Unicode. - Which character falls in which bucket is arbitrary. - - The second half of the table is a replica of the first half, because of - laziness. -*/ -static const char indexOf[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -// ! " # $ % & ' ( ) * + , - . / - 0, 2, 6, 7, 10, 12, 15, 19, 2, 6, 7, 10, 12, 15, 19, 0, -// 0 1 2 3 4 5 6 7 8 9 : ; < = > ? - 1, 3, 4, 5, 8, 9, 11, 13, 14, 16, 2, 6, 7, 10, 12, 15, -// @ A B C D E F G H I J K L M N O - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 6, 10, 11, 12, 13, 14, -// P Q R S T U V W X Y Z [ \ ] ^ _ - 15, 12, 16, 17, 18, 19, 2, 10, 15, 7, 19, 2, 6, 7, 10, 0, -// ` a b c d e f g h i j k l m n o - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 6, 10, 11, 12, 13, 14, -// p q r s t u v w x y z { | } ~ - 15, 12, 16, 17, 18, 19, 2, 10, 15, 7, 19, 2, 6, 7, 10, 0, - - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 2, 6, 7, 10, 12, 15, 19, 2, 6, 7, 10, 12, 15, 19, 0, - 1, 3, 4, 5, 8, 9, 11, 13, 14, 16, 2, 6, 7, 10, 12, 15, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 6, 10, 11, 12, 13, 14, - 15, 12, 16, 17, 18, 19, 2, 10, 15, 7, 19, 2, 6, 7, 10, 0, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 6, 10, 11, 12, 13, 14, - 15, 12, 16, 17, 18, 19, 2, 10, 15, 7, 19, 2, 6, 7, 10, 0 -}; - -/* - The entry bitCount[i] (for i between 0 and 255) is the number of - bits used to represent i in binary. -*/ -static const char bitCount[256] = { - 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, - 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 -}; - -class TQCoMatrix -{ -public: - /* - The matrix has 20 * 20 = 400 entries. This requires 50 bytes, or - 13 words. Some operations are performed on words for more - efficiency. - */ - union { - TQ_UINT8 b[52]; - TQ_UINT32 w[13]; - }; - - TQCoMatrix() { memset( b, 0, 52 ); } - TQCoMatrix( const char *text ) { - char c = '\0', d; - memset( b, 0, 52 ); - while ( (d = *text) != '\0' ) { - setCoocc( c, d ); - if ( (c = *++text) != '\0' ) { - setCoocc( d, c ); - text++; - } - } - } - - void setCoocc( char c, char d ) { - int k = indexOf[(uchar) c] + 20 * indexOf[(uchar) d]; - b[k >> 3] |= k & 0x7; - } - - int worth() const { - int result = 0; - for ( int i = 0; i < 50; i++ ) - result += bitCount[b[i]]; - return result; - } - - static TQCoMatrix reunion( const TQCoMatrix& m, const TQCoMatrix& n ) - { - TQCoMatrix p; - for ( int i = 0; i < 13; i++ ) - p.w[i] = m.w[i] | n.w[i]; - return p; - } - static TQCoMatrix intersection( const TQCoMatrix& m, const TQCoMatrix& n ) - { - TQCoMatrix p; - for ( int i = 0; i < 13; i++ ) - p.w[i] = m.w[i] & n.w[i]; - return p; - } -}; - -/* - Returns an integer between 0 (dissimilar) and 15 (very similar) - depending on how similar the string is to \a target. - - This function is efficient, but its results might change in future - versions of TQt as the algorithm evolves. - - \code - TQString s( "color" ); - a = similarity( s, "color" ); // a == 15 - a = similarity( s, "colour" ); // a == 8 - a = similarity( s, "flavor" ); // a == 4 - a = similarity( s, "dahlia" ); // a == 0 - \endcode -*/ -static int similarity( const TQString& s1, const TQString& s2 ) -{ - TQCoMatrix m1( s1 ); - TQCoMatrix m2( s2 ); - return ( 15 * (TQCoMatrix::intersection(m1, m2).worth() + 1) ) / - ( TQCoMatrix::reunion(m1, m2).worth() + 1 ); -} - -/*! - \class TQPluginManager qpluginmanager.h - \reentrant - \brief The TQPluginManager class provides basic functions to access a certain kind of functionality in libraries. - \ingroup componentmodel - - \internal - - A common usage of components is to extend the existing functionality in an application using plugins. The application - defines interfaces that abstract a certain group of functionality, and a plugin provides a specialized implementation - of one or more of those interfaces. - - The TQPluginManager template has to be instantiated with an interface definition and the IID for this interface. - - \code - TQPluginManager *manager = new TQPluginManager( IID_MyPluginInterface ); - \endcode - - It searches a specified directory for all shared libraries, queries for components that implement the specific interface and - reads information about the features the plugin wants to add to the application. The component can provide the set of features - provided by implementing either the TQFeatureListInterface or the TQComponentInformationInterface. The strings returned by the implementations - of - - \code - TQStringList TQFeatureListInterface::featureList() const - \endcode - - or - - \code - TQString TQComponentInformationInterface::name() const - \endcode - - respectively, can then be used to access the component that provides the requested feature: - - \code - MyPluginInterface *iface; - manager->queryInterface( "feature", &iface ); - if ( iface ) - iface->execute( "feature" ); - \endcode - - The application can use a TQPluginManager instance to create parts of the user interface based on the list of features - found in plugins: - - \code - TQPluginManager *manager = new TQPluginManager( IID_ImageFilterInterface ); - manager->addLibraryPath(...); - - TQStringList features = manager->featureList(); - for ( TQStringList::Iterator it = features.begin(); it != features.end(); ++it ) { - MyPluginInterface *iface; - manager->queryInterface( *it, &iface ); - - // use TQAction to provide toolbuttons and menuitems for each feature... - } - \endcode -*/ - -/*! - \fn TQPluginManager::TQPluginManager( const TQUuid& id, const TQStringList& paths = TQString::null, const TQString &suffix = TQString::null, bool cs = TRUE ) - - Creates an TQPluginManager for interfaces \a id that will load all shared library files in the \a paths + \a suffix. - If \a cs is FALSE the manager will handle feature strings case insensitive. - - \warning - Setting the cs flag to FALSE requires that components also convert to lower case when comparing with passed strings, so this has - to be handled with care and documented very well. - - \sa TQApplication::libraryPaths() -*/ - - -/*! - \fn TQRESULT TQPluginManager::queryInterface(const TQString& feature, Type** iface) const - - Sets \a iface to point to the interface providing \a feature. - - \sa featureList(), library() -*/ - - - -#include - -TQGPluginManager::TQGPluginManager( const TQUuid& id, const TQStringList& paths, const TQString &suffix, bool cs ) - : interfaceId( id ), plugDict( 17, cs ), casesens( cs ), autounload( TRUE ) -{ - // Every TQLibrary object is destroyed on destruction of the manager - libDict.setAutoDelete( TRUE ); - for ( TQStringList::ConstIterator it = paths.begin(); it != paths.end(); ++it ) { - TQString path = *it; - addLibraryPath( path + suffix ); - } -} - -TQGPluginManager::~TQGPluginManager() -{ - if ( !autounload ) { - TQDictIterator it( libDict ); - while ( it.current() ) { - TQLibrary *lib = it.current(); - ++it; - lib->setAutoUnload( FALSE ); - } - } -} - -void TQGPluginManager::addLibraryPath( const TQString& path ) -{ - if ( !enabled() || !TQDir( path ).exists( ".", TRUE ) ) - return; - -#if defined(Q_OS_WIN32) - TQString filter = "*.dll"; -#elif defined(Q_OS_MACX) - TQString filter = "*.dylib; *.so; *.bundle"; -#elif defined(Q_OS_HPUX) - TQString filter = "*.sl"; -#elif defined(Q_OS_OPENBSD) - TQString filter = "*.so; *.so.*"; -#elif defined(Q_OS_UNIX) - TQString filter = "*.so"; -#endif - - TQStringList plugins = TQDir(path).entryList( filter ); - for ( TQStringList::Iterator p = plugins.begin(); p != plugins.end(); ++p ) { - TQString lib = TQDir::cleanDirPath( path + "/" + *p ); - if ( libList.contains( lib ) ) - continue; - libList.append( lib ); - } -} - -const TQLibrary* TQGPluginManager::library( const TQString& feature ) const -{ - if ( !enabled() || feature.isEmpty() ) - return 0; - - // We already have a TQLibrary object for this feature - TQLibrary *library = 0; - if ( ( library = plugDict[feature] ) ) - return library; - - // Find the filename that matches the feature request best - TQMap map; - TQStringList::ConstIterator it = libList.begin(); - int best = 0; - int worst = 15; - while ( it != libList.end() ) { - if ( (*it).isEmpty() || libDict[*it] ) { - ++it; - continue; - } - TQString basename = TQFileInfo(*it).baseName(); - int s = similarity( feature, basename ); - if ( s < worst ) - worst = s; - if ( s > best ) - best = s; - map[s].append( basename + TQChar(0xfffd) + *it ); - ++it; - } - - if ( map.isEmpty() ) - return 0; // no libraries to add - - // Start with the best match to get the library object - TQGPluginManager *that = (TQGPluginManager*)this; - for ( int s = best; s >= worst; --s ) { - TQStringList group = map[s]; - group.sort(); // sort according to the base name - TQStringList::ConstIterator git = group.begin(); - while ( git != group.end() ) { - TQString lib = (*git).mid( (*git).find( TQChar(0xfffd) ) + 1 ); - TQString basename = (*git).left( (*git).find( TQChar(0xfffd) ) ); - ++git; - - TQStringList sameBasename; - while( git != group.end() && - basename == (*git).left( (*git).find( TQChar(0xfffd) ) ) ) { - sameBasename << (*git).mid( (*git).find( TQChar(0xfffd) ) + 1 ); - ++git; - } - - if ( sameBasename.isEmpty() ) { - that->addLibrary( new TQComLibrary( lib ) ); - } else { - TQPtrList same; - same.setAutoDelete( TRUE ); - same.append( new TQComLibrary( lib ) ); - for ( TQStringList::ConstIterator bit = sameBasename.begin(); - bit != sameBasename.end(); ++bit ) - same.append( new TQComLibrary( *bit ) ); - TQComLibrary* bestMatch = 0; - for ( TQComLibrary* candidate = same.first(); candidate; candidate = same.next() ) - if ( candidate->qtVersion() && candidate->qtVersion() <= TQT_VERSION - && ( !bestMatch || candidate->qtVersion() > bestMatch->qtVersion() ) ) - bestMatch = candidate; - if ( bestMatch ) { - same.find( bestMatch ); - that->addLibrary( same.take() ); - } - } - - if ( ( library = that->plugDict[feature] ) ) - return library; - } - } - return 0; -} - -TQStringList TQGPluginManager::featureList() const -{ - TQStringList features; - - if ( !enabled() ) - return features; - - TQGPluginManager *that = (TQGPluginManager*)this; - TQStringList theLibs = libList; - TQStringList phase2Libs; - TQStringList phase2Deny; - - /* In order to get the feature list we need to add all interesting - libraries. If there are libraries with the same base name, we - prioritze the one that fits our TQt version number and ignore the - others */ - TQStringList::Iterator it; - for ( it = theLibs.begin(); it != theLibs.end(); ++it ) { - if ( (*it).isEmpty() || libDict[*it] ) - continue; - TQComLibrary* library = new TQComLibrary( *it ); - if ( library->qtVersion() == TQT_VERSION ) { - that->addLibrary( library ); - phase2Deny << TQFileInfo( *it ).baseName(); - } else { - delete library; - phase2Libs << *it; - } - } - for ( it = phase2Libs.begin(); it != phase2Libs.end(); ++it ) - if ( !phase2Deny.contains( TQFileInfo( *it ).baseName() ) ) - that->addLibrary( new TQComLibrary( *it ) ); - - for ( TQDictIterator pit( plugDict ); pit.current(); ++pit ) - features << pit.currentKey(); - - return features; -} - -bool TQGPluginManager::addLibrary( TQLibrary* lib ) -{ - if ( !enabled() || !lib ) - return FALSE; - - TQComLibrary* plugin = (TQComLibrary*)lib; - bool useful = FALSE; - - TQUnknownInterface* iFace = 0; - plugin->queryInterface( interfaceId, &iFace ); - if ( iFace ) { - TQFeatureListInterface *fliFace = 0; - TQComponentInformationInterface *cpiFace = 0; - iFace->queryInterface( IID_QFeatureList, (TQUnknownInterface**)&fliFace ); - if ( !fliFace ) - plugin->queryInterface( IID_QFeatureList, (TQUnknownInterface**)&fliFace ); - if ( !fliFace ) { - iFace->queryInterface( IID_QComponentInformation, (TQUnknownInterface**)&cpiFace ); - if ( !cpiFace ) - plugin->queryInterface( IID_QComponentInformation, (TQUnknownInterface**)&cpiFace ); - } - TQStringList fl; - if ( fliFace ) - // Map all found features to the library - fl = fliFace->featureList(); - else if ( cpiFace ) - fl << cpiFace->name(); - - for ( TQStringList::Iterator f = fl.begin(); f != fl.end(); ++f ) { - TQLibrary *old = plugDict[*f]; - if ( !old ) { - useful = TRUE; - plugDict.replace( *f, plugin ); - } else { - // we have old *and* plugin, which one to pick? - TQComLibrary* first = (TQComLibrary*)old; - TQComLibrary* second = (TQComLibrary*)plugin; - bool takeFirst = TRUE; - if ( first->qtVersion() != TQT_VERSION ) { - if ( second->qtVersion() == TQT_VERSION ) - takeFirst = FALSE; - else if ( second->qtVersion() < TQT_VERSION && - first->qtVersion() > TQT_VERSION ) - takeFirst = FALSE; - } - if ( !takeFirst ) { - useful = TRUE; - plugDict.replace( *f, plugin ); - tqWarning("%s: Discarding feature %s in %s!", - (const char*) TQFile::encodeName( plugin->library()), - (*f).latin1(), - (const char*) TQFile::encodeName( old->library() ) ); - } else { - tqWarning("%s: Feature %s already defined in %s!", - (const char*) TQFile::encodeName( old->library() ), - (*f).latin1(), - (const char*) TQFile::encodeName( plugin->library() ) ); - } - } - } - if ( fliFace ) - fliFace->release(); - if ( cpiFace ) - cpiFace->release(); - iFace->release(); - } - - if ( useful ) { - libDict.replace( plugin->library(), plugin ); - if ( !libList.contains( plugin->library() ) ) - libList.append( plugin->library() ); - return TRUE; - } - delete plugin; - return FALSE; -} - - -bool TQGPluginManager::enabled() const -{ -#ifdef QT_SHARED - return TRUE; -#else - return FALSE; -#endif -} - -TQRESULT TQGPluginManager::queryUnknownInterface(const TQString& feature, TQUnknownInterface** iface) const -{ - TQComLibrary* plugin = 0; - plugin = (TQComLibrary*)library( feature ); - return plugin ? plugin->queryInterface( interfaceId, (TQUnknownInterface**)iface ) : TQE_NOINTERFACE; -} - -#endif //TQT_NO_COMPONENT diff --git a/src/tools/qgpluginmanager_p.h b/src/tools/qgpluginmanager_p.h deleted file mode 100644 index 069b7e27a..000000000 --- a/src/tools/qgpluginmanager_p.h +++ /dev/null @@ -1,110 +0,0 @@ -/********************************************************************** -** -** Definition of TQGPluginManager class -** -** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQGPLUGINMANAGER_P_H -#define TQGPLUGINMANAGER_P_H - -#ifndef QT_H -#include "tqdict.h" -#include "ntqlibrary.h" -#include "ntquuid.h" -#include "tqstringlist.h" -#include "qcom_p.h" -#endif // QT_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. It exists for the convenience -// of a number of TQt sources files. This header file may change from -// version to version without notice, or even be removed. -// -// We mean it. -// -// - -#ifndef TQT_NO_COMPONENT - -#if defined(Q_TEMPLATEDLL) -// MOC_SKIP_BEGIN -//Q_TEMPLATE_EXTERN template class TQ_EXPORT TQDict; -// MOC_SKIP_END -#endif - -class TQ_EXPORT TQGPluginManager -{ -public: - TQGPluginManager( const TQUuid& id, const TQStringList& paths = TQString::null, const TQString &suffix = TQString::null, bool cs = TRUE ); - ~TQGPluginManager(); - - void addLibraryPath( const TQString& path ); - const TQLibrary* library( const TQString& feature ) const; - TQStringList featureList() const; - - bool autoUnload() const; - void setAutoUnload( bool ); - -protected: - bool enabled() const; - bool addLibrary( TQLibrary* plugin ); - - TQRESULT queryUnknownInterface(const TQString& feature, TQUnknownInterface** iface) const; - - TQUuid interfaceId; - TQDict plugDict; // Dict to match feature with library - TQDict libDict; // Dict to match library file with library - TQStringList libList; - - uint casesens : 1; - uint autounload : 1; -}; - -inline void TQGPluginManager::setAutoUnload( bool unload ) -{ - autounload = unload; -} - -inline bool TQGPluginManager::autoUnload() const -{ - return autounload; -} - -#endif - -#endif //TQGPLUGINMANAGER_P_H diff --git a/src/tools/qgvector.cpp b/src/tools/qgvector.cpp deleted file mode 100644 index 03b502c0b..000000000 --- a/src/tools/qgvector.cpp +++ /dev/null @@ -1,598 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQGVector class -** -** Created : 930907 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the tools module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqglobal.h" -#if defined(Q_CC_BOR) -// needed for qsort() because of a std namespace problem on Borland -#include "qplatformdefs.h" -#endif - -#define TQGVECTOR_CPP -#include "ntqgvector.h" -#include "ntqglist.h" -#include "tqstring.h" -#include "tqdatastream.h" -#include - -#ifdef TQT_THREAD_SUPPORT -# include -#endif // TQT_THREAD_SUPPORT - -#define USE_MALLOC // comment to use new/delete - -#undef NEW -#undef DELETE - -#if defined(USE_MALLOC) -#define NEW(type,size) ((type*)malloc(size*sizeof(type))) -#define DELETE(array) (free((char*)array)) -#else -#define NEW(type,size) (new type[size]) -#define DELETE(array) (delete[] array) -#define DONT_USE_REALLOC // comment to use realloc() -#endif - -/*! - \class TQGVector - \reentrant - \ingroup collection - - \brief The TQGVector class is an internal class for implementing TQt - collection classes. - - \internal - - TQGVector is an internal class that acts as a base class for the - TQPtrVector collection class. - - TQGVector has some virtual functions that may be reimplemented in - subclasses to customize behavior. - - \list - \i compareItems() compares two collection/vector items. - \i read() reads a collection/vector item from a TQDataStream. - \i write() writes a collection/vector item to a TQDataStream. - \endlist -*/ - -/***************************************************************************** - Default implementation of virtual functions - *****************************************************************************/ - -/*! - This virtual function compares two list items. - - Returns: -
    -
  • 0 if \a d1 == \a d2 -
  • non-zero if \a d1 != \a d2 -
- - This function returns \e int rather than \e bool so that - reimplementations can return one of three values and use it to sort - by: -
    -
  • 0 if \a d1 == \a d2 -
  • \> 0 (positive integer) if \a d1 \> \a d2 -
  • \< 0 (negative integer) if \a d1 \< \a d2 -
- - The TQPtrVector::sort() and TQPtrVector::bsearch() functions require that - compareItems() is implemented as described here. - - This function should not modify the vector because some const - functions call compareItems(). -*/ - -int TQGVector::compareItems( Item d1, Item d2 ) -{ - return d1 != d2; // compare pointers -} - -#ifndef TQT_NO_DATASTREAM -/*! - Reads a collection/vector item from the stream \a s and returns a reference - to the stream. - - The default implementation sets \a d to 0. - - \sa write() -*/ - -TQDataStream &TQGVector::read( TQDataStream &s, Item &d ) -{ // read item from stream - d = 0; - return s; -} - -/*! - Writes a collection/vector item to the stream \a s and returns a reference - to the stream. - - The default implementation does nothing. - - \sa read() -*/ - -TQDataStream &TQGVector::write( TQDataStream &s, Item ) const -{ // write item to stream - return s; -} -#endif // TQT_NO_DATASTREAM - -/***************************************************************************** - TQGVector member functions - *****************************************************************************/ - -TQGVector::TQGVector() // create empty vector -{ - vec = 0; - len = numItems = 0; -} - -TQGVector::TQGVector( uint size ) // create vectors with nullptrs -{ - len = size; - numItems = 0; - if ( len == 0 ) { // zero length - vec = 0; - return; - } - vec = NEW(Item,len); - TQ_CHECK_PTR( vec ); - memset( (void*)vec, 0, len*sizeof(Item) ); // fill with nulls -} - -TQGVector::TQGVector( const TQGVector &a ) // make copy of other vector - : TQPtrCollection( a ) -{ - len = a.len; - numItems = a.numItems; - if ( len == 0 ) { - vec = 0; - return; - } - vec = NEW( Item, len ); - TQ_CHECK_PTR( vec ); - for ( uint i = 0; i < len; i++ ) { - if ( a.vec[i] ) { - vec[i] = newItem( a.vec[i] ); - TQ_CHECK_PTR( vec[i] ); - } else { - vec[i] = 0; - } - } -} - -TQGVector::~TQGVector() -{ - clear(); -} - -TQGVector& TQGVector::operator=( const TQGVector &v ) -{ - if ( &v == this ) - return *this; - - clear(); - len = v.len; - numItems = v.numItems; - if ( len == 0 ) { - vec = 0; - return *this; - } - vec = NEW( Item, len ); - TQ_CHECK_PTR( vec ); - for ( uint i = 0; i < len; i++ ) { - if ( v.vec[i] ) { - vec[i] = newItem( v.vec[i] ); - TQ_CHECK_PTR( vec[i] ); - } else { - vec[i] = 0; - } - } - return *this; -} - - -bool TQGVector::insert( uint index, Item d ) // insert item at index -{ -#if defined(QT_CHECK_RANGE) - if ( index >= len ) { // range error - tqWarning( "TQGVector::insert: Index %d out of range", index ); - return FALSE; - } -#endif - if ( vec[index] ) { // remove old item - deleteItem( vec[index] ); - numItems--; - } - if ( d ) { - vec[index] = newItem( d ); - TQ_CHECK_PTR( vec[index] ); - numItems++; - return vec[index] != 0; - } else { - vec[index] = 0; // reset item - } - return TRUE; -} - -bool TQGVector::remove( uint index ) // remove item at index -{ -#if defined(QT_CHECK_RANGE) - if ( index >= len ) { // range error - tqWarning( "TQGVector::remove: Index %d out of range", index ); - return FALSE; - } -#endif - if ( vec[index] ) { // valid item - deleteItem( vec[index] ); // delete it - vec[index] = 0; // reset pointer - numItems--; - } - return TRUE; -} - -TQPtrCollection::Item TQGVector::take( uint index ) // take out item -{ -#if defined(QT_CHECK_RANGE) - if ( index >= len ) { // range error - tqWarning( "TQGVector::take: Index %d out of range", index ); - return 0; - } -#endif - Item d = vec[index]; // don't delete item - if ( d ) - numItems--; - vec[index] = 0; - return d; -} - -void TQGVector::clear() // clear vector -{ - if ( vec ) { - for ( uint i=0; i len ) // init extra space added - memset( (void*)&vec[len], 0, (newsize-len)*sizeof(Item) ); - len = newsize; - return TRUE; -} - - -bool TQGVector::fill( Item d, int flen ) // resize and fill vector -{ - if ( flen < 0 ) - flen = len; // default: use vector length - else if ( !resize( flen ) ) - return FALSE; - for ( uint i=0; i<(uint)flen; i++ ) // insert d at every index - insert( i, d ); - return TRUE; -} - - -static TQGVector *sort_vec=0; // current sort vector - - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -#ifdef Q_OS_TEMP -static int _cdecl cmp_vec( const void *n1, const void *n2 ) -#else -static int cmp_vec( const void *n1, const void *n2 ) -#endif -{ - return sort_vec->compareItems( *((TQPtrCollection::Item*)n1), *((TQPtrCollection::Item*)n2) ); -} - -#if defined(Q_C_CALLBACKS) -} -#endif - - -void TQGVector::sort() // sort vector -{ - if ( count() == 0 ) // no elements - return; - Item *start = &vec[0]; - Item *end = &vec[len-1]; - Item tmp; - for (;;) { // put all zero elements behind - while ( start < end && *start != 0 ) - start++; - while ( end > start && *end == 0 ) - end--; - if ( start < end ) { - tmp = *start; - *start = *end; - *end = tmp; - } else { - break; - } - } - -#ifdef TQT_THREAD_SUPPORT - TQMutexLocker locker( tqt_global_mutexpool ? - tqt_global_mutexpool->get( &sort_vec ) : 0 ); -#endif // TQT_THREAD_SUPPORT - - sort_vec = (TQGVector*)this; - qsort( vec, count(), sizeof(Item), cmp_vec ); - sort_vec = 0; -} - -int TQGVector::bsearch( Item d ) const // binary search; when sorted -{ - if ( !len ) - return -1; - if ( !d ) { -#if defined(QT_CHECK_NULL) - tqWarning( "TQGVector::bsearch: Cannot search for null object" ); -#endif - return -1; - } - int n1 = 0; - int n2 = len - 1; - int mid = 0; - bool found = FALSE; - while ( n1 <= n2 ) { - int res; - mid = (n1 + n2)/2; - if ( vec[mid] == 0 ) // null item greater - res = -1; - else - res = ((TQGVector*)this)->compareItems( d, vec[mid] ); - if ( res < 0 ) - n2 = mid - 1; - else if ( res > 0 ) - n1 = mid + 1; - else { // found it - found = TRUE; - break; - } - } - if ( !found ) - return -1; - // search to first of equal items - while ( (mid - 1 >= 0) && !((TQGVector*)this)->compareItems(d, vec[mid-1]) ) - mid--; - return mid; -} - -int TQGVector::findRef( Item d, uint index) const // find exact item in vector -{ -#if defined(QT_CHECK_RANGE) - if ( index > len ) { // range error - tqWarning( "TQGVector::findRef: Index %d out of range", index ); - return -1; - } -#endif - for ( uint i=index; i= len ) { // range error - tqWarning( "TQGVector::find: Index %d out of range", index ); - return -1; - } -#endif - for ( uint i=index; icompareItems( vec[i], d ) == 0 ) - return i; - } - return -1; -} - -uint TQGVector::containsRef( Item d ) const // get number of exact matches -{ - uint count = 0; - for ( uint i=0; icompareItems( vec[i], d ) == 0 ) - count++; - } - return count; -} - -bool TQGVector::insertExpand( uint index, Item d )// insert and grow if necessary -{ - if ( index >= len ) { - if ( !resize( index+1 ) ) // no memory - return FALSE; - } - insert( index, d ); - return TRUE; -} - -void TQGVector::toList( TQGList *list ) const // store items in list -{ - list->clear(); - for ( uint i=0; iappend( vec[i] ); - } -} - - -void TQGVector::warningIndexRange( uint i ) -{ -#if defined(QT_CHECK_RANGE) - tqWarning( "TQGVector::operator[]: Index %d out of range", i ); -#else - Q_UNUSED( i ) -#endif -} - - -/***************************************************************************** - TQGVector stream functions - *****************************************************************************/ -#ifndef TQT_NO_DATASTREAM -TQDataStream &operator>>( TQDataStream &s, TQGVector &vec ) -{ // read vector - return vec.read( s ); -} - -TQDataStream &operator<<( TQDataStream &s, const TQGVector &vec ) -{ // write vector - return vec.write( s ); -} - -TQDataStream &TQGVector::read( TQDataStream &s ) // read vector from stream -{ - uint num; - s >> num; // read number of items - clear(); // clear vector - resize( num ); - for (uint i=0; icompareItems( at( i ), v.at( i ) ) != 0 ) - return FALSE; - } - return TRUE; -} - -#endif // TQT_NO_DATASTREAM diff --git a/src/tools/qpluginmanager_p.h b/src/tools/qpluginmanager_p.h index 8c29aaf84..4e42eed0f 100644 --- a/src/tools/qpluginmanager_p.h +++ b/src/tools/qpluginmanager_p.h @@ -54,7 +54,7 @@ // #ifndef QT_H -#include "qgpluginmanager_p.h" +#include "tqgpluginmanager_p.h" #endif // QT_H #ifndef TQT_NO_COMPONENT diff --git a/src/tools/qt_tools.pri b/src/tools/qt_tools.pri index 5eb816580..8a2ce897f 100644 --- a/src/tools/qt_tools.pri +++ b/src/tools/qt_tools.pri @@ -21,14 +21,13 @@ tools { $$TOOLS_H/tqfile.h \ $$TOOLS_P/tqfiledefs_p.h \ $$TOOLS_H/tqfileinfo.h \ - $$TOOLS_H/ntqgarray.h \ - $$TOOLS_H/ntqgcache.h \ - $$TOOLS_H/ntqgdict.h \ - $$TOOLS_H/ntqgeneric.h \ - $$TOOLS_H/ntqglist.h \ - $$TOOLS_H/ntqglobal.h \ - $$TOOLS_P/qgpluginmanager_p.h \ - $$TOOLS_H/ntqgvector.h \ + $$TOOLS_H/tqgarray.h \ + $$TOOLS_H/tqgcache.h \ + $$TOOLS_H/tqgdict.h \ + $$TOOLS_H/tqglist.h \ + $$TOOLS_H/tqglobal.h \ + $$TOOLS_P/tqgpluginmanager_p.h \ + $$TOOLS_H/tqgvector.h \ $$TOOLS_H/tqintcache.h \ $$TOOLS_H/tqintdict.h \ $$TOOLS_H/tqiodevice.h \ @@ -117,13 +116,13 @@ tools { $$TOOLS_CPP/tqdir.cpp \ $$TOOLS_CPP/tqfile.cpp \ $$TOOLS_CPP/tqfileinfo.cpp \ - $$TOOLS_CPP/qgarray.cpp \ - $$TOOLS_CPP/qgcache.cpp \ - $$TOOLS_CPP/qgdict.cpp \ - $$TOOLS_CPP/qglist.cpp \ - $$TOOLS_CPP/qglobal.cpp \ - $$TOOLS_CPP/qgpluginmanager.cpp \ - $$TOOLS_CPP/qgvector.cpp \ + $$TOOLS_CPP/tqgarray.cpp \ + $$TOOLS_CPP/tqgcache.cpp \ + $$TOOLS_CPP/tqgdict.cpp \ + $$TOOLS_CPP/tqglist.cpp \ + $$TOOLS_CPP/tqglobal.cpp \ + $$TOOLS_CPP/tqgpluginmanager.cpp \ + $$TOOLS_CPP/tqgvector.cpp \ $$TOOLS_CPP/tqiodevice.cpp \ $$TOOLS_CPP/qlibrary.cpp \ $$TOOLS_CPP/tqlocale.cpp \ diff --git a/src/tools/qwinexport.cpp b/src/tools/qwinexport.cpp index ca5bccb72..82d5ebc61 100644 --- a/src/tools/qwinexport.cpp +++ b/src/tools/qwinexport.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/tools/tqasciicache.h b/src/tools/tqasciicache.h index 7323635c6..879e5b759 100644 --- a/src/tools/tqasciicache.h +++ b/src/tools/tqasciicache.h @@ -42,7 +42,7 @@ #define TQASCIICACHE_H #ifndef QT_H -#include "ntqgcache.h" +#include "tqgcache.h" #endif // QT_H diff --git a/src/tools/tqasciidict.h b/src/tools/tqasciidict.h index ef09bc025..7489e1822 100644 --- a/src/tools/tqasciidict.h +++ b/src/tools/tqasciidict.h @@ -42,7 +42,7 @@ #define TQASCIIDICT_H #ifndef QT_H -#include "ntqgdict.h" +#include "tqgdict.h" #endif // QT_H template diff --git a/src/tools/tqcache.h b/src/tools/tqcache.h index 9d747e346..8225d7fd1 100644 --- a/src/tools/tqcache.h +++ b/src/tools/tqcache.h @@ -42,7 +42,7 @@ #define TQCACHE_H #ifndef QT_H -#include "ntqgcache.h" +#include "tqgcache.h" #endif // QT_H template diff --git a/src/tools/tqdeepcopy.h b/src/tools/tqdeepcopy.h index abe1fc8f1..7963154d4 100644 --- a/src/tools/tqdeepcopy.h +++ b/src/tools/tqdeepcopy.h @@ -42,7 +42,7 @@ #define TQDEEPCOPY_H #ifndef QT_H -# include "ntqglobal.h" +# include "tqglobal.h" #endif // QT_H template diff --git a/src/tools/tqdict.h b/src/tools/tqdict.h index d363538d0..f82579919 100644 --- a/src/tools/tqdict.h +++ b/src/tools/tqdict.h @@ -42,7 +42,7 @@ #define TQDICT_H #ifndef QT_H -#include "ntqgdict.h" +#include "tqgdict.h" #endif // QT_H template diff --git a/src/tools/tqdir.h b/src/tools/tqdir.h index 41ba93e8c..697d29f95 100644 --- a/src/tools/tqdir.h +++ b/src/tools/tqdir.h @@ -42,7 +42,7 @@ #define TQDIR_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #include "tqstrlist.h" #include "tqfileinfo.h" #endif // QT_H diff --git a/src/tools/tqfile.cpp b/src/tools/tqfile.cpp index 06a127fc2..d67578929 100644 --- a/src/tools/tqfile.cpp +++ b/src/tools/tqfile.cpp @@ -628,7 +628,7 @@ TQString locale_decoder( const TQCString &localFileName ) #ifndef TQ_WS_MAC return TQString::fromLocal8Bit(localFileName); #else - extern TQString qt_mac_precomposeFileName(const TQString &); // qglobal.cpp + extern TQString qt_mac_precomposeFileName(const TQString &); // tqglobal.cpp return qt_mac_precomposeFileName(TQString::fromLocal8Bit(localFileName)); #endif } diff --git a/src/tools/tqfileinfo_unix.cpp b/src/tools/tqfileinfo_unix.cpp index 300515e3a..98ed9050e 100644 --- a/src/tools/tqfileinfo_unix.cpp +++ b/src/tools/tqfileinfo_unix.cpp @@ -177,7 +177,7 @@ TQString TQFileInfo::readLink() const if(FSNewAlias(0, &fref, &alias) == noErr && alias) { CFStringRef cfstr; if(FSCopyAliasInfo(alias, 0, 0, &cfstr, 0, 0) == noErr) { - TQString cfstring2qstring(CFStringRef str); //qglobal.cpp + TQString cfstring2qstring(CFStringRef str); //tqglobal.cpp return cfstring2qstring(cfstr); } } diff --git a/src/tools/tqgarray.cpp b/src/tools/tqgarray.cpp new file mode 100644 index 000000000..b8d500adf --- /dev/null +++ b/src/tools/tqgarray.cpp @@ -0,0 +1,830 @@ +/**************************************************************************** +** +** Implementation of TQGArray class +** +** Created : 930906 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqglobal.h" +#if defined(Q_CC_BOR) + // needed for qsort() because of a std namespace problem on Borland +# include "qplatformdefs.h" +#elif defined(TQ_WS_WIN) + // needed for bsearch on some platforms +# include "qt_windows.h" +#endif + +#define TQGARRAY_CPP +#include "tqgarray.h" +#include +#include + +#ifdef TQT_THREAD_SUPPORT +# include +#endif // TQT_THREAD_SUPPORT + +/* + If USE_MALLOC isn't defined, we use new[] and delete[] to allocate + memory. The documentation for TQMemArray::assign() explicitly + mentions that the array is freed using free(), so don't mess around + with USE_MALLOC unless you know what you're doing. +*/ +#define USE_MALLOC + +#undef NEW +#undef DELETE + +#if defined(USE_MALLOC) +#define NEW(type,size) ((type*)malloc(size*sizeof(type))) +#define DELETE(array) (free((char*)array)) +#else +#define NEW(type,size) (new type[size]) +#define DELETE(array) (delete[] array) +#define DONT_USE_REALLOC // comment to use realloc() +#endif + +/*! + \class TQShared ntqshared.h + \reentrant + \ingroup shared + \brief The TQShared class is used internally for implementing shared classes. + + \internal + + It only contains a reference count and member functions to increment and + decrement it. + + Shared classes normally have internal classes that inherit TQShared and + add the shared data. + + \sa \link shclass.html Shared Classes\endlink +*/ + +/*! + \class TQGArray tqgarray.h + \reentrant + \ingroup shared + \ingroup collection + \brief The TQGArray class is an internal class for implementing the TQMemArray class. + + \internal + + TQGArray is a strictly internal class that acts as base class for the + TQMemArray template array. + + It contains an array of bytes and has no notion of an array element. +*/ + + +/*! + Constructs a null array. +*/ + +TQGArray::TQGArray() +{ + shd = newData(); + TQ_CHECK_PTR( shd ); +} + +/*! + Dummy constructor; does not allocate any data. + + This constructor does not initialize any array data so subclasses + must do it. The intention is to make the code more efficient. +*/ + +TQGArray::TQGArray( int, int ) +{ +} + +/*! + Constructs an array with room for \a size bytes. +*/ + +TQGArray::TQGArray( int size ) +{ + if ( size < 0 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQGArray: Cannot allocate array with negative length" ); +#endif + size = 0; + } + shd = newData(); + TQ_CHECK_PTR( shd ); + if ( size == 0 ) // zero length + return; + shd->data = NEW(char,size); + TQ_CHECK_PTR( shd->data ); + shd->len = +#ifdef QT_QGARRAY_SPEED_OPTIM + shd->maxl = +#endif + size; +} + +/*! + Constructs a shallow copy of \a a. +*/ + +TQGArray::TQGArray( const TQGArray &a ) +{ + shd = a.shd; + shd->ref(); +} + +/*! + Dereferences the array data and deletes it if this was the last + reference. +*/ + +TQGArray::~TQGArray() +{ + if ( shd && shd->deref() ) { // delete when last reference + if ( shd->data ) // is lost + DELETE(shd->data); + deleteData( shd ); + shd = 0; + } +} + + +/*! + \fn TQGArray &TQGArray::operator=( const TQGArray &a ) + + Assigns a shallow copy of \a a to this array and returns a reference to + this array. Equivalent to assign(). +*/ + +/*! + \fn void TQGArray::detach() + + Detaches this array from shared array data. +*/ + +/*! + \fn char *TQGArray::data() const + + Returns a pointer to the actual array data. +*/ + +/*! + \fn uint TQGArray::nrefs() const + + Returns the reference count. +*/ + +/*! + \fn uint TQGArray::size() const + + Returns the size of the array, in bytes. +*/ + + +/*! + Returns TRUE if this array is equal to \a a, otherwise FALSE. + The comparison is bitwise, of course. +*/ + +bool TQGArray::isEqual( const TQGArray &a ) const +{ + if ( size() != a.size() ) // different size + return FALSE; + if ( data() == a.data() ) // has same data + return TRUE; + return (size() ? memcmp( data(), a.data(), size() ) : 0) == 0; +} + + +/*! + Resizes the array to \a newsize bytes. \a optim is either + \c MemOptim (the default) or \c SpeedOptim. + + Note: \c SpeedOptim is only available if TQt is built in a + particular configuration. By default, \c SpeedOptim is not available + for general use. +*/ +bool TQGArray::resize( uint newsize, Optimization optim ) +{ +#ifndef QT_QGARRAY_SPEED_OPTIM + Q_UNUSED(optim); +#endif + + if ( newsize == shd->len +#ifdef QT_QGARRAY_SPEED_OPTIM + && newsize == shd->maxl +#endif + ) // nothing to do + return TRUE; + if ( newsize == 0 ) { // remove array + if ( shd->data ) + DELETE(shd->data); + shd->data = 0; + shd->len = 0; +#ifdef QT_QGARRAY_SPEED_OPTIM + shd->maxl = 0; +#endif + return TRUE; + } + + uint newmaxl = newsize; +#ifdef QT_QGARRAY_SPEED_OPTIM + if ( optim == SpeedOptim ) { + if ( newsize <= shd->maxl && + ( newsize * 4 > shd->maxl || shd->maxl <= 4 ) ) { + shd->len = newsize; + return TRUE; + } + newmaxl = 4; + while ( newmaxl < newsize ) + newmaxl *= 2; + // try to spare some memory + if ( newmaxl >= 1024 * 1024 && newsize <= newmaxl - (newmaxl >> 2) ) + newmaxl -= newmaxl >> 2; + } + shd->maxl = newmaxl; +#endif + + if ( shd->data ) { // existing data +#if defined(DONT_USE_REALLOC) + char *newdata = NEW(char,newsize); // manual realloc + memcpy( newdata, shd->data, TQMIN(shd->len,newmaxl) ); + DELETE(shd->data); + shd->data = newdata; +#else + shd->data = (char *)realloc( shd->data, newmaxl ); +#endif + } else { + shd->data = NEW(char,newmaxl); + } + if ( !shd->data ) // no memory + return FALSE; + shd->len = newsize; + return TRUE; +} + +/*!\overload +*/ +bool TQGArray::resize( uint newsize ) +{ + return resize( newsize, MemOptim ); +} + + +/*! + Fills the array with the repeated occurrences of \a d, which is + \a sz bytes long. + If \a len is specified as different from -1, then the array will be + resized to \a len*sz before it is filled. + + Returns TRUE if successful, or FALSE if the memory cannot be allocated + (only when \a len != -1). + + \sa resize() +*/ + +bool TQGArray::fill( const char *d, int len, uint sz ) +{ + if ( len < 0 ) + len = shd->len/sz; // default: use array length + else if ( !resize( len*sz ) ) + return FALSE; + if ( sz == 1 ) // 8 bit elements + memset( data(), *d, len ); + else if ( sz == 4 ) { // 32 bit elements + TQ_INT32 *x = (TQ_INT32*)data(); + TQ_INT32 v = *((TQ_INT32*)d); + while ( len-- ) + *x++ = v; + } else if ( sz == 2 ) { // 16 bit elements + TQ_INT16 *x = (TQ_INT16*)data(); + TQ_INT16 v = *((TQ_INT16*)d); + while ( len-- ) + *x++ = v; + } else { // any other size elements + char *x = data(); + while ( len-- ) { // more complicated + memcpy( x, d, sz ); + x += sz; + } + } + return TRUE; +} + +/*! + \overload + Shallow copy. Dereference the current array and references the data + contained in \a a instead. Returns a reference to this array. + \sa operator=() +*/ + +TQGArray &TQGArray::assign( const TQGArray &a ) +{ + a.shd->ref(); // avoid 'a = a' + if ( shd->deref() ) { // delete when last reference + if ( shd->data ) // is lost + DELETE(shd->data); + deleteData( shd ); + } + shd = a.shd; + return *this; +} + +/*! + Shallow copy. Dereference the current array and references the + array data \a d, which contains \a len bytes. + Returns a reference to this array. + + Do not delete \a d later, because TQGArray takes care of that. +*/ + +TQGArray &TQGArray::assign( const char *d, uint len ) +{ + if ( shd->count > 1 ) { // disconnect this + shd->count--; + shd = newData(); + TQ_CHECK_PTR( shd ); + } else { + if ( shd->data ) + DELETE(shd->data); + } + shd->data = (char *)d; + shd->len = +#ifdef QT_QGARRAY_SPEED_OPTIM + shd->maxl = +#endif + len; + return *this; +} + +/*! + Deep copy. Dereference the current array and obtains a copy of the data + contained in \a a instead. Returns a reference to this array. + \sa assign(), operator=() +*/ + +TQGArray &TQGArray::duplicate( const TQGArray &a ) +{ + if ( a.shd == shd ) { // a.duplicate(a) ! + if ( shd->count > 1 ) { + shd->count--; + array_data *n = newData(); + TQ_CHECK_PTR( n ); + if ( (n->len=shd->len) ) { + n->data = NEW(char,n->len); + TQ_CHECK_PTR( n->data ); + if ( n->data ) + memcpy( n->data, shd->data, n->len ); + } else { + n->data = 0; + } + shd = n; + } + return *this; + } + char *oldptr = 0; + if ( shd->count > 1 ) { // disconnect this + shd->count--; + shd = newData(); + TQ_CHECK_PTR( shd ); + } else { // delete after copy was made + oldptr = shd->data; + } + if ( a.shd->len ) { // duplicate data + shd->data = NEW(char,a.shd->len); + TQ_CHECK_PTR( shd->data ); + if ( shd->data ) + memcpy( shd->data, a.shd->data, a.shd->len ); + } else { + shd->data = 0; + } + shd->len = +#ifdef QT_QGARRAY_SPEED_OPTIM + shd->maxl = +#endif + a.shd->len; + if ( oldptr ) + DELETE(oldptr); + return *this; +} + +/*! + \overload + Deep copy. Dereferences the current array and obtains a copy of + \a len characters from array data \a d instead. Returns a reference + to this array. + \sa assign(), operator=() +*/ + +TQGArray &TQGArray::duplicate( const char *d, uint len ) +{ + char *data; + if ( d == 0 || len == 0 ) { + data = 0; + len = 0; + } else { + if ( shd->count == 1 && shd->len == len ) { + if ( shd->data != d ) // avoid self-assignment + memcpy( shd->data, d, len ); // use same buffer + return *this; + } + data = NEW(char,len); + TQ_CHECK_PTR( data ); + memcpy( data, d, len ); + } + if ( shd->count > 1 ) { // detach + shd->count--; + shd = newData(); + TQ_CHECK_PTR( shd ); + } else { // just a single reference + if ( shd->data ) + DELETE(shd->data); + } + shd->data = data; + shd->len = +#ifdef QT_QGARRAY_SPEED_OPTIM + shd->maxl = +#endif + len; + return *this; +} + +/*! + Resizes this array to \a len bytes and copies the \a len bytes at + address \a d into it. + + \warning This function disregards the reference count mechanism. If + other TQGArrays reference the same data as this, all will be updated. +*/ + +void TQGArray::store( const char *d, uint len ) +{ // store, but not deref + resize( len ); + memcpy( shd->data, d, len ); +} + + +/*! + \fn array_data *TQGArray::sharedBlock() const + + Returns a pointer to the shared array block. + + \warning + + Do not use this function. Using it is begging for trouble. We dare + not remove it, for fear of breaking code, but we \e strongly + discourage new use of it. +*/ + +/*! + \fn void TQGArray::setSharedBlock( array_data *p ) + + Sets the shared array block to \a p. + + \warning + + Do not use this function. Using it is begging for trouble. We dare + not remove it, for fear of breaking code, but we \e strongly + discourage new use of it. +*/ + + +/*! + Sets raw data and returns a reference to the array. + + Dereferences the current array and sets the new array data to \a d and + the new array size to \a len. Do not attempt to resize or re-assign the + array data when raw data has been set. + Call resetRawData(d,len) to reset the array. + + Setting raw data is useful because it sets TQMemArray data without + allocating memory or copying data. + + Example of intended use: + \code + static uchar bindata[] = { 231, 1, 44, ... }; + TQByteArray a; + a.setRawData( bindata, sizeof(bindata) ); // a points to bindata + TQDataStream s( a, IO_ReadOnly ); // open on a's data + s >> ; // read raw bindata + s.close(); + a.resetRawData( bindata, sizeof(bindata) ); // finished + \endcode + + Example of misuse (do not do this): + \code + static uchar bindata[] = { 231, 1, 44, ... }; + TQByteArray a, b; + a.setRawData( bindata, sizeof(bindata) ); // a points to bindata + a.resize( 8 ); // will crash + b = a; // will crash + a[2] = 123; // might crash + // forget to resetRawData - will crash + \endcode + + \warning If you do not call resetRawData(), TQGArray will attempt to + deallocate or reallocate the raw data, which might not be too good. + Be careful. +*/ + +TQGArray &TQGArray::setRawData( const char *d, uint len ) +{ + duplicate( 0, 0 ); // set null data + shd->data = (char *)d; + shd->len = len; + return *this; +} + +/*! + Resets raw data. + + The arguments must be the data, \a d, and length \a len, that were + passed to setRawData(). This is for consistency checking. +*/ + +void TQGArray::resetRawData( const char *d, uint len ) +{ + if ( d != shd->data || len != shd->len ) { +#if defined(QT_CHECK_STATE) + tqWarning( "TQGArray::resetRawData: Inconsistent arguments" ); +#endif + return; + } + shd->data = 0; + shd->len = 0; +} + + +/*! + Finds the first occurrence of \a d in the array from position \a index, + where \a sz is the size of the \a d element. + + Note that \a index is given in units of \a sz, not bytes. + + This function only compares whole cells, not bytes. +*/ + +int TQGArray::find( const char *d, uint index, uint sz ) const +{ + index *= sz; + if ( index >= shd->len ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQGArray::find: Index %d out of range", index/sz ); +#endif + return -1; + } + uint i; + uint ii; + switch ( sz ) { + case 1: { // 8 bit elements + char *x = data() + index; + char v = *d; + for ( i=index; ilen; i++ ) { + if ( *x++ == v ) + break; + } + ii = i; + } + break; + case 2: { // 16 bit elements + TQ_INT16 *x = (TQ_INT16*)(data() + index); + TQ_INT16 v = *((TQ_INT16*)d); + for ( i=index; ilen; i+=2 ) { + if ( *x++ == v ) + break; + } + ii = i/2; + } + break; + case 4: { // 32 bit elements + TQ_INT32 *x = (TQ_INT32*)(data() + index); + TQ_INT32 v = *((TQ_INT32*)d); + for ( i=index; ilen; i+=4 ) { + if ( *x++ == v ) + break; + } + ii = i/4; + } + break; + default: { // any size elements + for ( i=index; ilen; i+=sz ) { + if ( memcmp( d, &shd->data[i], sz ) == 0 ) + break; + } + ii = i/sz; + } + break; + } + return ilen ? (int)ii : -1; +} + +/*! + Returns the number of occurrences of \a d in the array, where \a sz is + the size of the \a d element. + + This function only compares whole cells, not bytes. +*/ + +int TQGArray::contains( const char *d, uint sz ) const +{ + uint i = shd->len; + int count = 0; + switch ( sz ) { + case 1: { // 8 bit elements + char *x = data(); + char v = *d; + while ( i-- ) { + if ( *x++ == v ) + count++; + } + } + break; + case 2: { // 16 bit elements + TQ_INT16 *x = (TQ_INT16*)data(); + TQ_INT16 v = *((TQ_INT16*)d); + i /= 2; + while ( i-- ) { + if ( *x++ == v ) + count++; + } + } + break; + case 4: { // 32 bit elements + TQ_INT32 *x = (TQ_INT32*)data(); + TQ_INT32 v = *((TQ_INT32*)d); + i /= 4; + while ( i-- ) { + if ( *x++ == v ) + count++; + } + } + break; + default: { // any size elements + for ( i=0; ilen; i+=sz ) { + if ( memcmp(d, &shd->data[i], sz) == 0 ) + count++; + } + } + break; + } + return count; +} + +static int cmp_item_size = 0; + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif + +#ifdef Q_OS_TEMP +static int __cdecl cmp_arr( const void *n1, const void *n2 ) +#else +static int cmp_arr( const void *n1, const void *n2 ) +#endif +{ + return ( n1 && n2 ) ? memcmp( n1, n2, cmp_item_size ) + : ( n1 ? 1 : ( n2 ? -1 : 0 ) ); + // ### TQt 3.0: Add a virtual compareItems() method and call that instead +} + +#if defined(Q_C_CALLBACKS) +} +#endif + +/*! + Sorts the first \a sz items of the array. +*/ + +void TQGArray::sort( uint sz ) +{ + int numItems = size() / sz; + if ( numItems < 2 ) + return; + +#ifdef TQT_THREAD_SUPPORT + TQMutexLocker locker( tqt_global_mutexpool ? + tqt_global_mutexpool->get( &cmp_item_size ) : 0 ); +#endif // TQT_THREAD_SUPPORT + + cmp_item_size = sz; + qsort( shd->data, numItems, sz, cmp_arr ); +} + +/*! + Binary search; assumes that \a d is a sorted array of size \a sz. +*/ + +int TQGArray::bsearch( const char *d, uint sz ) const +{ + int numItems = size() / sz; + if ( !numItems ) + return -1; + +#ifdef TQT_THREAD_SUPPORT + TQMutexLocker locker( tqt_global_mutexpool ? + tqt_global_mutexpool->get( &cmp_item_size ) : 0 ); +#endif // TQT_THREAD_SUPPORT + + cmp_item_size = sz; + char* r = (char*)::bsearch( d, shd->data, numItems, sz, cmp_arr ); + if ( !r ) + return -1; + while( (r >= shd->data + sz) && (cmp_arr( r - sz, d ) == 0) ) + r -= sz; // search to first of equal elements; bsearch is undef + return (int)(( r - shd->data ) / sz); +} + + +/*! + \fn char *TQGArray::at( uint index ) const + + Returns a pointer to the byte at offset \a index in the array. +*/ + +/*! + Expand the array if necessary, and copies (the first part of) its + contents from the \a index * \a sz bytes at \a d. + + Returns TRUE if the operation succeeds, FALSE if it runs out of + memory. + + \warning This function disregards the reference count mechanism. If + other TQGArrays reference the same data as this, all will be changed. +*/ + +bool TQGArray::setExpand( uint index, const char *d, uint sz ) +{ + index *= sz; + if ( index >= shd->len ) { + if ( !resize( index+sz ) ) // no memory + return FALSE; + } + memcpy( data() + index, d, sz ); + return TRUE; +} + + +/*! + Prints a warning message if at() or [] is given a bad index. +*/ + +void TQGArray::msg_index( uint index ) +{ +#if defined(QT_CHECK_RANGE) + tqWarning( "TQGArray::at: Absolute index %d out of range", index ); +#else + Q_UNUSED( index ) +#endif +} + + +/*! + Returns a new shared array block. +*/ + +TQGArray::array_data * TQGArray::newData() +{ + return new array_data; +} + + +/*! + Deletes the shared array block \a p. +*/ + +void TQGArray::deleteData( array_data *p ) +{ + delete p; +} diff --git a/src/tools/tqgarray.h b/src/tools/tqgarray.h new file mode 100644 index 000000000..4d239dd66 --- /dev/null +++ b/src/tools/tqgarray.h @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Definition of TQGArray class +** +** Created : 930906 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQGARRAY_H +#define TQGARRAY_H + +#ifndef QT_H +#include "ntqshared.h" +#endif // QT_H + + +class TQ_EXPORT TQGArray // generic array +{ +friend class TQBuffer; +public: + // do not use this, even though this is public + // ### make protected or private in TQt 4.0 beta? + struct array_data : public TQShared { // shared array + array_data():data(0),len(0) +#ifdef QT_QGARRAY_SPEED_OPTIM + ,maxl(0) +#endif + {} + char *data; // actual array data + uint len; +#ifdef QT_QGARRAY_SPEED_OPTIM + uint maxl; +#endif + }; + TQGArray(); + enum Optimization { MemOptim, SpeedOptim }; +protected: + TQGArray( int, int ); // dummy; does not alloc + TQGArray( int size ); // allocate 'size' bytes + TQGArray( const TQGArray &a ); // shallow copy + virtual ~TQGArray(); + + TQGArray &operator=( const TQGArray &a ) { return assign( a ); } + + virtual void detach() { duplicate(*this); } + + // ### TQt 4.0: maybe provide two versions of data(), at(), etc. + char *data() const { return shd->data; } + uint nrefs() const { return shd->count; } + uint size() const { return shd->len; } + bool isEqual( const TQGArray &a ) const; + + bool resize( uint newsize, Optimization optim ); + bool resize( uint newsize ); + + bool fill( const char *d, int len, uint sz ); + + TQGArray &assign( const TQGArray &a ); + TQGArray &assign( const char *d, uint len ); + TQGArray &duplicate( const TQGArray &a ); + TQGArray &duplicate( const char *d, uint len ); + void store( const char *d, uint len ); + + array_data *sharedBlock() const { return shd; } + void setSharedBlock( array_data *p ) { shd=(array_data*)p; } + + TQGArray &setRawData( const char *d, uint len ); + void resetRawData( const char *d, uint len ); + + int find( const char *d, uint index, uint sz ) const; + int contains( const char *d, uint sz ) const; + + void sort( uint sz ); + int bsearch( const char *d, uint sz ) const; + + char *at( uint index ) const; + + bool setExpand( uint index, const char *d, uint sz ); + +protected: + virtual array_data *newData(); + virtual void deleteData( array_data *p ); + +private: + static void msg_index( uint ); + array_data *shd; +}; + + +inline char *TQGArray::at( uint index ) const +{ +#if defined(QT_CHECK_RANGE) + if ( index >= size() ) { + msg_index( index ); + index = 0; + } +#endif + return &shd->data[index]; +} + + +#endif // TQGARRAY_H diff --git a/src/tools/tqgcache.cpp b/src/tools/tqgcache.cpp new file mode 100644 index 000000000..471b59f6c --- /dev/null +++ b/src/tools/tqgcache.cpp @@ -0,0 +1,866 @@ +/**************************************************************************** +** +** Implementation of TQGCache and TQGCacheIterator classes +** +** Created : 950208 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqgcache.h" +#include "tqptrlist.h" +#include "tqdict.h" +#include "tqstring.h" + +/*! + \class TQGCache tqgcache.h + \reentrant + \ingroup shared + \ingroup collection + \brief The TQGCache class is an internal class for implementing TQCache + template classes. + + \internal + + TQGCache is a strictly internal class that acts as a base class for the + \link collection.html collection classes\endlink TQCache and TQIntCache. +*/ + + +/***************************************************************************** + TQGCacheItem class (internal cache item) + *****************************************************************************/ + +struct TQCacheItem +{ + TQCacheItem( void *k, TQPtrCollection::Item d, int c, short p ) + : priority(p), skipPriority(p), cost(c), key(k), data(d), node(0) {} + short priority; + short skipPriority; + int cost; + void *key; + TQPtrCollection::Item data; + TQLNode *node; +}; + + +/***************************************************************************** + TQCList class (internal list of cache items) + *****************************************************************************/ + +class TQCList : private TQPtrList +{ +friend class TQGCacheIterator; +friend class TQCListIt; +public: + TQCList() {} + ~TQCList(); + + void insert( TQCacheItem * ); // insert according to priority + void insert( int, TQCacheItem * ); + void take( TQCacheItem * ); + void reference( TQCacheItem * ); + + void setAutoDelete( bool del ) { TQPtrCollection::setAutoDelete(del); } + + bool removeFirst() { return TQPtrList::removeFirst(); } + bool removeLast() { return TQPtrList::removeLast(); } + + TQCacheItem *first() { return TQPtrList::first(); } + TQCacheItem *last() { return TQPtrList::last(); } + TQCacheItem *prev() { return TQPtrList::prev(); } + TQCacheItem *next() { return TQPtrList::next(); } + +#if defined(QT_DEBUG) + int inserts; // variables for statistics + int insertCosts; + int insertMisses; + int finds; + int hits; + int hitCosts; + int dumps; + int dumpCosts; +#endif +}; + + +TQCList::~TQCList() +{ +#if defined(QT_DEBUG) + Q_ASSERT( count() == 0 ); +#endif +} + + +void TQCList::insert( TQCacheItem *ci ) +{ + TQCacheItem *item = first(); + while( item && item->skipPriority > ci->priority ) { + item->skipPriority--; + item = next(); + } + if ( item ) + TQPtrList::insert( at(), ci ); + else + append( ci ); +#if defined(QT_DEBUG) + Q_ASSERT( ci->node == 0 ); +#endif + ci->node = currentNode(); +} + +inline void TQCList::insert( int i, TQCacheItem *ci ) +{ + TQPtrList::insert( i, ci ); +#if defined(QT_DEBUG) + Q_ASSERT( ci->node == 0 ); +#endif + ci->node = currentNode(); +} + + +void TQCList::take( TQCacheItem *ci ) +{ + if ( ci ) { +#if defined(QT_DEBUG) + Q_ASSERT( ci->node != 0 ); +#endif + takeNode( ci->node ); + ci->node = 0; + } +} + + +inline void TQCList::reference( TQCacheItem *ci ) +{ +#if defined(QT_DEBUG) + Q_ASSERT( ci != 0 && ci->node != 0 ); +#endif + ci->skipPriority = ci->priority; + relinkNode( ci->node ); // relink as first item +} + + +class TQCListIt: public TQPtrListIterator +{ +public: + TQCListIt( const TQCList *p ): TQPtrListIterator( *p ) {} + TQCListIt( const TQCListIt *p ): TQPtrListIterator( *p ) {} +}; + + +/***************************************************************************** + TQCDict class (internal dictionary of cache items) + *****************************************************************************/ + +// +// Since we need to decide if the dictionary should use an int or const +// char * key (the "bool trivial" argument in the constructor below) +// we cannot use the macro/template dict, but inherit directly from TQGDict. +// + +class TQCDict : public TQGDict +{ +public: + TQCDict( uint size, uint kt, bool caseSensitive, bool copyKeys ) + : TQGDict( size, (KeyType)kt, caseSensitive, copyKeys ) {} + ~TQCDict(); + + void clear() { TQGDict::clear(); } + + TQCacheItem *find_string(const TQString &key) const + { return (TQCacheItem*)((TQCDict*)this)->look_string(key, 0, 0); } + TQCacheItem *find_ascii(const char *key) const + { return (TQCacheItem*)((TQCDict*)this)->look_ascii(key, 0, 0); } + TQCacheItem *find_int(long key) const + { return (TQCacheItem*)((TQCDict*)this)->look_int(key, 0, 0); } + + TQCacheItem *take_string(const TQString &key) + { return (TQCacheItem*)TQGDict::take_string(key); } + TQCacheItem *take_ascii(const char *key) + { return (TQCacheItem*)TQGDict::take_ascii(key); } + TQCacheItem *take_int(long key) + { return (TQCacheItem*)TQGDict::take_int(key); } + + bool insert_string( const TQString &key, const TQCacheItem *ci ) + { return TQGDict::look_string(key,(Item)ci,1)!=0;} + bool insert_ascii( const char *key, const TQCacheItem *ci ) + { return TQGDict::look_ascii(key,(Item)ci,1)!=0;} + bool insert_int( long key, const TQCacheItem *ci ) + { return TQGDict::look_int(key,(Item)ci,1)!=0;} + + bool remove_string( TQCacheItem *item ) + { return TQGDict::remove_string(*((TQString*)(item->key)),item); } + bool remove_ascii( TQCacheItem *item ) + { return TQGDict::remove_ascii((const char *)item->key,item); } + bool remove_int( TQCacheItem *item ) + { return TQGDict::remove_int((long)item->key,item);} + + void statistics() { TQGDict::statistics(); } + +private: + void deleteItem( void *item ) + { if ( del_item ) { TQCacheItem *d = (TQCacheItem*)item; delete d; } } +}; + +inline TQCDict::~TQCDict() +{ + clear(); +} + +/***************************************************************************** + TQGDict member functions + *****************************************************************************/ + +/*! + Constructs a cache. + The maximum cost of the cache is given by \a maxCost and the size by \a + size. The key type is \a kt which may be \c StringKey, \c AsciiKey, + \c IntKey or \c PtrKey. The case-sensitivity of lookups is set with + \a caseSensitive. Keys are copied if \a copyKeys is TRUE. +*/ + +TQGCache::TQGCache( int maxCost, uint size, KeyType kt, bool caseSensitive, + bool copyKeys ) +{ + keytype = kt; + lruList = new TQCList; + TQ_CHECK_PTR( lruList ); + lruList->setAutoDelete( TRUE ); + copyk = ((keytype == AsciiKey) && copyKeys); + dict = new TQCDict( size, kt, caseSensitive, FALSE ); + TQ_CHECK_PTR( dict ); + mCost = maxCost; + tCost = 0; +#if defined(QT_DEBUG) + lruList->inserts = 0; + lruList->insertCosts = 0; + lruList->insertMisses = 0; + lruList->finds = 0; + lruList->hits = 0; + lruList->hitCosts = 0; + lruList->dumps = 0; + lruList->dumpCosts = 0; +#endif +} + +/*! + Cannot copy a cache. +*/ + +TQGCache::TQGCache( const TQGCache & ) + : TQPtrCollection() +{ +#if defined(QT_CHECK_NULL) + tqFatal( "TQGCache::TQGCache(TQGCache &): Cannot copy a cache" ); +#endif +} + +/*! + Removes all items from the cache and destroys it. +*/ + +TQGCache::~TQGCache() +{ + clear(); + delete dict; + delete lruList; +} + +/*! + Cannot assign a cache. +*/ + +TQGCache &TQGCache::operator=( const TQGCache & ) +{ +#if defined(QT_CHECK_NULL) + tqFatal( "TQGCache::operator=: Cannot copy a cache" ); +#endif + return *this; +} + + +/*! + Returns the number of items in the cache. +*/ + +uint TQGCache::count() const +{ + return dict->count(); +} + +/*! + Returns the size of the hash array. +*/ + +uint TQGCache::size() const +{ + return dict->size(); +} + +/*! + \fn int TQGCache::maxCost() const + + Returns the maximum cache cost. +*/ + +/*! + \fn int TQGCache::totalCost() const + + Returns the total cache cost. +*/ + +/*! + Sets the maximum cache cost to \a maxCost. +*/ + +void TQGCache::setMaxCost( int maxCost ) +{ + if ( maxCost < tCost ) { + if ( !makeRoomFor(tCost - maxCost) ) // remove excess cost + return; + } + mCost = maxCost; +} + + +/*! + Inserts an item with data \a data into the cache using key \a key. + The item has cost \a cost and priority \a priority. + + \warning If this function returns FALSE, you must delete \a data + yourself. Additionally, be very careful about using \a data after + calling this function, as any other insertions into the cache, from + anywhere in the application, or within TQt itself, could cause the + data to be discarded from the cache, and the pointer to become + invalid. +*/ + +bool TQGCache::insert_string( const TQString &key, TQPtrCollection::Item data, + int cost, int priority) +{ + if ( tCost + cost > mCost ) { + if ( !makeRoomFor(tCost + cost - mCost, priority) ) { +#if defined(QT_DEBUG) + lruList->insertMisses++; +#endif + return FALSE; + } + } +#if defined(QT_DEBUG) + Q_ASSERT( keytype == StringKey ); + lruList->inserts++; + lruList->insertCosts += cost; +#endif + if ( priority < -32768 ) + priority = -32768; + else if ( priority > 32767 ) + priority = 32677; + TQCacheItem *ci = new TQCacheItem( new TQString(key), newItem(data), + cost, (short)priority ); + TQ_CHECK_PTR( ci ); + lruList->insert( 0, ci ); + dict->insert_string( key, ci ); + tCost += cost; + return TRUE; +} + +bool TQGCache::insert_other( const char *key, TQPtrCollection::Item data, + int cost, int priority) +{ + if ( tCost + cost > mCost ) { + if ( !makeRoomFor(tCost + cost - mCost, priority) ) { +#if defined(QT_DEBUG) + lruList->insertMisses++; +#endif + return FALSE; + } + } +#if defined(QT_DEBUG) + Q_ASSERT( keytype != StringKey ); + lruList->inserts++; + lruList->insertCosts += cost; +#endif + if ( keytype == AsciiKey && copyk ) + key = tqstrdup( key ); + if ( priority < -32768 ) + priority = -32768; + else if ( priority > 32767 ) + priority = 32677; + TQCacheItem *ci = new TQCacheItem( (void*)key, newItem(data), cost, + (short)priority ); + TQ_CHECK_PTR( ci ); + lruList->insert( 0, ci ); + if ( keytype == AsciiKey ) + dict->insert_ascii( key, ci ); + else + dict->insert_int( (long)key, ci ); + tCost += cost; + return TRUE; +} + + +/*! + Removes the item with key \a key from the cache. Returns TRUE if the + item was removed; otherwise returns FALSE. +*/ + +bool TQGCache::remove_string( const TQString &key ) +{ + Item d = take_string( key ); + if ( d ) + deleteItem( d ); + return d != 0; +} + +bool TQGCache::remove_other( const char *key ) +{ + Item d = take_other( key ); + if ( d ) + deleteItem( d ); + return d != 0; +} + + +/*! + Takes the item with key \a key out of the cache. The item is not + deleted. If no item has this \a key 0 is returned. +*/ + +TQPtrCollection::Item TQGCache::take_string( const TQString &key ) +{ + TQCacheItem *ci = dict->take_string( key ); // take from dict + Item d; + if ( ci ) { + d = ci->data; + tCost -= ci->cost; + lruList->take( ci ); // take from list + delete (TQString*)ci->key; + delete ci; + } else { + d = 0; + } + return d; +} + +/*! + Takes the item with key \a key out of the cache. The item is not + deleted. If no item has this \a key 0 is returned. +*/ + +TQPtrCollection::Item TQGCache::take_other( const char *key ) +{ + TQCacheItem *ci; + if ( keytype == AsciiKey ) + ci = dict->take_ascii( key ); + else + ci = dict->take_int( (long)key ); + Item d; + if ( ci ) { + d = ci->data; + tCost -= ci->cost; + lruList->take( ci ); // take from list + if ( copyk ) + delete [] (char *)ci->key; + delete ci; + } else { + d = 0; + } + return d; +} + + +/*! + Clears the cache. +*/ + +void TQGCache::clear() +{ + TQCacheItem *ci; + while ( (ci = lruList->first()) ) { + switch ( keytype ) { + case StringKey: + dict->remove_string( ci ); + delete (TQString*)ci->key; + break; + case AsciiKey: + dict->remove_ascii( ci ); + if ( copyk ) + delete [] (char*)ci->key; + break; + case IntKey: + dict->remove_int( ci ); + break; + case PtrKey: // unused + break; + } + deleteItem( ci->data ); // delete data + lruList->removeFirst(); // remove from list + } + tCost = 0; +} + + +/*! + Finds an item for \a key in the cache and adds a reference if \a ref is TRUE. +*/ + +TQPtrCollection::Item TQGCache::find_string( const TQString &key, bool ref ) const +{ + TQCacheItem *ci = dict->find_string( key ); +#if defined(QT_DEBUG) + lruList->finds++; +#endif + if ( ci ) { +#if defined(QT_DEBUG) + lruList->hits++; + lruList->hitCosts += ci->cost; +#endif + if ( ref ) + lruList->reference( ci ); + return ci->data; + } + return 0; +} + + +/*! + Finds an item for \a key in the cache and adds a reference if \a ref is TRUE. +*/ + +TQPtrCollection::Item TQGCache::find_other( const char *key, bool ref ) const +{ + TQCacheItem *ci = keytype == AsciiKey ? dict->find_ascii(key) + : dict->find_int((long)key); +#if defined(QT_DEBUG) + lruList->finds++; +#endif + if ( ci ) { +#if defined(QT_DEBUG) + lruList->hits++; + lruList->hitCosts += ci->cost; +#endif + if ( ref ) + lruList->reference( ci ); + return ci->data; + } + return 0; +} + + +/*! + Allocates cache space for one or more items. +*/ + +bool TQGCache::makeRoomFor( int cost, int priority ) +{ + if ( cost > mCost ) // cannot make room for more + return FALSE; // than maximum cost + if ( priority == -1 ) + priority = 32767; + TQCacheItem *ci = lruList->last(); + int cntCost = 0; + int dumps = 0; // number of items to dump + while ( cntCost < cost && ci && ci->skipPriority <= priority ) { + cntCost += ci->cost; + ci = lruList->prev(); + dumps++; + } + if ( cntCost < cost ) // can enough cost be dumped? + return FALSE; // no +#if defined(QT_DEBUG) + Q_ASSERT( dumps > 0 ); +#endif + while ( dumps-- ) { + ci = lruList->last(); +#if defined(QT_DEBUG) + lruList->dumps++; + lruList->dumpCosts += ci->cost; +#endif + switch ( keytype ) { + case StringKey: + dict->remove_string( ci ); + delete (TQString*)ci->key; + break; + case AsciiKey: + dict->remove_ascii( ci ); + if ( copyk ) + delete [] (char *)ci->key; + break; + case IntKey: + dict->remove_int( ci ); + break; + case PtrKey: // unused + break; + } + deleteItem( ci->data ); // delete data + lruList->removeLast(); // remove from list + } + tCost -= cntCost; + return TRUE; +} + + +/*! + Outputs debug statistics. +*/ + +void TQGCache::statistics() const +{ +#if defined(QT_DEBUG) + TQString line; + line.fill( '*', 80 ); + tqDebug( "%s", line.ascii() ); + tqDebug( "CACHE STATISTICS:" ); + tqDebug( "cache contains %d item%s, with a total cost of %d", + count(), count() != 1 ? "s" : "", tCost ); + tqDebug( "maximum cost is %d, cache is %d%% full.", + mCost, (200*tCost + mCost) / (mCost*2) ); + tqDebug( "find() has been called %d time%s", + lruList->finds, lruList->finds != 1 ? "s" : "" ); + tqDebug( "%d of these were hits, items found had a total cost of %d.", + lruList->hits,lruList->hitCosts ); + tqDebug( "%d item%s %s been inserted with a total cost of %d.", + lruList->inserts,lruList->inserts != 1 ? "s" : "", + lruList->inserts != 1 ? "have" : "has", lruList->insertCosts ); + tqDebug( "%d item%s %s too large or had too low priority to be inserted.", + lruList->insertMisses, lruList->insertMisses != 1 ? "s" : "", + lruList->insertMisses != 1 ? "were" : "was" ); + tqDebug( "%d item%s %s been thrown away with a total cost of %d.", + lruList->dumps, lruList->dumps != 1 ? "s" : "", + lruList->dumps != 1 ? "have" : "has", lruList->dumpCosts ); + tqDebug( "Statistics from internal dictionary class:" ); + dict->statistics(); + tqDebug( "%s", line.ascii() ); +#endif +} + + +/***************************************************************************** + TQGCacheIterator member functions + *****************************************************************************/ + +/*! + \class TQGCacheIterator tqgcache.h + \reentrant + \ingroup shared + \ingroup collection + \brief The TQGCacheIterator class is an internal class for implementing TQCacheIterator and + TQIntCacheIterator. + + \internal + + TQGCacheIterator is a strictly internal class that does the heavy work for + TQCacheIterator and TQIntCacheIterator. +*/ + +/*! + Constructs an iterator that operates on the cache \a c. +*/ + +TQGCacheIterator::TQGCacheIterator( const TQGCache &c ) +{ + it = new TQCListIt( c.lruList ); +#if defined(QT_DEBUG) + Q_ASSERT( it != 0 ); +#endif +} + +/*! + Constructs an iterator that operates on the same cache as \a ci. +*/ + +TQGCacheIterator::TQGCacheIterator( const TQGCacheIterator &ci ) +{ + it = new TQCListIt( ci.it ); +#if defined(QT_DEBUG) + Q_ASSERT( it != 0 ); +#endif +} + +/*! + Destroys the iterator. +*/ + +TQGCacheIterator::~TQGCacheIterator() +{ + delete it; +} + +/*! + Assigns the iterator \a ci to this cache iterator. +*/ + +TQGCacheIterator &TQGCacheIterator::operator=( const TQGCacheIterator &ci ) +{ + *it = *ci.it; + return *this; +} + +/*! + Returns the number of items in the cache. +*/ + +uint TQGCacheIterator::count() const +{ + return it->count(); +} + +/*! + Returns TRUE if the iterator points to the first item. +*/ + +bool TQGCacheIterator::atFirst() const +{ + return it->atFirst(); +} + +/*! + Returns TRUE if the iterator points to the last item. +*/ + +bool TQGCacheIterator::atLast() const +{ + return it->atLast(); +} + +/*! + Sets the list iterator to point to the first item in the cache. +*/ + +TQPtrCollection::Item TQGCacheIterator::toFirst() +{ + TQCacheItem *item = it->toFirst(); + return item ? item->data : 0; +} + +/*! + Sets the list iterator to point to the last item in the cache. +*/ + +TQPtrCollection::Item TQGCacheIterator::toLast() +{ + TQCacheItem *item = it->toLast(); + return item ? item->data : 0; +} + +/*! + Returns the current item. +*/ + +TQPtrCollection::Item TQGCacheIterator::get() const +{ + TQCacheItem *item = it->current(); + return item ? item->data : 0; +} + +/*! + Returns the key of the current item. +*/ + +TQString TQGCacheIterator::getKeyString() const +{ + TQCacheItem *item = it->current(); + return item ? *((TQString*)item->key) : TQString::null; +} + +/*! + Returns the key of the current item, as a \0-terminated C string. +*/ + +const char *TQGCacheIterator::getKeyAscii() const +{ + TQCacheItem *item = it->current(); + return item ? (const char *)item->key : 0; +} + +/*! + Returns the key of the current item, as a long. +*/ + +long TQGCacheIterator::getKeyInt() const +{ + TQCacheItem *item = it->current(); + return item ? (long)item->key : 0; +} + +/*! + Moves to the next item (postfix). +*/ + +TQPtrCollection::Item TQGCacheIterator::operator()() +{ + TQCacheItem *item = it->operator()(); + return item ? item->data : 0; +} + +/*! + Moves to the next item (prefix). +*/ + +TQPtrCollection::Item TQGCacheIterator::operator++() +{ + TQCacheItem *item = it->operator++(); + return item ? item->data : 0; +} + +/*! + Moves \a jump positions forward. +*/ + +TQPtrCollection::Item TQGCacheIterator::operator+=( uint jump ) +{ + TQCacheItem *item = it->operator+=(jump); + return item ? item->data : 0; +} + +/*! + Moves to the previous item (prefix). +*/ + +TQPtrCollection::Item TQGCacheIterator::operator--() +{ + TQCacheItem *item = it->operator--(); + return item ? item->data : 0; +} + +/*! + Moves \a jump positions backward. +*/ + +TQPtrCollection::Item TQGCacheIterator::operator-=( uint jump ) +{ + TQCacheItem *item = it->operator-=(jump); + return item ? item->data : 0; +} diff --git a/src/tools/tqgcache.h b/src/tools/tqgcache.h new file mode 100644 index 000000000..5fea6c901 --- /dev/null +++ b/src/tools/tqgcache.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Definition of TQGCache and TQGCacheIterator classes +** +** Created : 950208 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQGCACHE_H +#define TQGCACHE_H + +#ifndef QT_H +#include "tqptrcollection.h" +#include "tqglist.h" +#include "tqgdict.h" +#endif // QT_H + + +class TQCList; // internal classes +class TQCListIt; +class TQCDict; + + +class TQ_EXPORT TQGCache : public TQPtrCollection // generic LRU cache +{ +friend class TQGCacheIterator; +protected: + enum KeyType { StringKey, AsciiKey, IntKey, PtrKey }; + // identical to TQGDict's, but PtrKey is not used at the moment + + TQGCache( int maxCost, uint size, KeyType kt, bool caseSensitive, + bool copyKeys ); + TQGCache( const TQGCache & ); // not allowed, calls fatal() + ~TQGCache(); + TQGCache &operator=( const TQGCache & ); // not allowed, calls fatal() + + uint count() const; + uint size() const; + int maxCost() const { return mCost; } + int totalCost() const { return tCost; } + void setMaxCost( int maxCost ); + void clear(); + + bool insert_string( const TQString &key, TQPtrCollection::Item, + int cost, int priority ); + bool insert_other( const char *key, TQPtrCollection::Item, + int cost, int priority ); + bool remove_string( const TQString &key ); + bool remove_other( const char *key ); + TQPtrCollection::Item take_string( const TQString &key ); + TQPtrCollection::Item take_other( const char *key ); + + TQPtrCollection::Item find_string( const TQString &key, bool ref=TRUE ) const; + TQPtrCollection::Item find_other( const char *key, bool ref=TRUE ) const; + + void statistics() const; + +private: + bool makeRoomFor( int cost, int priority = -1 ); + KeyType keytype; + TQCList *lruList; + TQCDict *dict; + int mCost; + int tCost; + bool copyk; +}; + + +class TQ_EXPORT TQGCacheIterator // generic cache iterator +{ +protected: + TQGCacheIterator( const TQGCache & ); + TQGCacheIterator( const TQGCacheIterator & ); + ~TQGCacheIterator(); + TQGCacheIterator &operator=( const TQGCacheIterator & ); + + uint count() const; + bool atFirst() const; + bool atLast() const; + TQPtrCollection::Item toFirst(); + TQPtrCollection::Item toLast(); + + TQPtrCollection::Item get() const; + TQString getKeyString() const; + const char *getKeyAscii() const; + long getKeyInt() const; + + TQPtrCollection::Item operator()(); + TQPtrCollection::Item operator++(); + TQPtrCollection::Item operator+=( uint ); + TQPtrCollection::Item operator--(); + TQPtrCollection::Item operator-=( uint ); + +protected: + TQCListIt *it; // iterator on cache list +}; + + +#endif // TQGCACHE_H diff --git a/src/tools/tqgdict.cpp b/src/tools/tqgdict.cpp new file mode 100644 index 000000000..894881a61 --- /dev/null +++ b/src/tools/tqgdict.cpp @@ -0,0 +1,1151 @@ +/**************************************************************************** +** +** Implementation of TQGDict and TQGDictIterator classes +** +** Created : 920529 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqgdict.h" +#include "tqptrlist.h" +#include "tqstring.h" +#include "tqdatastream.h" +#include + +/*! + \class TQGDict + \reentrant + \ingroup collection + \brief The TQGDict class is an internal class for implementing TQDict template classes. + + \internal + + TQGDict is a strictly internal class that acts as a base class for the + \link collection.html collection classes\endlink TQDict and TQIntDict. + + TQGDict has some virtual functions that can be reimplemented to customize + the subclasses. + \list + \i read() reads a collection/dictionary item from a TQDataStream. + \i write() writes a collection/dictionary item to a TQDataStream. + \endlist + Normally, you do not have to reimplement any of these functions. +*/ + +static const int op_find = 0; +static const int op_insert = 1; +static const int op_replace = 2; + + +class TQGDItList : public TQPtrList +{ +public: + TQGDItList() : TQPtrList() {} + TQGDItList( const TQGDItList &list ) : TQPtrList(list) {} + ~TQGDItList() { clear(); } + TQGDItList &operator=(const TQGDItList &list) + { return (TQGDItList&)TQPtrList::operator=(list); } +}; + + +/***************************************************************************** + Default implementation of special and virtual functions + *****************************************************************************/ + +/*! + Returns the hash key for \a key, when key is a string. +*/ + +int TQGDict::hashKeyString( const TQString &key ) +{ +#if defined(QT_CHECK_NULL) + if ( key.isNull() ) + tqWarning( "TQGDict::hashKeyString: Invalid null key" ); +#endif + int i; + uint h=0; + uint g; + const TQChar *p = key.unicode(); + if ( cases ) { // case sensitive + for ( i=0; i<(int)key.length(); i++ ) { + h = (h<<4) + p[i].cell(); + if ( (g = h & 0xf0000000) ) + h ^= g >> 24; + h &= ~g; + } + } else { // case insensitive + for ( i=0; i<(int)key.length(); i++ ) { + h = (h<<4) + p[i].lower().cell(); + if ( (g = h & 0xf0000000) ) + h ^= g >> 24; + h &= ~g; + } + } + int index = h; + if ( index < 0 ) // adjust index to table size + index = -index; + return index; +} + +/*! + Returns the hash key for \a key, which is a C string. +*/ + +int TQGDict::hashKeyAscii( const char *key ) +{ +#if defined(QT_CHECK_NULL) + if ( key == 0 ) + tqWarning( "TQGDict::hashAsciiKey: Invalid null key" ); +#endif + const char *k = key; + uint h=0; + uint g; + if ( cases ) { // case sensitive + while ( *k ) { + h = (h<<4) + *k++; + if ( (g = h & 0xf0000000) ) + h ^= g >> 24; + h &= ~g; + } + } else { // case insensitive + while ( *k ) { + h = (h<<4) + tolower((uchar) *k); + if ( (g = h & 0xf0000000) ) + h ^= g >> 24; + h &= ~g; + k++; + } + } + int index = h; + if ( index < 0 ) // adjust index to table size + index = -index; + return index; +} + +#ifndef TQT_NO_DATASTREAM + +/*! + \overload + Reads a collection/dictionary item from the stream \a s and returns a + reference to the stream. + + The default implementation sets \a item to 0. + + \sa write() +*/ + +TQDataStream& TQGDict::read( TQDataStream &s, TQPtrCollection::Item &item ) +{ + item = 0; + return s; +} + +/*! + \overload + Writes a collection/dictionary item to the stream \a s and returns a + reference to the stream. + + \sa read() +*/ + +TQDataStream& TQGDict::write( TQDataStream &s, TQPtrCollection::Item ) const +{ + return s; +} +#endif //TQT_NO_DATASTREAM + +/***************************************************************************** + TQGDict member functions + *****************************************************************************/ + +/*! + Constructs a dictionary. + + \a len is the initial size of the dictionary. + The key type is \a kt which may be \c StringKey, \c AsciiKey, + \c IntKey or \c PtrKey. The case-sensitivity of lookups is set with + \a caseSensitive. Keys are copied if \a copyKeys is TRUE. +*/ + +TQGDict::TQGDict( uint len, KeyType kt, bool caseSensitive, bool copyKeys ) +{ + init( len, kt, caseSensitive, copyKeys ); +} + + +void TQGDict::init( uint len, KeyType kt, bool caseSensitive, bool copyKeys ) +{ + vlen = len ? len : 17; + vec = new TQBaseBucket *[ vlen ]; + + TQ_CHECK_PTR( vec ); + memset( (char*)vec, 0, vlen*sizeof(TQBaseBucket*) ); + numItems = 0; + iterators = 0; + // The caseSensitive and copyKey options don't make sense for + // all dict types. + switch ( (keytype = (uint)kt) ) { + case StringKey: + cases = caseSensitive; + copyk = FALSE; + break; + case AsciiKey: + cases = caseSensitive; + copyk = copyKeys; + break; + default: + cases = FALSE; + copyk = FALSE; + break; + } +} + + +/*! + Constructs a copy of \a dict. +*/ + +TQGDict::TQGDict( const TQGDict & dict ) + : TQPtrCollection( dict ) +{ + init( dict.vlen, (KeyType)dict.keytype, dict.cases, dict.copyk ); + TQGDictIterator it( dict ); + while ( it.get() ) { // copy from other dict + switch ( keytype ) { + case StringKey: + look_string( it.getKeyString(), it.get(), op_insert ); + break; + case AsciiKey: + look_ascii( it.getKeyAscii(), it.get(), op_insert ); + break; + case IntKey: + look_int( it.getKeyInt(), it.get(), op_insert ); + break; + case PtrKey: + look_ptr( it.getKeyPtr(), it.get(), op_insert ); + break; + } + ++it; + } +} + + +/*! + Removes all items from the dictionary and destroys it. +*/ + +TQGDict::~TQGDict() +{ + clear(); // delete everything + delete [] vec; + if ( !iterators ) // no iterators for this dict + return; + TQGDictIterator *i = iterators->first(); + while ( i ) { // notify all iterators that + i->dict = 0; // this dict is deleted + i = iterators->next(); + } + delete iterators; +} + + +/*! + Assigns \a dict to this dictionary. +*/ + +TQGDict &TQGDict::operator=( const TQGDict &dict ) +{ + if ( &dict == this ) + return *this; + clear(); + TQGDictIterator it( dict ); + while ( it.get() ) { // copy from other dict + switch ( keytype ) { + case StringKey: + look_string( it.getKeyString(), it.get(), op_insert ); + break; + case AsciiKey: + look_ascii( it.getKeyAscii(), it.get(), op_insert ); + break; + case IntKey: + look_int( it.getKeyInt(), it.get(), op_insert ); + break; + case PtrKey: + look_ptr( it.getKeyPtr(), it.get(), op_insert ); + break; + } + ++it; + } + return *this; +} + +/*! + \fn uint TQGDict::count() const + + Returns the number of items in the dictionary. +*/ + +/*! + \fn uint TQGDict::size() const + + Returns the size of the hash array. +*/ + +/*! + The do-it-all function; \a op is one of op_find, op_insert, op_replace. + The key is \a key and the item is \a d. +*/ + +TQPtrCollection::Item TQGDict::look_string( const TQString &key, TQPtrCollection::Item d, + int op ) +{ + TQStringBucket *n = 0; + int index = hashKeyString(key) % vlen; + if ( op == op_find ) { // find + if ( cases ) { + n = (TQStringBucket*)vec[index]; + while( n != 0 ) { + if ( key == n->getKey() ) + return n->getData(); // item found + n = (TQStringBucket*)n->getNext(); + } + } else { + TQString k = key.lower(); + n = (TQStringBucket*)vec[index]; + while( n != 0 ) { + if ( k == n->getKey().lower() ) + return n->getData(); // item found + n = (TQStringBucket*)n->getNext(); + } + } + return 0; // not found + } + if ( op == op_replace ) { // replace + if ( vec[index] != 0 ) // maybe something there + remove_string( key ); + } + // op_insert or op_replace + n = new TQStringBucket(key,newItem(d),vec[index]); + TQ_CHECK_PTR( n ); +#if defined(QT_CHECK_NULL) + if ( n->getData() == 0 ) + tqWarning( "TQDict: Cannot insert null item" ); +#endif + vec[index] = n; + numItems++; + return n->getData(); +} + +TQPtrCollection::Item TQGDict::look_ascii( const char *key, TQPtrCollection::Item d, int op ) +{ + TQAsciiBucket *n; + int index = hashKeyAscii(key) % vlen; + if ( op == op_find ) { // find + if ( cases ) { + for ( n=(TQAsciiBucket*)vec[index]; n; + n=(TQAsciiBucket*)n->getNext() ) { + if ( qstrcmp(n->getKey(),key) == 0 ) + return n->getData(); // item found + } + } else { + for ( n=(TQAsciiBucket*)vec[index]; n; + n=(TQAsciiBucket*)n->getNext() ) { + if ( tqstricmp(n->getKey(),key) == 0 ) + return n->getData(); // item found + } + } + return 0; // not found + } + if ( op == op_replace ) { // replace + if ( vec[index] != 0 ) // maybe something there + remove_ascii( key ); + } + // op_insert or op_replace + n = new TQAsciiBucket(copyk ? tqstrdup(key) : key,newItem(d),vec[index]); + TQ_CHECK_PTR( n ); +#if defined(QT_CHECK_NULL) + if ( n->getData() == 0 ) + tqWarning( "TQAsciiDict: Cannot insert null item" ); +#endif + vec[index] = n; + numItems++; + return n->getData(); +} + +TQPtrCollection::Item TQGDict::look_int( long key, TQPtrCollection::Item d, int op ) +{ + TQIntBucket *n; + int index = (int)((ulong)key % vlen); // simple hash + if ( op == op_find ) { // find + for ( n=(TQIntBucket*)vec[index]; n; + n=(TQIntBucket*)n->getNext() ) { + if ( n->getKey() == key ) + return n->getData(); // item found + } + return 0; // not found + } + if ( op == op_replace ) { // replace + if ( vec[index] != 0 ) // maybe something there + remove_int( key ); + } + // op_insert or op_replace + n = new TQIntBucket(key,newItem(d),vec[index]); + TQ_CHECK_PTR( n ); +#if defined(QT_CHECK_NULL) + if ( n->getData() == 0 ) + tqWarning( "TQIntDict: Cannot insert null item" ); +#endif + vec[index] = n; + numItems++; + return n->getData(); +} + +TQPtrCollection::Item TQGDict::look_ptr( void *key, TQPtrCollection::Item d, int op ) +{ + TQPtrBucket *n; + int index = (int)((ulong)key % vlen); // simple hash + if ( op == op_find ) { // find + for ( n=(TQPtrBucket*)vec[index]; n; + n=(TQPtrBucket*)n->getNext() ) { + if ( n->getKey() == key ) + return n->getData(); // item found + } + return 0; // not found + } + if ( op == op_replace ) { // replace + if ( vec[index] != 0 ) // maybe something there + remove_ptr( key ); + } + // op_insert or op_replace + n = new TQPtrBucket(key,newItem(d),vec[index]); + TQ_CHECK_PTR( n ); +#if defined(QT_CHECK_NULL) + if ( n->getData() == 0 ) + tqWarning( "TQPtrDict: Cannot insert null item" ); +#endif + vec[index] = n; + numItems++; + return n->getData(); +} + + +/*! + Changes the size of the hashtable to \a newsize. + The contents of the dictionary are preserved, + but all iterators on the dictionary become invalid. +*/ +void TQGDict::resize( uint newsize ) +{ + // Save old information + TQBaseBucket **old_vec = vec; + uint old_vlen = vlen; + bool old_copyk = copyk; + + vec = new TQBaseBucket *[vlen = newsize]; + TQ_CHECK_PTR( vec ); + memset( (char*)vec, 0, vlen*sizeof(TQBaseBucket*) ); + numItems = 0; + copyk = FALSE; + + // Reinsert every item from vec, deleting vec as we go + for ( uint index = 0; index < old_vlen; index++ ) { + switch ( keytype ) { + case StringKey: + { + TQStringBucket *n=(TQStringBucket *)old_vec[index]; + while ( n ) { + look_string( n->getKey(), n->getData(), op_insert ); + TQStringBucket *t=(TQStringBucket *)n->getNext(); + delete n; + n = t; + } + } + break; + case AsciiKey: + { + TQAsciiBucket *n=(TQAsciiBucket *)old_vec[index]; + while ( n ) { + look_ascii( n->getKey(), n->getData(), op_insert ); + TQAsciiBucket *t=(TQAsciiBucket *)n->getNext(); + delete n; + n = t; + } + } + break; + case IntKey: + { + TQIntBucket *n=(TQIntBucket *)old_vec[index]; + while ( n ) { + look_int( n->getKey(), n->getData(), op_insert ); + TQIntBucket *t=(TQIntBucket *)n->getNext(); + delete n; + n = t; + } + } + break; + case PtrKey: + { + TQPtrBucket *n=(TQPtrBucket *)old_vec[index]; + while ( n ) { + look_ptr( n->getKey(), n->getData(), op_insert ); + TQPtrBucket *t=(TQPtrBucket *)n->getNext(); + delete n; + n = t; + } + } + break; + } + } + delete [] old_vec; + + // Restore state + copyk = old_copyk; + + // Invalidate all iterators, since order is lost + if ( iterators && iterators->count() ) { + TQGDictIterator *i = iterators->first(); + while ( i ) { + i->toFirst(); + i = iterators->next(); + } + } +} + +/*! + Unlinks the bucket with the specified key (and specified data pointer, + if it is set). +*/ + +void TQGDict::unlink_common( int index, TQBaseBucket *node, TQBaseBucket *prev ) +{ + if ( iterators && iterators->count() ) { // update iterators + TQGDictIterator *i = iterators->first(); + while ( i ) { // invalidate all iterators + if ( i->curNode == node ) // referring to pending node + i->operator++(); + i = iterators->next(); + } + } + if ( prev ) // unlink node + prev->setNext( node->getNext() ); + else + vec[index] = node->getNext(); + numItems--; +} + +TQStringBucket *TQGDict::unlink_string( const TQString &key, TQPtrCollection::Item d ) +{ + if ( numItems == 0 ) // nothing in dictionary + return 0; + TQStringBucket *n; + TQStringBucket *prev = 0; + int index = hashKeyString(key) % vlen; + if ( cases ) { + for ( n=(TQStringBucket*)vec[index]; n; + n=(TQStringBucket*)n->getNext() ) { + bool found = (key == n->getKey()); + if ( found && d ) + found = (n->getData() == d); + if ( found ) { + unlink_common(index,n,prev); + return n; + } + prev = n; + } + } else { + TQString k = key.lower(); + for ( n=(TQStringBucket*)vec[index]; n; + n=(TQStringBucket*)n->getNext() ) { + bool found = (k == n->getKey().lower()); + if ( found && d ) + found = (n->getData() == d); + if ( found ) { + unlink_common(index,n,prev); + return n; + } + prev = n; + } + } + return 0; +} + +TQAsciiBucket *TQGDict::unlink_ascii( const char *key, TQPtrCollection::Item d ) +{ + if ( numItems == 0 ) // nothing in dictionary + return 0; + TQAsciiBucket *n; + TQAsciiBucket *prev = 0; + int index = hashKeyAscii(key) % vlen; + for ( n=(TQAsciiBucket *)vec[index]; n; n=(TQAsciiBucket *)n->getNext() ) { + bool found = (cases ? qstrcmp(n->getKey(),key) + : tqstricmp(n->getKey(),key)) == 0; + if ( found && d ) + found = (n->getData() == d); + if ( found ) { + unlink_common(index,n,prev); + return n; + } + prev = n; + } + return 0; +} + +TQIntBucket *TQGDict::unlink_int( long key, TQPtrCollection::Item d ) +{ + if ( numItems == 0 ) // nothing in dictionary + return 0; + TQIntBucket *n; + TQIntBucket *prev = 0; + int index = (int)((ulong)key % vlen); + for ( n=(TQIntBucket *)vec[index]; n; n=(TQIntBucket *)n->getNext() ) { + bool found = (n->getKey() == key); + if ( found && d ) + found = (n->getData() == d); + if ( found ) { + unlink_common(index,n,prev); + return n; + } + prev = n; + } + return 0; +} + +TQPtrBucket *TQGDict::unlink_ptr( void *key, TQPtrCollection::Item d ) +{ + if ( numItems == 0 ) // nothing in dictionary + return 0; + TQPtrBucket *n; + TQPtrBucket *prev = 0; + int index = (int)((ulong)key % vlen); + for ( n=(TQPtrBucket *)vec[index]; n; n=(TQPtrBucket *)n->getNext() ) { + bool found = (n->getKey() == key); + if ( found && d ) + found = (n->getData() == d); + if ( found ) { + unlink_common(index,n,prev); + return n; + } + prev = n; + } + return 0; +} + + +/*! + Removes the item with the specified \a key. If \a item is not null, + the remove will match the \a item as well (used to remove an + item when several items have the same key). +*/ + +bool TQGDict::remove_string( const TQString &key, TQPtrCollection::Item item ) +{ + TQStringBucket *n = unlink_string( key, item ); + if ( n ) { + deleteItem( n->getData() ); + delete n; + return TRUE; + } else { + return FALSE; + } +} + +bool TQGDict::remove_ascii( const char *key, TQPtrCollection::Item item ) +{ + TQAsciiBucket *n = unlink_ascii( key, item ); + if ( n ) { + if ( copyk ) + delete [] (char *)n->getKey(); + deleteItem( n->getData() ); + delete n; + } + return n != 0; +} + +bool TQGDict::remove_int( long key, TQPtrCollection::Item item ) +{ + TQIntBucket *n = unlink_int( key, item ); + if ( n ) { + deleteItem( n->getData() ); + delete n; + } + return n != 0; +} + +bool TQGDict::remove_ptr( void *key, TQPtrCollection::Item item ) +{ + TQPtrBucket *n = unlink_ptr( key, item ); + if ( n ) { + deleteItem( n->getData() ); + delete n; + } + return n != 0; +} + +TQPtrCollection::Item TQGDict::take_string( const TQString &key ) +{ + TQStringBucket *n = unlink_string( key ); + Item d; + if ( n ) { + d = n->getData(); + delete n; + } else { + d = 0; + } + return d; +} + +TQPtrCollection::Item TQGDict::take_ascii( const char *key ) +{ + TQAsciiBucket *n = unlink_ascii( key ); + Item d; + if ( n ) { + if ( copyk ) + delete [] (char *)n->getKey(); + d = n->getData(); + delete n; + } else { + d = 0; + } + return d; +} + +TQPtrCollection::Item TQGDict::take_int( long key ) +{ + TQIntBucket *n = unlink_int( key ); + Item d; + if ( n ) { + d = n->getData(); + delete n; + } else { + d = 0; + } + return d; +} + +TQPtrCollection::Item TQGDict::take_ptr( void *key ) +{ + TQPtrBucket *n = unlink_ptr( key ); + Item d; + if ( n ) { + d = n->getData(); + delete n; + } else { + d = 0; + } + return d; +} + +/*! + Removes all items from the dictionary. +*/ +void TQGDict::clear() +{ + if ( !numItems ) + return; + numItems = 0; // disable remove() function + for ( uint j=0; jgetNext(); + deleteItem( n->getData() ); + delete n; + n = next; + } + } + break; + case AsciiKey: + { + TQAsciiBucket *n=(TQAsciiBucket *)vec[j]; + while ( n ) { + TQAsciiBucket *next = (TQAsciiBucket*)n->getNext(); + if ( copyk ) + delete [] (char *)n->getKey(); + deleteItem( n->getData() ); + delete n; + n = next; + } + } + break; + case IntKey: + { + TQIntBucket *n=(TQIntBucket *)vec[j]; + while ( n ) { + TQIntBucket *next = (TQIntBucket*)n->getNext(); + deleteItem( n->getData() ); + delete n; + n = next; + } + } + break; + case PtrKey: + { + TQPtrBucket *n=(TQPtrBucket *)vec[j]; + while ( n ) { + TQPtrBucket *next = (TQPtrBucket*)n->getNext(); + deleteItem( n->getData() ); + delete n; + n = next; + } + } + break; + } + vec[j] = 0; // detach list of buckets + } + } + if ( iterators && iterators->count() ) { // invalidate all iterators + TQGDictIterator *i = iterators->first(); + while ( i ) { + i->curNode = 0; + i = iterators->next(); + } + } +} + +/*! + Outputs debug statistics. +*/ +void TQGDict::statistics() const +{ +#if defined(QT_DEBUG) + TQString line; + line.fill( '-', 60 ); + double real, ideal; + tqDebug( "%s", line.ascii() ); + tqDebug( "DICTIONARY STATISTICS:" ); + if ( count() == 0 ) { + tqDebug( "Empty!" ); + tqDebug( "%s", line.ascii() ); + return; + } + real = 0.0; + ideal = (float)count()/(2.0*size())*(count()+2.0*size()-1); + uint i = 0; + while ( igetNext(); + } + real = real + (double)b * ((double)b+1.0)/2.0; + char buf[80], *pbuf; + if ( b > 78 ) + b = 78; + pbuf = buf; + while ( b-- ) + *pbuf++ = '*'; + *pbuf = '\0'; + tqDebug( "%s", buf ); + i++; + } + tqDebug( "Array size = %d", size() ); + tqDebug( "# items = %d", count() ); + tqDebug( "Real dist = %g", real ); + tqDebug( "Rand dist = %g", ideal ); + tqDebug( "Real/Rand = %g", real/ideal ); + tqDebug( "%s", line.ascii() ); +#endif // QT_DEBUG +} + + +/***************************************************************************** + TQGDict stream functions + *****************************************************************************/ +#ifndef TQT_NO_DATASTREAM +TQDataStream &operator>>( TQDataStream &s, TQGDict &dict ) +{ + return dict.read( s ); +} + +TQDataStream &operator<<( TQDataStream &s, const TQGDict &dict ) +{ + return dict.write( s ); +} + +#if defined(Q_CC_DEC) && defined(__alpha) && (__DECCXX_VER-0 >= 50190001) +#pragma message disable narrowptr +#endif + +/*! + Reads a dictionary from the stream \a s. +*/ + +TQDataStream &TQGDict::read( TQDataStream &s ) +{ + uint num; + s >> num; // read number of items + clear(); // clear dict + while ( num-- ) { // read all items + Item d; + switch ( keytype ) { + case StringKey: + { + TQString k; + s >> k; + read( s, d ); + look_string( k, d, op_insert ); + } + break; + case AsciiKey: + { + char *k; + s >> k; + read( s, d ); + look_ascii( k, d, op_insert ); + if ( copyk ) + delete [] k; + } + break; + case IntKey: + { + TQ_UINT32 k; + s >> k; + read( s, d ); + look_int( k, d, op_insert ); + } + break; + case PtrKey: + { + TQ_UINT32 k; + s >> k; + read( s, d ); + // ### cannot insert 0 - this renders the thing + // useless since all pointers are written as 0, + // but hey, serializing pointers? can it be done + // at all, ever? + if ( k ) + look_ptr( (void *)k, d, op_insert ); + } + break; + } + } + return s; +} + +/*! + Writes the dictionary to the stream \a s. +*/ + +TQDataStream& TQGDict::write( TQDataStream &s ) const +{ + s << count(); // write number of items + uint i = 0; + while ( igetKey(); + break; + case AsciiKey: + s << ((TQAsciiBucket*)n)->getKey(); + break; + case IntKey: + s << (TQ_UINT32)((TQIntBucket*)n)->getKey(); + break; + case PtrKey: + s << (TQ_UINT32)0; // ### cannot serialize a pointer + break; + } + write( s, n->getData() ); // write data + n = n->getNext(); + } + i++; + } + return s; +} +#endif //TQT_NO_DATASTREAM + +/***************************************************************************** + TQGDictIterator member functions + *****************************************************************************/ + +/*! + \class TQGDictIterator tqgdict.h + \reentrant + \ingroup collection + \brief The TQGDictIterator class is an internal class for implementing TQDictIterator and TQIntDictIterator. + + \internal + + TQGDictIterator is a strictly internal class that does the heavy work for + TQDictIterator and TQIntDictIterator. +*/ + +/*! + Constructs an iterator that operates on the dictionary \a d. +*/ + +TQGDictIterator::TQGDictIterator( const TQGDict &d ) +{ + dict = (TQGDict *)&d; // get reference to dict + toFirst(); // set to first noe + if ( !dict->iterators ) { + dict->iterators = new TQGDItList; // create iterator list + TQ_CHECK_PTR( dict->iterators ); + } + dict->iterators->append( this ); // attach iterator to dict +} + +/*! + Constructs a copy of the iterator \a it. +*/ + +TQGDictIterator::TQGDictIterator( const TQGDictIterator &it ) +{ + dict = it.dict; + curNode = it.curNode; + curIndex = it.curIndex; + if ( dict ) + dict->iterators->append( this ); // attach iterator to dict +} + +/*! + Assigns a copy of the iterator \a it and returns a reference to this + iterator. +*/ + +TQGDictIterator &TQGDictIterator::operator=( const TQGDictIterator &it ) +{ + if ( dict ) // detach from old dict + dict->iterators->removeRef( this ); + dict = it.dict; + curNode = it.curNode; + curIndex = it.curIndex; + if ( dict ) + dict->iterators->append( this ); // attach to new list + return *this; +} + +/*! + Destroys the iterator. +*/ + +TQGDictIterator::~TQGDictIterator() +{ + if ( dict ) // detach iterator from dict + dict->iterators->removeRef( this ); +} + + +/*! + Sets the iterator to point to the first item in the dictionary. +*/ + +TQPtrCollection::Item TQGDictIterator::toFirst() +{ + if ( !dict ) { +#if defined(QT_CHECK_NULL) + tqWarning( "TQGDictIterator::toFirst: Dictionary has been deleted" ); +#endif + return 0; + } + if ( dict->count() == 0 ) { // empty dictionary + curNode = 0; + return 0; + } + uint i = 0; + TQBaseBucket **v = dict->vec; + while ( !(*v++) ) + i++; + curNode = dict->vec[i]; + curIndex = i; + return curNode->getData(); +} + + +/*! + Moves to the next item (postfix). +*/ + +TQPtrCollection::Item TQGDictIterator::operator()() +{ + if ( !dict ) { +#if defined(QT_CHECK_NULL) + tqWarning( "TQGDictIterator::operator(): Dictionary has been deleted" ); +#endif + return 0; + } + if ( !curNode ) + return 0; + TQPtrCollection::Item d = curNode->getData(); + this->operator++(); + return d; +} + +/*! + Moves to the next item (prefix). +*/ + +TQPtrCollection::Item TQGDictIterator::operator++() +{ + if ( !dict ) { +#if defined(QT_CHECK_NULL) + tqWarning( "TQGDictIterator::operator++: Dictionary has been deleted" ); +#endif + return 0; + } + if ( !curNode ) + return 0; + curNode = curNode->getNext(); + if ( !curNode ) { // no next bucket + uint i = curIndex + 1; // look from next vec element + TQBaseBucket **v = &dict->vec[i]; + while ( i < dict->size() && !(*v++) ) + i++; + if ( i == dict->size() ) { // nothing found + curNode = 0; + return 0; + } + curNode = dict->vec[i]; + curIndex = i; + } + return curNode->getData(); +} + +/*! + Moves \a jumps positions forward. +*/ + +TQPtrCollection::Item TQGDictIterator::operator+=( uint jumps ) +{ + while ( curNode && jumps-- ) + operator++(); + return curNode ? curNode->getData() : 0; +} diff --git a/src/tools/tqgdict.h b/src/tools/tqgdict.h new file mode 100644 index 000000000..9a941ecb7 --- /dev/null +++ b/src/tools/tqgdict.h @@ -0,0 +1,225 @@ +/**************************************************************************** +** +** Definition of TQGDict and TQGDictIterator classes +** +** Created : 920529 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQGDICT_H +#define TQGDICT_H + +#ifndef QT_H +#include "tqptrcollection.h" +#include "tqstring.h" +#endif // QT_H + +class TQGDictIterator; +class TQGDItList; + + +class TQBaseBucket // internal dict node +{ +public: + TQPtrCollection::Item getData() { return data; } + TQPtrCollection::Item setData( TQPtrCollection::Item d ) { return data = d; } + TQBaseBucket *getNext() { return next; } + void setNext( TQBaseBucket *n) { next = n; } +protected: + TQBaseBucket( TQPtrCollection::Item d, TQBaseBucket *n ) : data(d), next(n) {} + TQPtrCollection::Item data; + TQBaseBucket *next; +}; + +class TQStringBucket : public TQBaseBucket +{ +public: + TQStringBucket( const TQString &k, TQPtrCollection::Item d, TQBaseBucket *n ) + : TQBaseBucket(d,n), key(k) {} + const TQString &getKey() const { return key; } +private: + TQString key; +}; + +class TQAsciiBucket : public TQBaseBucket +{ +public: + TQAsciiBucket( const char *k, TQPtrCollection::Item d, TQBaseBucket *n ) + : TQBaseBucket(d,n), key(k) {} + const char *getKey() const { return key; } +private: + const char *key; +}; + +class TQIntBucket : public TQBaseBucket +{ +public: + TQIntBucket( long k, TQPtrCollection::Item d, TQBaseBucket *n ) + : TQBaseBucket(d,n), key(k) {} + long getKey() const { return key; } +private: + long key; +}; + +class TQPtrBucket : public TQBaseBucket +{ +public: + TQPtrBucket( void *k, TQPtrCollection::Item d, TQBaseBucket *n ) + : TQBaseBucket(d,n), key(k) {} + void *getKey() const { return key; } +private: + void *key; +}; + + +class TQ_EXPORT TQGDict : public TQPtrCollection // generic dictionary class +{ +public: + uint count() const { return numItems; } + uint size() const { return vlen; } + TQPtrCollection::Item look_string( const TQString& key, TQPtrCollection::Item, + int ); + TQPtrCollection::Item look_ascii( const char *key, TQPtrCollection::Item, int ); + TQPtrCollection::Item look_int( long key, TQPtrCollection::Item, int ); + TQPtrCollection::Item look_ptr( void *key, TQPtrCollection::Item, int ); +#ifndef TQT_NO_DATASTREAM + TQDataStream &read( TQDataStream & ); + TQDataStream &write( TQDataStream & ) const; +#endif +protected: + enum KeyType { StringKey, AsciiKey, IntKey, PtrKey }; + + TQGDict( uint len, KeyType kt, bool cs, bool ck ); + TQGDict( const TQGDict & ); + ~TQGDict(); + + TQGDict &operator=( const TQGDict & ); + + bool remove_string( const TQString &key, TQPtrCollection::Item item=0 ); + bool remove_ascii( const char *key, TQPtrCollection::Item item=0 ); + bool remove_int( long key, TQPtrCollection::Item item=0 ); + bool remove_ptr( void *key, TQPtrCollection::Item item=0 ); + TQPtrCollection::Item take_string( const TQString &key ); + TQPtrCollection::Item take_ascii( const char *key ); + TQPtrCollection::Item take_int( long key ); + TQPtrCollection::Item take_ptr( void *key ); + + void clear(); + void resize( uint ); + + int hashKeyString( const TQString & ); + int hashKeyAscii( const char * ); + + void statistics() const; + +#ifndef TQT_NO_DATASTREAM + virtual TQDataStream &read( TQDataStream &, TQPtrCollection::Item & ); + virtual TQDataStream &write( TQDataStream &, TQPtrCollection::Item ) const; +#endif +private: + TQBaseBucket **vec; + uint vlen; + uint numItems; + uint keytype : 2; + uint cases : 1; + uint copyk : 1; + TQGDItList *iterators; + void unlink_common( int, TQBaseBucket *, TQBaseBucket * ); + TQStringBucket *unlink_string( const TQString &, + TQPtrCollection::Item item = 0 ); + TQAsciiBucket *unlink_ascii( const char *, TQPtrCollection::Item item = 0 ); + TQIntBucket *unlink_int( long, TQPtrCollection::Item item = 0 ); + TQPtrBucket *unlink_ptr( void *, TQPtrCollection::Item item = 0 ); + void init( uint, KeyType, bool, bool ); + friend class TQGDictIterator; +}; + + +class TQ_EXPORT TQGDictIterator // generic dictionary iterator +{ +friend class TQGDict; +public: + TQGDictIterator( const TQGDict & ); + TQGDictIterator( const TQGDictIterator & ); + TQGDictIterator &operator=( const TQGDictIterator & ); + ~TQGDictIterator(); + + TQPtrCollection::Item toFirst(); + + TQPtrCollection::Item get() const; + TQString getKeyString() const; + const char *getKeyAscii() const; + long getKeyInt() const; + void *getKeyPtr() const; + + TQPtrCollection::Item operator()(); + TQPtrCollection::Item operator++(); + TQPtrCollection::Item operator+=(uint); + +protected: + TQGDict *dict; + +private: + TQBaseBucket *curNode; + uint curIndex; +}; + +inline TQPtrCollection::Item TQGDictIterator::get() const +{ + return curNode ? curNode->getData() : 0; +} + +inline TQString TQGDictIterator::getKeyString() const +{ + return curNode ? ((TQStringBucket*)curNode)->getKey() : TQString::null; +} + +inline const char *TQGDictIterator::getKeyAscii() const +{ + return curNode ? ((TQAsciiBucket*)curNode)->getKey() : 0; +} + +inline long TQGDictIterator::getKeyInt() const +{ + return curNode ? ((TQIntBucket*)curNode)->getKey() : 0; +} + +inline void *TQGDictIterator::getKeyPtr() const +{ + return curNode ? ((TQPtrBucket*)curNode)->getKey() : 0; +} + + +#endif // TQGDICT_H diff --git a/src/tools/tqglist.cpp b/src/tools/tqglist.cpp new file mode 100644 index 000000000..def2fd4e3 --- /dev/null +++ b/src/tools/tqglist.cpp @@ -0,0 +1,1566 @@ +/**************************************************************************** +** +** Implementation of TQGList and TQGListIterator classes +** +** Created : 920624 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqglist.h" +#include "tqgvector.h" +#include "tqdatastream.h" +#include "tqvaluelist.h" + +#if defined(TQT_THREAD_SUPPORT) + #include "tqmutex.h" +#endif // defined(TQT_THREAD_SUPPORT) + +/*! + \class TQLNode tqglist.h + \reentrant + \ingroup collection + \brief The TQLNode class is an internal class for the TQPtrList template collection. + + \internal + + TQLNode is a doubly-linked list node. It has three pointers: + \list 1 + \i Pointer to the previous node. + \i Pointer to the next node. + \i Pointer to the actual data. + \endlist + + It might sometimes be practical to have direct access to the list nodes + in a TQPtrList, but it is seldom required. + + Be very careful if you want to access the list nodes. The heap can + easily get corrupted if you make a mistake. + + \sa TQPtrList::currentNode(), TQPtrList::removeNode(), TQPtrList::takeNode() +*/ + +/*! + \fn TQPtrCollection::Item TQLNode::getData() + Returns a pointer (\c void*) to the actual data in the list node. +*/ + + +/*! + \class TQGList tqglist.h + \reentrant + \ingroup collection + \brief The TQGList class is an internal class for implementing TQt collection classes. + + \internal + + TQGList is a strictly internal class that acts as a base class for + several collection classes; TQPtrList, TQPtrQueue and TQPtrStack. + + TQGList has some virtual functions that can be reimplemented to + customize the subclasses, namely compareItems(), read() and + write. Normally, you do not have to reimplement any of these + functions. If you still want to reimplement them, see the TQStrList + class (tqstrlist.h) for an example. +*/ + + +/* Internal helper class for TQGList. Contains some optimization for + the typically case where only one iterators is activre on the list. + */ +class TQGListIteratorList +{ +public: + TQGListIteratorList() + : list(0), iterator(0) { + } + ~TQGListIteratorList() { + notifyClear( TRUE ); + delete list; + } + + void add( TQGListIterator* i ) { + if ( !iterator ) { + iterator = i; + } else if ( list ) { + list->push_front( i ); + } else { + list = new TQValueList; + list->push_front( i ); + } + } + + void remove( TQGListIterator* i ) { + if ( iterator == i ) { + iterator = 0; + } else if ( list ) { + list->remove( i ); + if ( list->isEmpty() ) { + delete list; + list = 0; + } + } + } + + void notifyClear( bool zeroList ) { + if ( iterator ) { + if ( zeroList ) + iterator->list = 0; + iterator->curNode = 0; + } + if ( list ) { + for ( TQValueList::Iterator i = list->begin(); i != list->end(); ++i ) { + if ( zeroList ) + (*i)->list = 0; + (*i)->curNode = 0; + } + } + } + + void notifyRemove( TQLNode* n, TQLNode* curNode ) { + if ( iterator ) { + if ( iterator->curNode == n ) + iterator->curNode = curNode; + } + if ( list ) { + for ( TQValueList::Iterator i = list->begin(); i != list->end(); ++i ) { + if ( (*i)->curNode == n ) + (*i)->curNode = curNode; + } + } + } + +private: + TQValueList* list; + TQGListIterator* iterator; +}; + + + +/***************************************************************************** + Default implementation of virtual functions + *****************************************************************************/ + +/*! + Documented as TQPtrList::compareItems(). + + Compares \a item1 with \a item2. +*/ +int TQGList::compareItems( TQPtrCollection::Item item1, TQPtrCollection::Item item2 ) +{ + return item1 != item2; // compare pointers +} + +#ifndef TQT_NO_DATASTREAM +/*! + \overload + Reads a collection/list item from the stream \a s and returns a reference + to the stream. + + The default implementation sets \a item to 0. + + \sa write() +*/ + +TQDataStream &TQGList::read( TQDataStream &s, TQPtrCollection::Item &item ) +{ + item = 0; + return s; +} + +/*! + \overload + Writes a collection/list item to the stream \a s and + returns a reference to the stream. + + The default implementation does nothing. + + \sa read() +*/ + +TQDataStream &TQGList::write( TQDataStream &s, TQPtrCollection::Item ) const +{ + return s; +} +#endif // TQT_NO_DATASTREAM + +/***************************************************************************** + TQGList member functions + *****************************************************************************/ + +/*! + Constructs an empty list. +*/ + +TQGList::TQGList() +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex = new TQMutex(true); +#endif + firstNode = lastNode = curNode = 0; // initialize list + numNodes = 0; + curIndex = -1; + iterators = 0; // initialize iterator list +} + +/*! + Constructs a copy of \a list. +*/ + +TQGList::TQGList( const TQGList & list ) + : TQPtrCollection( list ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex = new TQMutex(true); +#endif + firstNode = lastNode = curNode = 0; // initialize list + numNodes = 0; + curIndex = -1; + iterators = 0; // initialize iterator list + TQLNode *n = list.firstNode; + while ( n ) { // copy all items from list + append( n->data ); + n = n->next; + } +} + +/*! + Removes all items from the list and destroys the list. +*/ + +TQGList::~TQGList() +{ + clear(); + delete iterators; + // Workaround for GCC 2.7.* bug. Compiler constructs 'static' TQGList + // instances twice on the same address and therefore tries to destruct + // twice on the same address! This is insane but let's try not to crash + // here. + iterators = 0; +#if defined(TQT_THREAD_SUPPORT) + //delete mutex; +#endif +} + + +/*! + Assigns \a list to this list. +*/ + +TQGList& TQGList::operator=( const TQGList &list ) +{ + if ( &list == this ) + return *this; + + clear(); + if ( list.count() > 0 ) { + TQLNode *n = list.firstNode; + while ( n ) { // copy all items from list + append( n->data ); + n = n->next; + } + curNode = firstNode; + curIndex = 0; + } + return *this; +} + +/*! + Compares this list with \a list. Returns TRUE if the lists + contain the same data, otherwise FALSE. +*/ + +bool TQGList::operator==( const TQGList &list ) const +{ + if ( count() != list.count() ) { + return FALSE; + } + + if ( count() == 0 ) { + return TRUE; + } + + TQLNode *n1 = firstNode; + TQLNode *n2 = list.firstNode; + while ( n1 && n2 ) { + // should be mutable + if ( ( (TQGList*)this )->compareItems( n1->data, n2->data ) != 0 ) + return FALSE; + n1 = n1->next; + n2 = n2->next; + } + + return TRUE; +} + +/*! + \fn uint TQGList::count() const + + Returns the number of items in the list. +*/ + + +/*! + Returns the node at position \a index. Sets this node to current. +*/ + +TQLNode *TQGList::locate( uint index ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + if ( index == (uint)curIndex ) { // current node ? +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return curNode; + } + if ( !curNode && firstNode ) { // set current node + curNode = firstNode; + curIndex = 0; + } + TQLNode *node; + int distance = index - curIndex; // node distance to cur node + bool forward; // direction to traverse + + if ( index >= numNodes ) { +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return 0; + } + + if ( distance < 0 ) { + distance = -distance; + } + if ( (uint)distance < index && (uint)distance < numNodes - index ) { + node = curNode; // start from current node + forward = index > (uint)curIndex; + } else if ( index < numNodes - index ) { // start from first node + node = firstNode; + distance = index; + forward = TRUE; + } else { // start from last node + node = lastNode; + distance = numNodes - index - 1; + if ( distance < 0 ) + distance = 0; + forward = FALSE; + } + if ( forward ) { // now run through nodes + while ( distance-- ) { + node = node->next; + } + } else { + while ( distance-- ) { + node = node->prev; + } + } + curIndex = index; // must update index +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return curNode = node; +} + + +/*! + Inserts item \a d at its sorted position in the list. +*/ + +void TQGList::inSort( TQPtrCollection::Item d ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + int index = 0; + TQLNode *n = firstNode; + while ( n && compareItems(n->data,d) < 0 ){ // find position in list + n = n->next; + index++; + } + insertAt( index, d ); +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif +} + + +/*! + Inserts item \a d at the start of the list. +*/ + +void TQGList::prepend( TQPtrCollection::Item d ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + TQLNode *n = new TQLNode( newItem(d) ); + TQ_CHECK_PTR( n ); + n->prev = 0; + if ( (n->next = firstNode) ) // list is not empty + firstNode->prev = n; + else // initialize list + lastNode = n; + firstNode = curNode = n; // curNode affected + numNodes++; + curIndex = 0; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif +} + + +/*! + Inserts item \a d at the end of the list. +*/ + +void TQGList::append( TQPtrCollection::Item d ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + TQLNode *n = new TQLNode( newItem(d) ); + TQ_CHECK_PTR( n ); + n->next = 0; + if ( (n->prev = lastNode) ) { // list is not empty + lastNode->next = n; + } + else { // initialize list + firstNode = n; + } + lastNode = curNode = n; // curNode affected + curIndex = numNodes; + numNodes++; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif +} + + +/*! + Inserts item \a d at position \a index in the list. +*/ + +bool TQGList::insertAt( uint index, TQPtrCollection::Item d ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + if ( index == 0 ) { + prepend( d ); +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return TRUE; + } + else if ( index == numNodes ) { + append( d ); +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return TRUE; + } + TQLNode *nextNode = locate( index ); + if ( !nextNode ) { +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return FALSE; + } + TQLNode *prevNode = nextNode->prev; + TQLNode *n = new TQLNode( newItem(d) ); + TQ_CHECK_PTR( n ); + nextNode->prev = n; + Q_ASSERT( (!((curIndex > 0) && (!prevNode))) ); + prevNode->next = n; + n->prev = prevNode; // link new node into list + n->next = nextNode; + curNode = n; // curIndex set by locate() + numNodes++; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return TRUE; +} + + +/*! + Relinks node \a n and makes it the first node in the list. +*/ + +void TQGList::relinkNode( TQLNode *n ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + if ( n == firstNode ) { // already first +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return; + } + curNode = n; + unlink(); + n->prev = 0; + if ( (n->next = firstNode) ) { // list is not empty + firstNode->prev = n; + } + else { // initialize list + lastNode = n; + } + firstNode = curNode = n; // curNode affected + numNodes++; + curIndex = 0; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif +} + + +/*! + Unlinks the current list node and returns a pointer to this node. +*/ + +TQLNode *TQGList::unlink() +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + if ( curNode == 0 ) { // null current node +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return 0; + } + TQLNode *n = curNode; // unlink this node + if ( n == firstNode ) { // removing first node ? + if ( (firstNode = n->next) ) { + firstNode->prev = 0; + } else { + lastNode = curNode = 0; // list becomes empty + curIndex = -1; + } + } else { + if ( n == lastNode ) { // removing last node ? + lastNode = n->prev; + lastNode->next = 0; + } else { // neither last nor first node + n->prev->next = n->next; + n->next->prev = n->prev; + } + } + + if ( n->next ) { // change current node + curNode = n->next; + } else if ( n->prev ) { + curNode = n->prev; + curIndex--; + } + + if ( iterators ) { + iterators->notifyRemove( n, curNode ); + } + numNodes--; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return n; +} + + +/*! + Removes the node \a n from the list. +*/ + +bool TQGList::removeNode( TQLNode *n ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif +#if defined(QT_CHECK_NULL) + if ( n == 0 || (n->prev && n->prev->next != n) || + (n->next && n->next->prev != n) ) { + tqWarning( "TQGList::removeNode: Corrupted node" ); + return FALSE; + } +#endif + curNode = n; + unlink(); // unlink node + deleteItem( n->data ); // deallocate this node + delete n; + curNode = firstNode; + curIndex = curNode ? 0 : -1; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return TRUE; +} + +/*! + Removes the item \a d from the list. Uses compareItems() to find the item. + + If \a d is 0, removes the current item. +*/ + +bool TQGList::remove( TQPtrCollection::Item d ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + if ( d && find(d) == -1 ) { +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return FALSE; + } + TQLNode *n = unlink(); + if ( !n ) { +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return FALSE; + } + deleteItem( n->data ); + delete n; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return TRUE; +} + +/*! + Removes the item \a d from the list. +*/ + +bool TQGList::removeRef( TQPtrCollection::Item d ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + if ( findRef(d) == -1 ) { +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return FALSE; + } + TQLNode *n = unlink(); + if ( !n ) { +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return FALSE; + } + deleteItem( n->data ); + delete n; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return TRUE; +} + +/*! + \fn bool TQGList::removeFirst() + + Removes the first item in the list. +*/ + +/*! + \fn bool TQGList::removeLast() + + Removes the last item in the list. +*/ + +/*! + Removes the item at position \a index from the list. +*/ + +bool TQGList::removeAt( uint index ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + if ( !locate(index) ) { +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return FALSE; + } + TQLNode *n = unlink(); + if ( !n ) { +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return FALSE; + } + deleteItem( n->data ); + delete n; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return TRUE; +} + + +/*! + Replaces the item at index \a index with \a d. +*/ +bool TQGList::replaceAt( uint index, TQPtrCollection::Item d ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + TQLNode *n = locate( index ); + if ( !n ) { +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return FALSE; + } + if ( n->data != d ) { + deleteItem( n->data ); + n->data = newItem( d ); + } +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return TRUE; +} + + + +/*! + Takes the node \a n out of the list. +*/ + +TQPtrCollection::Item TQGList::takeNode( TQLNode *n ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif +#if defined(QT_CHECK_NULL) + if ( n == 0 || (n->prev && n->prev->next != n) || + (n->next && n->next->prev != n) ) { + tqWarning( "TQGList::takeNode: Corrupted node" ); +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return 0; + } +#endif + curNode = n; + unlink(); // unlink node + Item d = n->data; + delete n; // delete the node, not data + curNode = firstNode; + curIndex = curNode ? 0 : -1; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return d; +} + +/*! + Takes the current item out of the list. +*/ + +TQPtrCollection::Item TQGList::take() +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + TQLNode *n = unlink(); // unlink node + Item d = n ? n->data : 0; + delete n; // delete node, keep contents +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return d; +} + +/*! + Takes the item at position \a index out of the list. +*/ + +TQPtrCollection::Item TQGList::takeAt( uint index ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + if ( !locate(index) ) { +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return 0; + } + TQLNode *n = unlink(); // unlink node + Item d = n ? n->data : 0; + delete n; // delete node, keep contents +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return d; +} + +/*! + Takes the first item out of the list. +*/ + +TQPtrCollection::Item TQGList::takeFirst() +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + first(); + TQLNode *n = unlink(); // unlink node + Item d = n ? n->data : 0; + delete n; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return d; +} + +/*! + Takes the last item out of the list. +*/ + +TQPtrCollection::Item TQGList::takeLast() +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + last(); + TQLNode *n = unlink(); // unlink node + Item d = n ? n->data : 0; + delete n; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return d; +} + + +/*! + Removes all items from the list. +*/ + +void TQGList::clear() +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + TQLNode *n = firstNode; + + firstNode = lastNode = curNode = 0; // initialize list + numNodes = 0; + curIndex = -1; + + if ( iterators ) { + iterators->notifyClear( FALSE ); + } + + TQLNode *prevNode; + while ( n ) { // for all nodes ... + deleteItem( n->data ); // deallocate data + prevNode = n; + n = n->next; + delete prevNode; // deallocate node + } +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif +} + + +/*! + Finds item \a d in the list. If \a fromStart is TRUE the search + begins at the first node; otherwise it begins at the current node. +*/ + +int TQGList::findRef( TQPtrCollection::Item d, bool fromStart ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + TQLNode *n; + int index; + if ( fromStart ) { // start from first node + n = firstNode; + index = 0; + } else { // start from current node + n = curNode; + index = curIndex; + } + while ( n && n->data != d ) { // find exact match + n = n->next; + index++; + } + curNode = n; + curIndex = n ? index : -1; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return curIndex; // return position of item +} + +/*! + Finds item \a d in the list using compareItems(). If \a fromStart is + TRUE the search begins at the first node; otherwise it begins at the + current node. +*/ + +int TQGList::find( TQPtrCollection::Item d, bool fromStart ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + TQLNode *n; + int index; + if ( fromStart ) { // start from first node + n = firstNode; + index = 0; + } else { // start from current node + n = curNode; + index = curIndex; + } + while ( n && compareItems(n->data,d) ){ // find equal match + n = n->next; + index++; + } + curNode = n; + curIndex = n ? index : -1; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return curIndex; // return position of item +} + + +/*! + Counts the number item \a d occurs in the list. +*/ + +uint TQGList::containsRef( TQPtrCollection::Item d ) const +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + TQLNode *n = firstNode; + uint count = 0; + while ( n ) { // for all nodes... + if ( n->data == d ) // count # exact matches + count++; + n = n->next; + } +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return count; +} + +/*! + Counts the number of times item \a d occurs in the list. Uses + compareItems(). +*/ + +uint TQGList::contains( TQPtrCollection::Item d ) const +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + TQLNode *n = firstNode; + uint count = 0; + TQGList *that = (TQGList*)this; // mutable for compareItems() + while ( n ) { // for all nodes... + if ( !that->compareItems(n->data,d) ) // count # equal matches + count++; + n = n->next; + } +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return count; +} + + +/*! + \overload TQPtrCollection::Item TQGList::at( uint index ) + + Sets the item at position \a index to the current item. +*/ + +/*! + \fn int TQGList::at() const + + Returns the current index. +*/ + +/*! + \fn TQLNode *TQGList::currentNode() const + + Returns the current node. +*/ + +/*! + \fn TQPtrCollection::Item TQGList::get() const + + Returns the current item. +*/ + +/*! + \fn TQPtrCollection::Item TQGList::cfirst() const + + Returns the first item in the list. +*/ + +/*! + \fn TQPtrCollection::Item TQGList::clast() const + + Returns the last item in the list. +*/ + + +/*! + Returns the first list item. Sets this to current. +*/ + +TQPtrCollection::Item TQGList::first() +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + if ( firstNode ) { + curIndex = 0; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return (curNode=firstNode)->data; + } +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return 0; +} + +/*! + Returns the last list item. Sets this to current. +*/ + +TQPtrCollection::Item TQGList::last() +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + if ( lastNode ) { + curIndex = numNodes-1; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return (curNode=lastNode)->data; + } +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return 0; +} + +/*! + Returns the next list item (after current). Sets this to current. +*/ + +TQPtrCollection::Item TQGList::next() +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + if ( curNode ) { + if ( curNode->next ) { + curIndex++; + curNode = curNode->next; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return curNode->data; + } + curIndex = -1; + curNode = 0; + } +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return 0; +} + +/*! + Returns the previous list item (before current). Sets this to current. +*/ + +TQPtrCollection::Item TQGList::prev() +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + if ( curNode ) { + if ( curNode->prev ) { + curIndex--; + curNode = curNode->prev; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return curNode->data; + } + curIndex = -1; + curNode = 0; + } +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return 0; +} + + +/*! + Converts the list to a vector, \a vector. +*/ + +void TQGList::toVector( TQGVector *vector ) const +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + vector->clear(); + if ( !vector->resize( count() ) ) { +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return; + } + TQLNode *n = firstNode; + uint i = 0; + while ( n ) { + vector->insert( i, n->data ); + n = n->next; + i++; + } +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif +} + +void TQGList::heapSortPushDown( TQPtrCollection::Item* heap, int first, int last ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + int r = first; + while( r <= last/2 ) { + // Node r has only one child ? + if ( last == 2*r ) { + // Need for swapping ? + if ( compareItems( heap[r], heap[ 2*r ] ) > 0 ) { + TQPtrCollection::Item tmp = heap[r]; + heap[ r ] = heap[ 2*r ]; + heap[ 2*r ] = tmp; + } + // That's it ... + r = last; + } else { + // Node has two children + if ( compareItems( heap[r], heap[ 2*r ] ) > 0 && + compareItems( heap[ 2*r ], heap[ 2*r+1 ] ) <= 0 ) { + // Swap with left child + TQPtrCollection::Item tmp = heap[r]; + heap[ r ] = heap[ 2*r ]; + heap[ 2*r ] = tmp; + r *= 2; + } else if ( compareItems( heap[r], heap[ 2*r+1 ] ) > 0 && + compareItems( heap[ 2*r+1 ], heap[ 2*r ] ) < 0 ) { + // Swap with right child + TQPtrCollection::Item tmp = heap[r]; + heap[ r ] = heap[ 2*r+1 ]; + heap[ 2*r+1 ] = tmp; + r = 2*r+1; + } else { + // We are done + r = last; + } + } + } +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif +} + + +/*! Sorts the list by the result of the virtual compareItems() function. + + The Heap-Sort algorithm is used for sorting. It sorts n items with + O(n*log n) compares. This is the asymptotic optimal solution of the + sorting problem. +*/ + +void TQGList::sort() +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + uint n = count(); + if ( n < 2 ) { +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return; + } + + // Create the heap + TQPtrCollection::Item* realheap = new TQPtrCollection::Item[ n ]; + // Wow, what a fake. But I want the heap to be indexed as 1...n + TQPtrCollection::Item* heap = realheap - 1; + int size = 0; + TQLNode* insert = firstNode; + for( ; insert != 0; insert = insert->next ) { + heap[++size] = insert->data; + int i = size; + while( i > 1 && compareItems( heap[i], heap[ i / 2 ] ) < 0 ) { + TQPtrCollection::Item tmp = heap[ i ]; + heap[ i ] = heap[ i/2 ]; + heap[ i/2 ] = tmp; + i /= 2; + } + } + + insert = firstNode; + // Now do the sorting + for ( int i = n; i > 0; i-- ) { + insert->data = heap[1]; + insert = insert->next; + if ( i > 1 ) { + heap[1] = heap[i]; + heapSortPushDown( heap, 1, i - 1 ); + } + } + + delete [] realheap; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif +} + + +/***************************************************************************** + TQGList stream functions + *****************************************************************************/ + +#ifndef TQT_NO_DATASTREAM +TQDataStream &operator>>( TQDataStream &s, TQGList &list ) +{ // read list + return list.read( s ); +} + +TQDataStream &operator<<( TQDataStream &s, const TQGList &list ) +{ // write list + return list.write( s ); +} + +/*! + Reads a list from the stream \a s. +*/ + +TQDataStream &TQGList::read( TQDataStream &s ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + uint num; + s >> num; // read number of items + clear(); // clear list + while ( num-- ) { // read all items + Item d; + read( s, d ); + TQ_CHECK_PTR( d ); + if ( !d ) // no memory + break; + TQLNode *n = new TQLNode( d ); + TQ_CHECK_PTR( n ); + if ( !n ) // no memory + break; + n->next = 0; + if ( (n->prev = lastNode) ) // list is not empty + lastNode->next = n; + else // initialize list + firstNode = n; + lastNode = n; + numNodes++; + } + curNode = firstNode; + curIndex = curNode ? 0 : -1; +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return s; +} + +/*! + Writes the list to the stream \a s. +*/ + +TQDataStream &TQGList::write( TQDataStream &s ) const +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + s << count(); // write number of items + TQLNode *n = firstNode; + while ( n ) { // write all items + write( s, n->data ); + n = n->next; + } +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return s; +} + +#endif // TQT_NO_DATASTREAM + + + +/*! \internal + */ +TQLNode* TQGList::erase( TQLNode* it ) +{ +#if defined(TQT_THREAD_SUPPORT) + //mutex->lock(); +#endif + TQLNode* n = it; + it = it->next; + removeNode( n ); +#if defined(TQT_THREAD_SUPPORT) + //mutex->unlock(); +#endif + return it; +} + + +/***************************************************************************** + TQGListIterator member functions + *****************************************************************************/ + +/*! + \class TQGListIterator tqglist.h + \reentrant + \ingroup collection + \brief The TQGListIterator class is an internal class for implementing TQPtrListIterator. + + \internal + + TQGListIterator is a strictly internal class that does the heavy work for + TQPtrListIterator. +*/ + +/*! + \internal + Constructs an iterator that operates on the list \a l. +*/ + +TQGListIterator::TQGListIterator( const TQGList &l ) +{ + list = (TQGList *)&l; // get reference to list + curNode = list->firstNode; // set to first node + if ( !list->iterators ) { + list->iterators = new TQGListIteratorList; // create iterator list + TQ_CHECK_PTR( list->iterators ); + } + list->iterators->add( this ); // attach iterator to list +} + +/*! + \internal + Constructs a copy of the iterator \a it. +*/ + +TQGListIterator::TQGListIterator( const TQGListIterator &it ) +{ + list = it.list; + curNode = it.curNode; + if ( list ) + list->iterators->add( this ); // attach iterator to list +} + +/*! + \internal + Assigns a copy of the iterator \a it and returns a reference to this + iterator. +*/ + +TQGListIterator &TQGListIterator::operator=( const TQGListIterator &it ) +{ + if ( list ) // detach from old list + list->iterators->remove( this ); + list = it.list; + curNode = it.curNode; + if ( list ) + list->iterators->add( this ); // attach to new list + return *this; +} + +/*! + \internal + Destroys the iterator. +*/ + +TQGListIterator::~TQGListIterator() +{ + if ( list ) // detach iterator from list + list->iterators->remove(this); +} + + +/*! + \fn bool TQGListIterator::atFirst() const + \internal + Returns TRUE if the iterator points to the first item, otherwise FALSE. +*/ + +/*! + \fn bool TQGListIterator::atLast() const + \internal + Returns TRUE if the iterator points to the last item, otherwise FALSE. +*/ + + +/*! + \internal + Sets the list iterator to point to the first item in the list. +*/ + +TQPtrCollection::Item TQGListIterator::toFirst() +{ + if ( !list ) { +#if defined(QT_CHECK_NULL) + tqWarning( "TQGListIterator::toFirst: List has been deleted" ); +#endif + return 0; + } + return list->firstNode ? (curNode = list->firstNode)->getData() : 0; +} + +/*! + \internal + Sets the list iterator to point to the last item in the list. +*/ + +TQPtrCollection::Item TQGListIterator::toLast() +{ + if ( !list ) { +#if defined(QT_CHECK_NULL) + tqWarning( "TQGListIterator::toLast: List has been deleted" ); +#endif + return 0; + } + return list->lastNode ? (curNode = list->lastNode)->getData() : 0; +} + + +/*! + \fn TQPtrCollection::Item TQGListIterator::get() const + \internal + Returns the iterator item. +*/ + + +/*! + \internal + Moves to the next item (postfix). +*/ + +TQPtrCollection::Item TQGListIterator::operator()() +{ + if ( !curNode ) + return 0; + TQPtrCollection::Item d = curNode->getData(); + curNode = curNode->next; + return d; +} + +/*! + \internal + Moves to the next item (prefix). +*/ + +TQPtrCollection::Item TQGListIterator::operator++() +{ + if ( !curNode ) + return 0; + curNode = curNode->next; + return curNode ? curNode->getData() : 0; +} + +/*! + \internal + Moves \a jumps positions forward. +*/ + +TQPtrCollection::Item TQGListIterator::operator+=( uint jumps ) +{ + while ( curNode && jumps-- ) + curNode = curNode->next; + return curNode ? curNode->getData() : 0; +} + +/*! + \internal + Moves to the previous item (prefix). +*/ + +TQPtrCollection::Item TQGListIterator::operator--() +{ + if ( !curNode ) + return 0; + curNode = curNode->prev; + return curNode ? curNode->getData() : 0; +} + +/*! + \internal + Moves \a jumps positions backward. +*/ + +TQPtrCollection::Item TQGListIterator::operator-=( uint jumps ) +{ + while ( curNode && jumps-- ) + curNode = curNode->prev; + return curNode ? curNode->getData() : 0; +} diff --git a/src/tools/tqglist.h b/src/tools/tqglist.h new file mode 100644 index 000000000..95a5786d3 --- /dev/null +++ b/src/tools/tqglist.h @@ -0,0 +1,279 @@ +/**************************************************************************** +** +** Definition of TQGList and TQGListIterator classes +** +** Created : 920624 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQGLIST_H +#define TQGLIST_H + +#ifndef QT_H +#include "tqptrcollection.h" +#endif // QT_H + +class TQ_EXPORT TQLNode +{ +friend class TQGList; +friend class TQGListIterator; +friend class TQGListStdIterator; +public: + TQPtrCollection::Item getData() { return data; } +private: + TQPtrCollection::Item data; + TQLNode *prev; + TQLNode *next; + TQLNode( TQPtrCollection::Item d ) { data = d; } +}; + +class TQMutex; +class TQGListPrivate; +class TQGListIteratorList; // internal helper class + +class TQ_EXPORT TQGList : public TQPtrCollection // doubly linked generic list +{ +friend class TQGListIterator; +friend class TQGListIteratorList; +friend class TQGVector; // needed by TQGVector::toList +public: + uint count() const; // return number of nodes + +#ifndef TQT_NO_DATASTREAM + TQDataStream &read( TQDataStream & ); // read list from stream + TQDataStream &write( TQDataStream & ) const; // write list to stream +#endif +protected: + TQGList(); // create empty list + TQGList( const TQGList & ); // make copy of other list + virtual ~TQGList(); + + TQGList &operator=( const TQGList & ); // assign from other list + bool operator==( const TQGList& ) const; + + void inSort( TQPtrCollection::Item ); // add item sorted in list + void append( TQPtrCollection::Item ); // add item at end of list + bool insertAt( uint index, TQPtrCollection::Item ); // add item at i'th position + void relinkNode( TQLNode * ); // relink as first item + bool removeNode( TQLNode * ); // remove node + bool remove( TQPtrCollection::Item = 0 ); // remove item (0=current) + bool removeRef( TQPtrCollection::Item = 0 ); // remove item (0=current) + bool removeFirst(); // remove first item + bool removeLast(); // remove last item + bool removeAt( uint ); // remove item at i'th position + bool replaceAt( uint, TQPtrCollection::Item ); // replace item at position i with item + TQPtrCollection::Item takeNode( TQLNode * ); // take out node + TQPtrCollection::Item take(); // take out current item + TQPtrCollection::Item takeAt( uint index ); // take out item at i'th pos + TQPtrCollection::Item takeFirst(); // take out first item + TQPtrCollection::Item takeLast(); // take out last item + + void sort(); // sort all items; + void clear(); // remove all items + + int findRef( TQPtrCollection::Item, bool = TRUE ); // find exact item in list + int find( TQPtrCollection::Item, bool = TRUE ); // find equal item in list + + uint containsRef( TQPtrCollection::Item ) const; // get number of exact matches + uint contains( TQPtrCollection::Item ) const; // get number of equal matches + + TQPtrCollection::Item at( uint index ); // access item at i'th pos + int at() const; // get current index + TQLNode *currentNode() const; // get current node + + TQPtrCollection::Item get() const; // get current item + + TQPtrCollection::Item cfirst() const; // get ptr to first list item + TQPtrCollection::Item clast() const; // get ptr to last list item + TQPtrCollection::Item first(); // set first item in list curr + TQPtrCollection::Item last(); // set last item in list curr + TQPtrCollection::Item next(); // set next item in list curr + TQPtrCollection::Item prev(); // set prev item in list curr + + void toVector( TQGVector * ) const; // put items in vector + + virtual int compareItems( TQPtrCollection::Item, TQPtrCollection::Item ); + +#ifndef TQT_NO_DATASTREAM + virtual TQDataStream &read( TQDataStream &, TQPtrCollection::Item & ); + virtual TQDataStream &write( TQDataStream &, TQPtrCollection::Item ) const; +#endif + + TQLNode* begin() const { return firstNode; } + TQLNode* end() const { return 0; } + TQLNode* erase( TQLNode* it ); + +private: + void prepend( TQPtrCollection::Item ); // add item at start of list + + void heapSortPushDown( TQPtrCollection::Item* heap, int first, int last ); + + TQLNode *firstNode; // first node + TQLNode *lastNode; // last node + TQLNode *curNode; // current node + int curIndex; // current index + uint numNodes; // number of nodes + TQGListIteratorList *iterators; // list of iterators + + TQLNode *locate( uint ); // get node at i'th pos + TQLNode *unlink(); // unlink node + +#if defined(TQT_THREAD_SUPPORT) +// TQMutex* mutex; +#endif + +// TQGListPrivate* d; +}; + + +inline uint TQGList::count() const +{ + return numNodes; +} + +inline bool TQGList::removeFirst() +{ + first(); + return remove(); +} + +inline bool TQGList::removeLast() +{ + last(); + return remove(); +} + +inline int TQGList::at() const +{ + return curIndex; +} + +inline TQPtrCollection::Item TQGList::at( uint index ) +{ + TQLNode *n = locate( index ); + return n ? n->data : 0; +} + +inline TQLNode *TQGList::currentNode() const +{ + return curNode; +} + +inline TQPtrCollection::Item TQGList::get() const +{ + return curNode ? curNode->data : 0; +} + +inline TQPtrCollection::Item TQGList::cfirst() const +{ + return firstNode ? firstNode->data : 0; +} + +inline TQPtrCollection::Item TQGList::clast() const +{ + return lastNode ? lastNode->data : 0; +} + + +/***************************************************************************** + TQGList stream functions + *****************************************************************************/ + +#ifndef TQT_NO_DATASTREAM +TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQGList & ); +TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQGList & ); +#endif + +/***************************************************************************** + TQGListIterator class + *****************************************************************************/ + +class TQ_EXPORT TQGListIterator // TQGList iterator +{ +friend class TQGList; +friend class TQGListIteratorList; +protected: + TQGListIterator( const TQGList & ); + TQGListIterator( const TQGListIterator & ); + TQGListIterator &operator=( const TQGListIterator & ); + ~TQGListIterator(); + + bool atFirst() const; // test if at first item + bool atLast() const; // test if at last item + TQPtrCollection::Item toFirst(); // move to first item + TQPtrCollection::Item toLast(); // move to last item + + TQPtrCollection::Item get() const; // get current item + TQPtrCollection::Item operator()(); // get current and move to next + TQPtrCollection::Item operator++(); // move to next item (prefix) + TQPtrCollection::Item operator+=(uint); // move n positions forward + TQPtrCollection::Item operator--(); // move to prev item (prefix) + TQPtrCollection::Item operator-=(uint); // move n positions backward + +protected: + TQGList *list; // reference to list + +private: + TQLNode *curNode; // current node in list +}; + + +inline bool TQGListIterator::atFirst() const +{ + return curNode == list->firstNode; +} + +inline bool TQGListIterator::atLast() const +{ + return curNode == list->lastNode; +} + +inline TQPtrCollection::Item TQGListIterator::get() const +{ + return curNode ? curNode->data : 0; +} + +class TQ_EXPORT TQGListStdIterator +{ +public: + inline TQGListStdIterator( TQLNode* n ) : node( n ){} + inline operator TQLNode* () { return node; } +protected: + inline TQLNode *next() { return node->next; } + TQLNode *node; +}; + + +#endif // TQGLIST_H diff --git a/src/tools/tqglobal.cpp b/src/tools/tqglobal.cpp new file mode 100644 index 000000000..d33bfdf95 --- /dev/null +++ b/src/tools/tqglobal.cpp @@ -0,0 +1,889 @@ +/**************************************************************************** +** +** Global functions +** +** Created : 920604 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "qplatformdefs.h" + +#include "tqasciidict.h" +#include +#include +#include +#include +#include +#include + +#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) && !defined(Q_OS_TEMP) +#include +#endif + + +/*! + \relates TQApplication + + Returns the TQt version number as a string, for example, "2.3.0" or + "3.0.5". + + The \c TQT_VERSION define has the numeric value in the form: + 0xmmiibb (m = major, i = minor, b = bugfix). For example, TQt + 3.0.5's \c TQT_VERSION is 0x030005. +*/ + +const char *tqVersion() +{ + return TQT_VERSION_STR; +} + +bool tqSharedBuild() +{ +#ifdef QT_SHARED + return TRUE; +#else + return FALSE; +#endif +} + +/***************************************************************************** + System detection routines + *****************************************************************************/ + +static bool si_alreadyDone = FALSE; +static int si_wordSize; +static bool si_bigEndian; + +/*! + \relates TQApplication + + Obtains information about the system. + + The system's word size in bits (typically 32) is returned in \a + *wordSize. The \a *bigEndian is set to TRUE if this is a big-endian + machine, or to FALSE if this is a little-endian machine. + + In debug mode, this function calls tqFatal() with a message if the + computer is truly weird (i.e. different endianness for 16 bit and + 32 bit integers); in release mode it returns FALSE. +*/ + +bool tqSysInfo( int *wordSize, bool *bigEndian ) +{ +#if defined(QT_CHECK_NULL) + Q_ASSERT( wordSize != 0 ); + Q_ASSERT( bigEndian != 0 ); +#endif + + if ( si_alreadyDone ) { // run it only once + *wordSize = si_wordSize; + *bigEndian = si_bigEndian; + return TRUE; + } + + si_wordSize = 0; + TQ_ULONG n = (TQ_ULONG)(~0); + while ( n ) { // detect word size + si_wordSize++; + n /= 2; + } + *wordSize = si_wordSize; + + if ( *wordSize != 64 && + *wordSize != 32 && + *wordSize != 16 ) { // word size: 16, 32 or 64 +#if defined(QT_CHECK_RANGE) + tqFatal( "qSysInfo: Unsupported system word size %d", *wordSize ); +#endif + return FALSE; + } + if ( sizeof(TQ_INT8) != 1 || sizeof(TQ_INT16) != 2 || sizeof(TQ_INT32) != 4 || + sizeof(TQ_ULONG)*8 != si_wordSize || sizeof(float) != 4 || sizeof(double) != 8 ) { +#if defined(QT_CHECK_RANGE) + tqFatal( "qSysInfo: Unsupported system data type size" ); +#endif + return FALSE; + } + + bool be16, be32; // determine byte ordering + short ns = 0x1234; + int nl = 0x12345678; + + unsigned char *p = (unsigned char *)(&ns); // 16-bit integer + be16 = *p == 0x12; + + p = (unsigned char *)(&nl); // 32-bit integer + if ( p[0] == 0x12 && p[1] == 0x34 && p[2] == 0x56 && p[3] == 0x78 ) + be32 = TRUE; + else + if ( p[0] == 0x78 && p[1] == 0x56 && p[2] == 0x34 && p[3] == 0x12 ) + be32 = FALSE; + else + be32 = !be16; + + if ( be16 != be32 ) { // strange machine! +#if defined(QT_CHECK_RANGE) + tqFatal( "qSysInfo: Inconsistent system byte order" ); +#endif + return FALSE; + } + + *bigEndian = si_bigEndian = be32; + si_alreadyDone = TRUE; + return TRUE; +} + +#if defined(Q_OS_MAC) + +#include "qt_mac.h" + +// This function has descended from Apple Source Code (FSpLocationFromFullPath), +// but changes have been made. [Creates a minimal alias from the full pathname] +OSErr qt_mac_create_fsspec(const TQString &file, FSSpec *spec) +{ + FSRef fref; + TQCString utfs = file.utf8(); + OSErr ret = FSPathMakeRef((const UInt8 *)utfs.data(), &fref, NULL); + if(ret == noErr) + ret = FSGetCatalogInfo(&fref, kFSCatInfoNone, NULL, NULL, spec, NULL); + return ret; +} + +CFStringRef tqstring2cfstring(const TQString &str) +{ + return CFStringCreateWithCharacters(0, (UniChar *)str.unicode(), str.length()); +} + +TQString cfstring2qstring(CFStringRef str) +{ + if(!str) + return TQString(); + + CFIndex length = CFStringGetLength(str); + if(const UniChar *chars = CFStringGetCharactersPtr(str)) + return TQString((TQChar *)chars, length); + UniChar *buffer = (UniChar*)malloc(length * sizeof(UniChar)); + CFStringGetCharacters(str, CFRangeMake(0, length), buffer); + TQString ret((TQChar *)buffer, length); + free(buffer); + return ret; +} + +unsigned char *p_str(const TQString &s) +{ + CFStringRef cfstr = tqstring2cfstring(s); + uchar *p = (uchar*)malloc(256); + CFStringGetPascalString(cfstr, p, 256, CFStringGetSystemEncoding()); + CFRelease(cfstr); + return p; +} + +TQString p2qstring(const unsigned char *c) { + CFStringRef cfstr = CFStringCreateWithPascalString(0, c, CFStringGetSystemEncoding()); + TQString str = cfstring2qstring(cfstr); + CFRelease(cfstr); + return str; +} + +int qMacVersion() +{ + static int macver = TQt::MV_Unknown; + static bool first = TRUE; + if(first) { + first = FALSE; + long gestalt_version; + if(Gestalt(gestaltSystemVersion, &gestalt_version) == noErr) { + macver = ((gestalt_version & 0x00f0) >> 4) + 2; + + } + } + return macver; +} +TQt::MacintoshVersion qt_macver = (TQt::MacintoshVersion)qMacVersion(); + +// HFS+ filesystems use decomposing unicode for certain layers in unicode +// In general these don't look great as a user visible string. +// Therefore it is a good idea to normalize them ourselves. +// These technotes on Apple's website: +// http://developer.apple.com/qa/qa2001/qa1235.html +// http://developer.apple.com/qa/qa2001/qa1173.html +TQString qt_mac_precomposeFileName(const TQString &str) +{ + if (str.isEmpty()) + return str; + int strLength = str.length(); + CFMutableStringRef cfmstr = CFStringCreateMutable(0, strLength); + CFStringAppendCharacters(cfmstr, (UniChar *)str.unicode(), strLength); + CFStringNormalize(cfmstr, kCFStringNormalizationFormC); + TQString newStr = cfstring2qstring(cfmstr); + CFRelease(cfmstr); + return newStr; +} +#elif defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN) || defined(Q_OS_TEMP) +bool qt_winunicode; +# ifdef Q_OS_TEMP + DWORD qt_cever = 0; +# endif // Q_OS_TEMP + +#include "qt_windows.h" + +int qWinVersion() +{ +#ifndef VER_PLATFORM_WIN32s +#define VER_PLATFORM_WIN32s 0 +#endif +#ifndef VER_PLATFORM_WIN32_WINDOWS +#define VER_PLATFORM_WIN32_WINDOWS 1 +#endif +#ifndef VER_PLATFORM_WIN32_NT +#define VER_PLATFORM_WIN32_NT 2 +#endif +#ifndef VER_PLATFORM_WIN32_CE +#define VER_PLATFORM_WIN32_CE 3 +#endif + + static int winver = TQt::WV_NT; + static int t=0; + if ( !t ) { + t=1; +#ifndef Q_OS_TEMP + OSVERSIONINFOA osver; + osver.dwOSVersionInfoSize = sizeof(osver); + GetVersionExA( &osver ); +#else + OSVERSIONINFOW osver; + osver.dwOSVersionInfoSize = sizeof(osver); + GetVersionEx( &osver ); + qt_cever = osver.dwMajorVersion * 100; + qt_cever += osver.dwMinorVersion * 10; +#endif + switch ( osver.dwPlatformId ) { + case VER_PLATFORM_WIN32s: + winver = TQt::WV_32s; + break; + case VER_PLATFORM_WIN32_WINDOWS: + // We treat Windows Me (minor 90) the same as Windows 98 + if ( osver.dwMinorVersion == 90 ) + winver = TQt::WV_Me; + else if ( osver.dwMinorVersion == 10 ) + winver = TQt::WV_98; + else + winver = TQt::WV_95; + break; + case VER_PLATFORM_WIN32_CE: +#ifdef Q_OS_TEMP + if ( qt_cever >= 400 ) + winver = TQt::WV_CENET; + else +#endif + winver = TQt::WV_CE; + break; + default: // VER_PLATFORM_WIN32_NT + if ( osver.dwMajorVersion < 5 ) { + winver = TQt::WV_NT; + } else if (osver.dwMajorVersion == 6) { + winver = TQt::WV_VISTA; + } else if ( osver.dwMinorVersion == 0 ) { + winver = TQt::WV_2000; + } else if ( osver.dwMinorVersion == 1 ) { + winver = TQt::WV_XP; + } else if ( osver.dwMinorVersion == 2 ) { + winver = TQt::WV_2003; + } else { + tqWarning("Untested Windows version detected!"); + winver = TQt::WV_NT_based; + } + } + } + +#if defined(UNICODE) + if ( winver & TQt::WV_NT_based ) + qt_winunicode = TRUE; + else +#endif + qt_winunicode = FALSE; + + return winver; +} + +TQt::WindowsVersion qt_winver = (TQt::WindowsVersion)qWinVersion(); +#endif + + +/***************************************************************************** + Debug output routines + *****************************************************************************/ + +/*! + \fn void tqDebug( const char *msg, ... ) + + \relates TQApplication + + Prints a debug message \a msg, or calls the message handler (if it + has been installed). + + This function takes a format string and a list of arguments, + similar to the C printf() function. + + Example: + \code + tqDebug( "my window handle = %x", myWidget->id() ); + \endcode + + Under X11, the text is printed to stderr. Under Windows, the text + is sent to the debugger. + + \warning The internal buffer is limited to 8196 bytes (including + the '\0'-terminator). + + \warning Passing (const char *)0 as argument to tqDebug might lead + to crashes on certain platforms due to the platforms printf implementation. + + \sa tqWarning(), tqFatal(), qInstallMsgHandler(), + \link debug.html Debugging\endlink +*/ + +/*! + \fn void tqWarning( const char *msg, ... ) + + \relates TQApplication + + Prints a warning message \a msg, or calls the message handler (if + it has been installed). + + This function takes a format string and a list of arguments, + similar to the C printf() function. + + Example: + \code + void f( int c ) + { + if ( c > 200 ) + tqWarning( "f: bad argument, c == %d", c ); + } + \endcode + + Under X11, the text is printed to stderr. Under Windows, the text + is sent to the debugger. + + \warning The internal buffer is limited to 8196 bytes (including + the '\0'-terminator). + + \warning Passing (const char *)0 as argument to tqWarning might lead + to crashes on certain platforms due to the platforms printf implementation. + + \sa tqDebug(), tqFatal(), qInstallMsgHandler(), + \link debug.html Debugging\endlink +*/ + +/*! + \fn void tqFatal( const char *msg, ... ) + + \relates TQApplication + + Prints a fatal error message \a msg and exits, or calls the + message handler (if it has been installed). + + This function takes a format string and a list of arguments, + similar to the C printf() function. + + Example: + \code + int divide( int a, int b ) + { + if ( b == 0 ) // program error + tqFatal( "divide: cannot divide by zero" ); + return a/b; + } + \endcode + + Under X11, the text is printed to stderr. Under Windows, the text + is sent to the debugger. + + \warning The internal buffer is limited to 8196 bytes (including + the '\0'-terminator). + + \warning Passing (const char *)0 as argument to tqFatal might lead + to crashes on certain platforms due to the platforms printf implementation. + + \sa tqDebug(), tqWarning(), qInstallMsgHandler(), + \link debug.html Debugging\endlink +*/ + + +static TQtMsgHandler handler = 0; // pointer to debug handler +static const int QT_BUFFER_LENGTH = 8196; // internal buffer length + + +#ifdef Q_CC_MWERKS + +#include "qt_mac.h" + +extern bool tqt_is_gui_used; +static void mac_default_handler( const char *msg ) +{ + if ( tqt_is_gui_used ) { + const unsigned char *p = p_str(msg); + DebugStr(p); + free((void*)p); + } else { + fprintf( stderr, msg ); + } +} + +#endif + +void handle_buffer(const char *buf, TQtMsgType msgType) +{ + if ( handler ) { + (*handler)( msgType, buf ); + } else if (msgType == TQtFatalMsg) { +#if defined(Q_CC_MWERKS) + mac_default_handler(buf); +#else + fprintf( stderr, "%s\n", buf ); // add newline +#endif +#if defined(Q_OS_UNIX) && defined(QT_DEBUG) + abort(); // trap; generates core dump +#elif defined(Q_OS_TEMP) && defined(QT_DEBUG) + TQString fstr; + fstr.sprintf( "%s:%s %s %s\n", __FILE__, __LINE__, TQT_VERSION_STR, buf ); + OutputDebugString( fstr.ucs2() ); +#elif defined(_CRT_ERROR) && defined(_DEBUG) + _CrtDbgReport( _CRT_ERROR, __FILE__, __LINE__, TQT_VERSION_STR, buf ); +#else + exit( 1 ); // goodbye cruel world +#endif + } else { +#if defined(Q_CC_MWERKS) + mac_default_handler(buf); +#elif defined(Q_OS_TEMP) + TQString fstr( buf ); + OutputDebugString( (fstr + "\n").ucs2() ); +#else + fprintf( stderr, "%s\n", buf ); // add newline +#endif + } +} + +void tqDebug( const TQString &msg ) +{ + char buf[QT_BUFFER_LENGTH]; + strcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").local8Bit() ); + int len = strlen(buf); + strncpy( &buf[len], msg.local8Bit(), QT_BUFFER_LENGTH - len - 1 ); + len += msg.length(); + if (len >= QT_BUFFER_LENGTH) { + len = QT_BUFFER_LENGTH - 1; + } + buf[len] = '\0'; + handle_buffer(buf, TQtDebugMsg); +} + +void tqDebug( const char *msg, ... ) +{ + char buf[QT_BUFFER_LENGTH]; + strcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").local8Bit() ); + int len = strlen(buf); + va_list ap; + va_start( ap, msg ); // use variable arg list +#if defined(QT_VSNPRINTF) + QT_VSNPRINTF( &buf[len], QT_BUFFER_LENGTH-len, msg, ap ); +#else + vsprintf( &buf[len], msg, ap ); +#endif + va_end( ap ); + handle_buffer(buf, TQtDebugMsg); +} + +void tqDebug( const TQCString &s ) +{ + tqDebug("%s", s.data()); +} + +void tqWarning( const TQString &msg ) +{ + char buf[QT_BUFFER_LENGTH]; + strcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").local8Bit() ); + int len = strlen(buf); + strncpy( &buf[len], msg.local8Bit(), QT_BUFFER_LENGTH - len - 1 ); + len += msg.length(); + if (len >= QT_BUFFER_LENGTH) { + len = QT_BUFFER_LENGTH - 1; + } + buf[len] = '\0'; + handle_buffer(buf, TQtWarningMsg); +} + +void tqWarning( const char *msg, ... ) +{ + char buf[QT_BUFFER_LENGTH]; + strcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").local8Bit() ); + int len = strlen(buf); + va_list ap; + va_start( ap, msg ); // use variable arg list +#if defined(QT_VSNPRINTF) + QT_VSNPRINTF( &buf[len], QT_BUFFER_LENGTH-len, msg, ap ); +#else + vsprintf( &buf[len], msg, ap ); +#endif + va_end( ap ); + handle_buffer(buf, TQtWarningMsg); +} + +void tqWarning( const TQCString &s ) +{ + tqWarning("%s", s.data()); +} + +void tqFatal( const TQString &msg ) +{ + char buf[QT_BUFFER_LENGTH]; + strcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").local8Bit() ); + int len = strlen(buf); + strncpy( &buf[len], msg.local8Bit(), QT_BUFFER_LENGTH - len - 1 ); + len += msg.length(); + if (len >= QT_BUFFER_LENGTH) { + len = QT_BUFFER_LENGTH - 1; + } + buf[len] = '\0'; + handle_buffer(buf, TQtFatalMsg); +} + +void tqFatal( const char *msg, ... ) +{ + char buf[QT_BUFFER_LENGTH]; + strcpy( buf, TQDateTime::currentDateTime().toString("[yyyy/MM/dd hh:mm:ss.zzz] ").local8Bit() ); + int len = strlen(buf); + va_list ap; + va_start( ap, msg ); // use variable arg list +#if defined(QT_VSNPRINTF) + QT_VSNPRINTF( &buf[len], QT_BUFFER_LENGTH-len, msg, ap ); +#else + vsprintf( &buf[len], msg, ap ); +#endif + va_end( ap ); + handle_buffer(buf, TQtFatalMsg); +} + +void tqFatal( const TQCString &s ) +{ + tqWarning("%s", s.data()); +} + +/*! + \relates TQApplication + + Prints the message \a msg and uses \a code to get a system specific + error message. When \a code is -1 (the default), the system's last + error code will be used if possible. Use this method to handle + failures in platform specific API calls. + + This function does nothing when TQt is built with \c TQT_NO_DEBUG + defined. +*/ +void tqSystemWarning( const char* msg, int code ) +{ +#ifndef TQT_NO_DEBUG +#if defined(Q_OS_WIN32) + if ( code == -1 ) + code = GetLastError(); + + if ( !code ) + return; + + unsigned short *string; + QT_WA( { + FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + code, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&string, + 0, + NULL ); + + tqWarning( "%s\n\tError code %d - %s", msg, code, TQString::fromUcs2(string).latin1() ); + }, { + FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + code, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (char*)&string, + 0, + NULL ); + + tqWarning( "%s\n\tError code %d - %s", msg, code, (const char*)string ); + } ); + LocalFree( (HLOCAL)string ); +#else + if ( code != -1 ) + tqWarning( "%s\n\tError code %d - %s", msg, code, strerror( code ) ); + else + tqWarning( "%s", msg ); +#endif +#else + Q_UNUSED( msg ); + Q_UNUSED( code ); +#endif +} + +/*! + \fn void Q_ASSERT( bool test ) + + \relates TQApplication + + Prints a warning message containing the source code file name and + line number if \a test is FALSE. + + This is really a macro defined in \c tqglobal.h. + + Q_ASSERT is useful for testing pre- and post-conditions. + + Example: + \code + // + // File: div.cpp + // + + #include + + int divide( int a, int b ) + { + Q_ASSERT( b != 0 ); // this is line 9 + return a/b; + } + \endcode + + If \c b is zero, the Q_ASSERT statement will output the following + message using the tqWarning() function: + \code + ASSERT: "b != 0" in div.cpp (9) + \endcode + + \sa tqWarning(), \link debug.html Debugging\endlink +*/ + + +/*! + \fn void TQ_CHECK_PTR( void *p ) + + \relates TQApplication + + If \a p is 0, prints a warning message containing the source code file + name and line number, saying that the program ran out of memory. + + This is really a macro defined in \c tqglobal.h. + + Example: + \code + int *a; + + TQ_CHECK_PTR( a = new int[80] ); // WRONG! + + a = new (nothrow) int[80]; // Right + TQ_CHECK_PTR( a ); + \endcode + + \sa tqWarning(), \link debug.html Debugging\endlink +*/ + + +// +// The TQ_CHECK_PTR macro calls this function to check if an allocation went ok. +// +bool tqt_check_pointer( bool c, const char *n, int l ) +{ + if ( c ) + tqWarning( "In file %s, line %d: Out of memory", n, l ); + return TRUE; +} + + +static bool firstObsoleteWarning(const char *obj, const char *oldfunc ) +{ + static TQAsciiDict *obsoleteDict = 0; + if ( !obsoleteDict ) { // first time func is called + obsoleteDict = new TQAsciiDict; +#if defined(QT_DEBUG) + tqDebug( + "You are using obsolete functions in the TQt library. Call the function\n" + "qSuppressObsoleteWarnings() to suppress obsolete warnings.\n" + ); +#endif + } + TQCString s( obj ); + s += "::"; + s += oldfunc; + if ( obsoleteDict->find(s.data()) == 0 ) { + obsoleteDict->insert( s.data(), (int*)1 ); // anything different from 0 + return TRUE; + } + return FALSE; +} + +static bool suppressObsolete = FALSE; + +void tqSuppressObsoleteWarnings( bool suppress ) +{ + suppressObsolete = suppress; +} + +void tqObsolete( const char *obj, const char *oldfunc, const char *newfunc ) +{ + if ( suppressObsolete ) + return; + if ( !firstObsoleteWarning(obj, oldfunc) ) + return; + if ( obj ) + tqDebug( "%s::%s: This function is obsolete, use %s instead.", + obj, oldfunc, newfunc ); + else + tqDebug( "%s: This function is obsolete, use %s instead.", + oldfunc, newfunc ); +} + +void tqObsolete( const char *obj, const char *oldfunc ) +{ + if ( suppressObsolete ) + return; + if ( !firstObsoleteWarning(obj, oldfunc) ) + return; + if ( obj ) + tqDebug( "%s::%s: This function is obsolete.", obj, oldfunc ); + else + tqDebug( "%s: This function is obsolete.", oldfunc ); +} + +void tqObsolete( const char *message ) +{ + if ( suppressObsolete ) + return; + if ( !firstObsoleteWarning( "TQt", message) ) + return; + tqDebug( "%s", message ); +} + + +/*! + \relates TQApplication + + Installs a TQt message handler \a h. Returns a pointer to the + message handler previously defined. + + The message handler is a function that prints out debug messages, + warnings and fatal error messages. The TQt library (debug version) + contains hundreds of warning messages that are printed when + internal errors (usually invalid function arguments) occur. If you + implement your own message handler, you get total control of these + messages. + + The default message handler prints the message to the standard + output under X11 or to the debugger under Windows. If it is a + fatal message, the application aborts immediately. + + Only one message handler can be defined, since this is usually + done on an application-wide basis to control debug output. + + To restore the message handler, call \c qInstallMsgHandler(0). + + Example: + \code + #include + #include + #include + + void myMessageOutput( TQtMsgType type, const char *msg ) + { + switch ( type ) { + case TQtDebugMsg: + fprintf( stderr, "Debug: %s\n", msg ); + break; + case TQtWarningMsg: + fprintf( stderr, "Warning: %s\n", msg ); + break; + case TQtFatalMsg: + fprintf( stderr, "Fatal: %s\n", msg ); + abort(); // deliberately core dump + } + } + + int main( int argc, char **argv ) + { + qInstallMsgHandler( myMessageOutput ); + TQApplication a( argc, argv ); + ... + return a.exec(); + } + \endcode + + \sa tqDebug(), tqWarning(), tqFatal(), \link debug.html Debugging\endlink +*/ + +TQtMsgHandler qInstallMsgHandler( TQtMsgHandler h ) +{ + TQtMsgHandler old = handler; + handler = h; + return old; +} + + +/* + Dijkstra's bisection algorithm to find the square root as an integer. + Deliberately not exported as part of the TQt API, but used in + tqsimplerichtext.cpp +*/ +unsigned int qt_int_sqrt( unsigned int n ) +{ + // n must be in the range 0...UINT_MAX/2-1 + if ( n >= ( UINT_MAX>>2 ) ) { + unsigned int r = 2 * qt_int_sqrt( n / 4 ); + unsigned int r2 = r + 1; + return ( n >= r2 * r2 ) ? r2 : r; + } + uint h, p= 0, q= 1, r= n; + while ( q <= n ) + q <<= 2; + while ( q != 1 ) { + q >>= 2; + h= p + q; + p >>= 1; + if ( r >= h ) { + p += q; + r -= h; + } + } + return p; +} + diff --git a/src/tools/tqglobal.h b/src/tools/tqglobal.h new file mode 100644 index 000000000..64115edf3 --- /dev/null +++ b/src/tools/tqglobal.h @@ -0,0 +1,1085 @@ +/**************************************************************************** +** +** Global type declarations and definitions +** +** Created : 920529 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQGLOBAL_H +#define TQGLOBAL_H + +#define TQT_VERSION_STR "3.5.0" +/* + TQT_VERSION is (major << 16) + (minor << 8) + patch. + */ +#define TQT_VERSION 0x030500 + +/* + The operating system, must be one of: (Q_OS_x) + + MACX - Mac OS X + MAC9 - Mac OS 9 + DARWIN - Darwin OS (Without Mac OS X) + MSDOS - MS-DOS and Windows + OS2 - OS/2 + OS2EMX - XFree86 on OS/2 (not PM) + WIN32 - Win32 (Windows 95/98/ME and Windows NT/2000/XP) + CYGWIN - Cygwin + SOLARIS - Sun Solaris + HPUX - HP-UX + ULTRIX - DEC Ultrix + LINUX - Linux + FREEBSD - FreeBSD + NETBSD - NetBSD + OPENBSD - OpenBSD + BSDI - BSD/OS + IRIX - SGI Irix + OSF - HP Tru64 UNIX + SCO - SCO OpenServer 5 + UNIXWARE - UnixWare 7, Open UNIX 8 + AIX - AIX + HURD - GNU Hurd + DGUX - DG/UX + RELIANT - Reliant UNIX + DYNIX - DYNIX/ptx + TQNX - TQNX + TQNX6 - TQNX RTP 6.1 + LYNX - LynxOS + BSD4 - Any BSD 4.4 system + UNIX - Any UNIX BSD/SYSV system +*/ + +#if defined(__DARWIN_X11__) +# define Q_OS_DARWIN +#elif defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__)) +# define Q_OS_MACX +#elif defined(__MACOSX__) +# define Q_OS_MACX +#elif defined(macintosh) +# define Q_OS_MAC9 +#elif defined(__CYGWIN__) +# define Q_OS_CYGWIN +#elif defined(MSDOS) || defined(_MSDOS) +# define Q_OS_MSDOS +#elif defined(__OS2__) +# if defined(__EMX__) +# define Q_OS_OS2EMX +# else +# define Q_OS_OS2 +# endif +#elif !defined(SAG_COM) && (defined(WIN64) || defined(_WIN64) || defined(__WIN64__)) +# define Q_OS_WIN32 +# define Q_OS_WIN64 +#elif !defined(SAG_COM) && (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)) +# define Q_OS_WIN32 +#elif defined(__MWERKS__) && defined(__INTEL__) +# define Q_OS_WIN32 +#elif defined(__sun) || defined(sun) +# define Q_OS_SOLARIS +#elif defined(hpux) || defined(__hpux) +# define Q_OS_HPUX +#elif defined(__ultrix) || defined(ultrix) +# define Q_OS_ULTRIX +#elif defined(sinix) +# define Q_OS_RELIANT +#elif defined(__GNU__) +# define Q_OS_HURD +#elif defined(__linux__) || defined(__linux) || defined(__GNU__) || defined(__GLIBC__) +# define Q_OS_LINUX +#elif defined(__FreeBSD__) || defined(__DragonFly__) +# define Q_OS_FREEBSD +# define Q_OS_BSD4 +#elif defined(__NetBSD__) +# define Q_OS_NETBSD +# define Q_OS_BSD4 +#elif defined(__OpenBSD__) +# define Q_OS_OPENBSD +# define Q_OS_BSD4 +#elif defined(__bsdi__) +# define Q_OS_BSDI +# define Q_OS_BSD4 +#elif defined(__sgi) +# define Q_OS_IRIX +#elif defined(__osf__) +# define Q_OS_OSF +#elif defined(_AIX) +# define Q_OS_AIX +#elif defined(__Lynx__) +# define Q_OS_LYNX +#elif defined(__DGUX__) +# define Q_OS_DGUX +#elif defined(__QNXNTO__) +# define Q_OS_QNX6 +#elif defined(__QNX__) +# define Q_OS_QNX +#elif defined(_SEQUENT_) +# define Q_OS_DYNIX +#elif defined(_SCO_DS) /* SCO OpenServer 5 + GCC */ +# define Q_OS_SCO +#elif defined(__USLC__) /* all SCO platforms + UDK or OUDK */ +# define Q_OS_UNIXWARE +# define Q_OS_UNIXWARE7 +#elif defined(__svr4__) && defined(i386) /* Open UNIX 8 + GCC */ +# define Q_OS_UNIXWARE +# define Q_OS_UNIXWARE7 +#elif defined(__MAKEDEPEND__) +#else +# error "TQt has not been ported to this OS - talk to qt-bugs@trolltech.com" +#endif + +#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64) +# define Q_OS_WIN +#endif + +#if defined(Q_OS_MAC9) || defined(Q_OS_MACX) +# define Q_OS_MAC +#endif + +#if defined(Q_OS_MAC9) || defined(Q_OS_MSDOS) || defined(Q_OS_OS2) || defined(Q_OS_WIN) +# undef Q_OS_UNIX +#elif !defined(Q_OS_UNIX) +# define Q_OS_UNIX +#endif + +#if defined(Q_OS_MACX) +# ifdef MAC_OS_X_VERSION_MIN_REQUIRED +# undef MAC_OS_X_VERSION_MIN_REQUIRED +# endif +# define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_2 +# include +# if !defined(MAC_OS_X_VERSION_10_3) +# define MAC_OS_X_VERSION_10_3 MAC_OS_X_VERSION_10_2 + 1 +# endif +# if !defined(MAC_OS_X_VERSION_10_4) +# define MAC_OS_X_VERSION_10_4 MAC_OS_X_VERSION_10_3 + 1 +# endif +# if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) +# error "This version of Mac OS X is unsupported" +# endif +#endif + + +/* + The compiler, must be one of: (Q_CC_x) + + SYM - Symantec C++ for both PC and Macintosh + MPW - MPW C++ + MWERKS - Metrowerks CodeWarrior + MSVC - Microsoft Visual C/C++, Intel C++ for Windows + BOR - Borland/Turbo C++ + WAT - Watcom C++ + GNU - GNU C++ + COMEAU - Comeau C++ + EDG - Edison Design Group C++ + OC - CenterLine C++ + SUN - Sun WorkShop, Forte Developer, or Sun ONE Studio C++ + MIPS - MIPSpro C++ + DEC - DEC C++ + HP - HPUX C++ + HPACC - HPUX ANSI C++ + USLC - SCO OUDK, UDK, and UnixWare 2.X C++ + CDS - Reliant C++ + KAI - KAI C++ + INTEL - Intel C++ for Linux, Intel C++ for Windows + HIGHC - MetaWare High C/C++ + PGI - Portland Group C++ + GHS - Green Hills Optimizing C++ Compilers + + Should be sorted most to least authoritative. +*/ + +/* Symantec C++ is now Digital Mars */ +#if defined(__DMC__) || defined(__SC__) +# define Q_CC_SYM +/* "explicit" semantics implemented in 8.1e but keyword recognized since 7.5 */ +# if defined(__SC__) && __SC__ < 0x750 +# define Q_NO_EXPLICIT_KEYWORD +# endif +# define Q_NO_USING_KEYWORD +# if !defined(_CPPUNWIND) +# define Q_NO_EXCEPTIONS +# endif + +#elif defined(applec) +# define Q_CC_MPW +# define Q_NO_BOOL_TYPE +# define Q_NO_EXPLICIT_KEYWORD +# define Q_NO_USING_KEYWORD + +#elif defined(__MWERKS__) +# define Q_CC_MWERKS +/* "explicit" recognized since 4.0d1 */ +# define TQMAC_PASCAL pascal + +#elif defined(_MSC_VER) +# define Q_CC_MSVC +/* proper support of bool for _MSC_VER >= 1100 */ +# define Q_CANNOT_DELETE_CONSTANT +# define TQ_INLINE_TEMPLATES inline +/* Visual C++.Net issues for _MSC_VER >= 1300 */ +# if _MSC_VER >= 1300 +# define Q_CC_MSVC_NET +# if _MSC_VER < 1310 || (defined(Q_OS_WIN64) && defined(_M_IA64)) +# define TQ_TYPENAME +# endif +# endif +/* Intel C++ disguising as Visual C++: the `using' keyword avoids warnings */ +# if defined(__INTEL_COMPILER) +# define Q_CC_INTEL +# if !defined(__EXCEPTIONS) +# define Q_NO_EXCEPTIONS +# endif +# else +# define Q_NO_USING_KEYWORD /* ### check "using" status */ +# endif + +#elif defined(__BORLANDC__) || defined(__TURBOC__) +# define Q_CC_BOR +# if __BORLANDC__ < 0x502 +# define Q_NO_BOOL_TYPE +# define Q_NO_EXPLICIT_KEYWORD +# endif +# define Q_NO_USING_KEYWORD /* ### check "using" status */ + +#elif defined(__WATCOMC__) +# define Q_CC_WAT +# if defined(Q_OS_QNX4) +/* compiler flags */ +# define TQ_TYPENAME +# define Q_NO_BOOL_TYPE +# define Q_CANNOT_DELETE_CONSTANT +# define mutable +/* ??? */ +# define Q_BROKEN_TEMPLATE_SPECIALIZATION +/* no template classes in TQVariant */ +# define TQT_NO_TEMPLATE_VARIANT +/* Wcc does not fill in functions needed by valuelists, maps, and + valuestacks implicitly */ +# define TQ_FULL_TEMPLATE_INSTANTIATION +/* can we just compare the structures? */ +# define TQ_FULL_TEMPLATE_INSTANTIATION_MEMCMP +/* these are not useful to our customers */ +# define TQT_NO_SQL +# endif + +#elif defined(__GNUC__) +# define Q_CC_GNU +# define Q_C_CALLBACKS +# if __GNUC__ == 2 && __GNUC_MINOR__ <= 7 +# define TQ_FULL_TEMPLATE_INSTANTIATION +# endif +/* GCC 2.95 knows "using" but does not support it correctly */ +# if __GNUC__ == 2 && __GNUC_MINOR__ <= 95 +# define Q_NO_USING_KEYWORD +# endif +/* GCC 3.1 and GCC 3.2 wrongly define _SB_CTYPE_MACROS on HP-UX */ +# if defined(Q_OS_HPUX) && __GNUC__ == 3 && __GNUC_MINOR__ >= 1 +# define Q_WRONG_SB_CTYPE_MACROS +# endif + +/* ARM gcc pads structs to 32 bits, even when they contain a single + char, or short. We tell gcc to pack TQChars to 16 bits, to avoid + TQString bloat. However, gcc 3.4 doesn't allow us to create references to + members of a packed struct. (Pointers are OK, because then you + supposedly know what you are doing.) */ +# if (defined(__arm__) || defined(__ARMEL__)) && !defined(__ARM_EABI__) && !defined(QT_MOC_CPP) +# define TQ_PACKED __attribute__ ((packed)) +# if __GNUC__ == 3 && __GNUC_MINOR__ >= 4 || __GNUC__ > 3 +# define Q_NO_PACKED_REFERENCE +# endif +# endif +# if !defined(__EXCEPTIONS) +# define Q_NO_EXCEPTIONS +# endif + +/* IBM compiler versions are a bit messy. There are actually two products: + the C product, and the C++ product. The C++ compiler is always packaged + with the latest version of the C compiler. Version numbers do not always + match. This little table (I'm not sure it's accurate) should be helpful: + + C++ product C product + + C Set 3.1 C Compiler 3.0 + ... ... + C++ Compiler 3.6.6 C Compiler 4.3 + ... ... + Visual Age C++ 4.0 ... + ... ... + Visual Age C++ 5.0 C Compiler 5.0 + ... ... + Visual Age C++ 6.0 C Compiler 6.0 + + Now: + __xlC__ is the version of the C compiler in hexadecimal notation + is only an approximation of the C++ compiler version + __IBMCPP__ is the version of the C++ compiler in decimal notation + but it is not defined on older compilers like C Set 3.1 */ +#elif defined(__xlC__) +# define Q_CC_XLC +# define TQ_FULL_TEMPLATE_INSTANTIATION +# if __xlC__ < 0x400 +# define Q_NO_BOOL_TYPE +# define Q_NO_EXPLICIT_KEYWORD +# define Q_NO_USING_KEYWORD +# define TQ_TYPENAME +# define TQ_INLINE_TEMPLATES inline +# define Q_BROKEN_TEMPLATE_SPECIALIZATION +# define Q_CANNOT_DELETE_CONSTANT +# endif + +/* Older versions of DEC C++ do not define __EDG__ or __EDG - observed + on DEC C++ V5.5-004. New versions do define __EDG__ - observed on + Compaq C++ V6.3-002. + This compiler is different enough from other EDG compilers to handle + it separately anyway. */ +#elif defined(__DECCXX) || defined(__DECC) +# define Q_CC_DEC +/* Compaq C++ V6 compilers are EDG-based but I'm not sure about older + DEC C++ V5 compilers. */ +# if defined(__EDG__) +# define Q_CC_EDG +# endif +/* Compaq have disabled EDG's _BOOL macro and use _BOOL_EXISTS instead + - observed on Compaq C++ V6.3-002. + In any case versions prior to Compaq C++ V6.0-005 do not have bool. */ +# if !defined(_BOOL_EXISTS) +# define Q_NO_BOOL_TYPE +# endif +/* Spurious (?) error messages observed on Compaq C++ V6.5-014. */ +# define Q_NO_USING_KEYWORD +/* Apply to all versions prior to Compaq C++ V6.0-000 - observed on + DEC C++ V5.5-004. */ +# if __DECCXX_VER < 60060000 +# define TQ_TYPENAME +# define Q_BROKEN_TEMPLATE_SPECIALIZATION +# define Q_CANNOT_DELETE_CONSTANT +# endif +/* avoid undefined symbol problems with out-of-line template members */ +# define TQ_INLINE_TEMPLATES inline + +/* Compilers with EDG front end are similar. To detect them we test: + __EDG documented by SGI, observed on MIPSpro 7.3.1.1 and KAI C++ 4.0b + __EDG__ documented in EDG online docs, observed on Compaq C++ V6.3-002 */ +#elif defined(__EDG) || defined(__EDG__) +# define Q_CC_EDG +/* From the EDG documentation (does not seem to apply to Compaq C++): + _BOOL + Defined in C++ mode when bool is a keyword. The name of this + predefined macro is specified by a configuration flag. _BOOL + is the default. + __BOOL_DEFINED + Defined in Microsoft C++ mode when bool is a keyword. */ +# if !defined(_BOOL) && !defined(__BOOL_DEFINED) +# define Q_NO_BOOL_TYPE +# endif + +/* The Comeau compiler is based on EDG and does define __EDG__ */ +# if defined(__COMO__) +# define Q_CC_COMEAU +# define Q_C_CALLBACKS + +/* The `using' keyword was introduced to avoid KAI C++ warnings + but it's now causing KAI C++ errors instead. The standard is + unclear about the use of this keyword, and in practice every + compiler is using its own set of rules. Forget it. */ +# elif defined(__KCC) +# define Q_CC_KAI +# if !defined(_EXCEPTIONS) +# define Q_NO_EXCEPTIONS +# endif +# define Q_NO_USING_KEYWORD + +/* Using the `using' keyword avoids Intel C++ for Linux warnings */ +# elif defined(__INTEL_COMPILER) +# define Q_CC_INTEL +# if !defined(__EXCEPTIONS) +# define Q_NO_EXCEPTIONS +# endif + +/* The Portland Group compiler is based on EDG and does define __EDG__ */ +# elif defined(__PGI) +# define Q_CC_PGI +# if !defined(__EXCEPTIONS) +# define Q_NO_EXCEPTIONS +# endif + +/* Never tested! */ +# elif defined(__ghs) +# define Q_CC_GHS + +/* The UnixWare 7 UDK compiler is based on EDG and does define __EDG__ */ +# elif defined(__USLC__) && defined(__SCO_VERSION__) +# define Q_CC_USLC +/* The latest UDK 7.1.1b does not need this, but previous versions do */ +# if !defined(__SCO_VERSION__) || (__SCO_VERSION__ < 302200010) +# define TQ_INLINE_TEMPLATES inline +# endif +# define Q_NO_USING_KEYWORD /* ### check "using" status */ + +/* Never tested! */ +# elif defined(CENTERLINE_CLPP) || defined(OBJECTCENTER) +# define Q_CC_OC +# define Q_NO_USING_KEYWORD + +/* CDS++ defines __EDG__ although this is not documented in the Reliant + documentation. It also follows conventions like _BOOL and this documented */ +# elif defined(sinix) +# define Q_CC_CDS +# define Q_NO_USING_KEYWORD +# if defined(__cplusplus) && (__cplusplus < 2) /* Cfront C++ mode */ +# define Q_NO_EXCEPTIONS +# endif + +/* The MIPSpro compiler in o32 mode is based on EDG but disables features + such as template specialization nevertheless */ +# elif defined(__sgi) +# define Q_CC_MIPS +# if defined(_MIPS_SIM) && (_MIPS_SIM == _ABIO32) /* o32 ABI */ +# define TQ_TYPENAME +# define Q_BROKEN_TEMPLATE_SPECIALIZATION +# define Q_NO_EXPLICIT_KEYWORD +# define TQ_INLINE_TEMPLATES inline +# elif defined(_COMPILER_VERSION) && (_COMPILER_VERSION < 730) /* 7.2 */ +# define TQ_TYPENAME +# define Q_BROKEN_TEMPLATE_SPECIALIZATION +# endif +# define Q_NO_USING_KEYWORD /* ### check "using" status */ +# if defined(_COMPILER_VERSION) && (_COMPILER_VERSION >= 740) +# pragma set woff 3624,3625, 3649 /* turn off some harmless warnings */ +# endif +# endif + +/* The older UnixWare 2.X compiler? */ +#elif defined(__USLC__) +# define Q_CC_USLC +# define TQ_TYPENAME +# define Q_NO_BOOL_TYPE +# define Q_NO_EXPLICIT_KEYWORD +# define Q_NO_USING_KEYWORD +# define TQ_INLINE_TEMPLATES inline + +/* Never tested! */ +#elif defined(__HIGHC__) +# define Q_CC_HIGHC + +#elif defined(__SUNPRO_CC) || defined(__SUNPRO_C) +# define Q_CC_SUN +/* 5.0 compiler or better + 'bool' is enabled by default but can be disabled using -features=nobool + in which case _BOOL is not defined + this is the default in 4.2 compatibility mode triggered by -compat=4 */ +# if __SUNPRO_CC >= 0x500 +# if !defined(_BOOL) +# define Q_NO_BOOL_TYPE +# endif +# if defined(__SUNPRO_CC_COMPAT) && (__SUNPRO_CC_COMPAT <= 4) +# define Q_NO_USING_KEYWORD +# endif +# define Q_C_CALLBACKS +/* 4.2 compiler or older */ +# else +# define Q_NO_BOOL_TYPE +# define Q_NO_EXPLICIT_KEYWORD +# define Q_NO_USING_KEYWORD +# endif + +/* CDS++ does not seem to define __EDG__ or __EDG according to Reliant + documentation but nevertheless uses EDG conventions like _BOOL */ +#elif defined(sinix) +# define Q_CC_EDG +# define Q_CC_CDS +# if !defined(_BOOL) +# define Q_NO_BOOL_TYPE +# endif +# define Q_BROKEN_TEMPLATE_SPECIALIZATION + +#elif defined(Q_OS_HPUX) +/* __HP_aCC was not defined in first aCC releases */ +# if defined(__HP_aCC) || __cplusplus >= 199707L +# define Q_CC_HPACC +# else +# define Q_CC_HP +# define Q_NO_BOOL_TYPE +# define TQ_FULL_TEMPLATE_INSTANTIATION +# define Q_BROKEN_TEMPLATE_SPECIALIZATION +# define Q_NO_EXPLICIT_KEYWORD +# endif +# define Q_NO_USING_KEYWORD /* ### check "using" status */ + +#else +# error "TQt has not been tested with this compiler - talk to qt-bugs@trolltech.com" +#endif + +#ifndef TQ_PACKED +# define TQ_PACKED +#endif + + +/* + The window system, must be one of: (TQ_WS_x) + + MACX - Mac OS X + MAC9 - Mac OS 9 + WIN32 - Windows + X11 - X Window System + PM - unsupported + WIN16 - unsupported +*/ + +#if defined(Q_OS_MAC9) +# define TQ_WS_MAC9 +#elif defined(Q_OS_MSDOS) +# define TQ_WS_WIN16 +# error "TQt requires Win32 and does not work with Windows 3.x" +#elif defined(_WIN32_X11_) +# define TQ_WS_X11 +#elif defined(Q_OS_WIN32) +# define TQ_WS_WIN32 +# if defined(Q_OS_WIN64) +# define TQ_WS_WIN64 +# endif +#elif defined(Q_OS_OS2) +# define TQ_WS_PM +# error "TQt does not work with OS/2 Presentation Manager or Workplace Shell" +#elif defined(Q_OS_UNIX) +# if defined(Q_OS_MACX) +# define TQ_WS_MACX +# else +# define TQ_WS_X11 +# endif +#endif +#if defined(Q_OS_MAC) && !defined(TQMAC_PASCAL) +# define TQMAC_PASCAL +#endif + +#if defined(TQ_WS_WIN16) || defined(TQ_WS_WIN32) +# define TQ_WS_WIN +#endif + +#if (defined(TQ_WS_MAC9) || defined(TQ_WS_MACX)) && !defined(TQ_WS_X11) +# define TQ_WS_MAC +#endif + + +/* + Some classes do not permit copies to be made of an object. + These classes contains a private copy constructor and operator= + to disable copying (the compiler gives an error message). + Undefine TQ_DISABLE_COPY to turn off this checking. +*/ + +#define TQ_DISABLE_COPY + +#if defined(__cplusplus) + + +// +// Useful type definitions for TQt +// + +#if defined(Q_NO_BOOL_TYPE) +#if defined(Q_CC_HP) +// bool is an unsupported reserved keyword in later versions +#define bool int +#else +typedef int bool; +#endif +#endif + +typedef unsigned char uchar; +typedef unsigned short ushort; +typedef unsigned uint; +typedef unsigned long ulong; +typedef char *pchar; +typedef uchar *puchar; +typedef const char *pcchar; + + +// +// Constant bool values +// + +#ifndef TRUE +const bool FALSE = 0; +const bool TRUE = !0; +#endif +#if defined(__WATCOMC__) +# if defined(Q_OS_QNX4) +const bool false = FALSE; +const bool true = TRUE; +# endif +#endif + +// +// Proper for-scoping +// ### turn on in 4.0 + +#if 0 && defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) +# define for if(0){}else for +#endif + +// +// Use the "explicit" keyword on platforms that support it. +// + +#if !defined(Q_NO_EXPLICIT_KEYWORD) +# define Q_EXPLICIT explicit +#else +# define Q_EXPLICIT +#endif + + +// +// Utility macros and inline functions +// + +#define TQMAX(a, b) ((b) < (a) ? (a) : (b)) +#define TQMIN(a, b) ((a) < (b) ? (a) : (b)) +#define TQABS(a) ((a) >= 0 ? (a) : -(a)) + +inline int tqRound( double d ) +{ + return d >= 0.0 ? int(d + 0.5) : int( d - ((int)d-1) + 0.5 ) + ((int)d-1); +} + + +// +// Size-dependent types (architechture-dependent byte order) +// + +typedef signed char TQ_INT8; // 8 bit signed +typedef unsigned char TQ_UINT8; // 8 bit unsigned +typedef short TQ_INT16; // 16 bit signed +typedef unsigned short TQ_UINT16; // 16 bit unsigned +typedef int TQ_INT32; // 32 bit signed +typedef unsigned int TQ_UINT32; // 32 bit unsigned +#if defined(Q_OS_WIN64) +typedef __int64 TQ_LONG; // word up to 64 bit signed +typedef unsigned __int64 TQ_ULONG; // word up to 64 bit unsigned +#else +typedef long TQ_LONG; // word up to 64 bit signed +typedef unsigned long TQ_ULONG; // word up to 64 bit unsigned +#endif +#if defined(Q_OS_WIN) && !defined(Q_CC_GNU) +# define TQ_INT64_C(c) c ## i64 // signed 64 bit constant +# define TQ_UINT64_C(c) c ## ui64 // unsigned 64 bit constant +typedef __int64 TQ_INT64; // 64 bit signed +typedef unsigned __int64 TQ_UINT64; // 64 bit unsigned +#else +# define TQ_INT64_C(c) c ## LL // signed 64 bit constant +# define TQ_UINT64_C(c) c ## ULL // unsigned 64 bit constant +typedef long long TQ_INT64; // 64 bit signed +typedef unsigned long long TQ_UINT64; // 64 bit unsigned +#endif +typedef TQ_INT64 TQ_LLONG; // signed long long +typedef TQ_UINT64 TQ_ULLONG; // unsigned long long + +#if defined(Q_OS_MACX) && !defined(QT_LARGEFILE_SUPPORT) +# define QT_LARGEFILE_SUPPORT 64 +#endif +#if defined(QT_LARGEFILE_SUPPORT) + typedef TQ_ULLONG TQtOffset; +#else + typedef TQ_ULONG TQtOffset; +#endif + + +// +// Data stream functions is provided by many classes (defined in tqdatastream.h) +// + +class TQCString; +class TQDataStream; +class TQString; + +// +// Feature subsetting +// +// Note that disabling some features will produce a libtqt that is not +// compatible with other libtqt builds. Such modifications are only +// supported on TQt/Embedded where reducing the library size is important +// and where the application-suite is often a fixed set. +// + +#if !defined(QT_MOC) +#if defined(TQCONFIG_LOCAL) +#include "qconfig-local.h" +#elif defined(TQCONFIG_MINIMAL) +#include "qconfig-minimal.h" +#elif defined(TQCONFIG_SMALL) +#include "qconfig-small.h" +#elif defined(TQCONFIG_MEDIUM) +#include "qconfig-medium.h" +#elif defined(TQCONFIG_LARGE) +#include "qconfig-large.h" +#else // everything... +#include "ntqconfig.h" +#endif +#endif + + +#ifndef TQT_BUILD_KEY +#define TQT_BUILD_KEY "unspecified" +#endif + +// prune to local config +#include "ntqmodules.h" +#ifndef TQT_MODULE_DIALOGS +# define TQT_NO_DIALOG +#endif +#ifndef TQT_MODULE_INPUTMETHOD +# define TQT_NO_IM +#endif +#ifndef TQT_MODULE_WORKSPACE +# define TQT_NO_WORKSPACE +#endif +#ifndef TQT_MODULE_NETWORK +#define TQT_NO_NETWORK +#endif +#ifndef TQT_MODULE_CANVAS +# define TQT_NO_CANVAS +#endif +#ifndef TQT_MODULE_TABLE +#define TQT_NO_TABLE +#endif +#ifndef TQT_MODULE_XML +# define TQT_NO_XML +#endif +#ifndef TQT_MODULE_OPENGL +# define TQT_NO_OPENGL +#endif +#if !defined(TQT_MODULE_SQL) +# define TQT_NO_SQL +#endif + +#if defined(TQ_WS_MAC9) +//No need for menu merging +# ifndef TQMAC_QMENUBAR_NO_MERGE +# define TQMAC_QMENUBAR_NO_MERGE +# endif +//Mac9 does not use quartz +# ifndef TQMAC_NO_QUARTZ +# define TQMAC_NO_QUARTZ +# endif +# ifndef TQMAC_QMENUBAR_NO_EVENT +# define TQMAC_QMENUBAR_NO_EVENT +# endif +#endif +#if defined(TQ_WS_MACX) //for no nobody uses quartz, just putting in first level hooks +# ifndef TQMAC_NO_QUARTZ +# define TQMAC_NO_QUARTZ +# endif +# ifndef TQMAC_QMENUBAR_NO_EVENT +# define TQMAC_QMENUBAR_NO_EVENT +# endif +#endif + +#ifndef QT_H +#include "ntqfeatures.h" +#endif /* QT_H */ + + +// +// Create TQt DLL if QT_DLL is defined (Windows only) +// or QT_SHARED is defined (Kylix only) +// + +#if defined(Q_OS_WIN) +# if defined(QT_NODLL) +# undef QT_MAKEDLL +# undef QT_DLL +# elif defined(QT_MAKEDLL) /* create a TQt DLL library */ +# if defined(QT_DLL) +# undef QT_DLL +# endif +# define TQ_EXPORT __declspec(dllexport) +# define Q_TEMPLATEDLL +# define Q_TEMPLATE_EXTERN +# undef TQ_DISABLE_COPY /* avoid unresolved externals */ +# elif defined(QT_DLL) /* use a TQt DLL library */ +# define TQ_EXPORT __declspec(dllimport) +# define Q_TEMPLATEDLL +# ifndef Q_TEMPLATE_EXTERN +# if defined(Q_CC_MSVC_NET) +# define Q_TEMPLATE_EXTERN extern +# else +# define Q_TEMPLATE_EXTERN +# endif +# endif +# undef TQ_DISABLE_COPY /* avoid unresolved externals */ +# endif +#elif defined(Q_OS_LINUX) && defined(Q_CC_BOR) +# if defined(QT_SHARED) /* create a TQt shared library */ +# define TQ_EXPORT __declspec(dllexport) +# define Q_TEMPLATEDLL +# define Q_TEMPLATE_EXTERN +# undef TQ_DISABLE_COPY /* avoid unresolved externals */ +# else +# define Q_TEMPLATEDLL +# define Q_TEMPLATE_EXTERN +# undef TQ_DISABLE_COPY /* avoid unresolved externals */ +# endif +#elif defined(Q_CC_GNU) && __GNUC__ - 0 >= 4 +# define TQ_EXPORT __attribute__((visibility("default"))) +# undef QT_MAKEDLL /* ignore these for other platforms */ +# undef QT_DLL +#else +# undef QT_MAKEDLL /* ignore these for other platforms */ +# undef QT_DLL +#endif + +#ifndef TQ_EXPORT +# define TQ_EXPORT +#endif + + +// +// Some platform specific stuff +// + +#if defined(TQ_WS_WIN) +extern TQ_EXPORT bool qt_winunicode; +#endif + + +// +// System information +// + +TQ_EXPORT const char *tqVersion(); +TQ_EXPORT bool tqSysInfo( int *wordSize, bool *bigEndian ); +TQ_EXPORT bool tqSharedBuild(); +#if defined(Q_OS_MAC) +int qMacVersion(); +#elif defined(TQ_WS_WIN) +TQ_EXPORT int qWinVersion(); +#if defined(UNICODE) +#define QT_WA( uni, ansi ) if ( qt_winunicode ) { uni } else { ansi } +#define QT_WA_INLINE( uni, ansi ) ( qt_winunicode ? uni : ansi ) +#else +#define QT_WA( uni, ansi ) ansi +#define QT_WA_INLINE( uni, ansi ) ansi +#endif +#endif + +#ifdef Q_OS_TEMP +#ifdef QT_WA +#undef QT_WA +#undef QT_WA_INLINE +#endif +#define QT_WA( uni, ansi ) uni +#define QT_WA_INLINE( uni, ansi ) ( uni ) +#endif + +#ifndef TQ_INLINE_TEMPLATES +# define TQ_INLINE_TEMPLATES +#endif + +#ifndef TQ_TYPENAME +# define TQ_TYPENAME typename +#endif + +// +// Use to avoid "unused parameter" warnings +// +#define Q_UNUSED(x) (void)x; + +// +// Debugging and error handling +// + +#if !defined(TQT_NO_CHECK) +# define QT_CHECK_STATE // check state of objects etc. +# define QT_CHECK_RANGE // check range of indexes etc. +# define QT_CHECK_NULL // check null pointers +# define QT_CHECK_MATH // check math functions +#endif + +#if !defined(TQT_NO_DEBUG) && !defined(QT_DEBUG) +# define QT_DEBUG // display debug messages +# if !defined(TQT_NO_COMPAT) // compatibility with TQt 2 +# if !defined(NO_DEBUG) && !defined(DEBUG) +# if !defined(Q_OS_MACX) // clash with MacOS X headers +# define DEBUG +# endif +# endif +# endif +#endif + + +TQ_EXPORT void tqDebug( const TQString& ); // print debug message +TQ_EXPORT void tqDebug( const TQCString& ); // print debug message +TQ_EXPORT void tqDebug( const char *, ... ) // print debug message +#if defined(Q_CC_GNU) && !defined(__INSURE__) + __attribute__ ((format (printf, 1, 2))) +#endif +; + +TQ_EXPORT void tqWarning( const TQString& ); // print warning message +TQ_EXPORT void tqWarning( const TQCString& ); // print warning message +TQ_EXPORT void tqWarning( const char *, ... ) // print warning message +#if defined(Q_CC_GNU) && !defined(__INSURE__) + __attribute__ ((format (printf, 1, 2))) +#endif +; + +TQ_EXPORT void tqFatal( const TQString& ); // print fatal message and exit +TQ_EXPORT void tqFatal( const TQCString& ); // print fatal message and exit +TQ_EXPORT void tqFatal( const char *, ... ) // print fatal message and exit +#if defined(Q_CC_GNU) + __attribute__ ((format (printf, 1, 2))) +#endif +; + +TQ_EXPORT void tqSystemWarning( const char *, int code = -1 ); + + +#if !defined(Q_ASSERT) +# if defined(QT_CHECK_STATE) +# if defined(QT_FATAL_ASSERT) +# define Q_ASSERT(x) ((x) ? (void)0 : tqFatal("ASSERT: \"%s\" in %s (%d)",#x,__FILE__,__LINE__)) +# else +# define Q_ASSERT(x) ((x) ? (void)0 : tqWarning("ASSERT: \"%s\" in %s (%d)",#x,__FILE__,__LINE__)) +# endif +# else +# define Q_ASSERT(x) +# endif +#endif + +#if !defined(TQT_NO_COMPAT) // compatibility with TQt 2 +# if !defined(ASSERT) +# if !defined(Q_OS_TEMP) +# define ASSERT(x) Q_ASSERT(x) +# endif +# endif +#endif // TQT_NO_COMPAT + + +TQ_EXPORT bool tqt_check_pointer( bool c, const char *, int ); + +#if defined(QT_CHECK_NULL) +# define TQ_CHECK_PTR(p) (tqt_check_pointer((p)==0,__FILE__,__LINE__)) +#else +# define TQ_CHECK_PTR(p) +#endif + +enum TQtMsgType { TQtDebugMsg, TQtWarningMsg, TQtFatalMsg }; + +typedef void (*TQtMsgHandler)(TQtMsgType, const char *); +TQ_EXPORT TQtMsgHandler qInstallMsgHandler( TQtMsgHandler ); + +#if !defined(TQT_NO_COMPAT) // compatibility with TQt 2 +typedef TQtMsgHandler msg_handler; +#endif // TQT_NO_COMPAT + +TQ_EXPORT void tqSuppressObsoleteWarnings( bool = TRUE ); + +TQ_EXPORT void tqObsolete( const char *obj, const char *oldfunc, + const char *newfunc ); +TQ_EXPORT void tqObsolete( const char *obj, const char *oldfunc ); +TQ_EXPORT void tqObsolete( const char *message ); + + +// +// Install paths from configure +// + +TQ_EXPORT const char *tqInstallPath(); +TQ_EXPORT const char *tqInstallPathDocs(); +TQ_EXPORT const char *tqInstallPathHeaders(); +TQ_EXPORT const char *tqInstallPathLibs(); +TQ_EXPORT const char *tqInstallPathBins(); +TQ_EXPORT const char *tqInstallPathPlugins(); +TQ_EXPORT const char *tqInstallPathData(); +TQ_EXPORT const char *tqInstallPathTranslations(); +TQ_EXPORT const char *tqInstallPathSysconf(); +TQ_EXPORT const char *tqInstallPathShare(); + +#endif /* __cplusplus */ + +/* + compilers which follow outdated template instantiation rules + require a class to have a comparison operator to exist when + a TQValueList of this type is instantiated. It's not actually + used in the list, though. Hence the dummy implementation. + Just in case other code relies on it we better trigger a warning + mandating a real implementation. +*/ +#ifdef TQ_FULL_TEMPLATE_INSTANTIATION +# define TQ_DUMMY_COMPARISON_OPERATOR(C) \ + bool operator==( const C& ) const { \ + tqWarning( #C"::operator==( const "#C"& ) got called." ); \ + return FALSE; \ + } +#else +# define TQ_DUMMY_COMPARISON_OPERATOR(C) +#endif + +#endif /* TQGLOBAL_H */ + +/* + Avoid some particularly useless warnings from some stupid compilers. + To get ALL C++ compiler warnings, define QT_CC_WARNINGS or comment out + the line "#define TQT_NO_WARNINGS" +*/ + +#if !defined(QT_CC_WARNINGS) +# define TQT_NO_WARNINGS +#endif +#if defined(TQT_NO_WARNINGS) +# if defined(Q_CC_MSVC) +# pragma warning(disable: 4244) // 'conversion' conversion from 'type1' to 'type2', possible loss of data +# pragma warning(disable: 4275) // non - DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier' +# pragma warning(disable: 4514) // unreferenced inline/local function has been removed +# pragma warning(disable: 4800) // 'type' : forcing value to bool 'true' or 'false' (performance warning) +# pragma warning(disable: 4097) // typedef-name 'identifier1' used as synonym for class-name 'identifier2' +# pragma warning(disable: 4706) // assignment within conditional expression +# pragma warning(disable: 4786) // truncating debug info after 255 characters +# pragma warning(disable: 4660) // template-class specialization 'identifier' is already instantiated +# pragma warning(disable: 4355) // 'this' : used in base member initializer list +# pragma warning(disable: 4231) // nonstandard extension used : 'extern' before template explicit instantiation +# pragma warning(disable: 4710) // function not inlined +# elif defined(Q_CC_BOR) +# pragma option -w-inl +# pragma option -w-aus +# pragma warn -inl +# pragma warn -pia +# pragma warn -ccc +# pragma warn -rch +# pragma warn -sig +# endif +#endif + diff --git a/src/tools/tqgpluginmanager.cpp b/src/tools/tqgpluginmanager.cpp new file mode 100644 index 000000000..d53e4f5f5 --- /dev/null +++ b/src/tools/tqgpluginmanager.cpp @@ -0,0 +1,552 @@ +/**************************************************************************** +** +** Implementation of TQGPluginManager class +** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqgpluginmanager_p.h" +#ifndef TQT_NO_COMPONENT +#include "qcomlibrary_p.h" +#include "tqmap.h" +#include "tqdir.h" + +/* + The following co-occurrence code is borrowed from TQt Linguist. + + How similar are two texts? The approach used here relies on + co-occurrence matrices and is very efficient. + + Let's see with an example: how similar are "here" and "hither"? The + co-occurrence matrix M for "here" is M[h,e] = 1, M[e,r] = 1, + M[r,e] = 1 and 0 elsewhere; the matrix N for "hither" is N[h,i] = 1, + N[i,t] = 1, ..., N[h,e] = 1, N[e,r] = 1 and 0 elsewhere. The union + U of both matrices is the matrix U[i,j] = max { M[i,j], N[i,j] }, + and the intersection V is V[i,j] = min { M[i,j], N[i,j] }. The score + for a pair of texts is + + score = (sum of V[i,j] over all i, j) / (sum of U[i,j] over all i, j), + + a formula suggested by Arnt Gulbrandsen. Here we have + + score = 2 / 6, + + or one third. + + The implementation differs from this in a few details. Most + importantly, repetitions are ignored; for input "xxx", M[x,x] equals + 1, not 2. +*/ + +/* + Every character is assigned to one of 20 buckets so that the + co-occurrence matrix requires only 20 * 20 = 400 bits, not + 256 * 256 = 65536 bits or even more if we want the whole Unicode. + Which character falls in which bucket is arbitrary. + + The second half of the table is a replica of the first half, because of + laziness. +*/ +static const char indexOf[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +// ! " # $ % & ' ( ) * + , - . / + 0, 2, 6, 7, 10, 12, 15, 19, 2, 6, 7, 10, 12, 15, 19, 0, +// 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + 1, 3, 4, 5, 8, 9, 11, 13, 14, 16, 2, 6, 7, 10, 12, 15, +// @ A B C D E F G H I J K L M N O + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 6, 10, 11, 12, 13, 14, +// P Q R S T U V W X Y Z [ \ ] ^ _ + 15, 12, 16, 17, 18, 19, 2, 10, 15, 7, 19, 2, 6, 7, 10, 0, +// ` a b c d e f g h i j k l m n o + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 6, 10, 11, 12, 13, 14, +// p q r s t u v w x y z { | } ~ + 15, 12, 16, 17, 18, 19, 2, 10, 15, 7, 19, 2, 6, 7, 10, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 2, 6, 7, 10, 12, 15, 19, 2, 6, 7, 10, 12, 15, 19, 0, + 1, 3, 4, 5, 8, 9, 11, 13, 14, 16, 2, 6, 7, 10, 12, 15, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 6, 10, 11, 12, 13, 14, + 15, 12, 16, 17, 18, 19, 2, 10, 15, 7, 19, 2, 6, 7, 10, 0, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 6, 10, 11, 12, 13, 14, + 15, 12, 16, 17, 18, 19, 2, 10, 15, 7, 19, 2, 6, 7, 10, 0 +}; + +/* + The entry bitCount[i] (for i between 0 and 255) is the number of + bits used to represent i in binary. +*/ +static const char bitCount[256] = { + 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, + 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 +}; + +class TQCoMatrix +{ +public: + /* + The matrix has 20 * 20 = 400 entries. This requires 50 bytes, or + 13 words. Some operations are performed on words for more + efficiency. + */ + union { + TQ_UINT8 b[52]; + TQ_UINT32 w[13]; + }; + + TQCoMatrix() { memset( b, 0, 52 ); } + TQCoMatrix( const char *text ) { + char c = '\0', d; + memset( b, 0, 52 ); + while ( (d = *text) != '\0' ) { + setCoocc( c, d ); + if ( (c = *++text) != '\0' ) { + setCoocc( d, c ); + text++; + } + } + } + + void setCoocc( char c, char d ) { + int k = indexOf[(uchar) c] + 20 * indexOf[(uchar) d]; + b[k >> 3] |= k & 0x7; + } + + int worth() const { + int result = 0; + for ( int i = 0; i < 50; i++ ) + result += bitCount[b[i]]; + return result; + } + + static TQCoMatrix reunion( const TQCoMatrix& m, const TQCoMatrix& n ) + { + TQCoMatrix p; + for ( int i = 0; i < 13; i++ ) + p.w[i] = m.w[i] | n.w[i]; + return p; + } + static TQCoMatrix intersection( const TQCoMatrix& m, const TQCoMatrix& n ) + { + TQCoMatrix p; + for ( int i = 0; i < 13; i++ ) + p.w[i] = m.w[i] & n.w[i]; + return p; + } +}; + +/* + Returns an integer between 0 (dissimilar) and 15 (very similar) + depending on how similar the string is to \a target. + + This function is efficient, but its results might change in future + versions of TQt as the algorithm evolves. + + \code + TQString s( "color" ); + a = similarity( s, "color" ); // a == 15 + a = similarity( s, "colour" ); // a == 8 + a = similarity( s, "flavor" ); // a == 4 + a = similarity( s, "dahlia" ); // a == 0 + \endcode +*/ +static int similarity( const TQString& s1, const TQString& s2 ) +{ + TQCoMatrix m1( s1 ); + TQCoMatrix m2( s2 ); + return ( 15 * (TQCoMatrix::intersection(m1, m2).worth() + 1) ) / + ( TQCoMatrix::reunion(m1, m2).worth() + 1 ); +} + +/*! + \class TQPluginManager qpluginmanager.h + \reentrant + \brief The TQPluginManager class provides basic functions to access a certain kind of functionality in libraries. + \ingroup componentmodel + + \internal + + A common usage of components is to extend the existing functionality in an application using plugins. The application + defines interfaces that abstract a certain group of functionality, and a plugin provides a specialized implementation + of one or more of those interfaces. + + The TQPluginManager template has to be instantiated with an interface definition and the IID for this interface. + + \code + TQPluginManager *manager = new TQPluginManager( IID_MyPluginInterface ); + \endcode + + It searches a specified directory for all shared libraries, queries for components that implement the specific interface and + reads information about the features the plugin wants to add to the application. The component can provide the set of features + provided by implementing either the TQFeatureListInterface or the TQComponentInformationInterface. The strings returned by the implementations + of + + \code + TQStringList TQFeatureListInterface::featureList() const + \endcode + + or + + \code + TQString TQComponentInformationInterface::name() const + \endcode + + respectively, can then be used to access the component that provides the requested feature: + + \code + MyPluginInterface *iface; + manager->queryInterface( "feature", &iface ); + if ( iface ) + iface->execute( "feature" ); + \endcode + + The application can use a TQPluginManager instance to create parts of the user interface based on the list of features + found in plugins: + + \code + TQPluginManager *manager = new TQPluginManager( IID_ImageFilterInterface ); + manager->addLibraryPath(...); + + TQStringList features = manager->featureList(); + for ( TQStringList::Iterator it = features.begin(); it != features.end(); ++it ) { + MyPluginInterface *iface; + manager->queryInterface( *it, &iface ); + + // use TQAction to provide toolbuttons and menuitems for each feature... + } + \endcode +*/ + +/*! + \fn TQPluginManager::TQPluginManager( const TQUuid& id, const TQStringList& paths = TQString::null, const TQString &suffix = TQString::null, bool cs = TRUE ) + + Creates an TQPluginManager for interfaces \a id that will load all shared library files in the \a paths + \a suffix. + If \a cs is FALSE the manager will handle feature strings case insensitive. + + \warning + Setting the cs flag to FALSE requires that components also convert to lower case when comparing with passed strings, so this has + to be handled with care and documented very well. + + \sa TQApplication::libraryPaths() +*/ + + +/*! + \fn TQRESULT TQPluginManager::queryInterface(const TQString& feature, Type** iface) const + + Sets \a iface to point to the interface providing \a feature. + + \sa featureList(), library() +*/ + + + +#include + +TQGPluginManager::TQGPluginManager( const TQUuid& id, const TQStringList& paths, const TQString &suffix, bool cs ) + : interfaceId( id ), plugDict( 17, cs ), casesens( cs ), autounload( TRUE ) +{ + // Every TQLibrary object is destroyed on destruction of the manager + libDict.setAutoDelete( TRUE ); + for ( TQStringList::ConstIterator it = paths.begin(); it != paths.end(); ++it ) { + TQString path = *it; + addLibraryPath( path + suffix ); + } +} + +TQGPluginManager::~TQGPluginManager() +{ + if ( !autounload ) { + TQDictIterator it( libDict ); + while ( it.current() ) { + TQLibrary *lib = it.current(); + ++it; + lib->setAutoUnload( FALSE ); + } + } +} + +void TQGPluginManager::addLibraryPath( const TQString& path ) +{ + if ( !enabled() || !TQDir( path ).exists( ".", TRUE ) ) + return; + +#if defined(Q_OS_WIN32) + TQString filter = "*.dll"; +#elif defined(Q_OS_MACX) + TQString filter = "*.dylib; *.so; *.bundle"; +#elif defined(Q_OS_HPUX) + TQString filter = "*.sl"; +#elif defined(Q_OS_OPENBSD) + TQString filter = "*.so; *.so.*"; +#elif defined(Q_OS_UNIX) + TQString filter = "*.so"; +#endif + + TQStringList plugins = TQDir(path).entryList( filter ); + for ( TQStringList::Iterator p = plugins.begin(); p != plugins.end(); ++p ) { + TQString lib = TQDir::cleanDirPath( path + "/" + *p ); + if ( libList.contains( lib ) ) + continue; + libList.append( lib ); + } +} + +const TQLibrary* TQGPluginManager::library( const TQString& feature ) const +{ + if ( !enabled() || feature.isEmpty() ) + return 0; + + // We already have a TQLibrary object for this feature + TQLibrary *library = 0; + if ( ( library = plugDict[feature] ) ) + return library; + + // Find the filename that matches the feature request best + TQMap map; + TQStringList::ConstIterator it = libList.begin(); + int best = 0; + int worst = 15; + while ( it != libList.end() ) { + if ( (*it).isEmpty() || libDict[*it] ) { + ++it; + continue; + } + TQString basename = TQFileInfo(*it).baseName(); + int s = similarity( feature, basename ); + if ( s < worst ) + worst = s; + if ( s > best ) + best = s; + map[s].append( basename + TQChar(0xfffd) + *it ); + ++it; + } + + if ( map.isEmpty() ) + return 0; // no libraries to add + + // Start with the best match to get the library object + TQGPluginManager *that = (TQGPluginManager*)this; + for ( int s = best; s >= worst; --s ) { + TQStringList group = map[s]; + group.sort(); // sort according to the base name + TQStringList::ConstIterator git = group.begin(); + while ( git != group.end() ) { + TQString lib = (*git).mid( (*git).find( TQChar(0xfffd) ) + 1 ); + TQString basename = (*git).left( (*git).find( TQChar(0xfffd) ) ); + ++git; + + TQStringList sameBasename; + while( git != group.end() && + basename == (*git).left( (*git).find( TQChar(0xfffd) ) ) ) { + sameBasename << (*git).mid( (*git).find( TQChar(0xfffd) ) + 1 ); + ++git; + } + + if ( sameBasename.isEmpty() ) { + that->addLibrary( new TQComLibrary( lib ) ); + } else { + TQPtrList same; + same.setAutoDelete( TRUE ); + same.append( new TQComLibrary( lib ) ); + for ( TQStringList::ConstIterator bit = sameBasename.begin(); + bit != sameBasename.end(); ++bit ) + same.append( new TQComLibrary( *bit ) ); + TQComLibrary* bestMatch = 0; + for ( TQComLibrary* candidate = same.first(); candidate; candidate = same.next() ) + if ( candidate->qtVersion() && candidate->qtVersion() <= TQT_VERSION + && ( !bestMatch || candidate->qtVersion() > bestMatch->qtVersion() ) ) + bestMatch = candidate; + if ( bestMatch ) { + same.find( bestMatch ); + that->addLibrary( same.take() ); + } + } + + if ( ( library = that->plugDict[feature] ) ) + return library; + } + } + return 0; +} + +TQStringList TQGPluginManager::featureList() const +{ + TQStringList features; + + if ( !enabled() ) + return features; + + TQGPluginManager *that = (TQGPluginManager*)this; + TQStringList theLibs = libList; + TQStringList phase2Libs; + TQStringList phase2Deny; + + /* In order to get the feature list we need to add all interesting + libraries. If there are libraries with the same base name, we + prioritze the one that fits our TQt version number and ignore the + others */ + TQStringList::Iterator it; + for ( it = theLibs.begin(); it != theLibs.end(); ++it ) { + if ( (*it).isEmpty() || libDict[*it] ) + continue; + TQComLibrary* library = new TQComLibrary( *it ); + if ( library->qtVersion() == TQT_VERSION ) { + that->addLibrary( library ); + phase2Deny << TQFileInfo( *it ).baseName(); + } else { + delete library; + phase2Libs << *it; + } + } + for ( it = phase2Libs.begin(); it != phase2Libs.end(); ++it ) + if ( !phase2Deny.contains( TQFileInfo( *it ).baseName() ) ) + that->addLibrary( new TQComLibrary( *it ) ); + + for ( TQDictIterator pit( plugDict ); pit.current(); ++pit ) + features << pit.currentKey(); + + return features; +} + +bool TQGPluginManager::addLibrary( TQLibrary* lib ) +{ + if ( !enabled() || !lib ) + return FALSE; + + TQComLibrary* plugin = (TQComLibrary*)lib; + bool useful = FALSE; + + TQUnknownInterface* iFace = 0; + plugin->queryInterface( interfaceId, &iFace ); + if ( iFace ) { + TQFeatureListInterface *fliFace = 0; + TQComponentInformationInterface *cpiFace = 0; + iFace->queryInterface( IID_QFeatureList, (TQUnknownInterface**)&fliFace ); + if ( !fliFace ) + plugin->queryInterface( IID_QFeatureList, (TQUnknownInterface**)&fliFace ); + if ( !fliFace ) { + iFace->queryInterface( IID_QComponentInformation, (TQUnknownInterface**)&cpiFace ); + if ( !cpiFace ) + plugin->queryInterface( IID_QComponentInformation, (TQUnknownInterface**)&cpiFace ); + } + TQStringList fl; + if ( fliFace ) + // Map all found features to the library + fl = fliFace->featureList(); + else if ( cpiFace ) + fl << cpiFace->name(); + + for ( TQStringList::Iterator f = fl.begin(); f != fl.end(); ++f ) { + TQLibrary *old = plugDict[*f]; + if ( !old ) { + useful = TRUE; + plugDict.replace( *f, plugin ); + } else { + // we have old *and* plugin, which one to pick? + TQComLibrary* first = (TQComLibrary*)old; + TQComLibrary* second = (TQComLibrary*)plugin; + bool takeFirst = TRUE; + if ( first->qtVersion() != TQT_VERSION ) { + if ( second->qtVersion() == TQT_VERSION ) + takeFirst = FALSE; + else if ( second->qtVersion() < TQT_VERSION && + first->qtVersion() > TQT_VERSION ) + takeFirst = FALSE; + } + if ( !takeFirst ) { + useful = TRUE; + plugDict.replace( *f, plugin ); + tqWarning("%s: Discarding feature %s in %s!", + (const char*) TQFile::encodeName( plugin->library()), + (*f).latin1(), + (const char*) TQFile::encodeName( old->library() ) ); + } else { + tqWarning("%s: Feature %s already defined in %s!", + (const char*) TQFile::encodeName( old->library() ), + (*f).latin1(), + (const char*) TQFile::encodeName( plugin->library() ) ); + } + } + } + if ( fliFace ) + fliFace->release(); + if ( cpiFace ) + cpiFace->release(); + iFace->release(); + } + + if ( useful ) { + libDict.replace( plugin->library(), plugin ); + if ( !libList.contains( plugin->library() ) ) + libList.append( plugin->library() ); + return TRUE; + } + delete plugin; + return FALSE; +} + + +bool TQGPluginManager::enabled() const +{ +#ifdef QT_SHARED + return TRUE; +#else + return FALSE; +#endif +} + +TQRESULT TQGPluginManager::queryUnknownInterface(const TQString& feature, TQUnknownInterface** iface) const +{ + TQComLibrary* plugin = 0; + plugin = (TQComLibrary*)library( feature ); + return plugin ? plugin->queryInterface( interfaceId, (TQUnknownInterface**)iface ) : TQE_NOINTERFACE; +} + +#endif //TQT_NO_COMPONENT diff --git a/src/tools/tqgpluginmanager_p.h b/src/tools/tqgpluginmanager_p.h new file mode 100644 index 000000000..069b7e27a --- /dev/null +++ b/src/tools/tqgpluginmanager_p.h @@ -0,0 +1,110 @@ +/********************************************************************** +** +** Definition of TQGPluginManager class +** +** Copyright (C) 2000-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQGPLUGINMANAGER_P_H +#define TQGPLUGINMANAGER_P_H + +#ifndef QT_H +#include "tqdict.h" +#include "ntqlibrary.h" +#include "ntquuid.h" +#include "tqstringlist.h" +#include "qcom_p.h" +#endif // QT_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. It exists for the convenience +// of a number of TQt sources files. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// +// + +#ifndef TQT_NO_COMPONENT + +#if defined(Q_TEMPLATEDLL) +// MOC_SKIP_BEGIN +//Q_TEMPLATE_EXTERN template class TQ_EXPORT TQDict; +// MOC_SKIP_END +#endif + +class TQ_EXPORT TQGPluginManager +{ +public: + TQGPluginManager( const TQUuid& id, const TQStringList& paths = TQString::null, const TQString &suffix = TQString::null, bool cs = TRUE ); + ~TQGPluginManager(); + + void addLibraryPath( const TQString& path ); + const TQLibrary* library( const TQString& feature ) const; + TQStringList featureList() const; + + bool autoUnload() const; + void setAutoUnload( bool ); + +protected: + bool enabled() const; + bool addLibrary( TQLibrary* plugin ); + + TQRESULT queryUnknownInterface(const TQString& feature, TQUnknownInterface** iface) const; + + TQUuid interfaceId; + TQDict plugDict; // Dict to match feature with library + TQDict libDict; // Dict to match library file with library + TQStringList libList; + + uint casesens : 1; + uint autounload : 1; +}; + +inline void TQGPluginManager::setAutoUnload( bool unload ) +{ + autounload = unload; +} + +inline bool TQGPluginManager::autoUnload() const +{ + return autounload; +} + +#endif + +#endif //TQGPLUGINMANAGER_P_H diff --git a/src/tools/tqgvector.cpp b/src/tools/tqgvector.cpp new file mode 100644 index 000000000..001b777a4 --- /dev/null +++ b/src/tools/tqgvector.cpp @@ -0,0 +1,598 @@ +/**************************************************************************** +** +** Implementation of TQGVector class +** +** Created : 930907 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqglobal.h" +#if defined(Q_CC_BOR) +// needed for qsort() because of a std namespace problem on Borland +#include "qplatformdefs.h" +#endif + +#define TQGVECTOR_CPP +#include "tqgvector.h" +#include "tqglist.h" +#include "tqstring.h" +#include "tqdatastream.h" +#include + +#ifdef TQT_THREAD_SUPPORT +# include +#endif // TQT_THREAD_SUPPORT + +#define USE_MALLOC // comment to use new/delete + +#undef NEW +#undef DELETE + +#if defined(USE_MALLOC) +#define NEW(type,size) ((type*)malloc(size*sizeof(type))) +#define DELETE(array) (free((char*)array)) +#else +#define NEW(type,size) (new type[size]) +#define DELETE(array) (delete[] array) +#define DONT_USE_REALLOC // comment to use realloc() +#endif + +/*! + \class TQGVector + \reentrant + \ingroup collection + + \brief The TQGVector class is an internal class for implementing TQt + collection classes. + + \internal + + TQGVector is an internal class that acts as a base class for the + TQPtrVector collection class. + + TQGVector has some virtual functions that may be reimplemented in + subclasses to customize behavior. + + \list + \i compareItems() compares two collection/vector items. + \i read() reads a collection/vector item from a TQDataStream. + \i write() writes a collection/vector item to a TQDataStream. + \endlist +*/ + +/***************************************************************************** + Default implementation of virtual functions + *****************************************************************************/ + +/*! + This virtual function compares two list items. + + Returns: +
    +
  • 0 if \a d1 == \a d2 +
  • non-zero if \a d1 != \a d2 +
+ + This function returns \e int rather than \e bool so that + reimplementations can return one of three values and use it to sort + by: +
    +
  • 0 if \a d1 == \a d2 +
  • \> 0 (positive integer) if \a d1 \> \a d2 +
  • \< 0 (negative integer) if \a d1 \< \a d2 +
+ + The TQPtrVector::sort() and TQPtrVector::bsearch() functions require that + compareItems() is implemented as described here. + + This function should not modify the vector because some const + functions call compareItems(). +*/ + +int TQGVector::compareItems( Item d1, Item d2 ) +{ + return d1 != d2; // compare pointers +} + +#ifndef TQT_NO_DATASTREAM +/*! + Reads a collection/vector item from the stream \a s and returns a reference + to the stream. + + The default implementation sets \a d to 0. + + \sa write() +*/ + +TQDataStream &TQGVector::read( TQDataStream &s, Item &d ) +{ // read item from stream + d = 0; + return s; +} + +/*! + Writes a collection/vector item to the stream \a s and returns a reference + to the stream. + + The default implementation does nothing. + + \sa read() +*/ + +TQDataStream &TQGVector::write( TQDataStream &s, Item ) const +{ // write item to stream + return s; +} +#endif // TQT_NO_DATASTREAM + +/***************************************************************************** + TQGVector member functions + *****************************************************************************/ + +TQGVector::TQGVector() // create empty vector +{ + vec = 0; + len = numItems = 0; +} + +TQGVector::TQGVector( uint size ) // create vectors with nullptrs +{ + len = size; + numItems = 0; + if ( len == 0 ) { // zero length + vec = 0; + return; + } + vec = NEW(Item,len); + TQ_CHECK_PTR( vec ); + memset( (void*)vec, 0, len*sizeof(Item) ); // fill with nulls +} + +TQGVector::TQGVector( const TQGVector &a ) // make copy of other vector + : TQPtrCollection( a ) +{ + len = a.len; + numItems = a.numItems; + if ( len == 0 ) { + vec = 0; + return; + } + vec = NEW( Item, len ); + TQ_CHECK_PTR( vec ); + for ( uint i = 0; i < len; i++ ) { + if ( a.vec[i] ) { + vec[i] = newItem( a.vec[i] ); + TQ_CHECK_PTR( vec[i] ); + } else { + vec[i] = 0; + } + } +} + +TQGVector::~TQGVector() +{ + clear(); +} + +TQGVector& TQGVector::operator=( const TQGVector &v ) +{ + if ( &v == this ) + return *this; + + clear(); + len = v.len; + numItems = v.numItems; + if ( len == 0 ) { + vec = 0; + return *this; + } + vec = NEW( Item, len ); + TQ_CHECK_PTR( vec ); + for ( uint i = 0; i < len; i++ ) { + if ( v.vec[i] ) { + vec[i] = newItem( v.vec[i] ); + TQ_CHECK_PTR( vec[i] ); + } else { + vec[i] = 0; + } + } + return *this; +} + + +bool TQGVector::insert( uint index, Item d ) // insert item at index +{ +#if defined(QT_CHECK_RANGE) + if ( index >= len ) { // range error + tqWarning( "TQGVector::insert: Index %d out of range", index ); + return FALSE; + } +#endif + if ( vec[index] ) { // remove old item + deleteItem( vec[index] ); + numItems--; + } + if ( d ) { + vec[index] = newItem( d ); + TQ_CHECK_PTR( vec[index] ); + numItems++; + return vec[index] != 0; + } else { + vec[index] = 0; // reset item + } + return TRUE; +} + +bool TQGVector::remove( uint index ) // remove item at index +{ +#if defined(QT_CHECK_RANGE) + if ( index >= len ) { // range error + tqWarning( "TQGVector::remove: Index %d out of range", index ); + return FALSE; + } +#endif + if ( vec[index] ) { // valid item + deleteItem( vec[index] ); // delete it + vec[index] = 0; // reset pointer + numItems--; + } + return TRUE; +} + +TQPtrCollection::Item TQGVector::take( uint index ) // take out item +{ +#if defined(QT_CHECK_RANGE) + if ( index >= len ) { // range error + tqWarning( "TQGVector::take: Index %d out of range", index ); + return 0; + } +#endif + Item d = vec[index]; // don't delete item + if ( d ) + numItems--; + vec[index] = 0; + return d; +} + +void TQGVector::clear() // clear vector +{ + if ( vec ) { + for ( uint i=0; i len ) // init extra space added + memset( (void*)&vec[len], 0, (newsize-len)*sizeof(Item) ); + len = newsize; + return TRUE; +} + + +bool TQGVector::fill( Item d, int flen ) // resize and fill vector +{ + if ( flen < 0 ) + flen = len; // default: use vector length + else if ( !resize( flen ) ) + return FALSE; + for ( uint i=0; i<(uint)flen; i++ ) // insert d at every index + insert( i, d ); + return TRUE; +} + + +static TQGVector *sort_vec=0; // current sort vector + + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif + +#ifdef Q_OS_TEMP +static int _cdecl cmp_vec( const void *n1, const void *n2 ) +#else +static int cmp_vec( const void *n1, const void *n2 ) +#endif +{ + return sort_vec->compareItems( *((TQPtrCollection::Item*)n1), *((TQPtrCollection::Item*)n2) ); +} + +#if defined(Q_C_CALLBACKS) +} +#endif + + +void TQGVector::sort() // sort vector +{ + if ( count() == 0 ) // no elements + return; + Item *start = &vec[0]; + Item *end = &vec[len-1]; + Item tmp; + for (;;) { // put all zero elements behind + while ( start < end && *start != 0 ) + start++; + while ( end > start && *end == 0 ) + end--; + if ( start < end ) { + tmp = *start; + *start = *end; + *end = tmp; + } else { + break; + } + } + +#ifdef TQT_THREAD_SUPPORT + TQMutexLocker locker( tqt_global_mutexpool ? + tqt_global_mutexpool->get( &sort_vec ) : 0 ); +#endif // TQT_THREAD_SUPPORT + + sort_vec = (TQGVector*)this; + qsort( vec, count(), sizeof(Item), cmp_vec ); + sort_vec = 0; +} + +int TQGVector::bsearch( Item d ) const // binary search; when sorted +{ + if ( !len ) + return -1; + if ( !d ) { +#if defined(QT_CHECK_NULL) + tqWarning( "TQGVector::bsearch: Cannot search for null object" ); +#endif + return -1; + } + int n1 = 0; + int n2 = len - 1; + int mid = 0; + bool found = FALSE; + while ( n1 <= n2 ) { + int res; + mid = (n1 + n2)/2; + if ( vec[mid] == 0 ) // null item greater + res = -1; + else + res = ((TQGVector*)this)->compareItems( d, vec[mid] ); + if ( res < 0 ) + n2 = mid - 1; + else if ( res > 0 ) + n1 = mid + 1; + else { // found it + found = TRUE; + break; + } + } + if ( !found ) + return -1; + // search to first of equal items + while ( (mid - 1 >= 0) && !((TQGVector*)this)->compareItems(d, vec[mid-1]) ) + mid--; + return mid; +} + +int TQGVector::findRef( Item d, uint index) const // find exact item in vector +{ +#if defined(QT_CHECK_RANGE) + if ( index > len ) { // range error + tqWarning( "TQGVector::findRef: Index %d out of range", index ); + return -1; + } +#endif + for ( uint i=index; i= len ) { // range error + tqWarning( "TQGVector::find: Index %d out of range", index ); + return -1; + } +#endif + for ( uint i=index; icompareItems( vec[i], d ) == 0 ) + return i; + } + return -1; +} + +uint TQGVector::containsRef( Item d ) const // get number of exact matches +{ + uint count = 0; + for ( uint i=0; icompareItems( vec[i], d ) == 0 ) + count++; + } + return count; +} + +bool TQGVector::insertExpand( uint index, Item d )// insert and grow if necessary +{ + if ( index >= len ) { + if ( !resize( index+1 ) ) // no memory + return FALSE; + } + insert( index, d ); + return TRUE; +} + +void TQGVector::toList( TQGList *list ) const // store items in list +{ + list->clear(); + for ( uint i=0; iappend( vec[i] ); + } +} + + +void TQGVector::warningIndexRange( uint i ) +{ +#if defined(QT_CHECK_RANGE) + tqWarning( "TQGVector::operator[]: Index %d out of range", i ); +#else + Q_UNUSED( i ) +#endif +} + + +/***************************************************************************** + TQGVector stream functions + *****************************************************************************/ +#ifndef TQT_NO_DATASTREAM +TQDataStream &operator>>( TQDataStream &s, TQGVector &vec ) +{ // read vector + return vec.read( s ); +} + +TQDataStream &operator<<( TQDataStream &s, const TQGVector &vec ) +{ // write vector + return vec.write( s ); +} + +TQDataStream &TQGVector::read( TQDataStream &s ) // read vector from stream +{ + uint num; + s >> num; // read number of items + clear(); // clear vector + resize( num ); + for (uint i=0; icompareItems( at( i ), v.at( i ) ) != 0 ) + return FALSE; + } + return TRUE; +} + +#endif // TQT_NO_DATASTREAM diff --git a/src/tools/tqgvector.h b/src/tools/tqgvector.h new file mode 100644 index 000000000..d1e8385df --- /dev/null +++ b/src/tools/tqgvector.h @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Definition of TQGVector class +** +** Created : 930907 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the tools module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQGVECTOR_H +#define TQGVECTOR_H + +#ifndef QT_H +#include "tqptrcollection.h" +#endif // QT_H + + +class TQ_EXPORT TQGVector : public TQPtrCollection // generic vector +{ +friend class TQGList; // needed by TQGList::toVector +public: +#ifndef TQT_NO_DATASTREAM + TQDataStream &read( TQDataStream & ); // read vector from stream + TQDataStream &write( TQDataStream & ) const; // write vector to stream +#endif + virtual int compareItems( Item, Item ); + +protected: + TQGVector(); // create empty vector + TQGVector( uint size ); // create vector with nullptrs + TQGVector( const TQGVector &v ); // make copy of other vector + ~TQGVector(); + + TQGVector &operator=( const TQGVector &v ); // assign from other vector + bool operator==( const TQGVector &v ) const; + + Item *data() const { return vec; } + uint size() const { return len; } + uint count() const { return numItems; } + + bool insert( uint index, Item ); // insert item at index + bool remove( uint index ); // remove item + Item take( uint index ); // take out item + + void clear(); // clear vector + bool resize( uint newsize ); // resize vector + + bool fill( Item, int flen ); // resize and fill vector + + void sort(); // sort vector + int bsearch( Item ) const; // binary search (when sorted) + + int findRef( Item, uint index ) const; // find exact item in vector + int find( Item, uint index ) const; // find equal item in vector + uint containsRef( Item ) const; // get number of exact matches + uint contains( Item ) const; // get number of equal matches + + Item at( uint index ) const // return indexed item + { +#if defined(QT_CHECK_RANGE) + if ( index >= len ) + warningIndexRange( index ); +#endif + return vec[index]; + } + + bool insertExpand( uint index, Item ); // insert, expand if necessary + + void toList( TQGList * ) const; // put items in list + +#ifndef TQT_NO_DATASTREAM + virtual TQDataStream &read( TQDataStream &, Item & ); + virtual TQDataStream &write( TQDataStream &, Item ) const; +#endif +private: + Item *vec; + uint len; + uint numItems; + + static void warningIndexRange( uint ); +}; + + +/***************************************************************************** + TQGVector stream functions + *****************************************************************************/ + +#ifndef TQT_NO_DATASTREAM +TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQGVector & ); +TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQGVector & ); +#endif + +#endif // TQGVECTOR_H diff --git a/src/tools/tqintcache.h b/src/tools/tqintcache.h index 116618058..7a22d1cd5 100644 --- a/src/tools/tqintcache.h +++ b/src/tools/tqintcache.h @@ -42,7 +42,7 @@ #define TQINTCACHE_H #ifndef QT_H -#include "ntqgcache.h" +#include "tqgcache.h" #endif // QT_H diff --git a/src/tools/tqintdict.h b/src/tools/tqintdict.h index 162625855..4c20aa486 100644 --- a/src/tools/tqintdict.h +++ b/src/tools/tqintdict.h @@ -42,7 +42,7 @@ #define TQINTDICT_H #ifndef QT_H -#include "ntqgdict.h" +#include "tqgdict.h" #endif // QT_H template diff --git a/src/tools/tqiodevice.h b/src/tools/tqiodevice.h index 712288d8e..d7cb31fae 100644 --- a/src/tools/tqiodevice.h +++ b/src/tools/tqiodevice.h @@ -42,7 +42,7 @@ #define TQIODEVICE_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #include "tqcstring.h" #endif // QT_H diff --git a/src/tools/tqmap.h b/src/tools/tqmap.h index a173e7575..6a813dd6c 100644 --- a/src/tools/tqmap.h +++ b/src/tools/tqmap.h @@ -42,7 +42,7 @@ #define TQMAP_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #include "ntqshared.h" #include "tqdatastream.h" #include "tqpair.h" diff --git a/src/tools/tqmemarray.h b/src/tools/tqmemarray.h index 8a07bf9a9..1ea8c2ad5 100644 --- a/src/tools/tqmemarray.h +++ b/src/tools/tqmemarray.h @@ -42,7 +42,7 @@ #define TQMEMARRAY_H #ifndef QT_H -#include "ntqgarray.h" +#include "tqgarray.h" #endif // QT_H diff --git a/src/tools/tqmutex.h b/src/tools/tqmutex.h index c517c6355..8009d672d 100644 --- a/src/tools/tqmutex.h +++ b/src/tools/tqmutex.h @@ -42,7 +42,7 @@ #define TQMUTEX_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H #if defined(TQT_THREAD_SUPPORT) diff --git a/src/tools/tqpair.h b/src/tools/tqpair.h index 5b197d8d4..8d487e38b 100644 --- a/src/tools/tqpair.h +++ b/src/tools/tqpair.h @@ -41,7 +41,7 @@ #define TQPAIR_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #include "tqdatastream.h" #endif // QT_H diff --git a/src/tools/tqptrcollection.h b/src/tools/tqptrcollection.h index da6fc6670..424512627 100644 --- a/src/tools/tqptrcollection.h +++ b/src/tools/tqptrcollection.h @@ -41,7 +41,7 @@ #define TQPTRCOLLECTION_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H diff --git a/src/tools/tqptrdict.h b/src/tools/tqptrdict.h index 181492bd9..c14c132c1 100644 --- a/src/tools/tqptrdict.h +++ b/src/tools/tqptrdict.h @@ -42,7 +42,7 @@ #define TQPTRDICT_H #ifndef QT_H -#include "ntqgdict.h" +#include "tqgdict.h" #endif // QT_H template diff --git a/src/tools/tqptrlist.h b/src/tools/tqptrlist.h index 579c1b226..0fbea042b 100644 --- a/src/tools/tqptrlist.h +++ b/src/tools/tqptrlist.h @@ -40,7 +40,7 @@ #define TQPTRLIST_H #ifndef QT_H -#include "ntqglist.h" +#include "tqglist.h" #endif // QT_H template diff --git a/src/tools/tqptrqueue.h b/src/tools/tqptrqueue.h index c905b4fd6..2cebf08f8 100644 --- a/src/tools/tqptrqueue.h +++ b/src/tools/tqptrqueue.h @@ -42,7 +42,7 @@ #define TQPTRQUEUE_H #ifndef QT_H -#include "ntqglist.h" +#include "tqglist.h" #endif // QT_H template diff --git a/src/tools/tqptrstack.h b/src/tools/tqptrstack.h index 6f404f1b9..229f03ef9 100644 --- a/src/tools/tqptrstack.h +++ b/src/tools/tqptrstack.h @@ -42,7 +42,7 @@ #define TQPTRSTACK_H #ifndef QT_H -#include "ntqglist.h" +#include "tqglist.h" #endif // QT_H template diff --git a/src/tools/tqptrvector.h b/src/tools/tqptrvector.h index b2e641e7a..764b5732d 100644 --- a/src/tools/tqptrvector.h +++ b/src/tools/tqptrvector.h @@ -42,7 +42,7 @@ #define TQPTRVECTOR_H #ifndef QT_H -#include "ntqgvector.h" +#include "tqgvector.h" #endif // QT_H template diff --git a/src/tools/tqsemaphore.h b/src/tools/tqsemaphore.h index 0dc8e81de..0524fcc67 100644 --- a/src/tools/tqsemaphore.h +++ b/src/tools/tqsemaphore.h @@ -42,7 +42,7 @@ #define TQSEMAPHORE_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H #if defined(TQT_THREAD_SUPPORT) diff --git a/src/tools/tqthreadstorage.h b/src/tools/tqthreadstorage.h index 588621237..42319ccd6 100644 --- a/src/tools/tqthreadstorage.h +++ b/src/tools/tqthreadstorage.h @@ -42,7 +42,7 @@ #ifdef TQT_THREAD_SUPPORT #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H class TQ_EXPORT TQThreadStorageData diff --git a/src/tools/tqwaitcondition.h b/src/tools/tqwaitcondition.h index 503d5d6c9..4ce262134 100644 --- a/src/tools/tqwaitcondition.h +++ b/src/tools/tqwaitcondition.h @@ -42,7 +42,7 @@ #define TQWAITCONDITION_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #endif // QT_H #if defined(TQT_THREAD_SUPPORT) diff --git a/src/widgets/ntqdockarea.h b/src/widgets/ntqdockarea.h index 10a62debd..9ccdc21d8 100644 --- a/src/widgets/ntqdockarea.h +++ b/src/widgets/ntqdockarea.h @@ -47,7 +47,7 @@ #include "ntqdockwindow.h" #include "tqlayout.h" #include "tqvaluelist.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "tqtextstream.h" #endif // QT_H diff --git a/src/widgets/ntqrangecontrol.h b/src/widgets/ntqrangecontrol.h index 0afb75ed8..39f2e2abc 100644 --- a/src/widgets/ntqrangecontrol.h +++ b/src/widgets/ntqrangecontrol.h @@ -42,7 +42,7 @@ #define TQRANGECONTROL_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #include "tqframe.h" #endif // QT_H diff --git a/src/widgets/qdockwindow.cpp b/src/widgets/qdockwindow.cpp index 1c056828e..bfe89fcda 100644 --- a/src/widgets/qdockwindow.cpp +++ b/src/widgets/qdockwindow.cpp @@ -53,7 +53,7 @@ #include "tqmainwindow.h" #include "tqtimer.h" #include "tqtooltip.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "ntqcursor.h" #include "tqstyle.h" diff --git a/src/widgets/qeffects.cpp b/src/widgets/qeffects.cpp index b98de479f..5fce0e854 100644 --- a/src/widgets/qeffects.cpp +++ b/src/widgets/qeffects.cpp @@ -46,7 +46,7 @@ #include "tqimage.h" #include "tqtimer.h" #include "tqdatetime.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "tqscrollview.h" /* diff --git a/src/widgets/qrangecontrol.cpp b/src/widgets/qrangecontrol.cpp index 2aa8f86c6..95056e578 100644 --- a/src/widgets/qrangecontrol.cpp +++ b/src/widgets/qrangecontrol.cpp @@ -40,7 +40,7 @@ #include "ntqrangecontrol.h" #ifndef TQT_NO_RANGECONTROL -#include "ntqglobal.h" +#include "tqglobal.h" #include static bool sumOutOfRange(int current, int add); diff --git a/src/widgets/tqbutton.cpp b/src/widgets/tqbutton.cpp index e29ae1546..d44c5baa0 100644 --- a/src/widgets/tqbutton.cpp +++ b/src/widgets/tqbutton.cpp @@ -49,7 +49,7 @@ #include "ntqapplication.h" #include "tqpushbutton.h" #include "tqradiobutton.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "../kernel/qinternal_p.h" #if defined(QT_ACCESSIBILITY_SUPPORT) diff --git a/src/widgets/tqdialogbuttons.cpp b/src/widgets/tqdialogbuttons.cpp index 939384281..cbc791ebb 100644 --- a/src/widgets/tqdialogbuttons.cpp +++ b/src/widgets/tqdialogbuttons.cpp @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include #ifndef TQT_NO_DIALOG diff --git a/src/widgets/tqiconview.cpp b/src/widgets/tqiconview.cpp index 70462bc05..e897ccc42 100644 --- a/src/widgets/tqiconview.cpp +++ b/src/widgets/tqiconview.cpp @@ -38,7 +38,7 @@ ** **********************************************************************/ -#include "ntqglobal.h" +#include "tqglobal.h" #if defined(Q_CC_BOR) // needed for qsort() because of a std namespace problem on Borland #include "qplatformdefs.h" diff --git a/src/widgets/tqlineedit.cpp b/src/widgets/tqlineedit.cpp index 558069752..b781b4814 100644 --- a/src/widgets/tqlineedit.cpp +++ b/src/widgets/tqlineedit.cpp @@ -57,7 +57,7 @@ #include "tqtimer.h" #include "tqpopupmenu.h" #include "tqstringlist.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "tqstyle.h" #include "tqwhatsthis.h" #include "../kernel/qinternal_p.h" diff --git a/src/widgets/tqlistbox.cpp b/src/widgets/tqlistbox.cpp index 96aa747c1..fcda9ac5f 100644 --- a/src/widgets/tqlistbox.cpp +++ b/src/widgets/tqlistbox.cpp @@ -38,7 +38,7 @@ ** **********************************************************************/ -#include "ntqglobal.h" +#include "tqglobal.h" #if defined(Q_CC_BOR) // needed for qsort() because of a std namespace problem on Borland #include "qplatformdefs.h" @@ -57,7 +57,7 @@ #include "tqstringlist.h" #include "tqstyle.h" #include "tqpopupmenu.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #if defined(QT_ACCESSIBILITY_SUPPORT) #include "ntqaccessible.h" #endif diff --git a/src/widgets/tqmenubar.cpp b/src/widgets/tqmenubar.cpp index b288f6280..6432d432b 100644 --- a/src/widgets/tqmenubar.cpp +++ b/src/widgets/tqmenubar.cpp @@ -49,7 +49,7 @@ #include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqapplication.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "tqlayout.h" #include "ntqcleanuphandler.h" #include "../kernel/qinternal_p.h" diff --git a/src/widgets/tqmenudata.cpp b/src/widgets/tqmenudata.cpp index c3e773e24..5a3872d31 100644 --- a/src/widgets/tqmenudata.cpp +++ b/src/widgets/tqmenudata.cpp @@ -43,7 +43,7 @@ #include "tqpopupmenu.h" #include "tqmenubar.h" #include "ntqapplication.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" class TQMenuItemData { public: diff --git a/src/widgets/tqmenudata.h b/src/widgets/tqmenudata.h index 5abace6a2..b5e92cb6a 100644 --- a/src/widgets/tqmenudata.h +++ b/src/widgets/tqmenudata.h @@ -42,7 +42,7 @@ #define TQMENUDATA_H #ifndef QT_H -#include "ntqglobal.h" +#include "tqglobal.h" #include "tqiconset.h" // conversion TQPixmap->TQIconset #include "ntqkeysequence.h" #include "tqstring.h" diff --git a/src/widgets/tqpopupmenu.cpp b/src/widgets/tqpopupmenu.cpp index 26aa7f9cc..8030b23e8 100644 --- a/src/widgets/tqpopupmenu.cpp +++ b/src/widgets/tqpopupmenu.cpp @@ -50,7 +50,7 @@ #include "tqtimer.h" #include "tqwhatsthis.h" #include "tqobjectlist.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "qeffects_p.h" #include "ntqcursor.h" #include "tqstyle.h" diff --git a/src/widgets/tqpushbutton.cpp b/src/widgets/tqpushbutton.cpp index 105bae12a..2b329e9d7 100644 --- a/src/widgets/tqpushbutton.cpp +++ b/src/widgets/tqpushbutton.cpp @@ -47,7 +47,7 @@ #include "tqpixmap.h" #include "tqbitmap.h" #include "tqpopupmenu.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "ntqapplication.h" #include "tqtoolbar.h" #include "tqstyle.h" diff --git a/src/widgets/tqtextedit.cpp b/src/widgets/tqtextedit.cpp index d57724ab3..1d5805f6d 100644 --- a/src/widgets/tqtextedit.cpp +++ b/src/widgets/tqtextedit.cpp @@ -76,7 +76,7 @@ #include "tqtextbrowser.h" #include #include "private/tqsyntaxhighlighter_p.h" -#include +#include #ifndef TQT_NO_ACCEL #include diff --git a/src/widgets/tqtoolbutton.cpp b/src/widgets/tqtoolbutton.cpp index 9872936e1..53d4b971f 100644 --- a/src/widgets/tqtoolbutton.cpp +++ b/src/widgets/tqtoolbutton.cpp @@ -54,7 +54,7 @@ #include "tqiconset.h" #include "tqtimer.h" #include "tqpopupmenu.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" class TQToolButtonPrivate { diff --git a/src/widgets/tqtooltip.cpp b/src/widgets/tqtooltip.cpp index 7a9166452..ee0a097fe 100644 --- a/src/widgets/tqtooltip.cpp +++ b/src/widgets/tqtooltip.cpp @@ -41,7 +41,7 @@ #include "tqlabel.h" #include "tqptrdict.h" #include "ntqapplication.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "tqtimer.h" #include "qeffects_p.h" diff --git a/src/widgets/tqwidgetplugin.h b/src/widgets/tqwidgetplugin.h index d1cf9b257..68b26b4f7 100644 --- a/src/widgets/tqwidgetplugin.h +++ b/src/widgets/tqwidgetplugin.h @@ -42,7 +42,7 @@ #define TQWIDGETPLUGIN_H #ifndef QT_H -#include "ntqgplugin.h" +#include "tqgplugin.h" #include "tqstringlist.h" #include "tqiconset.h" #endif // QT_H diff --git a/src/workspace/tqworkspace.cpp b/src/workspace/tqworkspace.cpp index 62b8e2732..48973398a 100644 --- a/src/workspace/tqworkspace.cpp +++ b/src/workspace/tqworkspace.cpp @@ -51,7 +51,7 @@ #include "ntqcursor.h" #include "tqpopupmenu.h" #include "tqmenubar.h" -#include "ntqguardedptr.h" +#include "tqguardedptr.h" #include "tqiconset.h" #include "../widgets/tqwidgetresizehandler_p.h" #include "ntqfocusdata.h" -- cgit v1.2.1