1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26
27 #ifndef GCC
28 #endif
29
30 #include <sfx2/minarray.hxx>
31
32 // -----------------------------------------------------------------------
33
SfxPtrArr(sal_uInt8 nInitSize,sal_uInt8 nGrowSize)34 SfxPtrArr::SfxPtrArr( sal_uInt8 nInitSize, sal_uInt8 nGrowSize ):
35 nUsed( 0 ),
36 nGrow( nGrowSize ? nGrowSize : 1 ),
37 nUnused( nInitSize )
38 {
39 DBG_MEMTEST();
40 sal_uInt16 nMSCBug = nInitSize;
41
42 if ( nMSCBug > 0 )
43 pData = new void*[nMSCBug];
44 else
45 pData = 0;
46 }
47
48 // -----------------------------------------------------------------------
49
SfxPtrArr(const SfxPtrArr & rOrig)50 SfxPtrArr::SfxPtrArr( const SfxPtrArr& rOrig )
51 {
52 DBG_MEMTEST();
53 nUsed = rOrig.nUsed;
54 nGrow = rOrig.nGrow;
55 nUnused = rOrig.nUnused;
56
57 if ( rOrig.pData != 0 )
58 {
59 pData = new void*[nUsed+nUnused];
60 memcpy( pData, rOrig.pData, nUsed*sizeof(void*) );
61 }
62 else
63 pData = 0;
64 }
65
66 // -----------------------------------------------------------------------
67
~SfxPtrArr()68 SfxPtrArr::~SfxPtrArr()
69 {
70 DBG_MEMTEST();
71 delete [] pData;
72 }
73
74 // -----------------------------------------------------------------------
75
operator =(const SfxPtrArr & rOrig)76 SfxPtrArr& SfxPtrArr::operator=( const SfxPtrArr& rOrig )
77 {
78 DBG_MEMTEST();
79
80 delete [] pData;
81
82 nUsed = rOrig.nUsed;
83 nGrow = rOrig.nGrow;
84 nUnused = rOrig.nUnused;
85
86 if ( rOrig.pData != 0 )
87 {
88 pData = new void*[nUsed+nUnused];
89 memcpy( pData, rOrig.pData, nUsed*sizeof(void*) );
90 }
91 else
92 pData = 0;
93 return *this;
94 }
95
96 // -----------------------------------------------------------------------
97
Append(void * aElem)98 void SfxPtrArr::Append( void* aElem )
99 {
100 DBG_MEMTEST();
101 DBG_ASSERT( sal::static_int_cast< unsigned >(nUsed+1) < ( USHRT_MAX / sizeof(void*) ), "array too large" );
102 // musz das Array umkopiert werden?
103 if ( nUnused == 0 )
104 {
105 sal_uInt16 nNewSize = (nUsed == 1) ? (nGrow==1 ? 2 : nGrow) : nUsed+nGrow;
106 void** pNewData = new void*[nNewSize];
107 if ( pData )
108 {
109 DBG_ASSERT( nUsed <= nNewSize, "" );
110 memmove( pNewData, pData, sizeof(void*)*nUsed );
111 delete [] pData;
112 }
113 nUnused = sal::static_int_cast< sal_uInt8 >(nNewSize-nUsed);
114 pData = pNewData;
115 }
116
117 // jetzt hinten in den freien Raum schreiben
118 pData[nUsed] = aElem;
119 ++nUsed;
120 --nUnused;
121 }
122
123 // -----------------------------------------------------------------------
124
Remove(sal_uInt16 nPos,sal_uInt16 nLen)125 sal_uInt16 SfxPtrArr::Remove( sal_uInt16 nPos, sal_uInt16 nLen )
126 {
127 DBG_MEMTEST();
128 // nLen adjustieren, damit nicht ueber das Ende hinaus geloescht wird
129 nLen = Min( (sal_uInt16)(nUsed-nPos), nLen );
130
131 // einfache Aufgaben erfordern einfache Loesungen!
132 if ( nLen == 0 )
133 return 0;
134
135 // bleibt vielleicht keiner uebrig
136 if ( (nUsed-nLen) == 0 )
137 {
138 delete [] pData;
139 pData = 0;
140 nUsed = 0;
141 nUnused = 0;
142 return nLen;
143 }
144
145 // feststellen, ob das Array dadurch physikalisch schrumpft...
146 if ( (nUnused+nLen) >= nGrow )
147 {
148 // auf die naechste Grow-Grenze aufgerundet verkleinern
149 sal_uInt16 nNewUsed = nUsed-nLen;
150 sal_uInt16 nNewSize = ((nNewUsed+nGrow-1)/nGrow) * nGrow;
151 DBG_ASSERT( nNewUsed <= nNewSize && nNewUsed+nGrow > nNewSize,
152 "shrink size computation failed" );
153 void** pNewData = new void*[nNewSize];
154 if ( nPos > 0 )
155 {
156 DBG_ASSERT( nPos <= nNewSize, "" );
157 memmove( pNewData, pData, sizeof(void*)*nPos );
158 }
159 if ( nNewUsed != nPos )
160 memmove( pNewData+nPos, pData+nPos+nLen,
161 sizeof(void*)*(nNewUsed-nPos) );
162 delete [] pData;
163 pData = pNewData;
164 nUsed = nNewUsed;
165 nUnused = sal::static_int_cast< sal_uInt8 >(nNewSize - nNewUsed);
166 return nLen;
167 }
168
169 // in allen anderen Faellen nur zusammenschieben
170 if ( nUsed-nPos-nLen > 0 )
171 memmove( pData+nPos, pData+nPos+nLen, (nUsed-nPos-nLen)*sizeof(void*) );
172 nUsed = nUsed - nLen;
173 nUnused = sal::static_int_cast< sal_uInt8 >(nUnused + nLen);
174 return nLen;
175 }
176
177 // -----------------------------------------------------------------------
178
Remove(void * aElem)179 sal_Bool SfxPtrArr::Remove( void* aElem )
180 {
181 DBG_MEMTEST();
182 // einfache Aufgaben ...
183 if ( nUsed == 0 )
184 return sal_False;
185
186 // rueckwaerts, da meist der letzte zuerst wieder entfernt wird
187 void* *pIter = pData + nUsed - 1;
188 for ( sal_uInt16 n = 0; n < nUsed; ++n, --pIter )
189 if ( *pIter == aElem )
190 {
191 Remove(nUsed-n-1, 1);
192 return sal_True;
193 }
194 return sal_False;
195 }
196
197 // -----------------------------------------------------------------------
198
Replace(void * aOldElem,void * aNewElem)199 sal_Bool SfxPtrArr::Replace( void* aOldElem, void* aNewElem )
200 {
201 DBG_MEMTEST();
202 // einfache Aufgaben ...
203 if ( nUsed == 0 )
204 return sal_False;
205
206 // rueckwaerts, da meist der letzte zuerst wieder entfernt wird
207 void* *pIter = pData + nUsed - 1;
208 for ( sal_uInt16 n = 0; n < nUsed; ++n, --pIter )
209 if ( *pIter == aOldElem )
210 {
211 pData[nUsed-n-1] = aNewElem;
212 return sal_True;
213 }
214 return sal_False;
215 }
216
217 // -----------------------------------------------------------------------
218
Contains(const void * rItem) const219 sal_Bool SfxPtrArr::Contains( const void* rItem ) const
220 {
221 DBG_MEMTEST();
222 if ( !nUsed )
223 return sal_False;
224
225 for ( sal_uInt16 n = 0; n < nUsed; ++n )
226 {
227 void* p = GetObject(n);
228 if ( p == rItem )
229 return sal_True;
230 }
231
232 return sal_False;
233 }
234
235 // -----------------------------------------------------------------------
236
Insert(sal_uInt16 nPos,void * rElem)237 void SfxPtrArr::Insert( sal_uInt16 nPos, void* rElem )
238 {
239 DBG_MEMTEST();
240 DBG_ASSERT( sal::static_int_cast< unsigned >(nUsed+1) < ( USHRT_MAX / sizeof(void*) ), "array too large" );
241 // musz das Array umkopiert werden?
242 if ( nUnused == 0 )
243 {
244 // auf die naechste Grow-Grenze aufgerundet vergroeszern
245 sal_uInt16 nNewSize = nUsed+nGrow;
246 void** pNewData = new void*[nNewSize];
247
248 if ( pData )
249 {
250 DBG_ASSERT( nUsed < nNewSize, "" );
251 memmove( pNewData, pData, sizeof(void*)*nUsed );
252 delete [] pData;
253 }
254 nUnused = sal::static_int_cast< sal_uInt8 >(nNewSize-nUsed);
255 pData = pNewData;
256 }
257
258 // jetzt den hinteren Teil verschieben
259 if ( nPos < nUsed )
260 memmove( pData+nPos+1, pData+nPos, (nUsed-nPos)*sizeof(void*) );
261
262 // jetzt in den freien Raum schreiben
263 memmove( pData+nPos, &rElem, sizeof(void*) );
264 nUsed += 1;
265 nUnused -= 1;
266 }
267
268 // class ByteArr ---------------------------------------------------------
269
ByteArr(sal_uInt8 nInitSize,sal_uInt8 nGrowSize)270 ByteArr::ByteArr( sal_uInt8 nInitSize, sal_uInt8 nGrowSize ):
271 nUsed( 0 ),
272 nGrow( nGrowSize ? nGrowSize : 1 ),
273 nUnused( nInitSize )
274 {
275 DBG_MEMTEST();
276 sal_uInt16 nMSCBug = nInitSize;
277
278 if ( nInitSize > 0 )
279 pData = new char[nMSCBug];
280 else
281 pData = 0;
282 }
283
284 // -----------------------------------------------------------------------
285
ByteArr(const ByteArr & rOrig)286 ByteArr::ByteArr( const ByteArr& rOrig )
287 {
288 DBG_MEMTEST();
289 nUsed = rOrig.nUsed;
290 nGrow = rOrig.nGrow;
291 nUnused = rOrig.nUnused;
292
293 if ( rOrig.pData != 0 )
294 {
295 pData = new char[nUsed+nUnused];
296 memcpy( pData, rOrig.pData, nUsed*sizeof(char) );
297 }
298 else
299 pData = 0;
300 }
301
302 // -----------------------------------------------------------------------
303
~ByteArr()304 ByteArr::~ByteArr()
305 {
306 DBG_MEMTEST();
307 delete [] pData;
308 }
309
310 // -----------------------------------------------------------------------
311
operator =(const ByteArr & rOrig)312 ByteArr& ByteArr::operator=( const ByteArr& rOrig )
313 {
314 DBG_MEMTEST();
315
316 delete [] pData;
317
318 nUsed = rOrig.nUsed;
319 nGrow = rOrig.nGrow;
320 nUnused = rOrig.nUnused;
321
322 if ( rOrig.pData != 0 )
323 {
324 pData = new char[nUsed+nUnused];
325 memcpy( pData, rOrig.pData, nUsed*sizeof(char) );
326 }
327 else
328 pData = 0;
329 return *this;
330 }
331
332 // -----------------------------------------------------------------------
333
Append(char aElem)334 void ByteArr::Append( char aElem )
335 {
336 DBG_MEMTEST();
337 // musz das Array umkopiert werden?
338 if ( nUnused == 0 )
339 {
340 sal_uInt16 nNewSize = (nUsed == 1) ? (nGrow==1 ? 2 : nGrow) : nUsed+nGrow;
341 char* pNewData = new char[nNewSize];
342 if ( pData )
343 {
344 DBG_ASSERT( nUsed <= nNewSize, "" );
345 memmove( pNewData, pData, sizeof(char)*nUsed );
346 delete [] pData;
347 }
348 nUnused = sal::static_int_cast< sal_uInt8 >(nNewSize-nUsed);
349 pData = pNewData;
350 }
351
352 // jetzt hinten in den freien Raum schreiben
353 pData[nUsed] = aElem;
354 ++nUsed;
355 --nUnused;
356 }
357
358 // -----------------------------------------------------------------------
359
Remove(sal_uInt16 nPos,sal_uInt16 nLen)360 sal_uInt16 ByteArr::Remove( sal_uInt16 nPos, sal_uInt16 nLen )
361 {
362 DBG_MEMTEST();
363 // nLen adjustieren, damit nicht ueber das Ende hinaus geloescht wird
364 nLen = Min( (sal_uInt16)(nUsed-nPos), nLen );
365
366 // einfache Aufgaben erfordern einfache Loesungen!
367 if ( nLen == 0 )
368 return 0;
369
370 // bleibt vielleicht keiner uebrig
371 if ( (nUsed-nLen) == 0 )
372 {
373 delete [] pData;
374 pData = 0;
375 nUsed = 0;
376 nUnused = 0;
377 return nLen;
378 }
379
380 // feststellen, ob das Array dadurch physikalisch schrumpft...
381 if ( (nUnused+nLen) >= nGrow )
382 {
383 // auf die naechste Grow-Grenze aufgerundet verkleinern
384 sal_uInt16 nNewUsed = nUsed-nLen;
385 sal_uInt16 nNewSize = ((nNewUsed+nGrow-1)/nGrow) * nGrow;
386 DBG_ASSERT( nNewUsed <= nNewSize && nNewUsed+nGrow > nNewSize,
387 "shrink size computation failed" );
388 char* pNewData = new char[nNewSize];
389 if ( nPos > 0 )
390 {
391 DBG_ASSERT( nPos <= nNewSize, "" );
392 memmove( pNewData, pData, sizeof(char)*nPos );
393 }
394 if ( nNewUsed != nPos )
395 memmove( pNewData+nPos, pData+nPos+nLen,
396 sizeof(char)*(nNewUsed-nPos) );
397 delete [] pData;
398 pData = pNewData;
399 nUsed = nNewUsed;
400 nUnused = sal::static_int_cast< sal_uInt8 >(nNewSize - nNewUsed);
401 return nLen;
402 }
403
404 // in allen anderen Faellen nur zusammenschieben
405 if ( nUsed-nPos-nLen > 0 )
406 memmove( pData+nPos, pData+nPos+nLen, (nUsed-nPos-nLen)*sizeof(char) );
407 nUsed = nUsed - nLen;
408 nUnused = sal::static_int_cast< sal_uInt8 >(nUnused + nLen);
409 return nLen;
410 }
411
412 // -----------------------------------------------------------------------
413
Remove(char aElem)414 sal_Bool ByteArr::Remove( char aElem )
415 {
416 DBG_MEMTEST();
417 // einfache Aufgaben ...
418 if ( nUsed == 0 )
419 return sal_False;
420
421 // rueckwaerts, da meist der letzte zuerst wieder entfernt wird
422 char *pIter = pData + nUsed - 1;
423 for ( sal_uInt16 n = 0; n < nUsed; ++n, --pIter )
424 if ( *pIter == aElem )
425 {
426 Remove(nUsed-n-1, 1);
427 return sal_True;
428 }
429 return sal_False;
430 }
431
432 // -----------------------------------------------------------------------
433
Contains(const char rItem) const434 sal_Bool ByteArr::Contains( const char rItem ) const
435 {
436 DBG_MEMTEST();
437 if ( !nUsed )
438 return sal_False;
439
440 for ( sal_uInt16 n = 0; n < nUsed; ++n )
441 {
442 char p = GetObject(n);
443 if ( p == rItem )
444 return sal_True;
445 }
446
447 return sal_False;
448 }
449
450 // -----------------------------------------------------------------------
451
Insert(sal_uInt16 nPos,char rElem)452 void ByteArr::Insert( sal_uInt16 nPos, char rElem )
453 {
454 DBG_MEMTEST();
455 // musz das Array umkopiert werden?
456 if ( nUnused == 0 )
457 {
458 // auf die naechste Grow-Grenze aufgerundet vergroeszern
459 sal_uInt16 nNewSize = nUsed+nGrow;
460 char* pNewData = new char[nNewSize];
461
462 if ( pData )
463 {
464 DBG_ASSERT( nUsed < nNewSize, "" );
465 memmove( pNewData, pData, sizeof(char)*nUsed );
466 delete [] pData;
467 }
468 nUnused = sal::static_int_cast< sal_uInt8 >(nNewSize-nUsed);
469 pData = pNewData;
470 }
471
472 // jetzt den hinteren Teil verschieben
473 if ( nPos < nUsed )
474 memmove( pData+nPos+1, pData+nPos, (nUsed-nPos)*sizeof(char) );
475
476 // jetzt in den freien Raum schreiben
477 memmove( pData+nPos, &rElem, sizeof(char) );
478 nUsed += 1;
479 nUnused -= 1;
480 }
481
482 // -----------------------------------------------------------------------
483
operator [](sal_uInt16 nPos) const484 char ByteArr::operator[]( sal_uInt16 nPos ) const
485 {
486 DBG_MEMTEST();
487 DBG_ASSERT( nPos < nUsed, "" );
488 return *(pData+nPos);
489 }
490
491 // -----------------------------------------------------------------------
492
operator [](sal_uInt16 nPos)493 char& ByteArr::operator [] (sal_uInt16 nPos)
494 {
495 DBG_MEMTEST();
496 DBG_ASSERT( nPos < nUsed, "" );
497 return *(pData+nPos);
498 }
499
500 // class WordArr ---------------------------------------------------------
501
WordArr(sal_uInt8 nInitSize,sal_uInt8 nGrowSize)502 WordArr::WordArr( sal_uInt8 nInitSize, sal_uInt8 nGrowSize ):
503 nUsed( 0 ),
504 nGrow( nGrowSize ? nGrowSize : 1 ),
505 nUnused( nInitSize )
506 {
507 DBG_MEMTEST();
508 sal_uInt16 nMSCBug = nInitSize;
509
510 if ( nInitSize > 0 )
511 pData = new short[nMSCBug];
512 else
513 pData = 0;
514 }
515
516 // -----------------------------------------------------------------------
517
WordArr(const WordArr & rOrig)518 WordArr::WordArr( const WordArr& rOrig )
519 {
520 DBG_MEMTEST();
521 nUsed = rOrig.nUsed;
522 nGrow = rOrig.nGrow;
523 nUnused = rOrig.nUnused;
524
525 if ( rOrig.pData != 0 )
526 {
527 pData = new short[nUsed+nUnused];
528 memcpy( pData, rOrig.pData, nUsed*sizeof(short) );
529 }
530 else
531 pData = 0;
532 }
533
534 // -----------------------------------------------------------------------
535
~WordArr()536 WordArr::~WordArr()
537 {
538 DBG_MEMTEST();
539 delete [] pData;
540 }
541
542 // -----------------------------------------------------------------------
543
operator =(const WordArr & rOrig)544 WordArr& WordArr::operator=( const WordArr& rOrig )
545 {
546 DBG_MEMTEST();
547
548 delete [] pData;
549
550 nUsed = rOrig.nUsed;
551 nGrow = rOrig.nGrow;
552 nUnused = rOrig.nUnused;
553
554 if ( rOrig.pData != 0 )
555 {
556 pData = new short[nUsed+nUnused];
557 memcpy( pData, rOrig.pData, nUsed*sizeof(short) );
558 }
559 else
560 pData = 0;
561 return *this;
562 }
563
564 // -----------------------------------------------------------------------
565
Append(short aElem)566 void WordArr::Append( short aElem )
567 {
568 DBG_MEMTEST();
569 // musz das Array umkopiert werden?
570 if ( nUnused == 0 )
571 {
572 sal_uInt16 nNewSize = (nUsed == 1) ? (nGrow==1 ? 2 : nGrow) : nUsed+nGrow;
573 short* pNewData = new short[nNewSize];
574 if ( pData )
575 {
576 DBG_ASSERT( nUsed <= nNewSize, " " );
577 memmove( pNewData, pData, sizeof(short)*nUsed );
578 delete [] pData;
579 }
580 nUnused = sal::static_int_cast< sal_uInt8 >(nNewSize-nUsed);
581 pData = pNewData;
582 }
583
584 // jetzt hinten in den freien Raum schreiben
585 pData[nUsed] = aElem;
586 ++nUsed;
587 --nUnused;
588 }
589
590 // -----------------------------------------------------------------------
591
Remove(sal_uInt16 nPos,sal_uInt16 nLen)592 sal_uInt16 WordArr::Remove( sal_uInt16 nPos, sal_uInt16 nLen )
593 {
594 DBG_MEMTEST();
595 // nLen adjustieren, damit nicht ueber das Ende hinaus geloescht wird
596 nLen = Min( (sal_uInt16)(nUsed-nPos), nLen );
597
598 // einfache Aufgaben erfordern einfache Loesungen!
599 if ( nLen == 0 )
600 return 0;
601
602 // bleibt vielleicht keiner uebrig
603 if ( (nUsed-nLen) == 0 )
604 {
605 delete [] pData;
606 pData = 0;
607 nUsed = 0;
608 nUnused = 0;
609 return nLen;
610 }
611
612 // feststellen, ob das Array dadurch physikalisch schrumpft...
613 if ( (nUnused+nLen) >= nGrow )
614 {
615 // auf die naechste Grow-Grenze aufgerundet verkleinern
616 sal_uInt16 nNewUsed = nUsed-nLen;
617 sal_uInt16 nNewSize = ((nNewUsed+nGrow-1)/nGrow) * nGrow;
618 DBG_ASSERT( nNewUsed <= nNewSize && nNewUsed+nGrow > nNewSize,
619 "shrink size computation failed" );
620 short* pNewData = new short[nNewSize];
621 if ( nPos > 0 )
622 {
623 DBG_ASSERT( nPos <= nNewSize, "" );
624 memmove( pNewData, pData, sizeof(short)*nPos );
625 }
626 if ( nNewUsed != nPos )
627 memmove( pNewData+nPos, pData+nPos+nLen,
628 sizeof(short)*(nNewUsed-nPos) );
629 delete [] pData;
630 pData = pNewData;
631 nUsed = nNewUsed;
632 nUnused = sal::static_int_cast< sal_uInt8 >(nNewSize - nNewUsed);
633 return nLen;
634 }
635
636 // in allen anderen Faellen nur zusammenschieben
637 if ( nUsed-nPos-nLen > 0 )
638 memmove( pData+nPos, pData+nPos+nLen, (nUsed-nPos-nLen)*sizeof(short) );
639 nUsed = nUsed - nLen;
640 nUnused = sal::static_int_cast< sal_uInt8 >(nUnused + nLen);
641 return nLen;
642 }
643
644 // -----------------------------------------------------------------------
645
Remove(short aElem)646 sal_Bool WordArr::Remove( short aElem )
647 {
648 DBG_MEMTEST();
649 // einfache Aufgaben ...
650 if ( nUsed == 0 )
651 return sal_False;
652
653 // rueckwaerts, da meist der letzte zuerst wieder entfernt wird
654 short *pIter = pData + nUsed - 1;
655 for ( sal_uInt16 n = 0; n < nUsed; ++n, --pIter )
656 if ( *pIter == aElem )
657 {
658 Remove(nUsed-n-1, 1);
659 return sal_True;
660 }
661 return sal_False;
662 }
663
664 // -----------------------------------------------------------------------
665
Contains(const short rItem) const666 sal_Bool WordArr::Contains( const short rItem ) const
667 {
668 DBG_MEMTEST();
669 if ( !nUsed )
670 return sal_False;
671
672 for ( sal_uInt16 n = 0; n < nUsed; ++n )
673 {
674 short p = GetObject(n);
675 if ( p == rItem )
676 return sal_True;
677 }
678
679 return sal_False;
680 }
681
682 // -----------------------------------------------------------------------
683
Insert(sal_uInt16 nPos,short rElem)684 void WordArr::Insert( sal_uInt16 nPos, short rElem )
685 {
686 DBG_MEMTEST();
687 // musz das Array umkopiert werden?
688 if ( nUnused == 0 )
689 {
690 // auf die naechste Grow-Grenze aufgerundet vergroeszern
691 sal_uInt16 nNewSize = nUsed+nGrow;
692 short* pNewData = new short[nNewSize];
693
694 if ( pData )
695 {
696 DBG_ASSERT( nUsed < nNewSize, "" );
697 memmove( pNewData, pData, sizeof(short)*nUsed );
698 delete [] pData;
699 }
700 nUnused = sal::static_int_cast< sal_uInt8 >(nNewSize-nUsed);
701 pData = pNewData;
702 }
703
704 // jetzt den hinteren Teil verschieben
705 if ( nPos < nUsed )
706 memmove( pData+nPos+1, pData+nPos, (nUsed-nPos)*sizeof(short) );
707
708 // jetzt in den freien Raum schreiben
709 memmove( pData+nPos, &rElem, sizeof(short) );
710 nUsed += 1;
711 nUnused -= 1;
712 }
713
714 // -----------------------------------------------------------------------
715
operator [](sal_uInt16 nPos) const716 short WordArr::operator[]( sal_uInt16 nPos ) const
717 {
718 DBG_MEMTEST();
719 DBG_ASSERT( nPos < nUsed, "" );
720 return *(pData+nPos);
721 }
722
723 // -----------------------------------------------------------------------
724
operator [](sal_uInt16 nPos)725 short& WordArr::operator [] (sal_uInt16 nPos)
726 {
727 DBG_MEMTEST();
728 DBG_ASSERT( nPos < nUsed, "" );
729 return *(pData+nPos);
730 }
731
732
733