//接上面
# |4 ~) f4 B* z% ?; R+ t$ F6 Mtemplate<class TYPE, class ARG_TYPE>
, U" S% G% w% V2 E3 O; b* SYCArray<TYPE, ARG_TYPE>::~YCArray()
! c- U0 t1 k+ k: E j/ t) S{: ]- V; n! W7 Q) [! ~
ASSERT_VALID(this); if (Ym_pData != NULL)
1 S) i' s% _* r6 A6 K H {% ~/ O3 Q5 f* K x/ t3 u; o! m4 M+ N
DestructAllElement(0,m_nSize);
7 ~4 B7 M, ~: b0 e //DestructElements<TYPE>(Ym_pData, m_nSize);
- L/ _% q+ v" F9 D; w8 Y9 q delete[] (BYTE*)Ym_pData;( k$ N' `2 b/ H5 S5 r+ g3 L! y" a
}
$ g* B/ Q# f1 E# M% G, O}2 q: E* }3 ~6 C8 ^6 o* u. \4 Y
template<class TYPE, class ARG_TYPE>
) l p5 Y) l6 O# K3 h, x# _1 S/ qCString YCArray<TYPE, ARG_TYPE>::GetSign() J7 F+ Y, m" t) `) {
{6 {. t o) u. s" S, f3 C4 i& M
lock_sign=0; X: s' b2 q4 P. [6 H( J) w% q- [
return Sign;
" d' Y+ G/ }6 N. Z2 r}
+ A& i( i5 s7 v3 e% J$ Xtemplate<class TYPE, class ARG_TYPE>
) l, V* ~2 c, ~1 |; n. B3 Hint YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign)
2 p2 ?$ k7 ~$ }{/ F% p- q$ G( k% T3 \1 W( |4 H3 n
int i=0;
2 r: k9 U# x# t4 U- V while(lock_sign&&i<MAXSIGNTIME){! G* P% p' N+ w5 m6 R0 q6 K; o
Sleep(1);! K \$ s: N, a: ]3 z0 R
i++;; z9 T% s( g; p. p
}
7 I) g/ s$ W0 u# q3 b9 B9 f0 _ lock_sign=1;% T( f8 W) U" A3 m7 h* x W W3 |
Sign=sign;
C* q h9 ]& Y) _2 |/ z% C* v7 k return TRUE;
% O! H/ A7 T1 u* A7 h- J}6 V: C" }* V' Q/ u2 c f
//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer
) H$ ~3 l9 i/ u: vtemplate<class TYPE, class ARG_TYPE>
$ V- C' ?/ O! q C- u% N* }BOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)
1 b& ^ ^+ p. \3 V% @{
5 d5 g( v% w& b; R; i if(strIndexNum < nNewSize){) l% S: V% ?$ T
CString* tp = new CString[nNewSize];//新的buffer& E# l* _2 ^1 v7 S! Z [# T/ p3 w/ W
for(int i=0;i<strIndexNum;i++){//把老索引复制过来& a* y. W2 F& J8 @; B3 R
tp = strIndex;1 S, M4 i! `9 r
}
7 ^) w" ]* J$ w) |/ B, @ for(i=strIndexNum;i<nNewSize;i++){
$ L3 i! f$ j# O1 s tp = "" ;
* t1 \9 u- N# H6 g$ X } ( f$ F( [- J- c" H- T+ j/ E
delete[] strIndex ;
; b, M% d" P1 T* V0 W strIndex = tp ;
, ?$ U( B+ d0 ~7 W; l2 `: R strIndexNum = nNewSize ;
8 n9 M: E; @& ]: O }else if(strIndexNum < nNewSize){7 v5 M2 N( h7 { H& D& C7 S
for(int i=nNewSize;i<strIndexNum;i++){
& G9 f& \6 ~6 B$ l; D m strIndex = "" ;* W# J' e3 M3 r8 P4 ]
}
7 @2 ]8 \: q" C7 e) | N( D% G }4 ^6 c8 ^) t+ D( E) H& D8 _
return TRUE;
0 t/ J( s5 d3 K3 b& @}, T7 ]- }2 j& f2 N Q
template<class TYPE, class ARG_TYPE>5 W9 ~. t, @5 n& c5 [( n
BOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/)+ S+ E s) |. {+ s) ~: C
{0 K' w# i/ A! d. [9 J( x* E. s
CString* tp = new CString[m_nSize+nCount];//新的buffer* I `) Q: Q0 [0 Y9 { A. @4 n/ f
for(int i=0;i<nIndex;i++){//把老索引复制过来5 Z' a8 Y3 D7 n2 M) J
tp = strIndex;4 P% E0 c8 z( q$ R. Z+ |6 D+ O
}int j =0 ;% b; e$ |8 Q, n+ g$ K
for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
- |* M5 T* @1 T3 |; g, |% n9 p# r tp = strIndex[nIndex+j];' n: `) D& D; Z- |+ }4 J
j++;
2 q% G0 w J8 F$ q1 o$ y( O9 | }" ?2 j$ C% O9 q; H
delete[] strIndex ;; V9 L( c( V1 J% P
strIndex = tp ;
# G" z* l' A5 O+ T6 `$ Q$ U5 V return TRUE; P; ^+ y/ p4 ] c. g
}
$ S* N' R; P8 p7 |) {7 Gtemplate<class TYPE, class ARG_TYPE>0 t9 h/ D6 R" W2 C/ C! f
BOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex)
1 x9 i6 y( G- A' K6 o& ] I{//在 nIndex 后面添加一个 字符串索引
! j: D, _: b- F s strIndex[nIndex] = cIndex ; F' A7 w, U3 F' K7 D6 L4 e
return TRUE;
6 h+ S0 Q0 o3 Q0 y0 p1 `, H4 f9 K6 k}( y8 ]: }( Y7 Q- p
template<class TYPE, class ARG_TYPE>+ S# m; g1 O2 L$ C. ]) l
BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/)' E7 K S7 Z5 q2 h$ A
{//需要在 m_nSize 变化之前调用!!
0 u0 C& _, a( U6 N0 d$ v ASSERT(nIndex >= 0);' Q Y! z3 S0 \1 M: H" |
ASSERT(nCount >= 0);3 C' _' P, ?' R8 Q* N
ASSERT(nIndex + nCount <= m_nSize);8 e: k" q0 Z( Z1 D/ l: @
int j =0 ;1 |& w* m9 \" G( R, m
for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
3 x5 _& t7 Y- Z D# ? strIndex[nIndex+j] = strIndex;0 O) }( }, R& X; M7 o+ R3 w2 p
j++;
9 s$ Z; g. Z$ z% l; Z* f }" p9 f4 U X7 o# n; l
return TRUE;
" m8 w: L! N+ l1 U2 G6 L- h2 U}% o V# d9 ?) `0 }3 c8 E
template<class TYPE, class ARG_TYPE>0 V# W4 g' n* o2 e5 j: @& Z0 b. a
BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)
7 {. U7 K$ X6 i{
' z( q! L& @6 c% a! t int nIndex=this->GetIndex(cIndex);
1 U5 [/ e3 I3 [ Y9 d8 @7 W return this->DELIndex(nIndex,nCount);1 l- n7 H' _( W, O
}
% u9 M: w# [. ltemplate<class TYPE, class ARG_TYPE>
7 q6 u0 i/ B9 _/ T) Z+ Iint YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex)4 J2 \& q1 G% ~. @% ]& _& n, ~8 P! y
{//得到 cIndex 的数字索引8 I! ?2 Y% B7 r3 K0 D) c I4 q
int nPos = -1;2 O# ^5 O! m! [3 j* ~* G
for(int i=0;i<m_nSize;i++){
$ B1 l$ C" P3 o2 Z1 f! L9 D if(strIndex == cIndex){
% }8 G% m6 U0 l4 b1 X, g- s nPos = i ;break;
: e! e- y9 N' C2 `. b/ w5 [ }
2 g! [4 U- i6 a$ X; |$ N- j }
! u( n% g6 _& H6 O2 d return nPos;* v5 O" W! U) Q$ ^& Z3 o* N& S* L
}2 J; `# Q! i% u% u5 [
template<class TYPE, class ARG_TYPE>
6 ~) T" g; U3 \; YCString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex)1 ]$ s9 ] N |/ p
{//返回 nIndex 的字符串索引
' Q/ ]9 J7 m8 X3 o. \; |# N3 Q return strIndex[nIndex];$ Y+ _8 m% ^; J# t/ b% n4 A: f
}$ k7 s( C0 N: X- X' ^+ |
/////////////////////////////////////////////////////////////////////////////) p& D1 o8 d% \4 M
// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE>
% D5 }! x$ Q/ M. E2 j1 x/ HAFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const) W, I& Z; Y. y# n
{ return m_nSize; }
) |) q8 c* ?. rtemplate<class TYPE, class ARG_TYPE>
" c% F( b W) u2 ^2 fAFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const
' ^$ E% L' [: y" X( S) V) x { return m_nSize-1; }3 @3 b; Z" r0 b: |' V* l
template<class TYPE, class ARG_TYPE>
B. L$ `$ y3 m. h4 nAFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll(): a3 [' \% E% ]
{ SetSize(0, -1); }
' ]+ X5 p6 [: d. Jtemplate<class TYPE, class ARG_TYPE>+ H& d8 i+ U. o: w6 V- m1 a! }
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const2 A& N2 N8 V. W. m) m9 |5 l
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);1 h0 c! U$ w: P0 J* X% p4 z8 P
return *Ym_pData[nIndex]; }
& D& V) b7 [# \/ b7 {, ^# stemplate<class TYPE, class ARG_TYPE>
) A. g0 a r6 z8 l1 ]2 AAFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)
! ^3 v% w4 Q- V5 |& }3 Z& b! B { ASSERT(nIndex >= 0 && nIndex < m_nSize);: y# b/ q9 G' q# [) N9 g
*(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>
K) R, S; N' D+ hAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex)1 Y- ?. D e" V2 S: a
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
& r& S; M7 L9 O7 p8 G9 R0 u+ Q return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>, Z8 X3 e Y/ z: q1 Z
TYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const
0 r2 D/ A0 w/ D) Y8 x{0 O( v k* T6 i9 s$ \: \4 x1 B! [
int nIndex=GetIndex(cIndex);! z* {1 c* i- V- I: ]. n/ Y7 o6 ^
return GetAt(nIndex);) T! X* [/ a( @2 ^0 I
}
0 X+ W8 w; F4 j# w# Gtemplate<class TYPE, class ARG_TYPE>
$ I% z* S5 t3 x, N" j% avoid YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement)7 E4 I6 S# P, N/ N, o1 N
{/ l( l( ~2 K+ P/ c: l% z4 p. G
int nIndex=GetIndex(cIndex);
+ i) |! k# r7 J' n; u+ |; R return SetAt(nIndex, newElement);
9 C$ E8 v: I% I* a3 h* J. g. ^+ C( [}
+ ^* l0 g( L% t v0 z w0 @& m% ~template<class TYPE, class ARG_TYPE>7 Z3 [9 K" r t" {9 s
TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)1 c4 Y3 _! ^ x/ ^
{: I& \+ `5 E% h: d
int nIndex=GetIndex(cIndex);6 |$ e' W! a* w8 p1 A F0 f* Q* K
return ElementAt(nIndex);
y8 g9 m' J% J$ [9 L}
7 d l7 O% e4 \3 \template<class TYPE, class ARG_TYPE>- V# c' P2 G) Q
AFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const
( C( t! S! J" h! T4 W { return (const TYPE**)Ym_pData; }
, m: E- G w2 P2 Itemplate<class TYPE, class ARG_TYPE>( F8 X' ^( z1 Z6 Y
AFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData()
6 P& h9 L- s8 {4 a { return (TYPE**)Ym_pData; }
; k8 A& K4 [) i, u9 Jtemplate<class TYPE, class ARG_TYPE>$ h7 d2 X4 L: S; H
AFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */)) t2 Z3 k% K" H* @
{ int nIndex = m_nSize;
( w ?0 G2 ?* a3 }4 y# l+ L9 V SetAtGrow(nIndex, newElement);& K) C% u, ?+ u7 E: o% r# n
SETIndex(cIndex,nIndex);0 D0 H$ y( L- T2 {
return nIndex; }- C. C% S5 v: V9 K. W' r- @) A
template<class TYPE, class ARG_TYPE>2 u. n1 p# D0 W8 Q# l$ R- h! }0 ?
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const
: E/ D/ ~0 K8 D- G { return GetAt(nIndex); }0 o% ]. e' E8 `3 ~+ N7 [* `- x8 L
template<class TYPE, class ARG_TYPE>2 s A+ ~! v9 o- x+ \
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)5 E+ l" d" N& e1 U1 u$ ~
{ return ElementAt(nIndex); }' X, B0 P0 Z+ [, v T
template<class TYPE, class ARG_TYPE>5 M4 @, P7 s) U2 W
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const
7 Z5 q, ^( l0 j( y{; v6 k) w: q2 [( r
int nIndex=GetIndex(cIndex); return operator[](nIndex);
$ o" W2 [) E. o7 Y4 H7 n}0 u5 I& p) @, s
template<class TYPE, class ARG_TYPE>
: L) U5 P$ A! xAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)
/ \, L* ~3 `9 g; G& l6 L4 K{" t4 y: K* Q8 v% `
int nIndex=GetIndex(cIndex);
$ y; g4 p5 c* X, [+ r( r d4 f- J return operator[](nIndex);
. K; {8 L4 j/ { k}
' `8 L+ h( H: S& A/*
0 O% z) w6 Z' J# htemplate<class TYPE, class ARG_TYPE>
; P/ g _4 x5 T; h! GAFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const
' h8 ?9 I' r. }. S& o{
7 B% ]7 S/ I/ t7 @6 E$ f int i,j;
$ s( i( W: W+ Y, T }0 j [ for(i=0;i<tparr.GetSize();i++){0 x# I6 l' a: k/ s0 V6 [
j = GetIndex(tparr.GetIndex(i));5 ~- s8 s7 Z+ ?% E6 B2 T, g
if(j>-1){" K! _9 A/ C5 @ g
operator[](tparr.GetIndex(i)) = tparr;
3 W; v* p! m. ^: j3 G }else{8 n/ ^3 s% ^$ `& s6 _
Add(tparr,tparr.GetIndex(i));
5 S0 c1 @# \" s. ]* x2 ` }! u% I9 S' R0 k* L% X: N* V) h
}
) T" G5 d, f. G( T. D/ k; c return this;
% k9 B4 c* F- Z+ R, z}
& }* u# C) M7 H% [% q E3 {*/
6 ~8 Z- n5 v! w% x7 W$ s) Itemplate<class TYPE, class ARG_TYPE>
3 o8 E! |* F, v% G ] {( {AFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src)
, Y, ~* [* b1 @+ K5 }$ J. _, b{' F3 N+ b8 }% c9 e+ }& m
ASSERT_VALID(this);
7 h" X% ]3 t3 R' a6 H8 ?& w ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);
, A( ^) N5 m% K# ]/ I for(int i=0;i<m_nSize;i++){% k, m# R1 i& e4 Z) J; e6 e. y
/*将此句修改为内存拷贝*///+ I' J" U P+ J( |# n% p
*Ym_pData = *src.Ym_pData ;; V/ y- [2 J1 z' F5 H
//memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));9 a% w7 V& Q- }+ m# |
SETIndex(src.GetIndex(i),i);- S9 K* [' y4 N( \' i) A3 |6 N
}
x* i" q+ H. f/ f+ r4 c7 \ return *this;
" A0 i6 L0 I8 w7 k- X& b0 v8 ], u' I. w}
: _& E. q2 ~/ G9 C, B0 ]/////////////////////////////////////////////////////////////////////////////
6 G/ \" ?/ L3 j( t1 C7 h4 {// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>; a& Z$ _0 s0 A9 k; K6 d# Q
YCArray<TYPE, ARG_TYPE>::YCArray()( c1 Q: U: v' x! g. @0 Z% W' }/ F
{
4 h( o- a' z+ x Ym_pData = NULL;2 ^ ]- J4 Q7 k9 W( g: K8 J& j8 s
strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
) y' O$ M" e' c5 i' K strIndex=NULL;MAXSIGNTIME=10;
6 E1 U% e- r4 W0 f! w0 }9 ^# T# W}
9 q( Y3 p9 K4 X% G, w; O/ rtemplate<class TYPE, class ARG_TYPE>
/ W. T* u+ C8 y/ b+ n( B2 HYCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp)7 |3 r: H/ w5 n& j' c
{. x" H$ R1 b6 B ~" J: z0 Y
Ym_pData = NULL;+ `2 L3 B$ w( A* I7 f6 O9 I
strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;4 k" H8 W2 k+ P5 l6 R3 P2 O
strIndex=NULL;MAXSIGNTIME=10;% _7 H0 {5 G D( u: J
operator=(tp);) n6 Q7 o9 }* I$ \/ `
} template<class TYPE, class ARG_TYPE>. ?! G! D( j V, i4 ^
void YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy)' U+ K7 Q" C% |3 K$ O" \
{
) W( p5 ]5 Z8 X; f, C ASSERT_VALID(this);) g# S( }* {1 v! E$ [1 {! N
ASSERT(nNewSize >= 0); if (nGrowBy != -1)
6 O5 f: X/ t9 b9 W% O+ h8 ]# f4 w m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){
z. x8 j2 L' l/ {& y$ w* V // shrink to nothing% d( F# v0 T" Z! Q$ M% a4 r. j
if (Ym_pData != NULL){) p% S4 {( B8 \+ l
DestructAllElement(0,m_nSize);- D k0 L% l- v% A
//DestructElements<TYPE>(Ym_pData, m_nSize);
) Z) |3 q& ~. i% j delete[] (BYTE*)Ym_pData;! _6 ?' b, r# W# z5 {! e
Ym_pData = NULL;
- O1 O L' a0 x* R }2 S0 K0 |; u# i! x
m_nSize = m_nMaxSize = 0;. W* @. G6 n; G& P c. q
} else if (Ym_pData == NULL){! h" O0 A( p* V. ?: I
// create one with exact size
$ b: A& V- h) p( D, t9 H/ K#ifdef SIZE_T_MAX
$ S5 U% X8 X5 B( w D+ K$ Y ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow
/ c: x- i/ w+ j) J7 C. n8 |: N7 n% j#endif
) A. m1 K; c2 V Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];
; f: _: B G" T$ F ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);' p2 y+ l5 Z6 {1 |. z* A
m_nSize = m_nMaxSize = nNewSize;
2 u3 x9 N& Z; y% g: o/ } n } else if (nNewSize <= m_nMaxSize){* ^3 l Y! J& [/ }7 }6 }
// it fits
# a; m* k# a _$ [; W S if (nNewSize > m_nSize)
* X9 W ?2 M! F! h& n* g. }2 l$ s {
, S# t3 i# w: G# t& @ // initialize the new elements3 x* W; j& }" N; E$ M6 g
ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);/ b: L+ }0 M U; [* f L Q& C; |
}1 p: @) `6 O V
else if (m_nSize > nNewSize)
6 y N! m/ C% @1 D9 z {) a" h3 p5 c6 k6 l! c9 o
// destroy the old elements9 p) K$ T& p7 g
DestructAllElement(nNewSize,m_nSize-nNewSize);
* E% U. I/ O6 K& X( q n% k //DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);1 P3 [+ G7 e; A, X" ^. A
}
5 g3 D6 `" c7 L; ~) X+ M" w m_nSize = nNewSize;+ p/ a* \7 ~ b+ z: c
}
9 G" y- ^+ g. k f) a, j4 q- J else( T/ R& |% G$ V0 s0 b" O; s
{
" q L/ d0 i- V7 |) H- U# T // otherwise, grow array4 W( o6 u+ T% s; A- b
int nGrowBy = m_nGrowBy;
% A, O* K& I1 K4 _6 G; _ if (nGrowBy == 0)
) s% v4 @# j2 [ {9 m0 c, \4 D+ ~+ ~, z+ k
// heuristically determine growth when nGrowBy == 0
/ S/ `9 P& v/ L" `6 ~" T // (this avoids heap fragmentation in many situations)
4 ?7 d* r1 E$ j6 m! f nGrowBy = m_nSize / 8;
! `! J% t" P& w% j nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);8 B% b8 Q& p8 n& b4 w
}
' g; |2 r/ k( P+ U5 ^2 B4 B int nNewMax;
5 f# k+ [2 Z( M } if (nNewSize < m_nMaxSize + nGrowBy)
* p* Q2 j" C8 O% z- c nNewMax = m_nMaxSize + nGrowBy; // granularity; P( g5 Q, i& W8 Y' Y; D! w
else
4 e8 a4 G$ L; V/ ^+ i nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around. }7 g$ f1 f0 c% r( w9 Z; e
#ifdef SIZE_T_MAX( }9 F' j0 J$ Z' L
ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow
; I7 e% w# n" b7 _, V#endif& J" B7 F, @' x- ^5 {. ]. _
TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old$ v1 k5 }% d, |
memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements8 J1 c9 H6 a$ T' w' O3 @
ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");9 k- S7 z8 S2 O
delete[] (BYTE*)Ym_pData;
& z: }; s9 g- C. B8 O Ym_pData = pNewData;% O/ k. N3 F3 ?+ N5 E
ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called)0 T6 v. m3 q; E) B8 P4 f# Y! J
m_nSize = nNewSize;
5 P0 N7 k5 y) S# k) F" h m_nMaxSize = nNewMax;* _ p; _; o, Y: m
} c# E9 _+ F: A% j7 }; O
SetIndexSize(nNewSize);
* z4 d8 i5 B" g" Z}
# t3 |" U- g2 A4 m& G |