00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
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
00145 if (nsize < 0)
00146 G_THROW( ERR_MSG("arrays.resize") );
00147
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
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
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
00182 int bytesize=elsize*(nmaxhi-nminlo+1);
00183 void * ndata;
00184 GPBufferBase gndata(ndata,bytesize,1);
00185 memset(ndata, 0, bytesize);
00186
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
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
00265
00266
00267
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
00304
00305