//接上面 , W" l' t0 @9 C" U% n4 K5 b
template<class TYPE, class ARG_TYPE>. u$ E* r' b* `$ @
YCArray<TYPE, ARG_TYPE>::~YCArray()3 K1 R* c5 v$ }0 U9 ^
{
5 m, `0 ]: _5 E ASSERT_VALID(this); if (Ym_pData != NULL)6 ~) Z5 y: V5 T9 j9 |
{4 U: Y O8 w! Z* d) f4 Z9 [ B/ @
DestructAllElement(0,m_nSize);4 u/ |) t& _7 E- F2 M9 v4 V
//DestructElements<TYPE>(Ym_pData, m_nSize);+ M. r& J2 \6 Q+ t4 h k4 _. H* V- m0 r
delete[] (BYTE*)Ym_pData;
6 b* f# @9 `+ h7 _) `+ b/ e }
m) Y2 b7 i q" H}
1 J" [, U2 P9 u1 a; z4 Ptemplate<class TYPE, class ARG_TYPE>
( G; I5 D' u5 F/ H. E! B. `: WCString YCArray<TYPE, ARG_TYPE>::GetSign()' ^2 ]+ @' ?5 [& B
{
4 s0 z$ \* n `3 C0 \$ ^6 z$ v lock_sign=0;5 B/ k7 s) J# y$ r. P# o9 ?0 X) a4 T$ @
return Sign;
# [# ]% c* H: \3 k& I% {}
9 J/ @, f' J$ L- ~$ p, ntemplate<class TYPE, class ARG_TYPE>
1 y' C; O( E7 |2 K1 jint YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign)
+ }7 \% P6 x2 o. b{
2 R) u- [# o5 D: S$ \ int i=0;
+ \ A* r6 U( c; x0 t while(lock_sign&&i<MAXSIGNTIME){
! @" `: S- v2 h2 ]6 k2 M Sleep(1);
0 j4 I$ t: _0 x" s/ @5 h9 I! P i++;: C4 o. N- m6 n9 l1 d" i
}( S: P9 I, ~# R8 i! b
lock_sign=1;; a' s: [% s, C1 `
Sign=sign;
W$ D _( E, \ return TRUE;+ p, {1 m* R4 L [$ _
}
$ x, c+ m% B( q+ B& {//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer
! d4 a& G0 E; d5 _8 Y3 Ftemplate<class TYPE, class ARG_TYPE>
8 R, G4 V1 G# z g& P, DBOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)" g; s6 P1 l K7 W+ i4 M8 v( ^$ N
{6 _ [0 h! [1 B: ^) r/ Z
if(strIndexNum < nNewSize){+ R7 I$ Q; B7 `& x2 Z! ^" j
CString* tp = new CString[nNewSize];//新的buffer
% R+ O9 A' s5 W' F0 a4 @6 H" A for(int i=0;i<strIndexNum;i++){//把老索引复制过来/ U* ?6 c. D# u/ ~( c
tp = strIndex;
$ b& e, J3 `+ `" V" s1 z }
! C; c, o1 s: S: D$ D for(i=strIndexNum;i<nNewSize;i++){
$ B0 l7 X4 {, E8 k tp = "" ;4 ^0 E1 D/ }& `& Q+ B) v# ~
}
" r- P/ g6 y d1 x9 _ delete[] strIndex ;
$ }) w& d: Q: Q1 m# A! K3 o strIndex = tp ;! }/ d7 o1 c' D5 p7 R
strIndexNum = nNewSize ;
2 D9 }5 p3 z& h* C: }1 N% f }else if(strIndexNum < nNewSize){6 Y# t# R; _: w( v! j5 W
for(int i=nNewSize;i<strIndexNum;i++){
) ]( p/ S) f# x5 ^' E strIndex = "" ;* ~( i4 B2 S2 `
}+ ]- m; h5 @6 s8 k P
}
h+ Y. U7 C. W0 F' f* j- h return TRUE;1 l' _) k9 l1 u8 x- C& h& g! Z9 ~: s
}; Z5 v+ T+ i% g1 o: r6 Z
template<class TYPE, class ARG_TYPE>
" K) f7 V2 q+ W* YBOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/)7 P# m" t, j9 x2 H+ h
{: A" i8 G, _. O" `8 Z7 J5 I
CString* tp = new CString[m_nSize+nCount];//新的buffer$ ?9 W$ a& ?' J( ]. S
for(int i=0;i<nIndex;i++){//把老索引复制过来
# o1 J I R( C w6 f8 L7 Y, w/ s tp = strIndex;
/ B* {. W r5 g }int j =0 ;
# ^) `5 s# u! _ for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
, L6 N5 q! I& r2 v5 L3 G tp = strIndex[nIndex+j];
; D; K: o* {/ L7 v! N& C: t$ h7 v j++;, a5 o. V1 M2 O/ I" ~; u6 n
}8 m: b3 d/ R. A5 ~) E2 T D$ i8 Y
delete[] strIndex ;; A+ e/ P" o0 ~% b+ }
strIndex = tp ;
/ E. @# D; [2 k return TRUE;1 U$ g- V+ M. I7 |" e5 ?' {
}/ w6 z/ H5 M( F9 j4 ^
template<class TYPE, class ARG_TYPE>
2 k2 E+ J) Y# ~8 R# I, }& g5 g, D$ BBOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex)! {( i2 a/ @2 G) ~+ B& `9 n
{//在 nIndex 后面添加一个 字符串索引
/ N t9 V& u3 u" @! d6 V strIndex[nIndex] = cIndex ;
& ~* _2 z) V- t3 r! J! S# v return TRUE;. k0 n1 y* G: B8 ~3 J8 _4 P
}) Y) g! H; P `: }0 h
template<class TYPE, class ARG_TYPE>0 K0 t, a2 {* n6 G# N
BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/)8 v+ T m8 p6 I! k3 P8 K
{//需要在 m_nSize 变化之前调用!!
5 J( S$ y8 I( p ASSERT(nIndex >= 0);
; b5 z8 l3 O" w6 g Z. d6 n1 l ASSERT(nCount >= 0);
. R) Y4 z- F: M% I ASSERT(nIndex + nCount <= m_nSize);
7 ^% O; D; O3 z* l int j =0 ;1 H0 T: `& K; l2 k3 X" V! }& I6 x5 w
for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来# w4 v9 L+ G9 Y8 a
strIndex[nIndex+j] = strIndex;
# b$ @' k, J5 A* b0 f j++;
+ p4 u; J3 f( L, y, C }. v: @) O, X# j% W
return TRUE;* y' U( y1 r8 E/ v7 I0 y$ U
}
. j& k- L4 S# z% K3 a) R" ?template<class TYPE, class ARG_TYPE>' w2 n% o4 @* w) O/ r9 u% @. p' n$ D
BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)4 p, S1 v; H( ?
{
3 n9 l( X0 q# ^+ V6 v; j int nIndex=this->GetIndex(cIndex);
3 C: _: a4 b/ r6 [3 `9 Y return this->DELIndex(nIndex,nCount);1 k& e' S; N" y$ h8 ~2 h. @4 @
}
2 F( q X5 L$ P. h, \1 s; wtemplate<class TYPE, class ARG_TYPE>$ R8 Y' G6 ~' z5 j. j) }+ M) ]
int YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex)
1 J9 A' W. } h$ k+ N9 y' N{//得到 cIndex 的数字索引
- w2 c$ k* B* l } c+ i8 ^% i. f& t int nPos = -1; {7 v l' z8 O. B- y/ x) l8 F3 {& g
for(int i=0;i<m_nSize;i++){
1 N5 v/ w' ^3 Q$ b9 e: ` if(strIndex == cIndex){
8 k- N9 t1 s! l* L9 O5 c+ v3 [ nPos = i ;break;7 J* t" D" k1 `" S- U$ {, ^" {6 W
}
) c& h+ R( T, A' V' E }* d! j1 [8 h( n, G" d& k1 K
return nPos;9 e0 \* z$ ?6 v5 I! D
}' _& {, b" t) n: u, \
template<class TYPE, class ARG_TYPE>3 {) ?) B- A& J2 K) A& ?) K5 Z
CString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex)
; O2 _+ z. D! W$ E) f$ }{//返回 nIndex 的字符串索引( |7 ?' e( f# t' D* l
return strIndex[nIndex];" y: T) R* X0 O) S9 h
}
3 f6 e+ [5 z5 }! F/////////////////////////////////////////////////////////////////////////////
4 b* n7 c3 e8 `* g$ B4 S// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE>1 N$ b# e5 h' D
AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const0 I/ I1 a; i+ N' U. r7 c# k" O
{ return m_nSize; }- _$ t4 W: _- a# a7 C: d
template<class TYPE, class ARG_TYPE>
5 v s3 T. x+ `! u4 xAFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const
+ A- w- y5 {5 _$ J9 i' }/ y { return m_nSize-1; }
/ y% b( k/ u; x9 R- stemplate<class TYPE, class ARG_TYPE>
! \$ @( d$ h: I/ a0 V6 ~# l1 GAFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll()
Q% ?& B3 W1 o4 P& E$ z8 y& g( k { SetSize(0, -1); }
. }/ |, E8 \0 Wtemplate<class TYPE, class ARG_TYPE>
" \( A* M2 [, b1 d( @$ @- c! [5 h! xAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const
$ I. n1 D; ], I+ M& y# ~ { ASSERT(nIndex >= 0 && nIndex < m_nSize);
3 S7 p8 k# j( b2 b4 E# C return *Ym_pData[nIndex]; }
& M& V Y' L2 I3 w- g itemplate<class TYPE, class ARG_TYPE>
7 u+ G4 M* ]" a0 ]1 S$ [9 NAFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)
2 Y, d. v" ^3 p) H. n7 p7 } { ASSERT(nIndex >= 0 && nIndex < m_nSize);% d' f6 n0 P" c5 E0 b5 \
*(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>. e" V; z: U% ]3 K) T
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex)
/ T$ L2 D' O# k9 q" q { ASSERT(nIndex >= 0 && nIndex < m_nSize);
6 R3 n2 x' y7 T+ ~5 m return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>7 b9 |6 V8 u- F% a; x) _
TYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const
! o0 A. m0 ], L2 u8 A{5 @' @& m4 O# m3 }( }' l
int nIndex=GetIndex(cIndex);
) |$ b: R" M: H, @9 x; y8 N, H$ ^ return GetAt(nIndex);
" q% g) H* p5 k* I1 U}3 O, _. f+ n" _- e/ P6 w( z. a! n
template<class TYPE, class ARG_TYPE>
) \, k" a4 Z( D( [7 C* ivoid YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement)( m; G/ c; C, z% R- }
{) c8 c$ W" ~. c/ }" y% c
int nIndex=GetIndex(cIndex);
3 k0 m {. }# n2 b4 [* H8 e return SetAt(nIndex, newElement);/ T ~: ?: I3 \& Q% J+ o* F4 N% w" G1 s( i
}: u$ K g! H% G9 k
template<class TYPE, class ARG_TYPE>
7 {1 V: R6 s5 V! \- dTYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)7 ]$ g- ~2 E, L
{
, R1 K$ M A1 x' i2 ]6 y/ q9 B int nIndex=GetIndex(cIndex);2 v- g& Q0 r, u" {
return ElementAt(nIndex);5 j0 C) d5 U! q- t( W# _6 K `. v
}
$ B* \" F1 K3 }' `! D$ V' u6 P3 Otemplate<class TYPE, class ARG_TYPE>
[, \6 O4 V2 [3 O' NAFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const
; ^0 G. B* [# w# Z { return (const TYPE**)Ym_pData; }+ @2 F3 x7 x; _" g: l
template<class TYPE, class ARG_TYPE>- ~2 d' A. g( n( Q$ c
AFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData()7 ^3 ^- \; h5 N% @8 v: F
{ return (TYPE**)Ym_pData; }2 M: d) R: x( \3 B: n
template<class TYPE, class ARG_TYPE>
4 z% `+ `4 U+ {8 G( W# |6 w: w$ A7 rAFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */)+ Z+ Y$ \8 g2 e5 Q- r7 n
{ int nIndex = m_nSize;7 B; z0 C# w0 `3 {! E
SetAtGrow(nIndex, newElement);
1 G( Q. s! o; V) t- I: t3 ?3 j$ ^6 G SETIndex(cIndex,nIndex);
8 I; I$ t5 c* u2 j return nIndex; }% V* j0 y5 C8 W8 j: G& F( p
template<class TYPE, class ARG_TYPE>& b( c( C7 \' J% h" `
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const- y. C, r* Y4 Y3 T# J; H6 }* X
{ return GetAt(nIndex); }& b0 `& Z; q6 ?" j) w: m
template<class TYPE, class ARG_TYPE>( ~. ]' V9 o% A5 C6 H
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)) ]8 ~- H8 y1 O+ }2 i
{ return ElementAt(nIndex); }& I! Y' s% a1 s$ n! [* p
template<class TYPE, class ARG_TYPE>
# a: `. g# g; Z; @7 e7 v8 yAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const
. d" A9 d# [" W8 o$ e* o0 M{
+ n4 D0 a+ \7 x& L0 I int nIndex=GetIndex(cIndex); return operator[](nIndex);. B" Q1 `, a# F" A! ^" l
}
5 i4 u* O* G3 {/ P3 B4 H, U9 q# ^template<class TYPE, class ARG_TYPE>
* S0 ?- [& w& NAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)
) D z/ j8 c5 S' T{
) z' e. J" }/ q$ K. q- C int nIndex=GetIndex(cIndex);5 l% F9 d2 X, k8 S: q
return operator[](nIndex);
' w- o8 ?2 Z& }- ]' k. X" C}
; @, e9 a) R, o/*4 T) s3 Z& _3 t, W( y5 o
template<class TYPE, class ARG_TYPE> q, i" t8 Z( N9 n. u: l [
AFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const1 n/ n! D" J: s9 O( k2 @
{
5 s9 v5 Z0 O- [3 ?0 W! _ int i,j;% L' v: }0 j. J* X) T- E
for(i=0;i<tparr.GetSize();i++){, w! g) V7 H' }; j9 _( ]
j = GetIndex(tparr.GetIndex(i));
/ M/ Q: s! R/ ]" C if(j>-1){
7 }- e8 ^( |/ f! u& D- F! \ operator[](tparr.GetIndex(i)) = tparr;0 A3 p2 ^" V& M7 t
}else{9 O% P& L) H8 s+ X
Add(tparr,tparr.GetIndex(i));9 N: A4 q& X, ^( l6 S
}* d& W9 ]2 B% u. B
}
. d' G* A$ l0 J+ z$ E return this;5 [' M- {0 I1 ~+ j% N: g" W
}
8 A( }% v2 `4 j, f*/% i: c3 x7 ]: F6 Y& ~
template<class TYPE, class ARG_TYPE>
5 p4 A) M% }' Q, _) O) t8 PAFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src)
) K+ q% h1 M# p( L! X+ B4 }# J, L; \2 C{
, S c5 u ]9 q; R( `! J ASSERT_VALID(this);) J: w* {" m s) G4 p
ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);
; y% k' @* k( o* d6 k" L: q for(int i=0;i<m_nSize;i++){2 F; `' S8 m3 X- q: _: A' d
/*将此句修改为内存拷贝*///
" ]/ f, K% o9 t9 o6 w- p% F *Ym_pData = *src.Ym_pData ;0 H) y' D4 {5 `8 M3 Q; N) i
//memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));
7 G, a k0 j: R' x SETIndex(src.GetIndex(i),i);* C9 a" K7 P8 b, A3 P+ z
}! h! u/ i: j, l1 y- x
return *this;! j) s9 z8 i: ]' @& n' y! D
}% i% |& P7 j9 v' f2 A6 o; T2 ]
/////////////////////////////////////////////////////////////////////////////
# R' S: E1 V! w2 |4 a* p& y9 @// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>
p' h+ e0 w6 EYCArray<TYPE, ARG_TYPE>::YCArray()
! J) }8 Y \! e{& H8 q0 ?4 o' |% @) i
Ym_pData = NULL;1 k& @5 [2 x R4 p8 w
strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;; q5 E- I% ?6 l4 b4 p+ E
strIndex=NULL;MAXSIGNTIME=10;1 o; `1 F s2 m9 l1 _
}; y7 F4 g) F" x" j& v* {& j: e
template<class TYPE, class ARG_TYPE>
" } ]$ x8 A7 n9 m' _YCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp)9 r. c) n6 y- q8 }) _/ n6 Z
{! X. i. y% {4 k) L
Ym_pData = NULL;! p$ j$ q4 W7 a' e, Z6 F S
strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;0 t+ G% g, c( l. j1 s
strIndex=NULL;MAXSIGNTIME=10;
& O* q2 g7 j; j* h0 r operator=(tp);4 S$ m7 x* O+ i A9 Q
} template<class TYPE, class ARG_TYPE>
# {5 R+ Q1 y' i; [: qvoid YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy)
& f4 W; i" v/ s" G5 k* w{
, ^1 Z6 K' g& T0 L, v8 W ASSERT_VALID(this);" ?! G D: K! O* _& m
ASSERT(nNewSize >= 0); if (nGrowBy != -1)
) ~$ V' I, J# l2 j3 Q7 w; Q2 X, ] m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){
S, n: B- e% j2 X R+ d7 C0 O& j // shrink to nothing
; ~, z: T) h, [6 r" F/ n( d if (Ym_pData != NULL){
- l* Y+ I; c5 k- o' K" b& l DestructAllElement(0,m_nSize);
2 f. r5 F v2 C/ q8 P" [1 j6 T4 ]( _ //DestructElements<TYPE>(Ym_pData, m_nSize);
# Y/ a- E# ?, x* y& x delete[] (BYTE*)Ym_pData;
1 |( k/ l0 v. @3 L& H3 I7 p* X5 h Ym_pData = NULL;
, x4 f: m1 E2 @& ~% t' g6 K8 s7 P }) o2 r" v8 ? \# t! o
m_nSize = m_nMaxSize = 0;3 R: E0 S: L6 M. d: B4 T
} else if (Ym_pData == NULL){
# I" K- E) B1 f h- b$ S! h1 t6 m // create one with exact size3 u n- n/ M& X0 X, W2 m
#ifdef SIZE_T_MAX
5 Y! U3 T6 a1 ]0 n- j+ @/ g ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow0 B+ ~! @6 _7 b- L- s8 F
#endif
% i ]- w7 N" Z3 i Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];
; l# K! _ w8 R ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);! {: {. M3 @" q8 c7 X* `# S* Z
m_nSize = m_nMaxSize = nNewSize;4 z, k, S" z/ @# I) Y0 W1 ?
} else if (nNewSize <= m_nMaxSize){
, {& K$ \* n, l3 P( `/ L7 U2 y/ L* g3 u // it fits
3 [# M8 Y0 C& o" N' h if (nNewSize > m_nSize)4 j. |* z8 O& b$ z( H
{
; P: q: z. V( L- _ // initialize the new elements
( C' V) d2 d2 {, i2 _! V ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);
# Z" P# x- X7 j, p4 c9 a }
' I( T+ |6 m" x9 q else if (m_nSize > nNewSize)- V7 R; Q$ R9 F0 i- R: O
{
1 m4 S5 S, ^2 f# s$ |) l& B" M // destroy the old elements
& A4 _5 P( S1 O- d DestructAllElement(nNewSize,m_nSize-nNewSize);- W- r: Z( J" ~) j3 f# E" l$ a
//DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);
. {* o( Y* j( A& {# g6 h } D7 ~% l. N& x7 u/ o: `( G9 i
m_nSize = nNewSize;5 q4 Z5 e$ Z/ | Y" ]
}! f4 P9 V% A% q% l0 O8 \+ S0 }9 h
else4 n F6 B( E0 W2 [5 c
{7 ?; {- p! \- s2 g/ R- u
// otherwise, grow array
" P4 i m/ _) h( C0 d5 T0 v int nGrowBy = m_nGrowBy;* u- q& a4 |- z3 l# ]+ S
if (nGrowBy == 0)
6 u# a; P: `" U; K {4 t0 C+ s/ N! j' x6 l! T
// heuristically determine growth when nGrowBy == 0
8 s& P, b5 O) j. u2 N, l& @! _' n // (this avoids heap fragmentation in many situations)
, x2 \( X7 w" k; x7 I nGrowBy = m_nSize / 8;
4 ~2 Q# R' v4 u' q2 m% U6 i nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);
) |" `5 p/ r/ R1 Z) X }, O: z! R( N1 s( S0 J* e
int nNewMax;
3 F& D6 L: D9 t+ |. y; ] if (nNewSize < m_nMaxSize + nGrowBy)4 V. Z Q1 ^1 e' t+ X/ [
nNewMax = m_nMaxSize + nGrowBy; // granularity) o- u, a. n% I% s! M2 ]
else" @( R6 b& }# m. _
nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around
3 q& o# l( h3 e2 T#ifdef SIZE_T_MAX
. A- a$ |7 V8 z" N. Z1 `. s: P8 ` ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow7 e$ M; f9 H1 W. N" e' P5 [. m' J
#endif
) a3 b3 |$ |3 O$ p! | TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old
- z+ J* a G+ A7 L& L7 W/ ?$ H memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements4 ~4 ^! d- K" T# Y6 S
ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");
8 s" ^$ ^) H3 U! ~+ z- v delete[] (BYTE*)Ym_pData;2 N( [$ k9 t+ L# [; K
Ym_pData = pNewData;4 A5 k; {% q) b+ K8 a; I8 N
ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called)
6 L8 X( ]$ z/ ~ m_nSize = nNewSize;
/ o8 d% G7 y& B) ^/ u, \+ V& x9 ` m_nMaxSize = nNewMax;
# ?6 ?* K: N0 W$ d1 K& V }
7 v4 g3 ]( Z- m. X- o' n SetIndexSize(nNewSize);- d# H5 V0 w/ E( P& P* s! v _
} j: ]' L O; P m/ u. ]6 d* c: s
|