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