• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kviewshell

Arrays.cpp

Go to the documentation of this file.
00001 //C-  -*- C++ -*-
00002 //C- -------------------------------------------------------------------
00003 //C- DjVuLibre-3.5
00004 //C- Copyright (c) 2002  Leon Bottou and Yann Le Cun.
00005 //C- Copyright (c) 2001  AT&T
00006 //C-
00007 //C- This software is subject to, and may be distributed under, the
00008 //C- GNU General Public License, Version 2. The license should have
00009 //C- accompanied the software or you may obtain a copy of the license
00010 //C- from the Free Software Foundation at http://www.fsf.org .
00011 //C-
00012 //C- This program is distributed in the hope that it will be useful,
00013 //C- but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //C- GNU General Public License for more details.
00016 //C- 
00017 //C- DjVuLibre-3.5 is derived from the DjVu(r) Reference Library
00018 //C- distributed by Lizardtech Software.  On July 19th 2002, Lizardtech 
00019 //C- Software authorized us to replace the original DjVu(r) Reference 
00020 //C- Library notice by the following text (see doc/lizard2002.djvu):
00021 //C-
00022 //C-  ------------------------------------------------------------------
00023 //C- | DjVu (r) Reference Library (v. 3.5)
00024 //C- | Copyright (c) 1999-2001 LizardTech, Inc. All Rights Reserved.
00025 //C- | The DjVu Reference Library is protected by U.S. Pat. No.
00026 //C- | 6,058,214 and patents pending.
00027 //C- |
00028 //C- | This software is subject to, and may be distributed under, the
00029 //C- | GNU General Public License, Version 2. The license should have
00030 //C- | accompanied the software or you may obtain a copy of the license
00031 //C- | from the Free Software Foundation at http://www.fsf.org .
00032 //C- |
00033 //C- | The computer code originally released by LizardTech under this
00034 //C- | license and unmodified by other parties is deemed "the LIZARDTECH
00035 //C- | ORIGINAL CODE."  Subject to any third party intellectual property
00036 //C- | claims, LizardTech grants recipient a worldwide, royalty-free, 
00037 //C- | non-exclusive license to make, use, sell, or otherwise dispose of 
00038 //C- | the LIZARDTECH ORIGINAL CODE or of programs derived from the 
00039 //C- | LIZARDTECH ORIGINAL CODE in compliance with the terms of the GNU 
00040 //C- | General Public License.   This grant only confers the right to 
00041 //C- | infringe patent claims underlying the LIZARDTECH ORIGINAL CODE to 
00042 //C- | the extent such infringement is reasonably necessary to enable 
00043 //C- | recipient to make, have made, practice, sell, or otherwise dispose 
00044 //C- | of the LIZARDTECH ORIGINAL CODE (or portions thereof) and not to 
00045 //C- | any greater extent that may be necessary to utilize further 
00046 //C- | modifications or combinations.
00047 //C- |
00048 //C- | The LIZARDTECH ORIGINAL CODE is provided "AS IS" WITHOUT WARRANTY
00049 //C- | OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
00050 //C- | TO ANY WARRANTY OF NON-INFRINGEMENT, OR ANY IMPLIED WARRANTY OF
00051 //C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
00052 //C- +------------------------------------------------------------------
00053 // 
00054 // $Id: Arrays.cpp,v 1.8 2003/11/07 22:08:20 leonb Exp $
00055 // $Name: release_3_5_15 $
00056 
00057 #ifdef HAVE_CONFIG_H
00058 # include "config.h"
00059 #endif
00060 #if NEED_GNUG_PRAGMAS
00061 # pragma implementation
00062 #endif
00063 
00064 #include "Arrays.h"
00065 #include "GException.h"
00066 
00067 
00068 #ifdef HAVE_NAMESPACES
00069 namespace DJVU {
00070 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00071 }
00072 #endif
00073 #endif
00074 
00075 ArrayRep::ArrayRep(int xelsize,
00076            void (* xdestroy)(void *, int, int),
00077            void (* xinit1)(void *, int, int),
00078            void (* xinit2)(void *, int, int, const void *, int, int),
00079            void (* xcopy)(void *, int, int, const void *, int, int),
00080            void (* xinsert)(void *, int, int, const void *, int)) :
00081       data(0), minlo(0), maxhi(-1), lobound(0), hibound(-1),
00082       elsize(xelsize), destroy(xdestroy), init1(xinit1),
00083       init2(xinit2), copy(xcopy), insert(xinsert)
00084 {
00085 }
00086 
00087 ArrayRep::ArrayRep(int xelsize,
00088            void (* xdestroy)(void *, int, int),
00089            void (* xinit1)(void *, int, int),
00090            void (* xinit2)(void *, int, int, const void *, int, int),
00091            void (* xcopy)(void *, int, int, const void *, int, int),
00092            void (* xinsert)(void *, int, int, const void *, int),
00093            int hi) : data(0), minlo(0), maxhi(-1),
00094    lobound(0), hibound(-1), elsize(xelsize), destroy(xdestroy), init1(xinit1),
00095    init2(xinit2), copy(xcopy), insert(xinsert)
00096 {
00097    resize(0, hi);
00098 }
00099 
00100 ArrayRep::ArrayRep(int xelsize,
00101            void (* xdestroy)(void *, int, int),
00102            void (* xinit1)(void *, int, int),
00103            void (* xinit2)(void *, int, int, const void *, int, int),
00104            void (* xcopy)(void *, int, int, const void *, int, int),
00105            void (* xinsert)(void *, int, int, const void *, int),
00106            int lo, int hi) : data(0), minlo(0), maxhi(-1),
00107    lobound(0), hibound(-1), elsize(xelsize), destroy(xdestroy), init1(xinit1),
00108    init2(xinit2), copy(xcopy), insert(xinsert)
00109 {
00110    resize(lo,hi);
00111 }
00112 
00113 ArrayRep::ArrayRep(const ArrayRep & arr) : data(0), minlo(0), maxhi(-1),
00114    lobound(0), hibound(-1), elsize(arr.elsize), destroy(arr.destroy),
00115    init1(arr.init1), init2(arr.init2), copy(arr.copy), insert(arr.insert)
00116 {
00117    resize(arr.lobound, arr.hibound);
00118    arr.copy(data, lobound-minlo, hibound-minlo,
00119         arr.data, arr.lobound-arr.minlo, arr.hibound-arr.minlo);
00120 }
00121 
00122 ArrayRep::~ArrayRep()
00123 {
00124    destroy(data, lobound-minlo, hibound-minlo);
00125    operator delete(data);
00126    data=0;
00127 }
00128 
00129 ArrayRep & 
00130 ArrayRep::operator= (const ArrayRep & rep)
00131 {
00132    if (&rep == this) return *this;
00133    empty();
00134    resize(rep.lobound, rep.hibound);
00135    copy(data, lobound-minlo, hibound-minlo,
00136     rep.data, rep.lobound-rep.minlo, rep.hibound-rep.minlo);
00137    return *this;
00138 }
00139 
00140 void
00141 ArrayRep::resize(int lo, int hi)
00142 {
00143   int nsize = hi - lo + 1;
00144   // Validation
00145   if (nsize < 0)
00146     G_THROW( ERR_MSG("arrays.resize") );
00147   // Destruction
00148   if (nsize == 0)
00149     {
00150       destroy(data, lobound-minlo, hibound-minlo);
00151       operator delete(data);
00152       data = 0;
00153       lobound = minlo = lo; 
00154       hibound = maxhi = hi; 
00155       return;
00156     }
00157   // Simple extension
00158   if (lo >= minlo && hi <= maxhi)
00159     {
00160       init1(data, lo-minlo, lobound-1-minlo);
00161       destroy(data, lobound-minlo, lo-1-minlo);
00162       init1(data, hibound+1-minlo, hi-minlo);
00163       destroy(data, hi+1-minlo, hibound-minlo);
00164       lobound = lo;
00165       hibound = hi;
00166       return;
00167     }
00168   // General case
00169   int nminlo = minlo;
00170   int nmaxhi = maxhi;
00171   if (nminlo > nmaxhi)
00172     nminlo = nmaxhi = lo;
00173   while (nminlo > lo) {
00174     int incr = nmaxhi - nminlo;
00175     nminlo -= (incr < 8 ? 8 : (incr > 32768 ? 32768 : incr));
00176   }
00177   while (nmaxhi < hi) {
00178     int incr = nmaxhi - nminlo;
00179     nmaxhi += (incr < 8 ? 8 : (incr > 32768 ? 32768 : incr));
00180   }
00181   // allocate
00182   int bytesize=elsize*(nmaxhi-nminlo+1);
00183   void * ndata;
00184   GPBufferBase gndata(ndata,bytesize,1);
00185   memset(ndata, 0, bytesize);
00186   // initialize
00187   init1(ndata, lo-nminlo, lobound-1-nminlo);
00188   init2(ndata, lobound-nminlo, hibound-nminlo,
00189         data, lobound-minlo, hibound-minlo);
00190   init1(ndata, hibound+1-nminlo, hi-nminlo);
00191   destroy(data, lobound-minlo, hibound-minlo);
00192 
00193   // free and replace
00194   void *tmp=data;
00195   data = ndata;
00196   ndata=tmp;
00197 
00198   minlo = nminlo;
00199   maxhi = nmaxhi;
00200   lobound = lo;
00201   hibound = hi;
00202 }
00203 
00204 void
00205 ArrayRep::shift(int disp)
00206 {
00207    lobound += disp;
00208    hibound += disp;
00209    minlo += disp;
00210    maxhi += disp;
00211 }
00212 
00213 void
00214 ArrayRep::del(int n, unsigned int howmany)
00215 {
00216    if (howmany == 0)
00217       return;
00218    if ((int)(n + howmany) > hibound +1)
00219       G_THROW( ERR_MSG("arrays.ill_arg") );
00220    copy(data, n-minlo, hibound-howmany-minlo,
00221     data, n+howmany-minlo, hibound-minlo);
00222    destroy(data, hibound+1-howmany-minlo, hibound-minlo);
00223    hibound = hibound - howmany;
00224 }
00225 
00226 void
00227 ArrayRep::ins(int n, const void * what, unsigned int howmany)
00228 {
00229    int nhi = hibound + howmany;
00230    if (howmany == 0) return;
00231    if (maxhi < nhi)
00232    {
00233       int nmaxhi = maxhi;
00234       while (nmaxhi < nhi)
00235      nmaxhi += (nmaxhi < 8 ? 8 : (nmaxhi > 32768 ? 32768 : nmaxhi));
00236       int bytesize = elsize*(nmaxhi-minlo+1);
00237       void *ndata;
00238       GPBufferBase gndata(ndata,bytesize,1);
00239       memset(ndata, 0, bytesize);
00240       copy(ndata, lobound-minlo, hibound-minlo,
00241        data, lobound-minlo, hibound-minlo);
00242       destroy(data, lobound-minlo, hibound-minlo);
00243       void *tmp=data;
00244       data=ndata;
00245       tmp=data;
00246       maxhi = nmaxhi;
00247    }
00248 
00249    insert(data, hibound+1-minlo, n-minlo, what, howmany);
00250    hibound=nhi;
00251 }
00252 
00253 
00254 
00255 #ifdef HAVE_NAMESPACES
00256 }
00257 # ifndef NOT_USING_DJVU_NAMESPACE
00258 using namespace DJVU;
00259 # endif
00260 #endif
00261 
00262 
00263 // ---------------------------------------
00264 // BEGIN HACK
00265 // ---------------------------------------
00266 // Included here to avoid dependency
00267 // from ByteStream.o to Arrays.o
00268 
00269 #ifndef DO_NOT_MOVE_GET_DATA_TO_ARRAYS_CPP
00270 #include "ByteStream.h"
00271 
00272 #ifdef HAVE_NAMESPACES
00273 namespace DJVU {
00274 # ifdef NOT_DEFINED // Just to fool emacs c++ mode
00275 }
00276 #endif
00277 #endif
00278 TArray<char>
00279 ByteStream::get_data(void)
00280 {
00281    const int s=size();
00282    if(s > 0)
00283    {
00284      TArray<char> data(0, s-1);
00285      readat((char*)data, s, 0);
00286      return data;
00287    }else
00288    {
00289      TArray<char> data(0, -1);
00290      return data;
00291    }
00292 }
00293 
00294 #ifdef HAVE_NAMESPACES
00295 }
00296 # ifndef NOT_USING_DJVU_NAMESPACE
00297 using namespace DJVU;
00298 # endif
00299 #endif
00300 #endif
00301 
00302 // ---------------------------------------
00303 // END HACK
00304 // ---------------------------------------
00305 

kviewshell

Skip menu "kviewshell"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • kviewshell
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal