//接上面 ' O* Z- C" V, p" l: n' Y
template<class TYPE, class ARG_TYPE>
, H" ^. B+ A- _ A3 C6 O' D$ _! N* rYCArray<TYPE, ARG_TYPE>::~YCArray()7 E" x1 r P) R/ A7 @; s5 Z
{ O) Z9 M. e( M
ASSERT_VALID(this); if (Ym_pData != NULL)
% p2 l; W4 }. r {" y/ X0 P* g! S1 a7 }! P
DestructAllElement(0,m_nSize);: y: E5 c; k1 M0 q9 T, ?8 p- A
//DestructElements<TYPE>(Ym_pData, m_nSize);! D& f( `& S2 d9 T& N
delete[] (BYTE*)Ym_pData;" `' N$ W; z( B% X: n
}
) C$ O; T9 \4 H% l}% E$ C/ B. m; |2 |# E( E' U
template<class TYPE, class ARG_TYPE>
3 ?* u% b8 R/ l; L8 { tCString YCArray<TYPE, ARG_TYPE>::GetSign()+ x# u1 ]% k+ u2 t
{( Z1 o* L0 `; }' P1 M# b
lock_sign=0;, D. _9 C0 Z: S( K$ O- H: P
return Sign;
' X$ N1 i9 J/ d}
T0 D, Q* Y) g0 z% Dtemplate<class TYPE, class ARG_TYPE>8 H1 w: r9 p q# d
int YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign), d' v4 Z' H8 `) O4 O
{
, D6 E- {2 P5 S, i- P8 @! x int i=0;0 Q$ J9 ~" t5 L# ~% i" D$ E. t* t
while(lock_sign&&i<MAXSIGNTIME){5 R6 ?/ F) _0 a9 j
Sleep(1);: t) N/ w5 [$ P; U
i++;+ Z* z- k; W2 y2 F
}: g+ F8 {8 r7 V& o# k( ]$ l
lock_sign=1;
9 Y0 T" c- B5 p. G6 f Sign=sign;2 x7 p: z3 j) Z& ~0 s
return TRUE;6 x3 E+ Q9 X: H/ i* F! \4 h) D3 ] ]
}
5 Y8 D7 k Y1 l0 `+ O- |//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer
; t- r) l7 h# t& r* }( g. ]3 U2 C# otemplate<class TYPE, class ARG_TYPE>/ T7 M5 \7 c& [' i1 o& R G
BOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)( S# H5 S* l: s, k$ X
{
; L5 H( d% z D if(strIndexNum < nNewSize){
8 z* b0 T, `$ e, T2 U CString* tp = new CString[nNewSize];//新的buffer
. K' l: e* A5 g1 {( i3 g for(int i=0;i<strIndexNum;i++){//把老索引复制过来
; X3 E7 J# k4 S$ n2 t, J tp = strIndex;
- ^' {; s, |; o4 c6 i }- S' |0 G S$ F2 v& Y! N# U4 e
for(i=strIndexNum;i<nNewSize;i++){, q) F7 U) _0 t. r: M% k
tp = "" ;4 e8 G4 E- x J: u; q: n5 y; J8 u
}
?* \6 W/ r6 @ delete[] strIndex ;
& J3 x& t' G& a; h' T strIndex = tp ;% j' `2 Q: w5 B
strIndexNum = nNewSize ;' N/ j! ~6 w& Z" K8 \
}else if(strIndexNum < nNewSize){& u2 k( j: s! }; a S, { }
for(int i=nNewSize;i<strIndexNum;i++){
9 G5 y8 _, |8 J. l- t+ G. `2 _ strIndex = "" ;
" ?' a8 Y& I: a* Y }( Q; i# V2 K" R; i5 M
}/ n( g( T; v& T W% F; i
return TRUE;2 U4 ?+ \% @- Z
}
6 J: p! h: r& u! O G& qtemplate<class TYPE, class ARG_TYPE>
8 c ? v% I8 PBOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/)' Q7 S2 e+ ~) U0 [7 L+ t3 K. u6 K
{* E [% k0 O2 ~! X& _
CString* tp = new CString[m_nSize+nCount];//新的buffer
# g& M2 \0 q9 x. B+ f6 n' E* @ for(int i=0;i<nIndex;i++){//把老索引复制过来
* R& N& d* U6 u6 J$ o tp = strIndex;9 e: P5 P" v5 Y. c
}int j =0 ;; C9 w: H$ ~6 `: ~; L
for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来6 e- b' T6 F5 E+ ?" @! x% E( w
tp = strIndex[nIndex+j];
6 W" U; ^: a. H$ `" B5 a6 w# C j++;
# ~' \! d; ]9 \3 N' F% e2 ` }( u) a0 j7 P" v1 J7 s# J+ G6 D
delete[] strIndex ;
* i9 M8 v* ~9 Y/ y/ ?# d" c! z/ W& A9 } strIndex = tp ;
7 b0 P s; f1 M* S return TRUE;
. a( m/ K1 q1 F; U6 M}
3 ]& ^# G+ |1 }. btemplate<class TYPE, class ARG_TYPE>
5 D; U% g6 S2 w1 o* H" _. B9 _BOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex)9 Y q0 @; B9 T( F( I+ @% Z! @* u
{//在 nIndex 后面添加一个 字符串索引! a' R2 n3 C; V* U* I+ k1 s
strIndex[nIndex] = cIndex ;
4 c& j4 A5 O' s! Y2 W. X) H return TRUE;
0 V2 n8 f: A3 b5 x}
$ a4 U* u7 l$ ltemplate<class TYPE, class ARG_TYPE>- b* S/ e) F6 T% T n, e! Z4 {
BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/)0 V4 q, x. Z' }( t* }3 U8 w
{//需要在 m_nSize 变化之前调用!!$ n1 \' k; J0 l. d. D
ASSERT(nIndex >= 0);
8 t& @; q/ @. {: y8 F" d ASSERT(nCount >= 0);
, h# v6 p4 @" v ASSERT(nIndex + nCount <= m_nSize);1 r* k( n6 [. F& Z4 Z4 v
int j =0 ;
* B" Z3 L: M! Q) G/ W7 C" @ for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
0 F( I% X2 R0 B$ Y( y9 M" ]: V/ X' E strIndex[nIndex+j] = strIndex;
" ?% ~2 _0 Z8 ^/ ~ j++;# \' N- K# p& [/ T( C
}
5 E1 G, G! Z! a return TRUE;, S' @7 u" n- l* O7 g' g( f; n; R3 C
}
- s+ |. D; F: E* H9 Vtemplate<class TYPE, class ARG_TYPE>
. J$ O4 W: g( w6 A; O- @3 [BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)- @2 K, l) f2 {' W" w7 ]3 M+ s! n
{
* w6 f4 |( u* ?; L% d int nIndex=this->GetIndex(cIndex);
( N- F- u, Y& X+ C$ A8 d+ l return this->DELIndex(nIndex,nCount);/ c0 P- ?1 }2 \5 G$ z% Z+ l; w
}
! F% f. I# i4 `# e8 R8 n' \template<class TYPE, class ARG_TYPE>
# K# K9 N( ?4 ]4 Z& ]int YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex)$ W/ \) n4 C& }# L5 b
{//得到 cIndex 的数字索引
! `) ^, i4 K& F int nPos = -1;
" e. I2 h' m+ y/ r6 D( X for(int i=0;i<m_nSize;i++){
) Q) A4 K. G2 B" P1 @' a: M4 H! C9 p% L if(strIndex == cIndex){7 C0 W$ g8 E2 D$ S0 t# a( C
nPos = i ;break;2 c* j0 T+ w! D* y! q
}
/ Q0 y) O2 [$ T- O7 n }
7 S( V# |+ B& I. V% T6 f" U4 ~ return nPos;9 Q8 y3 P$ d4 I3 b
}1 s4 |) b; y" D" _
template<class TYPE, class ARG_TYPE>
; O# i% D" Q: v; n" v8 dCString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex)
0 c7 b+ B( G3 |1 s* t2 a) |5 s" y{//返回 nIndex 的字符串索引* C, J5 h$ `. X8 D' {
return strIndex[nIndex];5 C& ]# k& T; X
}
J+ G7 s x$ p# l+ V6 \3 p: W/////////////////////////////////////////////////////////////////////////////
/ s; d! E7 W" K( W9 _7 U4 H4 Z// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE>* ]6 i* W+ U: b }: C' t/ t' y W
AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const) X: W9 I% J1 h$ c
{ return m_nSize; }
3 L. k6 Z) B7 Rtemplate<class TYPE, class ARG_TYPE>
6 m5 q H) m R# S% A3 l6 JAFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const5 ?4 D- c8 u1 y ?9 x
{ return m_nSize-1; }& b6 n& D1 N% `4 k1 q* }
template<class TYPE, class ARG_TYPE>
" ? d+ t0 A4 U, U6 C* C% G7 aAFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll()
k/ u+ M: y: W; E { SetSize(0, -1); }3 z. f3 k6 J0 Y" p9 g: I, f3 ~
template<class TYPE, class ARG_TYPE>
, t& M7 G; O, z, Y) ~9 vAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const
( m0 t m0 `" `" | { ASSERT(nIndex >= 0 && nIndex < m_nSize);4 }" p+ [0 n6 z9 P8 L. K
return *Ym_pData[nIndex]; }
" b7 ?5 \5 a* Q) ` \template<class TYPE, class ARG_TYPE>
! K) s# H: c# I. w d( m) EAFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)# ]" o# D+ o& \! w- p: @1 W
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
7 {' _1 s" P" c/ l, {) J *(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>4 _1 b" m( g. Y* y
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex)
) J/ F5 ]) U7 P2 Q1 ?, g* T% ?2 A { ASSERT(nIndex >= 0 && nIndex < m_nSize);: q. }" u l; D& r
return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>! x9 k1 _0 U8 \ l$ u0 L
TYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const# f* k/ H3 x( \) ?& Z% N3 q
{
5 q; a, f/ P+ ~; \& p int nIndex=GetIndex(cIndex);
( a0 x& L/ D" P+ l' v return GetAt(nIndex);
* u6 J1 u8 v/ N. L) i4 U}
: R) i1 |9 d. Z4 Ctemplate<class TYPE, class ARG_TYPE>
) U5 \- X" b7 [* r" I: kvoid YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement)6 R! \8 g; f0 y! S7 J# g
{
+ H4 h! [1 L* a! f' Z# O int nIndex=GetIndex(cIndex);
' D. V" Z' I% t! T5 E: l5 }( S return SetAt(nIndex, newElement);& y$ ~& i2 Z& Z
}: X. k0 ]2 Z5 H- {( \8 r1 H$ y
template<class TYPE, class ARG_TYPE>
; Z4 @: O7 N6 g+ N# ^TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)! B1 p+ I: e7 J q5 \$ O
{
@4 D8 e! M* r- D' I int nIndex=GetIndex(cIndex);7 y. T# U g7 w0 @; a" \4 @8 S
return ElementAt(nIndex);
" ~; a+ I% R6 E}' y- t. o1 D( ^, B7 y" N
template<class TYPE, class ARG_TYPE>
8 l% Y( R4 _0 t2 P, S; |AFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const" r& J3 o% ^! a) S$ V
{ return (const TYPE**)Ym_pData; }
) L' g2 c: O7 b# ?2 R$ F* {# {. u) a0 vtemplate<class TYPE, class ARG_TYPE>8 p8 i# w6 L1 U" Q7 {
AFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData()0 T7 |1 \0 G3 ?, p. I; D( y/ ?
{ return (TYPE**)Ym_pData; }0 g+ E+ S' f* K" f% z
template<class TYPE, class ARG_TYPE>
9 ~: F' r! J7 y1 \5 p. A7 OAFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */)& {( k/ P+ y. O5 u: D! X7 D
{ int nIndex = m_nSize;, H' Z/ Q6 z) ?- q
SetAtGrow(nIndex, newElement);7 A7 R% U+ `( m4 k0 K3 |7 H8 I
SETIndex(cIndex,nIndex);3 g( A6 y) R- q' \& ]
return nIndex; }
t8 w \( ~( _) g* s8 c" c3 Qtemplate<class TYPE, class ARG_TYPE>
! _, E. s. P! Z3 ^" [AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const
5 q! G8 ?+ _) L% S1 D$ |) F) G { return GetAt(nIndex); }/ G9 L2 O* E! m# Y/ O$ T( t5 n
template<class TYPE, class ARG_TYPE>
( v2 F; H4 E% Z1 \/ W" E4 KAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)
& Y0 k# z( X- _4 @$ W { return ElementAt(nIndex); }
4 }) j/ l, v3 c9 Ytemplate<class TYPE, class ARG_TYPE>
7 j6 l `. \: q) _- W, wAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const
0 L$ b y9 s! V/ ?, F- R{" y! V" C. r8 q' ~4 ]
int nIndex=GetIndex(cIndex); return operator[](nIndex);
6 u% k5 k/ x1 B}( ]: V3 Z8 a, p |' E
template<class TYPE, class ARG_TYPE>7 K: o& h- h3 x
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)+ f5 O! k# s% f
{
$ y8 L: d* ?! h. R. @ int nIndex=GetIndex(cIndex);
6 ^- q! C6 P2 k" Z. Z }/ S/ |6 e. Z return operator[](nIndex);
S. w: n' E, Q% F. Q# M}: T9 i) c7 O5 u# K
/*
% s+ S; {$ L5 b' B9 p7 r( etemplate<class TYPE, class ARG_TYPE>
6 \! k* @. P j b8 `8 BAFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const2 x- f- T) R. ?9 t; s; D
{: M2 s; o0 s2 l; l3 t! A
int i,j;* j2 b8 C+ B2 P
for(i=0;i<tparr.GetSize();i++){! g: v: H& r/ f! E# G5 y7 T
j = GetIndex(tparr.GetIndex(i));4 w, G) \* N7 I6 _8 g9 o( J6 T
if(j>-1){
$ q: B3 t2 `5 D! O operator[](tparr.GetIndex(i)) = tparr;
( v0 \6 }$ y# r2 }; ^ }else{2 i- |( J, Y2 J n) J
Add(tparr,tparr.GetIndex(i));" \3 n" @5 U. b# x2 Q
}
7 |+ {4 ~6 T( i, E+ T1 E }; t0 @8 b( k. Y0 Y
return this;$ x8 G( g/ S& u- e4 C h- b5 i
}2 y- o6 N% g* n5 ~
*/' g; m" n0 K# r' @
template<class TYPE, class ARG_TYPE>( o4 l4 [+ H2 _3 G( e' `
AFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src)/ j( J( g( T& Z+ M% Q7 y8 R9 V
{ N2 ~ T, ~* I5 |! {# n5 f, C) T9 a
ASSERT_VALID(this);* {% v/ K2 M' {6 b
ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);
; A+ J9 @ c+ J2 F for(int i=0;i<m_nSize;i++){
6 r# v7 B/ b( `. O /*将此句修改为内存拷贝*///6 w6 |1 {; D. a( o
*Ym_pData = *src.Ym_pData ;1 w! R1 Y$ l( w9 P& g o
//memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));1 H" g% @# L" Q q- t
SETIndex(src.GetIndex(i),i);
# C+ l1 `: g v J: W: v }
, ^1 H5 u$ P3 k- d) K4 z9 K, n, ~ return *this;) {$ u( A# m5 g! S9 G ]. m& }
}, c5 p/ B. r7 U% P% s
/////////////////////////////////////////////////////////////////////////////1 Y3 Y1 ]/ j* Z( C) n* V
// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>0 h u' z# w0 B# J' i! q8 e0 s7 n
YCArray<TYPE, ARG_TYPE>::YCArray()( F4 K- A5 J; e
{3 v6 Y9 v9 O( x1 c! m- y7 ~' D" ]. G% q
Ym_pData = NULL;
. Y( L/ }$ K& t( \( ~ strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
# J8 }8 d3 a# y( t8 T1 W& W( K# r0 e5 p strIndex=NULL;MAXSIGNTIME=10;
% m, U b* X9 b' Q# [$ [. H}- m4 p, L+ \8 k; b
template<class TYPE, class ARG_TYPE>+ d" l% \& d( A+ f4 q" b
YCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp); y; v! Q/ [, N R
{
8 g- g& w2 j \) S Ym_pData = NULL;
$ N/ X; E v5 I" ~ strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;# ^" b; q7 ?8 G' m/ |
strIndex=NULL;MAXSIGNTIME=10;7 N+ a5 @ i2 f' D: L A
operator=(tp);( m6 _ y$ v% u) N0 \* H6 D
} template<class TYPE, class ARG_TYPE>
8 G2 B4 t& k' v( J6 u( F$ `" `9 S! `void YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy), r) E( A; u# d& t/ s
{
* ~5 E& E) E) t! d ASSERT_VALID(this);! U( P3 q9 V# l- G- S% D- [
ASSERT(nNewSize >= 0); if (nGrowBy != -1)
! G4 m' M4 G9 d8 X1 H+ R m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){
0 N0 l/ ^+ P! Y1 [' _ // shrink to nothing
5 D9 V: [# w$ i8 d+ ]4 o! ] if (Ym_pData != NULL){
0 r3 ]& e0 [9 o s6 _& G DestructAllElement(0,m_nSize);
* S4 [5 D8 T# @ //DestructElements<TYPE>(Ym_pData, m_nSize);
5 u1 H3 Y6 H) d: Z, H delete[] (BYTE*)Ym_pData;$ k4 U, c% T( c
Ym_pData = NULL; G) c* A- c# v1 V* l" c# X
}9 c1 G) u- k* ?- w2 N! i
m_nSize = m_nMaxSize = 0;0 V9 Q, X& C6 L) [* H, Y! p
} else if (Ym_pData == NULL){9 I; i' N G6 r6 M
// create one with exact size2 B( z/ w1 B. y" F K3 m
#ifdef SIZE_T_MAX
+ s$ h8 o! s7 G& u; U$ L4 ]) B ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow" @; U0 P2 c I2 a! V3 p( }
#endif
R. K- D: f0 f7 ~ B @ Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];, y5 m/ a0 G8 b2 p
ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);
" C8 [' _6 Z' R9 U/ `/ Z* b- s m_nSize = m_nMaxSize = nNewSize;) x0 ?8 Y5 F& }$ Y3 g
} else if (nNewSize <= m_nMaxSize){
* l: Z) u7 x1 E3 M, C6 S! n // it fits
5 V2 ]2 t' Y5 D; e' K+ v- f: c2 ] if (nNewSize > m_nSize)
5 Y/ @8 i! j' }% r& ]. n M1 n2 ~ {; K9 k# Y2 @2 `+ E. |
// initialize the new elements
5 T& p: z% q# \, w j% L, ~8 b ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);" n) W: M9 l1 R7 x8 L! p3 \. \
}8 W- T# Q/ ^* Y) v& s, @
else if (m_nSize > nNewSize)8 T+ `) M% j, |, u0 z
{4 j- d# G e& P$ g4 z b" |- w
// destroy the old elements+ |) ?8 l$ N# B% S
DestructAllElement(nNewSize,m_nSize-nNewSize);9 ?4 ?, S( e1 O/ W1 G
//DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);
3 M, c& r% W6 `1 u0 _- t }
5 H: g* {7 ]' k: k0 h7 d m_nSize = nNewSize;# |/ O* U& E8 K, b# r# F1 m- F9 F
}
6 I: G' j7 @" x4 j, l8 X else$ s& m+ J5 A6 b/ L; f0 z3 c0 L6 ^
{2 S5 i9 Z) m; {
// otherwise, grow array4 [. a1 Q4 K+ _1 j- y
int nGrowBy = m_nGrowBy;1 F. z- U' y, D. z3 b
if (nGrowBy == 0)
4 ]. x- U6 u0 ~/ q {& ^% A! v9 V9 k2 x4 A3 B
// heuristically determine growth when nGrowBy == 0/ R, n5 U0 S7 ^* i( ]9 _& L! y" H" }
// (this avoids heap fragmentation in many situations)
2 K& Y( b1 ]3 T& e( {5 [ nGrowBy = m_nSize / 8;
7 w0 b0 u! T4 _ nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);, F2 B6 e9 n0 O
}
, [$ w% w, G( w/ B" } int nNewMax;
/ D8 \/ s, a, i& W8 z" M/ G$ O if (nNewSize < m_nMaxSize + nGrowBy)& g: y: x6 O1 y4 w
nNewMax = m_nMaxSize + nGrowBy; // granularity& w# D6 Q6 ?( k- |0 u8 T
else
% c- s+ Q1 S7 [6 M' z3 s* O nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around
/ ^ k' C; L! c) x% F4 t# z#ifdef SIZE_T_MAX
, T G3 m9 Z% | ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow
# Q" [4 D- w1 W8 n#endif. Y* e. s$ [& s& b4 ^" @) q
TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old
: C7 h# g1 f" C' w/ }6 D) T; E memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements9 {& V$ e" S3 O
ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");, J; w M4 J* w
delete[] (BYTE*)Ym_pData;, V. v- C0 t' D2 J
Ym_pData = pNewData;
; A1 ]8 ~, n! M1 ?: H ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called)1 Z$ m# |2 O+ U6 E( S7 E' K% ?
m_nSize = nNewSize;6 J3 l9 K( Y! y
m_nMaxSize = nNewMax;3 j) w- C9 @) K2 ` _9 W
}8 D' E8 ?2 R8 l g' C3 i/ l9 _
SetIndexSize(nNewSize);
. R9 s9 ^0 q _7 w2 B; E}0 |/ C* |3 ]# l, K# E
|