Lines 39-50
Link Here
|
39 |
* enthaelt. (Sie werden im Speicher verschoben, koennen also |
39 |
* enthaelt. (Sie werden im Speicher verschoben, koennen also |
40 |
* z.B. keine String sein) |
40 |
* z.B. keine String sein) |
41 |
* |
41 |
* |
42 |
* SV_DECL_OBJARR(nm, AE, IS, GS) |
|
|
43 |
* SV_IMPL_OBJARR( nm, AE ) |
44 |
* definiere/implementiere ein Array das Objecte enthaelt. |
45 |
* (Hier koennen es auch Strings sein) |
46 |
* |
47 |
* |
48 |
* SV_DECL_PTRARR(nm, AE, IS, GS) |
42 |
* SV_DECL_PTRARR(nm, AE, IS, GS) |
49 |
* SV_IMPL_PTRARR(nm, AE) |
43 |
* SV_IMPL_PTRARR(nm, AE) |
50 |
* definiere/implementiere ein Array das Pointer haelt. Diese |
44 |
* definiere/implementiere ein Array das Pointer haelt. Diese |
Lines 332-520
Link Here
|
332 |
#define SV_IMPL_VARARR_PLAIN( nm, AE ) \ |
326 |
#define SV_IMPL_VARARR_PLAIN( nm, AE ) \ |
333 |
SV_IMPL_VARARR_GEN( nm, AE, AE ) |
327 |
SV_IMPL_VARARR_GEN( nm, AE, AE ) |
334 |
|
328 |
|
335 |
#if defined(PRODUCT) |
|
|
336 |
|
337 |
#define _SVOBJARR_DEF_GET_OP_INLINE( nm,ArrElem )\ |
338 |
ArrElem& operator[](USHORT nP) const { return *(pData+nP); }\ |
339 |
\ |
340 |
void Insert( const nm *pI, USHORT nP,\ |
341 |
USHORT nS = 0, USHORT nE = USHRT_MAX )\ |
342 |
{\ |
343 |
if( USHRT_MAX == nE ) \ |
344 |
nE = pI->nA; \ |
345 |
if( nS < nE ) \ |
346 |
Insert( (const ArrElem*)pI->pData+nS, (USHORT)nE-nS, nP );\ |
347 |
} |
348 |
|
349 |
#define _SVOBJARR_IMPL_GET_OP_INLINE( nm, ArrElem ) |
350 |
|
351 |
#else |
352 |
|
353 |
#define _SVOBJARR_DEF_GET_OP_INLINE( nm,ArrElem ) \ |
354 |
ArrElem& operator[](USHORT nP) const;\ |
355 |
void Insert( const nm *pI, USHORT nP,\ |
356 |
USHORT nS = 0, USHORT nE = USHRT_MAX ); |
357 |
|
358 |
#define _SVOBJARR_IMPL_GET_OP_INLINE( nm, ArrElem )\ |
359 |
ArrElem& nm::operator[](USHORT nP) const\ |
360 |
{\ |
361 |
DBG_ASSERT( pData && nP < nA,"Op[]");\ |
362 |
return *(pData+nP);\ |
363 |
}\ |
364 |
void nm::Insert( const nm *pI, USHORT nP, USHORT nStt, USHORT nE )\ |
365 |
{\ |
366 |
DBG_ASSERT( nP <= nA,"Ins,Ar[Start.End]");\ |
367 |
if( USHRT_MAX == nE ) \ |
368 |
nE = pI->nA; \ |
369 |
if( nStt < nE ) \ |
370 |
Insert( (const ArrElem*)pI->pData+nStt, (USHORT)nE-nStt, nP );\ |
371 |
} |
372 |
|
373 |
#endif |
374 |
|
375 |
#define _SV_DECL_OBJARR(nm, AE, IS, GS)\ |
376 |
typedef BOOL (*FnForEach_##nm)( const AE&, void* );\ |
377 |
class nm\ |
378 |
{\ |
379 |
protected:\ |
380 |
AE *pData;\ |
381 |
USHORT nFree;\ |
382 |
USHORT nA;\ |
383 |
\ |
384 |
void _resize(size_t n);\ |
385 |
void _destroy();\ |
386 |
\ |
387 |
public:\ |
388 |
nm( USHORT= IS, BYTE= GS );\ |
389 |
~nm() { _destroy(); }\ |
390 |
\ |
391 |
_SVOBJARR_DEF_GET_OP_INLINE(nm,AE)\ |
392 |
AE& GetObject(USHORT nP) const { return (*this)[nP]; } \ |
393 |
\ |
394 |
void Insert( const AE &aE, USHORT nP );\ |
395 |
void Insert( const AE *pE, USHORT nL, USHORT nP );\ |
396 |
void Remove( USHORT nP, USHORT nL = 1 );\ |
397 |
USHORT Count() const { return nA; }\ |
398 |
const AE* GetData() const { return (const AE*)pData; }\ |
399 |
\ |
400 |
void ForEach( CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\ |
401 |
{\ |
402 |
_ForEach( 0, nA, fnForEach, pArgs );\ |
403 |
}\ |
404 |
void ForEach( USHORT nS, USHORT nE, \ |
405 |
CONCAT( FnForEach_, nm ) fnForEach, void* pArgs = 0 )\ |
406 |
{\ |
407 |
_ForEach( nS, nE, fnForEach, pArgs );\ |
408 |
}\ |
409 |
\ |
410 |
void _ForEach( USHORT nStt, USHORT nE, \ |
411 |
CONCAT( FnForEach_, nm ) fnCall, void* pArgs = 0 );\ |
412 |
\ |
413 |
|
414 |
#define SV_DECL_OBJARR(nm, AE, IS, GS)\ |
415 |
_SV_DECL_OBJARR(nm, AE, IS, GS)\ |
416 |
private:\ |
417 |
nm( const nm& );\ |
418 |
nm& operator=( const nm& );\ |
419 |
}; |
420 |
|
421 |
#define SV_IMPL_OBJARR( nm, AE )\ |
422 |
nm::nm( USHORT nInit, BYTE )\ |
423 |
: pData (0),\ |
424 |
nFree (nInit),\ |
425 |
nA (0)\ |
426 |
{\ |
427 |
if( nInit )\ |
428 |
{\ |
429 |
pData = (AE*)(rtl_allocateMemory(sizeof(AE) * nInit));\ |
430 |
DBG_ASSERT( pData, "CTOR, allocate");\ |
431 |
}\ |
432 |
}\ |
433 |
\ |
434 |
void nm::_destroy()\ |
435 |
{\ |
436 |
if(pData)\ |
437 |
{\ |
438 |
AE* pTmp=pData;\ |
439 |
for(USHORT n=0; n < nA; n++,pTmp++ )\ |
440 |
{\ |
441 |
pTmp->~AE();\ |
442 |
}\ |
443 |
rtl_freeMemory(pData);\ |
444 |
pData = 0;\ |
445 |
}\ |
446 |
}\ |
447 |
\ |
448 |
void nm::_resize (size_t n)\ |
449 |
{\ |
450 |
USHORT nL = ((n < USHRT_MAX) ? USHORT(n) : USHRT_MAX);\ |
451 |
AE* pE = (AE*)(rtl_reallocateMemory (pData, sizeof(AE) * nL));\ |
452 |
if ((pE != 0) || (nL == 0))\ |
453 |
{\ |
454 |
pData = pE;\ |
455 |
nFree = nL - nA;\ |
456 |
}\ |
457 |
}\ |
458 |
\ |
459 |
void nm::Insert( const AE &aE, USHORT nP )\ |
460 |
{\ |
461 |
DBG_ASSERT( nP <= nA && nA < USHRT_MAX,"Ins 1");\ |
462 |
if (nFree < 1)\ |
463 |
_resize (nA + ((nA > 1) ? nA : 1));\ |
464 |
if( pData && nP < nA )\ |
465 |
memmove( pData+nP+1, pData+nP, (nA-nP) * sizeof( AE ));\ |
466 |
AE* pTmp = pData+nP;\ |
467 |
new( (DummyType*) pTmp ) AE( (AE&)aE );\ |
468 |
++nA; --nFree;\ |
469 |
}\ |
470 |
\ |
471 |
void nm::Insert( const AE* pE, USHORT nL, USHORT nP )\ |
472 |
{\ |
473 |
DBG_ASSERT(nP<=nA && ((long)nA+nL) < USHRT_MAX, "Ins n");\ |
474 |
if (nFree < nL)\ |
475 |
_resize (nA + ((nA > nL) ? nA : nL));\ |
476 |
if( pData && nP < nA )\ |
477 |
memmove( pData+nP+nL, pData+nP, (nA-nP) * sizeof( AE ));\ |
478 |
if( pE )\ |
479 |
{\ |
480 |
AE* pTmp = pData+nP;\ |
481 |
for( USHORT n = 0; n < nL; n++, pTmp++, pE++)\ |
482 |
{\ |
483 |
new( (DummyType*) pTmp ) AE( (AE&)*pE );\ |
484 |
}\ |
485 |
}\ |
486 |
nA = nA + nL; nFree = nFree - nL;\ |
487 |
}\ |
488 |
\ |
489 |
void nm::Remove( USHORT nP, USHORT nL )\ |
490 |
{\ |
491 |
if( !nL )\ |
492 |
return;\ |
493 |
DBG_ASSERT( nP < nA && nP + nL <= nA,"Del");\ |
494 |
AE* pTmp=pData+nP;\ |
495 |
USHORT nCtr = nP;\ |
496 |
for(USHORT n=0; n < nL; n++,pTmp++,nCtr++)\ |
497 |
{\ |
498 |
if( nCtr < nA )\ |
499 |
pTmp->~AE();\ |
500 |
}\ |
501 |
if( pData && nP+1 < nA )\ |
502 |
memmove( pData+nP, pData+nP+nL, (nA-nP-nL) * sizeof( AE ));\ |
503 |
nA = nA - nL; nFree = nFree + nL;\ |
504 |
if (nFree > nA) \ |
505 |
_resize (nA);\ |
506 |
}\ |
507 |
\ |
508 |
void nm::_ForEach( USHORT nStt, USHORT nE, \ |
509 |
CONCAT( FnForEach_, nm ) fnCall, void* pArgs )\ |
510 |
{\ |
511 |
if( nStt >= nE || nE > nA )\ |
512 |
return;\ |
513 |
for( ; nStt < nE && (*fnCall)( *(pData+nStt), pArgs ); nStt++)\ |
514 |
;\ |
515 |
}\ |
516 |
\ |
517 |
_SVOBJARR_IMPL_GET_OP_INLINE(nm, AE)\ |
518 |
|
329 |
|
519 |
#define _SV_DECL_PTRARR_DEF_GEN( nm, AE, IS, GS, AERef, vis )\ |
330 |
#define _SV_DECL_PTRARR_DEF_GEN( nm, AE, IS, GS, AERef, vis )\ |
520 |
_SV_DECL_VARARR_GEN( nm, AE, IS, GS, AERef, vis)\ |
331 |
_SV_DECL_VARARR_GEN( nm, AE, IS, GS, AERef, vis)\ |