From 47d455dd55be855e4cc691c32f687f723d9247ee Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kviewshell/plugins/djvu/libdjvu/Arrays.cpp | 305 +++ kviewshell/plugins/djvu/libdjvu/Arrays.h | 997 +++++++ kviewshell/plugins/djvu/libdjvu/BSByteStream.cpp | 465 ++++ kviewshell/plugins/djvu/libdjvu/BSByteStream.h | 275 ++ .../plugins/djvu/libdjvu/BSEncodeByteStream.cpp | 1010 +++++++ kviewshell/plugins/djvu/libdjvu/ByteStream.cpp | 1445 ++++++++++ kviewshell/plugins/djvu/libdjvu/ByteStream.h | 416 +++ kviewshell/plugins/djvu/libdjvu/DataPool.cpp | 1837 +++++++++++++ kviewshell/plugins/djvu/libdjvu/DataPool.h | 627 +++++ kviewshell/plugins/djvu/libdjvu/DjVmDir.cpp | 839 ++++++ kviewshell/plugins/djvu/libdjvu/DjVmDir.h | 451 ++++ kviewshell/plugins/djvu/libdjvu/DjVmDir0.cpp | 169 ++ kviewshell/plugins/djvu/libdjvu/DjVmDir0.h | 217 ++ kviewshell/plugins/djvu/libdjvu/DjVmDoc.cpp | 663 +++++ kviewshell/plugins/djvu/libdjvu/DjVmDoc.h | 274 ++ kviewshell/plugins/djvu/libdjvu/DjVmNav.cpp | 338 +++ kviewshell/plugins/djvu/libdjvu/DjVmNav.h | 146 + kviewshell/plugins/djvu/libdjvu/DjVuAnno.cpp | 1514 +++++++++++ kviewshell/plugins/djvu/libdjvu/DjVuAnno.h | 295 ++ kviewshell/plugins/djvu/libdjvu/DjVuDocEditor.cpp | 2193 +++++++++++++++ kviewshell/plugins/djvu/libdjvu/DjVuDocEditor.h | 460 ++++ kviewshell/plugins/djvu/libdjvu/DjVuDocument.cpp | 1845 +++++++++++++ kviewshell/plugins/djvu/libdjvu/DjVuDocument.h | 1071 ++++++++ kviewshell/plugins/djvu/libdjvu/DjVuDumpHelper.cpp | 353 +++ kviewshell/plugins/djvu/libdjvu/DjVuDumpHelper.h | 126 + kviewshell/plugins/djvu/libdjvu/DjVuErrorList.cpp | 174 ++ kviewshell/plugins/djvu/libdjvu/DjVuErrorList.h | 194 ++ kviewshell/plugins/djvu/libdjvu/DjVuFile.cpp | 2831 ++++++++++++++++++++ kviewshell/plugins/djvu/libdjvu/DjVuFile.h | 848 ++++++ kviewshell/plugins/djvu/libdjvu/DjVuFileCache.cpp | 272 ++ kviewshell/plugins/djvu/libdjvu/DjVuFileCache.h | 292 ++ kviewshell/plugins/djvu/libdjvu/DjVuGlobal.cpp | 255 ++ kviewshell/plugins/djvu/libdjvu/DjVuGlobal.h | 398 +++ .../plugins/djvu/libdjvu/DjVuGlobalMemory.cpp | 306 +++ kviewshell/plugins/djvu/libdjvu/DjVuImage.cpp | 1486 ++++++++++ kviewshell/plugins/djvu/libdjvu/DjVuImage.h | 449 ++++ kviewshell/plugins/djvu/libdjvu/DjVuInfo.cpp | 205 ++ kviewshell/plugins/djvu/libdjvu/DjVuInfo.h | 193 ++ kviewshell/plugins/djvu/libdjvu/DjVuMessage.cpp | 647 +++++ kviewshell/plugins/djvu/libdjvu/DjVuMessage.h | 135 + .../plugins/djvu/libdjvu/DjVuMessageLite.cpp | 478 ++++ kviewshell/plugins/djvu/libdjvu/DjVuMessageLite.h | 227 ++ kviewshell/plugins/djvu/libdjvu/DjVuNavDir.cpp | 237 ++ kviewshell/plugins/djvu/libdjvu/DjVuNavDir.h | 192 ++ kviewshell/plugins/djvu/libdjvu/DjVuPalette.cpp | 590 ++++ kviewshell/plugins/djvu/libdjvu/DjVuPalette.h | 339 +++ kviewshell/plugins/djvu/libdjvu/DjVuPort.cpp | 710 +++++ kviewshell/plugins/djvu/libdjvu/DjVuPort.h | 518 ++++ kviewshell/plugins/djvu/libdjvu/DjVuText.cpp | 971 +++++++ kviewshell/plugins/djvu/libdjvu/DjVuText.h | 281 ++ kviewshell/plugins/djvu/libdjvu/DjVuToPS.cpp | 2582 ++++++++++++++++++ kviewshell/plugins/djvu/libdjvu/DjVuToPS.h | 425 +++ kviewshell/plugins/djvu/libdjvu/GBitmap.cpp | 1658 ++++++++++++ kviewshell/plugins/djvu/libdjvu/GBitmap.h | 673 +++++ kviewshell/plugins/djvu/libdjvu/GContainer.cpp | 802 ++++++ kviewshell/plugins/djvu/libdjvu/GContainer.h | 1366 ++++++++++ kviewshell/plugins/djvu/libdjvu/GException.cpp | 284 ++ kviewshell/plugins/djvu/libdjvu/GException.h | 356 +++ kviewshell/plugins/djvu/libdjvu/GIFFManager.cpp | 663 +++++ kviewshell/plugins/djvu/libdjvu/GIFFManager.h | 394 +++ kviewshell/plugins/djvu/libdjvu/GMapAreas.cpp | 1066 ++++++++ kviewshell/plugins/djvu/libdjvu/GMapAreas.h | 565 ++++ kviewshell/plugins/djvu/libdjvu/GOS.cpp | 370 +++ kviewshell/plugins/djvu/libdjvu/GOS.h | 161 ++ kviewshell/plugins/djvu/libdjvu/GPixmap.cpp | 1676 ++++++++++++ kviewshell/plugins/djvu/libdjvu/GPixmap.h | 531 ++++ kviewshell/plugins/djvu/libdjvu/GRect.cpp | 458 ++++ kviewshell/plugins/djvu/libdjvu/GRect.h | 407 +++ kviewshell/plugins/djvu/libdjvu/GScaler.cpp | 706 +++++ kviewshell/plugins/djvu/libdjvu/GScaler.h | 321 +++ kviewshell/plugins/djvu/libdjvu/GSmartPointer.cpp | 256 ++ kviewshell/plugins/djvu/libdjvu/GSmartPointer.h | 489 ++++ kviewshell/plugins/djvu/libdjvu/GString.cpp | 2811 +++++++++++++++++++ kviewshell/plugins/djvu/libdjvu/GString.h | 1676 ++++++++++++ kviewshell/plugins/djvu/libdjvu/GThreads.cpp | 1887 +++++++++++++ kviewshell/plugins/djvu/libdjvu/GThreads.h | 639 +++++ kviewshell/plugins/djvu/libdjvu/GURL.cpp | 1965 ++++++++++++++ kviewshell/plugins/djvu/libdjvu/GURL.h | 446 +++ kviewshell/plugins/djvu/libdjvu/GUnicode.cpp | 790 ++++++ kviewshell/plugins/djvu/libdjvu/IFFByteStream.cpp | 558 ++++ kviewshell/plugins/djvu/libdjvu/IFFByteStream.h | 312 +++ .../plugins/djvu/libdjvu/IW44EncodeCodec.cpp | 1797 +++++++++++++ kviewshell/plugins/djvu/libdjvu/IW44Image.cpp | 1935 +++++++++++++ kviewshell/plugins/djvu/libdjvu/IW44Image.h | 761 ++++++ kviewshell/plugins/djvu/libdjvu/JB2EncodeCodec.cpp | 564 ++++ kviewshell/plugins/djvu/libdjvu/JB2Image.cpp | 1427 ++++++++++ kviewshell/plugins/djvu/libdjvu/JB2Image.h | 805 ++++++ kviewshell/plugins/djvu/libdjvu/JPEGDecoder.cpp | 413 +++ kviewshell/plugins/djvu/libdjvu/JPEGDecoder.h | 133 + kviewshell/plugins/djvu/libdjvu/MMRDecoder.cpp | 961 +++++++ kviewshell/plugins/djvu/libdjvu/MMRDecoder.h | 238 ++ kviewshell/plugins/djvu/libdjvu/MMX.cpp | 209 ++ kviewshell/plugins/djvu/libdjvu/MMX.h | 194 ++ kviewshell/plugins/djvu/libdjvu/Makefile.am | 18 + kviewshell/plugins/djvu/libdjvu/README.djvulibre | 85 + kviewshell/plugins/djvu/libdjvu/Template.h | 258 ++ .../plugins/djvu/libdjvu/UnicodeByteStream.cpp | 368 +++ .../plugins/djvu/libdjvu/UnicodeByteStream.h | 199 ++ kviewshell/plugins/djvu/libdjvu/XMLParser.cpp | 1128 ++++++++ kviewshell/plugins/djvu/libdjvu/XMLParser.h | 123 + kviewshell/plugins/djvu/libdjvu/XMLTags.cpp | 417 +++ kviewshell/plugins/djvu/libdjvu/XMLTags.h | 242 ++ kviewshell/plugins/djvu/libdjvu/ZPCodec.cpp | 1292 +++++++++ kviewshell/plugins/djvu/libdjvu/ZPCodec.h | 747 ++++++ kviewshell/plugins/djvu/libdjvu/configure.in.in | 674 +++++ kviewshell/plugins/djvu/libdjvu/debug.cpp | 299 +++ kviewshell/plugins/djvu/libdjvu/debug.h | 304 +++ 107 files changed, 74443 insertions(+) create mode 100644 kviewshell/plugins/djvu/libdjvu/Arrays.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/Arrays.h create mode 100644 kviewshell/plugins/djvu/libdjvu/BSByteStream.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/BSByteStream.h create mode 100644 kviewshell/plugins/djvu/libdjvu/BSEncodeByteStream.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/ByteStream.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/ByteStream.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DataPool.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DataPool.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVmDir.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVmDir.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVmDir0.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVmDir0.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVmDoc.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVmDoc.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVmNav.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVmNav.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuAnno.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuAnno.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuDocEditor.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuDocEditor.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuDocument.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuDocument.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuDumpHelper.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuDumpHelper.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuErrorList.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuErrorList.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuFile.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuFile.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuFileCache.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuFileCache.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuGlobal.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuGlobal.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuGlobalMemory.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuImage.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuImage.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuInfo.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuInfo.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuMessage.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuMessage.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuMessageLite.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuMessageLite.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuNavDir.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuNavDir.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuPalette.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuPalette.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuPort.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuPort.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuText.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuText.h create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuToPS.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/DjVuToPS.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GBitmap.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/GBitmap.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GContainer.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/GContainer.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GException.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/GException.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GIFFManager.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/GIFFManager.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GMapAreas.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/GMapAreas.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GOS.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/GOS.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GPixmap.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/GPixmap.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GRect.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/GRect.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GScaler.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/GScaler.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GSmartPointer.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/GSmartPointer.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GString.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/GString.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GThreads.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/GThreads.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GURL.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/GURL.h create mode 100644 kviewshell/plugins/djvu/libdjvu/GUnicode.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/IFFByteStream.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/IFFByteStream.h create mode 100644 kviewshell/plugins/djvu/libdjvu/IW44EncodeCodec.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/IW44Image.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/IW44Image.h create mode 100644 kviewshell/plugins/djvu/libdjvu/JB2EncodeCodec.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/JB2Image.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/JB2Image.h create mode 100644 kviewshell/plugins/djvu/libdjvu/JPEGDecoder.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/JPEGDecoder.h create mode 100644 kviewshell/plugins/djvu/libdjvu/MMRDecoder.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/MMRDecoder.h create mode 100644 kviewshell/plugins/djvu/libdjvu/MMX.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/MMX.h create mode 100644 kviewshell/plugins/djvu/libdjvu/Makefile.am create mode 100644 kviewshell/plugins/djvu/libdjvu/README.djvulibre create mode 100644 kviewshell/plugins/djvu/libdjvu/Template.h create mode 100644 kviewshell/plugins/djvu/libdjvu/UnicodeByteStream.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/UnicodeByteStream.h create mode 100644 kviewshell/plugins/djvu/libdjvu/XMLParser.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/XMLParser.h create mode 100644 kviewshell/plugins/djvu/libdjvu/XMLTags.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/XMLTags.h create mode 100644 kviewshell/plugins/djvu/libdjvu/ZPCodec.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/ZPCodec.h create mode 100644 kviewshell/plugins/djvu/libdjvu/configure.in.in create mode 100644 kviewshell/plugins/djvu/libdjvu/debug.cpp create mode 100644 kviewshell/plugins/djvu/libdjvu/debug.h (limited to 'kviewshell/plugins/djvu/libdjvu') diff --git a/kviewshell/plugins/djvu/libdjvu/Arrays.cpp b/kviewshell/plugins/djvu/libdjvu/Arrays.cpp new file mode 100644 index 00000000..5cb7b04c --- /dev/null +++ b/kviewshell/plugins/djvu/libdjvu/Arrays.cpp @@ -0,0 +1,305 @@ +//C- -*- C++ -*- +//C- ------------------------------------------------------------------- +//C- DjVuLibre-3.5 +//C- Copyright (c) 2002 Leon Bottou and Yann Le Cun. +//C- Copyright (c) 2001 AT&T +//C- +//C- This software is subject to, and may be distributed under, the +//C- GNU General Public License, Version 2. The license should have +//C- accompanied the software or you may obtain a copy of the license +//C- from the Free Software Foundation at http://www.fsf.org . +//C- +//C- This program is distributed in the hope that it will be useful, +//C- but WITHOUT ANY WARRANTY; without even the implied warranty of +//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//C- GNU General Public License for more details. +//C- +//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library +//C- distributed by Lizardtech Software. On July 19th 2002, Lizardtech +//C- Software authorized us to replace the original DjVu(r) Reference +//C- Library notice by the following text (see doc/lizard2002.djvu): +//C- +//C- ------------------------------------------------------------------ +//C- | DjVu (r) Reference Library (v. 3.5) +//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved. +//C- | The DjVu Reference Library is protected by U.S. Pat. No. +//C- | 6,058,214 and patents pending. +//C- | +//C- | This software is subject to, and may be distributed under, the +//C- | GNU General Public License, Version 2. The license should have +//C- | accompanied the software or you may obtain a copy of the license +//C- | from the Free Software Foundation at http://www.fsf.org . +//C- | +//C- | The computer code originally released by LizardTech under this +//C- | license and unmodified by other parties is deemed "the LIZARDTECH +//C- | ORIGINAL CODE." Subject to any third party intellectual property +//C- | claims, LizardTech grants recipient a worldwide, royalty-free, +//C- | non-exclusive license to make, use, sell, or otherwise dispose of +//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the +//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU +//C- | General Public License. This grant only confers the right to +//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to +//C- | the extent such infringement is reasonably necessary to enable +//C- | recipient to make, have made, practice, sell, or otherwise dispose +//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to +//C- | any greater extent that may be necessary to utilize further +//C- | modifications or combinations. +//C- | +//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY +//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF +//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. +//C- +------------------------------------------------------------------ +// +// $Id: Arrays.cpp,v 1.8 2003/11/07 22:08:20 leonb Exp $ +// $Name: release_3_5_15 $ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif +#if NEED_GNUG_PRAGMAS +# pragma implementation +#endif + +#include "Arrays.h" +#include "GException.h" + + +#ifdef HAVE_NAMESPACES +namespace DJVU { +# ifdef NOT_DEFINED // Just to fool emacs c++ mode +} +#endif +#endif + +ArrayRep::ArrayRep(int xelsize, + void (* xdestroy)(void *, int, int), + void (* xinit1)(void *, int, int), + void (* xinit2)(void *, int, int, const void *, int, int), + void (* xcopy)(void *, int, int, const void *, int, int), + void (* xinsert)(void *, int, int, const void *, int)) : + data(0), minlo(0), maxhi(-1), lobound(0), hibound(-1), + elsize(xelsize), destroy(xdestroy), init1(xinit1), + init2(xinit2), copy(xcopy), insert(xinsert) +{ +} + +ArrayRep::ArrayRep(int xelsize, + void (* xdestroy)(void *, int, int), + void (* xinit1)(void *, int, int), + void (* xinit2)(void *, int, int, const void *, int, int), + void (* xcopy)(void *, int, int, const void *, int, int), + void (* xinsert)(void *, int, int, const void *, int), + int hi) : data(0), minlo(0), maxhi(-1), + lobound(0), hibound(-1), elsize(xelsize), destroy(xdestroy), init1(xinit1), + init2(xinit2), copy(xcopy), insert(xinsert) +{ + resize(0, hi); +} + +ArrayRep::ArrayRep(int xelsize, + void (* xdestroy)(void *, int, int), + void (* xinit1)(void *, int, int), + void (* xinit2)(void *, int, int, const void *, int, int), + void (* xcopy)(void *, int, int, const void *, int, int), + void (* xinsert)(void *, int, int, const void *, int), + int lo, int hi) : data(0), minlo(0), maxhi(-1), + lobound(0), hibound(-1), elsize(xelsize), destroy(xdestroy), init1(xinit1), + init2(xinit2), copy(xcopy), insert(xinsert) +{ + resize(lo,hi); +} + +ArrayRep::ArrayRep(const ArrayRep & arr) : data(0), minlo(0), maxhi(-1), + lobound(0), hibound(-1), elsize(arr.elsize), destroy(arr.destroy), + init1(arr.init1), init2(arr.init2), copy(arr.copy), insert(arr.insert) +{ + resize(arr.lobound, arr.hibound); + arr.copy(data, lobound-minlo, hibound-minlo, + arr.data, arr.lobound-arr.minlo, arr.hibound-arr.minlo); +} + +ArrayRep::~ArrayRep() +{ + destroy(data, lobound-minlo, hibound-minlo); + operator delete(data); + data=0; +} + +ArrayRep & +ArrayRep::operator= (const ArrayRep & rep) +{ + if (&rep == this) return *this; + empty(); + resize(rep.lobound, rep.hibound); + copy(data, lobound-minlo, hibound-minlo, + rep.data, rep.lobound-rep.minlo, rep.hibound-rep.minlo); + return *this; +} + +void +ArrayRep::resize(int lo, int hi) +{ + int nsize = hi - lo + 1; + // Validation + if (nsize < 0) + G_THROW( ERR_MSG("arrays.resize") ); + // Destruction + if (nsize == 0) + { + destroy(data, lobound-minlo, hibound-minlo); + operator delete(data); + data = 0; + lobound = minlo = lo; + hibound = maxhi = hi; + return; + } + // Simple extension + if (lo >= minlo && hi <= maxhi) + { + init1(data, lo-minlo, lobound-1-minlo); + destroy(data, lobound-minlo, lo-1-minlo); + init1(data, hibound+1-minlo, hi-minlo); + destroy(data, hi+1-minlo, hibound-minlo); + lobound = lo; + hibound = hi; + return; + } + // General case + int nminlo = minlo; + int nmaxhi = maxhi; + if (nminlo > nmaxhi) + nminlo = nmaxhi = lo; + while (nminlo > lo) { + int incr = nmaxhi - nminlo; + nminlo -= (incr < 8 ? 8 : (incr > 32768 ? 32768 : incr)); + } + while (nmaxhi < hi) { + int incr = nmaxhi - nminlo; + nmaxhi += (incr < 8 ? 8 : (incr > 32768 ? 32768 : incr)); + } + // allocate + int bytesize=elsize*(nmaxhi-nminlo+1); + void * ndata; + GPBufferBase gndata(ndata,bytesize,1); + memset(ndata, 0, bytesize); + // initialize + init1(ndata, lo-nminlo, lobound-1-nminlo); + init2(ndata, lobound-nminlo, hibound-nminlo, + data, lobound-minlo, hibound-minlo); + init1(ndata, hibound+1-nminlo, hi-nminlo); + destroy(data, lobound-minlo, hibound-minlo); + + // free and replace + void *tmp=data; + data = ndata; + ndata=tmp; + + minlo = nminlo; + maxhi = nmaxhi; + lobound = lo; + hibound = hi; +} + +void +ArrayRep::shift(int disp) +{ + lobound += disp; + hibound += disp; + minlo += disp; + maxhi += disp; +} + +void +ArrayRep::del(int n, unsigned int howmany) +{ + if (howmany == 0) + return; + if ((int)(n + howmany) > hibound +1) + G_THROW( ERR_MSG("arrays.ill_arg") ); + copy(data, n-minlo, hibound-howmany-minlo, + data, n+howmany-minlo, hibound-minlo); + destroy(data, hibound+1-howmany-minlo, hibound-minlo); + hibound = hibound - howmany; +} + +void +ArrayRep::ins(int n, const void * what, unsigned int howmany) +{ + int nhi = hibound + howmany; + if (howmany == 0) return; + if (maxhi < nhi) + { + int nmaxhi = maxhi; + while (nmaxhi < nhi) + nmaxhi += (nmaxhi < 8 ? 8 : (nmaxhi > 32768 ? 32768 : nmaxhi)); + int bytesize = elsize*(nmaxhi-minlo+1); + void *ndata; + GPBufferBase gndata(ndata,bytesize,1); + memset(ndata, 0, bytesize); + copy(ndata, lobound-minlo, hibound-minlo, + data, lobound-minlo, hibound-minlo); + destroy(data, lobound-minlo, hibound-minlo); + void *tmp=data; + data=ndata; + tmp=data; + maxhi = nmaxhi; + } + + insert(data, hibound+1-minlo, n-minlo, what, howmany); + hibound=nhi; +} + + + +#ifdef HAVE_NAMESPACES +} +# ifndef NOT_USING_DJVU_NAMESPACE +using namespace DJVU; +# endif +#endif + + +// --------------------------------------- +// BEGIN HACK +// --------------------------------------- +// Included here to avoid dependency +// from ByteStream.o to Arrays.o + +#ifndef DO_NOT_MOVE_GET_DATA_TO_ARRAYS_CPP +#include "ByteStream.h" + +#ifdef HAVE_NAMESPACES +namespace DJVU { +# ifdef NOT_DEFINED // Just to fool emacs c++ mode +} +#endif +#endif +TArray +ByteStream::get_data(void) +{ + const int s=size(); + if(s > 0) + { + TArray data(0, s-1); + readat((char*)data, s, 0); + return data; + }else + { + TArray data(0, -1); + return data; + } +} + +#ifdef HAVE_NAMESPACES +} +# ifndef NOT_USING_DJVU_NAMESPACE +using namespace DJVU; +# endif +#endif +#endif + +// --------------------------------------- +// END HACK +// --------------------------------------- + diff --git a/kviewshell/plugins/djvu/libdjvu/Arrays.h b/kviewshell/plugins/djvu/libdjvu/Arrays.h new file mode 100644 index 00000000..b2676d5a --- /dev/null +++ b/kviewshell/plugins/djvu/libdjvu/Arrays.h @@ -0,0 +1,997 @@ +//C- -*- C++ -*- +//C- ------------------------------------------------------------------- +//C- DjVuLibre-3.5 +//C- Copyright (c) 2002 Leon Bottou and Yann Le Cun. +//C- Copyright (c) 2001 AT&T +//C- +//C- This software is subject to, and may be distributed under, the +//C- GNU General Public License, Version 2. The license should have +//C- accompanied the software or you may obtain a copy of the license +//C- from the Free Software Foundation at http://www.fsf.org . +//C- +//C- This program is distributed in the hope that it will be useful, +//C- but WITHOUT ANY WARRANTY; without even the implied warranty of +//C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//C- GNU General Public License for more details. +//C- +//C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library +//C- distributed by Lizardtech Software. On July 19th 2002, Lizardtech +//C- Software authorized us to replace the original DjVu(r) Reference +//C- Library notice by the following text (see doc/lizard2002.djvu): +//C- +//C- ------------------------------------------------------------------ +//C- | DjVu (r) Reference Library (v. 3.5) +//C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved. +//C- | The DjVu Reference Library is protected by U.S. Pat. No. +//C- | 6,058,214 and patents pending. +//C- | +//C- | This software is subject to, and may be distributed under, the +//C- | GNU General Public License, Version 2. The license should have +//C- | accompanied the software or you may obtain a copy of the license +//C- | from the Free Software Foundation at http://www.fsf.org . +//C- | +//C- | The computer code originally released by LizardTech under this +//C- | license and unmodified by other parties is deemed "the LIZARDTECH +//C- | ORIGINAL CODE." Subject to any third party intellectual property +//C- | claims, LizardTech grants recipient a worldwide, royalty-free, +//C- | non-exclusive license to make, use, sell, or otherwise dispose of +//C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the +//C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU +//C- | General Public License. This grant only confers the right to +//C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to +//C- | the extent such infringement is reasonably necessary to enable +//C- | recipient to make, have made, practice, sell, or otherwise dispose +//C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to +//C- | any greater extent that may be necessary to utilize further +//C- | modifications or combinations. +//C- | +//C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY +//C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +//C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF +//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. +//C- +------------------------------------------------------------------ +// +// $Id: Arrays.h,v 1.10 2004/05/13 15:16:34 leonb Exp $ +// $Name: release_3_5_15 $ + +#ifndef _ARRAYS_H_ +#define _ARRAYS_H_ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#if NEED_GNUG_PRAGMAS +# pragma interface +#endif + +#include "GException.h" +#include "GSmartPointer.h" +#include + +#ifdef HAVE_NAMESPACES +namespace DJVU { +# ifdef NOT_DEFINED // Just to fool emacs c++ mode +} +#endif +#endif + + + +/** @name Arrays.h + + Files #"Arrays.h"# and #"Arrays.cpp"# implement three array template classes. + Class \Ref{TArray} implements an array of objects of trivial types + such as #char#, #int#, #float#, etc. It is faster than general implementation + for any type done in \Ref{DArray} because it does not cope with + element's constructors, destructors and copy operators. Although + implemented as a template, which makes it possible to incorrectly use + \Ref{TArray} with non-trivial classes, it should not be done. + + A lot of things is shared by these three arrays. That is why there are + more base classes: + \begin{itemize} + \item \Ref{ArrayBase} defines functions independent of the elements type + \item \Ref{ArrayBaseT} template class defining functions shared by + \Ref{DArray} and \Ref{TArray} + \end{itemize} + + The main difference between \Ref{GArray} (now obsolete) and these ones + is the copy-on-demand strategy, which allows you to copy array objects + without copying the real data. It's the same thing, which has been + implemented in \Ref{GString} long ago: as long as you don't try to modify + the underlying data, it may be shared between several copies of array + objects. As soon as you attempt to make any changes, a private copy + is created automatically and transparently for you - the procedure, that + we call "copy-on-demand". + + Also, please note that now there is no separate class, which does fast + sorting. Both \Ref{TArray} (dynamic array for trivial types) and + \Ref{DArray} (dynamic array for arbitrary types) can sort their elements. + + {\bf Historical comments} --- Leon chose to implement his own arrays because + the STL classes were not universally available and the compilers were + rarely able to deal with such a template galore. Later it became clear + that there is no really good reason why arrays should be derived from + containers. It was also suggested to create separate arrays implementation + for simple classes and do the copy-on-demand strategy, which would allow + to assign array objects without immediate copying of their elements. + + At this point \Ref{DArray} and \Ref{TArray} should only be used when + it is critical to have the copy-on-demand feature. The \Ref{GArray} + implementation is a lot more efficient. + + @memo Template array classes. + @author + Andrei Erofeev -- Copy-on-demand implementation. + @version + #$Id: Arrays.h,v 1.10 2004/05/13 15:16:34 leonb Exp $# */ +//@{ + +// Auxiliary classes: Will be used in place of GPBase and GPEnabled objects +class _ArrayRep +{ + friend class _ArrayBase; +public: + _ArrayRep(void) : count(0) {} + _ArrayRep(const _ArrayRep &) {} + virtual ~_ArrayRep(void) {} + + _ArrayRep & operator=(const _ArrayRep &) { return *this; } + + int get_count(void) const { return count; } +private: + int count; + + void ref(void) { count++; } + void unref(void) { if (--count==0) delete this; } +}; + +class _ArrayBase +{ +public: + _ArrayBase(void) : rep(0) {} + _ArrayBase(const _ArrayBase & ab) : rep(0) + { + if (ab.rep) ab.rep->ref(); + rep=ab.rep; + } + _ArrayBase(_ArrayRep * ar) : rep(0) + { + if (ar) ar->ref(); + rep=ar; + } + virtual ~_ArrayBase(void) + { + if (rep) { rep->unref(); rep=0; } + } + + _ArrayRep * get(void) const { return rep; } + _ArrayBase & assign(_ArrayRep * ar) + { + if (ar) ar->ref(); + if (rep) rep->unref(); + rep=ar; + return *this; + } + _ArrayBase & operator=(const _ArrayBase & ab) { return assign(ab.rep); } + bool operator==(const _ArrayBase & ab) { return rep==ab.rep; } +private: + _ArrayRep * rep; +}; + +// Internal "Array repository" holding the pointer to the actual data, +// data bounds, etc. It copes with data elements with the help of five +// static functions which pointers are supposed to be passed to the +// constructor. +class ArrayRep : public _ArrayRep +{ +public: + ArrayRep(int elsize, + void (* xdestroy)(void *, int, int), + void (* xinit1)(void *, int, int), + void (* xinit2)(void *, int, int, const void *, int, int), + void (* xcopy)(void *, int, int, const void *, int, int), + void (* xinsert)(void *, int, int, const void *, int)); + ArrayRep(int elsize, + void (* xdestroy)(void *, int, int), + void (* xinit1)(void *, int, int), + void (* xinit2)(void *, int, int, const void *, int, int), + void (* xcopy)(void *, int, int, const void *, int, int), + void (* xinsert)(void *, int, int, const void *, int), + int hibound); + ArrayRep(int elsize, + void (* xdestroy)(void *, int, int), + void (* xinit1)(void *, int, int), + void (* xinit2)(void *, int, int, const void *, int, int), + void (* xcopy)(void *, int, int, const void *, int, int), + void (* xinsert)(void *, int, int, const void *, int), + int lobound, int hibound); + ArrayRep(const ArrayRep & rep); + + virtual ~ArrayRep(); + + // Following is the standard interface to DArray. DArray will call these + // functions to access data. + int size() const; + int lbound() const; + int hbound() const; + + void empty(); + void touch(int n); + void resize(int lobound, int hibound); + void shift(int disp); + void del(int n, unsigned int howmany=1); + + // ins() is an exception. It does it job only partially. + // The derived class is supposed to finish insertion. + void ins(int n, const void * what, unsigned int howmany); + + ArrayRep & operator=(const ArrayRep & rep); + + // All data is public because DArray... classes will need access to it + void *data; + int minlo; + int maxhi; + int lobound; + int hibound; + int elsize; +private: + // These functions can't be virtual as they're called from + // constructors and destructors :(( + // destroy(): should destroy elements in data[] array from 'lo' to 'hi' + void (* destroy)(void * data, int lo, int hi); + // init1(): should initialize elements in data[] from 'lo' to 'hi' + // using default constructors + void (* init1)(void * data, int lo, int hi); + // init2(): should initialize elements in data[] from 'lo' to 'hi' + // using corresponding elements from src[] (copy constructor) + void (* init2)(void * data, int lo, int hi, + const void * src, int src_lo, int src_hi); + // copy(): should copy elements from src[] to dst[] (copy operator) + void (* copy)(void * dst, int dst_lo, int dst_hi, + const void * src, int src_lo, int src_hi); + // insert(): should insert '*what' at position 'where' 'howmany' times + // into array data[] having 'els' initialized elements + void (* insert)(void * data, int els, int where, const void * what, + int howmany); +}; + +inline int +ArrayRep::size() const +{ + return hibound - lobound + 1; +} + +inline int +ArrayRep::lbound() const +{ + return lobound; +} + +inline int +ArrayRep::hbound() const +{ + return hibound; +} + +inline void +ArrayRep::empty() +{ + resize(0, -1); +} + +inline void +ArrayRep::touch(int n) +{ + if (hibound < lobound) + { + resize(n,n); + } else + { + int nlo = lobound; + int nhi = hibound; + if (n < nlo) nlo = n; + if (n > nhi) nhi = n; + resize(nlo, nhi); + } +} + +/** Dynamic array base class. + This is an auxiliary base class for \Ref{DArray} and \Ref{TArray} + implementing some shared functions independent of the type of array + elements. It's not supposed to be constructed by hands. Use \Ref{DArray} + and \Ref{TArray} instead. + */ + +class ArrayBase : protected _ArrayBase +{ +protected: + void check(void); + void detach(void); + + ArrayBase(void) {}; +public: + /// Returns the number of elements in the array + int size() const; + /** Returns the lower bound of the valid subscript range. */ + int lbound() const; + /** Returns the upper bound of the valid subscript range. */ + int hbound() const; + /** Erases the array contents. All elements in the array are destroyed. + The valid subscript range is set to the empty range. */ + void empty(); + /** Extends the subscript range so that is contains #n#. + This function does nothing if #n# is already int the valid subscript range. + If the valid range was empty, both the lower bound and the upper bound + are set to #n#. Otherwise the valid subscript range is extended + to encompass #n#. This function is very handy when called before setting + an array element: + \begin{verbatim} + int lineno=1; + DArray a; + while (! end_of_file()) { + a.touch[lineno]; + a[lineno++] = read_a_line(); + } + \end{verbatim} + */ + void touch(int n); + /** Resets the valid subscript range to #0#---#hibound#. + This function may destroy some array elements and may construct + new array elements with the null constructor. Setting #hibound# to + #-1# resets the valid subscript range to the empty range. + @param hibound upper bound of the new subscript range. */ + void resize(int hibound); + /** Resets the valid subscript range to #lobound#---#hibound#. + This function may destroy some array elements and may construct + new array elements with the null constructor. Setting #lobound# to #0# and + #hibound# to #-1# resets the valid subscript range to the empty range. + @param lobound lower bound of the new subscript range. + @param hibound upper bound of the new subscript range. */ + void resize(int lobound, int hibound); + /** Shifts the valid subscript range. Argument #disp# is added to both + bounds of the valid subscript range. Array elements previously + located at subscript #x# will now be located at subscript #x+disp#. */ + void shift(int disp); + /** Deletes array elements. The array elements corresponding to + subscripts #n#...#n+howmany-1# are destroyed. All array elements + previously located at subscripts greater or equal to #n+howmany# + are moved to subscripts starting with #n#. The new subscript upper + bound is reduced in order to account for this shift. + @param n subscript of the first element to delete. + @param howmany number of elements to delete. */ + void del(int n, unsigned int howmany=1); + + virtual ~ArrayBase(void) {}; +}; + +inline void +ArrayBase::detach(void) +{ + ArrayRep * new_rep=new ArrayRep(*(ArrayRep *) get()); + assign(new_rep); +} + +inline void +ArrayBase::check(void) +{ + if (get()->get_count()>1) detach(); +} + +inline int +ArrayBase::size() const +{ + return ((const ArrayRep *) get())->size(); +} + +inline int +ArrayBase::lbound() const +{ + return ((const ArrayRep *) get())->lobound; +} + +inline int +ArrayBase::hbound() const +{ + return ((const ArrayRep *) get())->hibound; +} + +inline void +ArrayBase::empty() +{ + check(); + ((ArrayRep *) get())->empty(); +} + +inline void +ArrayBase::resize(int lo, int hi) +{ + check(); + ((ArrayRep *) get())->resize(lo, hi); +} + +inline void +ArrayBase::resize(int hi) +{ + resize(0, hi); +} + +inline void +ArrayBase::touch(int n) +{ + check(); + ((ArrayRep *) get())->touch(n); +} + +inline void +ArrayBase::shift(int disp) +{ + check(); + ((ArrayRep *) get())->shift(disp); +} + +inline void +ArrayBase::del(int n, unsigned int howmany) +{ + check(); + + ((ArrayRep *) get())->del(n, howmany); +} + +/** Dynamic array template base class. + This is an auxiliary template base class for \Ref{DArray} and \Ref{TArray} + implementing some shared functions which {\em depend} on the type of + the array elements (this is contrary to \Ref{ArrayBase}). + It's not supposed to be constructed by hands. Use \Ref{DArray} and + \Ref{TArray} instead. + */ + +template +class ArrayBaseT : public ArrayBase +{ +public: + virtual ~ArrayBaseT(void) {}; + + /** Returns a reference to the array element for subscript #n#. This + reference can be used for both reading (as "#a[n]#") and writing (as + "#a[n]=v#") an array element. This operation will not extend the valid + subscript range: an exception \Ref{GException} is thrown if argument #n# + is not in the valid subscript range. */ + TYPE& operator[](int n); + /** Returns a constant reference to the array element for subscript #n#. + This reference can only be used for reading (as "#a[n]#") an array + element. This operation will not extend the valid subscript range: an + exception \Ref{GException} is thrown if argument #n# is not in the valid + subscript range. This variant of #operator[]# is necessary when dealing + with a #const DArray#. */ + const TYPE& operator[](int n) const; + + /** Returns a pointer for reading or writing the array elements. This + pointer can be used to access the array elements with the same + subscripts and the usual bracket syntax. This pointer remains valid as + long as the valid subscript range is unchanged. If you change the + subscript range, you must stop using the pointers returned by prior + invocation of this conversion operator. */ + operator TYPE* (); + /** Returns a pointer for reading (but not modifying) the array elements. + This pointer can be used to access the array elements with the same + subscripts and the usual bracket syntax. This pointer remains valid as + long as the valid subscript range is unchanged. If you change the + subscript range, you must stop using the pointers returned by prior + invocation of this conversion operator. */ + operator const TYPE* () const; + +#ifndef __MWERKS__ //MCW can't compile + operator const TYPE* (); +#endif + /** Insert new elements into an array. This function inserts + #howmany# elements at position #n# into the array. The initial value #val# + is copied into the new elements. All array elements previously located at subscripts + #n# and higher are moved to subscripts #n+howmany# and higher. The upper bound of the + valid subscript range is increased in order to account for this shift. + @param n subscript of the first inserted element. + @param val initial value of the new elements. + @param howmany number of elements to insert. */ + void ins(int n, const TYPE &val, unsigned int howmany=1); + + /** Sort array elements. Sort all array elements in ascending order. Array + elements are compared using the less-or-equal comparison operator for + type #TYPE#. */ + void sort(); + /** Sort array elements in subscript range #lo# to #hi#. Sort all array + elements whose subscripts are in range #lo#..#hi# in ascending order. + The other elements of the array are left untouched. An exception is + thrown if arguments #lo# and #hi# are not in the valid subscript range. + Array elements are compared using the less-or-equal comparison operator + for type #TYPE#. + @param lo low bound for the subscripts of the elements to sort. + @param hi high bound for the subscripts of the elements to sort. */ + void sort(int lo, int hi); +protected: + ArrayBaseT(void) {}; +private: + // Callbacks called from ArrayRep + static void destroy(void * data, int lo, int hi); + static void init1(void * data, int lo, int hi); + static void init2(void * data, int lo, int hi, + const void * src, int src_lo, int src_hi); + static void copy(void * dst, int dst_lo, int dst_hi, + const void * src, int src_lo, int src_hi); + static void insert(void * data, int els, int where, + const void * what, int howmany); +}; + +template inline +ArrayBaseT::operator TYPE* () +{ + check(); + + ArrayRep * rep=(ArrayRep *) get(); + return &((TYPE *) rep->data)[-rep->minlo]; +} + +#ifndef __MWERKS__ //MCW can't compile +template inline +ArrayBaseT::operator const TYPE* () +{ + const ArrayRep * rep=(const ArrayRep *) get(); + return &((const TYPE *) rep->data)[-rep->minlo]; +} +#endif + +template inline +ArrayBaseT::operator const TYPE* () const +{ + const ArrayRep * rep=(const ArrayRep *) get(); + return &((const TYPE *) rep->data)[-rep->minlo]; +} + +template inline TYPE& +ArrayBaseT::operator[](int n) +{ + check(); + + ArrayRep * rep=(ArrayRep *) get(); + if (nlobound || n>rep->hibound) + G_THROW( ERR_MSG("arrays.ill_sub") ); + return ((TYPE *) rep->data)[n - rep->minlo]; +} + +template inline const TYPE& +ArrayBaseT::operator[](int n) const +{ + const ArrayRep * rep=(const ArrayRep *) get(); + if (nlobound || n>rep->hibound) + G_THROW( ERR_MSG("arrays.ill_sub") ); + return ((const TYPE *) rep->data)[n - rep->minlo]; +} + +template inline void +ArrayBaseT::ins(int n, const TYPE &val, unsigned int howmany) +{ + check(); + + ((ArrayRep *) get())->ins(n, &val, howmany); +} + +template void +ArrayBaseT::sort() +{ + sort(lbound(), hbound()); +} + +template void +ArrayBaseT::sort(int lo, int hi) +{ + if (hi <= lo) + return; + // Test for insertion sort (optimize!) + if (hi <= lo + 20) + { + for (int i=lo+1; i<=hi; i++) + { + int j = i; + TYPE tmp = (*this)[i]; + while ((--j>=lo) && !((*this)[j]<=tmp)) + (*this)[j+1] = (*this)[j]; + (*this)[j+1] = tmp; + } + return; + } + // -- determine suitable quick-sort pivot + TYPE tmp = (*this)[lo]; + TYPE pivot = (*this)[(lo+hi)/2]; + if (pivot <= tmp) + { tmp = pivot; pivot=(*this)[lo]; } + if ((*this)[hi] <= tmp) + { pivot = tmp; } + else if ((*this)[hi] <= pivot) + { pivot = (*this)[hi]; } + // -- partition set + int h = hi; + int l = lo; + while (l < h) + { + while (! (pivot <= (*this)[l])) l++; + while (! ((*this)[h] <= pivot)) h--; + if (l < h) + { + tmp = (*this)[l]; + (*this)[l] = (*this)[h]; + (*this)[h] = tmp; + l = l+1; + h = h-1; + } + } + // -- recursively restart + sort(lo, h); + sort(l, hi); +} + +/** Dynamic array for simple types. + Template class #TArray# implements an array of + elements of {\em simple} type #TYPE#. {\em Simple} means that the type + may be #char#, #int#, #float# etc. The limitation is imposed by the + way in which the #TArray# is working with its elements: it's not trying + to execute elements' constructors, destructors or copy operators. It's + just doing bitwise copy. Except for this it's pretty much the same as + \Ref{DArray}. + + Please note that most of the methods are implemented in the base classes + \Ref{ArrayBase} and \Ref{ArrayBaseT}. +*/ + +template +class TArray : public ArrayBaseT { +public: + /** Constructs an empty array. The valid subscript range is initially + empty. Member function #touch# and #resize# provide convenient ways + to enlarge the subscript range. */ + TArray(); + /** Constructs an array with subscripts in range 0 to #hibound#. + The subscript range can be subsequently modified with member functions + #touch# and #resize#. + @param hibound upper bound of the initial subscript range. */ + TArray(int hibound); + /** Constructs an array with subscripts in range #lobound# to #hibound#. + The subscript range can be subsequently modified with member functions + #touch# and #resize#. + @param lobound lower bound of the initial subscript range. + @param hibound upper bound of the initial subscript range. */ + TArray(int lobound, int hibound); + + virtual ~TArray() {}; +private: + // Callbacks called from ArrayRep + static void destroy(void * data, int lo, int hi); + static void init1(void * data, int lo, int hi); + static void init2(void * data, int lo, int hi, + const void * src, int src_lo, int src_hi); + static void insert(void * data, int els, int where, + const void * what, int howmany); +}; + +template void +TArray::destroy(void * data, int lo, int hi) +{ +} + +template void +TArray::init1(void * data, int lo, int hi) +{ +} + +template void +TArray::init2(void * data, int lo, int hi, + const void * src, int src_lo, int src_hi) +{ + if (data && src) + { + int els=hi-lo+1; + if (els>src_hi-src_lo+1) els=src_hi-src_lo+1; + if (els>0) + memmove((void *) &((TYPE *) data)[lo], + (void *) &((TYPE *) src)[src_lo], els*sizeof(TYPE)); + }; +} + +// inline removed +template void +TArray::insert(void * data, int els, int where, + const void * what, int howmany) +{ + memmove(((TYPE *) data)+where+howmany, + ((TYPE *) data)+where, sizeof(TYPE)*(els-where)); + for(int i=0;i +TArray::TArray () +{ + this->assign(new ArrayRep(sizeof(TYPE), destroy, init1, + init2, init2, insert)); +} + +template +TArray::TArray(int hi) +{ + this->assign(new ArrayRep(sizeof(TYPE), destroy, init1, + init2, init2, insert, hi)); +} + +template +TArray::TArray(int lo, int hi) +{ + this->assign(new ArrayRep(sizeof(TYPE), destroy, init1, + init2, init2, insert, lo, hi)); +} + +//inline removal ends + +/** Dynamic array for general types. + Template class #DArray# implements an array of + elements of type #TYPE#. Each element is identified by an integer + subscript. The valid subscripts range is defined by dynamically + adjustable lower- and upper-bounds. Besides accessing and setting + elements, member functions are provided to insert or delete elements at + specified positions. + + This template class must be able to access + \begin{itemize} + \item a null constructor #TYPE::TYPE()#, + \item a copy constructor #TYPE::TYPE(const TYPE &)#, + \item and a copy operator #TYPE & operator=(const TYPE &)#. + \end{itemize} + + The class offers "copy-on-demand" policy, which means that when you + copy the array object, array elements will stay intact as long as you + don't try to modify them. As soon as you make an attempt to change + array contents, the copying is done automatically and transparently + for you - the procedure that we call "copy-on-demand". This is the main + difference between this class and \Ref{GArray} (now obsolete) + + Please note that most of the methods are implemented in the base classes + \Ref{ArrayBase} and \Ref{ArrayBaseT}. +*/ + +template +class DArray : public ArrayBaseT { +public: + /** Constructs an empty array. The valid subscript range is initially + empty. Member function #touch# and #resize# provide convenient ways + to enlarge the subscript range. */ + DArray(void); + /** Constructs an array with subscripts in range 0 to #hibound#. + The subscript range can be subsequently modified with member functions + #touch# and #resize#. + @param hibound upper bound of the initial subscript range. */ + DArray(const int hibound); + /** Constructs an array with subscripts in range #lobound# to #hibound#. + The subscript range can be subsequently modified with member functions + #touch# and #resize#. + @param lobound lower bound of the initial subscript range. + @param hibound upper bound of the initial subscript range. */ + DArray(const int lobound, const int hibound); + + virtual ~DArray() {}; +private: + // Callbacks called from ArrayRep + static void destroy(void * data, int lo, int hi); + static void init1(void * data, int lo, int hi); + static void init2(void * data, int lo, int hi, + const void * src, int src_lo, int src_hi); + static void copy(void * dst, int dst_lo, int dst_hi, + const void * src, int src_lo, int src_hi); + static void insert(void * data, int els, int where, + const void * what, int howmany); +}; + +template void +DArray::destroy(void * data, int lo, int hi) +{ + if (data) + for(int i=lo;i<=hi;i++) + ((TYPE *) data)[i].TYPE::~TYPE(); +} + +template void +DArray::init1(void * data, int lo, int hi) +{ + if (data) + for(int i=lo;i<=hi;i++) + new ((void *) &((TYPE *) data)[i]) TYPE; +} + +template void +DArray::init2(void * data, int lo, int hi, + const void * src, int src_lo, int src_hi) +{ + if (data && src) + { + int i, j; + for(i=lo, j=src_lo;i<=hi && j<=src_hi;i++, j++) + new ((void *) &((TYPE *) data)[i]) TYPE(((TYPE *) src)[j]); + }; +} + +template void +DArray::copy(void * dst, int dst_lo, int dst_hi, + const void * src, int src_lo, int src_hi) +{ + if (dst && src) + { + int i, j; + for(i=dst_lo, j=src_lo;i<=dst_hi && j<=src_hi;i++, j++) + ((TYPE *) dst)[i]=((TYPE *) src)[j]; + }; +} + +template inline void +DArray::insert(void * data, int els, int where, + const void * what, int howmany) +{ + // Now do the insertion + TYPE * d=(TYPE *) data; + + int i; + for (i=els+howmany-1; i>=els; i--) + { + if (i-where >= (int)howmany) + new ((void*) &d[i]) TYPE (d[i-howmany]); + else + new ((void*) &d[i]) TYPE (*(TYPE *) what); + } + + for (i=els-1; i>=where; i--) + { + if (i-where >= (int)howmany) + d[i] = d[i-howmany]; + else + d[i] = *(TYPE *) what; + } +} + +template inline +DArray::DArray () +{ + this->assign(new ArrayRep(sizeof(TYPE), destroy, init1, + init2, copy, insert)); +} + +template inline +DArray::DArray(const int hi) +{ + this->assign(new ArrayRep(sizeof(TYPE), destroy, init1, + init2, copy, insert, hi)); +} + +template inline +DArray::DArray(const int lo, const int hi) +{ + this->assign(new ArrayRep(sizeof(TYPE), destroy, init1, + init2, copy, insert, lo, hi)); +} + +/** Dynamic array for \Ref{GPBase}d classes. + + There are many situations when it's necessary to create arrays of + \Ref{GP} pointers. For example, #DArray ># or #DArray >#. + This would result in compilation of two instances of \Ref{DArray} because + from the viewpoint of the compiler there are two different classes used + as array elements: #GP# and #GP