//接上面 . c0 s. J! k. l) k5 x
template<class TYPE, class ARG_TYPE>( W7 } Q( e1 M4 x1 x9 t& N5 g, I8 r
YCArray<TYPE, ARG_TYPE>::~YCArray()4 K7 `: F. z0 G
{: |0 _9 u0 I' q" s0 {- d
ASSERT_VALID(this); if (Ym_pData != NULL). I5 ` F2 T, G+ T* y6 C5 F
{7 N* o g3 M; W
DestructAllElement(0,m_nSize);3 g* k4 V4 w5 E8 f
//DestructElements<TYPE>(Ym_pData, m_nSize);' N5 H' |- U: P/ ]6 Y
delete[] (BYTE*)Ym_pData;
+ @. |$ J/ D+ S/ p! H' @ }# p& f8 Z v6 ~' s0 s
}
, T! i1 a4 T$ u: |5 w' R* h' Ytemplate<class TYPE, class ARG_TYPE>
: @) C1 _2 K2 j0 K+ T1 LCString YCArray<TYPE, ARG_TYPE>::GetSign()
' F4 e7 z' ~8 R: d{$ m( z R# l+ T2 G
lock_sign=0;$ l* P( V8 r1 P1 G) ?
return Sign;- R: w1 @( ~" J) {9 C
}
1 c! T# w+ |: F5 e" Ltemplate<class TYPE, class ARG_TYPE>
7 j/ z/ m! Q- S/ cint YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign)* K. u) h, \" {. F
{
; @8 l+ {6 D6 z R int i=0;
+ q8 ?! f" p) C' n3 D0 e8 I while(lock_sign&&i<MAXSIGNTIME){
0 _* P: e0 g" j$ V9 q Sleep(1);+ s) G4 Q1 f8 J9 C
i++;* l4 H9 x9 K; i# } D, K9 b1 x1 U
}2 w6 C' D/ A- O# m6 X) @1 A
lock_sign=1;
" z1 x7 R; S. j6 ?4 r Sign=sign;
: n* Q: j3 K, r" X6 N return TRUE;
$ j# x! H: _2 z" P! F3 J S}$ G h6 V& C# u- x* h
//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer/ N. k% S% W8 L. e
template<class TYPE, class ARG_TYPE>4 a# s& n6 T, p" O7 B6 b _/ ^
BOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)0 B0 R5 L: \6 U$ G) H& r. W
{' Q W) H5 C% E& ]8 a
if(strIndexNum < nNewSize){# s# B9 J2 G+ f) i
CString* tp = new CString[nNewSize];//新的buffer) q+ j/ a& P- o
for(int i=0;i<strIndexNum;i++){//把老索引复制过来6 J) b( ?6 E @. @4 r* B( `
tp = strIndex;/ ~6 y/ R. b" B# ?, ~+ c0 Z6 @
}
, H c: k' X9 ? for(i=strIndexNum;i<nNewSize;i++){
7 A) I+ J* b4 v" m& U; J$ ~ tp = "" ;/ a; @0 X+ X7 P- o, \6 C. Z
}
/ y t* ?: @1 J5 v; D" N2 T1 _6 E delete[] strIndex ;, J4 v- n: D' U/ ^$ Y; D2 L. j
strIndex = tp ;% i2 C/ h k* g0 {1 ]7 m
strIndexNum = nNewSize ;5 S+ s, H0 |$ |3 g- f6 Q
}else if(strIndexNum < nNewSize){
4 v0 I/ ]- _: |, Y+ I9 [1 @ for(int i=nNewSize;i<strIndexNum;i++){
1 m+ j" [" O% B( ^4 C% U strIndex = "" ;; q2 ?2 M/ E1 ~! l
}7 x/ z) d4 R/ \6 l9 w2 \; K# F
}* Y+ T3 F# C% H6 q# ?
return TRUE;$ X& Y4 e1 G2 x% n5 H8 M
}, e# L3 C% Z- H: f7 H; p
template<class TYPE, class ARG_TYPE>
. M/ X# u- {. [; P/ L# LBOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/)) M. u4 c" Q$ P1 d$ B2 Z* n& Z
{3 C$ j! }7 n) ?7 U. t$ h& G s
CString* tp = new CString[m_nSize+nCount];//新的buffer5 c' F- w# z7 `( x# h$ o4 M4 ], {% r# U
for(int i=0;i<nIndex;i++){//把老索引复制过来
" v6 @) R. B% z& j% T( g& J! Z tp = strIndex;9 U9 |# } _! d0 [; y
}int j =0 ;
2 z# t9 r: s. L! C. N/ g/ @ for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
+ ^* D$ H S0 v5 b4 z' ^0 b tp = strIndex[nIndex+j];' S: h# t, G! T& o9 j5 E9 y
j++;8 p) q) ], Q6 i7 _$ ?
}% q. b. {( `5 Q7 C7 Q
delete[] strIndex ;
7 D( ~& o# U, X, w H7 t strIndex = tp ;2 w* w6 q4 o7 R4 r
return TRUE;
* A2 }" K1 q9 M* @5 z}
1 G8 W5 E3 W( T$ T8 W$ O7 f1 m: Mtemplate<class TYPE, class ARG_TYPE>* A; e" M! {# o% K$ G
BOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex)
1 ~5 R: y- ^6 o$ s+ l4 N; X% N9 E{//在 nIndex 后面添加一个 字符串索引
$ ~3 v2 n n3 ~- } _3 S* t strIndex[nIndex] = cIndex ;
; R! t7 N* k1 b+ o return TRUE;9 e; s# W: K$ M: S. P
}; h* ]$ Y; n3 @( J" l
template<class TYPE, class ARG_TYPE>
; Z- ^6 V- u: i1 e1 G& _- iBOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/)
% j, f7 L, i, a2 ]9 s2 F. r6 C& S X{//需要在 m_nSize 变化之前调用!!
/ c9 L! ?/ I! I7 Z& o5 P9 R& r ASSERT(nIndex >= 0);" K& O3 h5 `" \! m5 G% p7 t
ASSERT(nCount >= 0);
. G" g. ]# F8 @: ]/ Y" ?% J ASSERT(nIndex + nCount <= m_nSize);
! i. A5 e6 m& k# [ int j =0 ;# W- N' ^1 p1 } J- q
for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来 Y4 R; `5 k! u' j% i8 Z
strIndex[nIndex+j] = strIndex;8 }$ D5 E+ J4 L
j++;
w) f( o+ O4 o }
c3 u! i6 q; j @ return TRUE;9 M1 `0 S2 r0 H: h& }; u
}
8 ~. X& w& a" O dtemplate<class TYPE, class ARG_TYPE>: N2 H8 S) s: ]. f
BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)) ]) h# {3 Y1 c8 U+ c* \
{1 g% s a! _- V
int nIndex=this->GetIndex(cIndex);- ~) s+ b1 A9 S4 \7 h
return this->DELIndex(nIndex,nCount);
- M4 O2 s) a. \# g}
/ J: M8 E9 U6 y, p5 k& N3 htemplate<class TYPE, class ARG_TYPE>
+ ]5 k# b) p" i1 Fint YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex)
) n# Z+ N. g$ \6 Q9 |{//得到 cIndex 的数字索引
) b- K' A% i+ N& M+ t int nPos = -1;
+ |2 c. n; n( G) g1 ?$ } for(int i=0;i<m_nSize;i++){) ~1 o" C* I2 i& w4 G0 ]$ ^9 n
if(strIndex == cIndex){
6 A3 I. ^- M6 z/ b9 x7 h nPos = i ;break;
: F* ^; _5 x \* v6 k8 [2 C3 a }
o! X1 J* g0 J2 l* z$ H }1 y5 G- k0 e ^3 P8 A2 m( h0 g
return nPos;
# R1 ~/ Q+ V6 a; {0 X# {& \2 ^}
; Z2 V: ?* q; f! \: e& Stemplate<class TYPE, class ARG_TYPE>. E1 ]8 x( r' H i& ]* z2 N/ Z
CString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex)
1 w# w% X. O6 s{//返回 nIndex 的字符串索引
6 H+ A& P" l1 x) ] return strIndex[nIndex];( k+ ?9 l& Z9 m/ Q9 A% E, q E/ a
}
0 F1 ^# r# z7 T! a9 E4 _' l8 M/////////////////////////////////////////////////////////////////////////////4 g6 a. n8 h8 r6 j p7 }+ w8 i5 l
// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE>6 ?- z/ F% w U7 d
AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const/ r1 p( R5 O- b# ^! J' ]6 S6 k
{ return m_nSize; }
7 S1 |' U! y2 h5 m" ttemplate<class TYPE, class ARG_TYPE>
+ ?/ p# U+ ~6 e9 \AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const
. @& j+ T: D1 u* I" o4 O { return m_nSize-1; }; Z5 W& G, \: N7 `. a) F8 X! K( D
template<class TYPE, class ARG_TYPE>
% W! \' ~* d" |: aAFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll()
* J Q- ~" |# B) l { SetSize(0, -1); }# O! k R7 k9 D+ G6 K
template<class TYPE, class ARG_TYPE>
8 k( o7 c9 ]0 E( ^0 l- H ZAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const
4 o. ~- @: G+ ]) d5 Z2 e- F" Y) z { ASSERT(nIndex >= 0 && nIndex < m_nSize);+ ?; ^3 Y& A: A7 ?4 ]
return *Ym_pData[nIndex]; }& q: j" j9 J$ D5 Y! a
template<class TYPE, class ARG_TYPE>3 P1 c9 y2 c2 y2 ~& l8 y6 D
AFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)" f( V$ b5 v0 t7 q4 A- E0 Z
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);# K) u9 @8 O% |1 F4 s% U
*(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>
3 O1 Y& |( y% i3 p7 n# U% zAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex)
( R+ `2 L/ Z/ l0 V1 E( g { ASSERT(nIndex >= 0 && nIndex < m_nSize);
: [6 t' h1 _# L9 H return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>0 ~; `# ~* s; H- ]& ~. K
TYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const
H8 h3 m& j5 U5 y1 I) Z: ^{" }" B; C$ S/ U1 o
int nIndex=GetIndex(cIndex);& B- g& [+ Z( \8 A# a8 E$ F2 d" m
return GetAt(nIndex);
! o9 ?1 s: W w5 ^/ m" l}
o+ S2 Z$ n* ytemplate<class TYPE, class ARG_TYPE>
9 Y& A! l- B6 C7 J* M# o& Cvoid YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement)
+ O5 P% h9 J+ l{; j$ c" N1 a" Y
int nIndex=GetIndex(cIndex);3 B1 T4 b: W: D: K: s* p; `" ~8 l
return SetAt(nIndex, newElement);
0 p3 K0 x* f8 T" ?}
- V$ b+ C2 Z$ i% r( j& ?template<class TYPE, class ARG_TYPE>
; d. n1 g$ U" C _* h; ~TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)
4 Z% H6 _ i+ D5 Y9 r; b{) q; i3 g: ^0 a, d
int nIndex=GetIndex(cIndex);4 Z% n+ v3 K9 l8 t1 p Y
return ElementAt(nIndex);
- g, x% y6 o4 x. Z+ V}
; K: W3 W) h o& Mtemplate<class TYPE, class ARG_TYPE>1 ?# V: Y, r+ ^6 n B8 f: Z& w
AFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const
0 ]7 Q0 x6 d5 ~- J) ~0 H, d { return (const TYPE**)Ym_pData; }6 K' F# Y( U; Z& p
template<class TYPE, class ARG_TYPE>
! T5 t, }7 w$ I. \, R' ]" FAFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData()
; ?1 d; I4 H9 E- j* t, N ] { return (TYPE**)Ym_pData; }% X- X) u4 \5 D/ I5 V7 S! H# l0 E
template<class TYPE, class ARG_TYPE>6 \ a. J6 u' q: t% `
AFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */)$ h/ c& l2 i/ @/ g8 v A
{ int nIndex = m_nSize;2 D& Z6 a: ?* s0 p, [; `* m
SetAtGrow(nIndex, newElement);& {8 v9 O; Z3 t4 D+ O( Y
SETIndex(cIndex,nIndex);2 U* G# t7 R% |& h1 _
return nIndex; }2 E; [! H) ~" l
template<class TYPE, class ARG_TYPE>7 X! ~5 `/ Y8 F) U
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const
$ \& E, }+ m5 |2 ~ { return GetAt(nIndex); }' C( L: l+ `5 T' z8 S0 v7 {# S
template<class TYPE, class ARG_TYPE>6 e9 p4 o- E% a6 @4 b% o' H
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)( Y4 D& Q Y* X' ~$ x
{ return ElementAt(nIndex); }
) }4 x f+ L5 a$ t( M( ftemplate<class TYPE, class ARG_TYPE>* K& R, }+ F. ~2 X) R2 I7 x5 H
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const$ e9 U4 q6 N v7 R
{
; l4 F! Y: Q; d int nIndex=GetIndex(cIndex); return operator[](nIndex);7 \" P* p ^# O, ?; x/ ^
}
1 |3 B6 L7 _% qtemplate<class TYPE, class ARG_TYPE>
- G% q1 N o" ]' }, g0 e5 z9 NAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)
# o/ k1 O: i. n k5 n7 a{" G2 K' t2 |, l( t+ y8 R
int nIndex=GetIndex(cIndex);
D" x$ ~' d) _; q4 U6 u return operator[](nIndex);7 N7 L8 v; [+ v6 T9 f
}
8 r6 _# v8 U; f* o: R0 N3 ^/*
" @0 L! l/ ~6 l+ `template<class TYPE, class ARG_TYPE>) F4 O, |8 F- Q3 i% w& u
AFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const- t6 l9 v- s8 l+ d1 x
{
4 @- d+ {7 f5 F! r* N: S1 p int i,j;+ I( T. U9 j, w1 U" ~! @6 e
for(i=0;i<tparr.GetSize();i++){
. r* V9 A+ e, Y. l j = GetIndex(tparr.GetIndex(i));7 H3 ?# a4 D. }- m
if(j>-1){
- |9 ~+ A P8 U0 @) D$ G' Q* k( t operator[](tparr.GetIndex(i)) = tparr;8 _% ?; d, e2 E
}else{
1 O- R" Z! A" H" }9 @1 J N Add(tparr,tparr.GetIndex(i));& W: X0 p, }, C5 V% _8 Y$ L! u k
}
+ ~" K! W) k9 H, d5 s; j4 r2 E }
: c' r, r1 K, L" _8 E# p& L: j" c return this;
0 M! M$ G0 P! f6 t}
7 Q4 P- \2 E8 J*/
. J; Q8 m* U0 v4 itemplate<class TYPE, class ARG_TYPE>; H0 u. [' [- b' m1 D2 |( J7 X
AFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src)
! E! s0 u2 j ]: e' C8 O+ t{
, ?* D* N8 s+ k4 R ASSERT_VALID(this);7 q9 v0 k1 a$ y% W
ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);
- b( K) D' ]4 Z# b for(int i=0;i<m_nSize;i++){) i; u& R5 \4 @. H6 O X4 f
/*将此句修改为内存拷贝*///7 b' _' V; l4 H* o- b) s
*Ym_pData = *src.Ym_pData ;
, W4 @- d g4 J3 V; n+ q8 F6 i //memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));+ W( N( D+ m( e0 M; m Y% m9 F
SETIndex(src.GetIndex(i),i);- }$ r. k5 Q5 {
}; R0 |/ k( h. A( p9 _- U
return *this;2 \6 x* t) }8 q' S# P3 `
}
; z% p3 s# I/ X: u" k" D% `. t% S+ r/////////////////////////////////////////////////////////////////////////////2 m' f7 _$ v; k* B
// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>
- e% H4 X U4 {% DYCArray<TYPE, ARG_TYPE>::YCArray()! Y8 z) v) j/ l I g/ k1 a
{$ r; v2 O& o+ ^* B+ ]
Ym_pData = NULL;# `. D3 L% I: h
strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
, t0 z& {" X$ @$ E& c strIndex=NULL;MAXSIGNTIME=10;+ n% z8 e4 `8 w9 ~6 S
}
# z% ]$ {# F8 C' a9 `9 R. Atemplate<class TYPE, class ARG_TYPE>
* I0 t' U M' B7 m: X; u/ eYCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp)8 p: x1 A& C: |) i8 J z; S
{
3 b9 L2 q3 @$ y2 ~1 S7 D- C M Ym_pData = NULL;
+ W! Z5 ?7 x% Z8 x strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
2 K8 o: X2 a! A/ h3 \4 {( e strIndex=NULL;MAXSIGNTIME=10;1 w: ~' J! k; o+ s l
operator=(tp);
! m X7 f4 }1 l3 j/ V; y} template<class TYPE, class ARG_TYPE>4 b3 g$ X; r( {/ q6 L/ F/ L# R$ O# M
void YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy)7 y, J/ L* ]) T8 q
{
% E3 u' r7 @! ?( o5 p ASSERT_VALID(this);' o( R6 Y% R9 Y1 g" C
ASSERT(nNewSize >= 0); if (nGrowBy != -1)3 L* a) [' a9 s) C1 B& v( ^
m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){/ y/ Y* d1 f' \* c i4 G* V
// shrink to nothing
$ y; o! k4 }7 b6 U/ q if (Ym_pData != NULL){
) k1 L! |% A/ ?9 ~ DestructAllElement(0,m_nSize);
& o3 M( T3 u! _6 X //DestructElements<TYPE>(Ym_pData, m_nSize);/ S! P3 r2 m! i. A
delete[] (BYTE*)Ym_pData;. S9 Y- Y0 d3 O! V+ Y# m r
Ym_pData = NULL;3 s7 M" [/ `2 w7 a
}
% G6 r3 R# E$ k8 ? p m_nSize = m_nMaxSize = 0;
) q3 a8 [& S# y, G& u } else if (Ym_pData == NULL){
! w+ e$ M$ E# g // create one with exact size
( M1 [, b! p3 V0 R7 D8 U4 Z y9 {#ifdef SIZE_T_MAX4 P! S& d1 L$ j% \7 b- C z( J& A
ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow
: ]5 e ?: `0 Q {#endif- N4 a5 R/ P9 T6 l' g
Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];
/ I6 q' V+ M# c% M/ t5 B, J! J ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);
# L( M3 J8 _0 E# ^) E" x m_nSize = m_nMaxSize = nNewSize;
6 E0 m3 Z+ _# O } else if (nNewSize <= m_nMaxSize){3 A& _8 M8 e4 k& Z% j3 W8 l
// it fits& h, \) K4 h+ v* I8 A1 r, [5 r
if (nNewSize > m_nSize); x# o1 C. X! O- h* a, b
{: _& |' r- v2 R% U! |0 V3 M6 a
// initialize the new elements
9 ^4 ~" n6 x8 v5 A1 V1 { ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);2 D1 [+ f1 {, s4 @3 ]2 |; {2 ~- F
}
9 E) Y8 q- V' ~+ w6 h! w4 k. C else if (m_nSize > nNewSize)
L$ Y# ?! q- W2 I! v9 u" n$ X {) d( p# M1 m; H! y5 H8 O! k- q
// destroy the old elements
, n1 S, S% D5 _. e- E DestructAllElement(nNewSize,m_nSize-nNewSize);/ [/ E# H! M) N! H
//DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);
7 ?5 _. [( U& a2 o( @) Z) m }1 E* v: v' {- D- x- T2 c6 n
m_nSize = nNewSize;5 ?6 m p5 u! ?" j
}, o3 H" q& W( q6 v% E
else% h- Z1 _* N6 {0 h
{/ Y4 |! f+ b) {# O, P
// otherwise, grow array( _( k! r) `- U4 T
int nGrowBy = m_nGrowBy;& J% J5 o% h5 i! j, s, |+ A
if (nGrowBy == 0) R" t/ J: y) _! v0 E7 w- U
{
* c3 y: }, |8 i // heuristically determine growth when nGrowBy == 07 }& Q* u& V: m9 x8 i# Y4 ]7 \
// (this avoids heap fragmentation in many situations): u% O! d% P. \$ n4 g; f& w
nGrowBy = m_nSize / 8;
) |) e; g4 C# T" k nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);
5 E8 e1 X* J0 C }
% t. N% M. {4 ?, U' E$ F L2 K int nNewMax;
9 f( i% ^; @ L; P6 Q if (nNewSize < m_nMaxSize + nGrowBy). z( L- o0 L% ~
nNewMax = m_nMaxSize + nGrowBy; // granularity7 i) m' J9 b- u- l$ ?) |. A4 e
else
% i! H8 ?3 ~1 C7 {0 p6 M3 c nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around" @( d& Y5 c+ G9 b6 a: M8 F2 n
#ifdef SIZE_T_MAX
* i% D. v$ j* O D3 @( h7 | ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow$ T0 W7 ]# f0 e
#endif5 G8 K# c. d y/ \
TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old6 N" j8 ~5 [* y
memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements; a: M9 [# v/ i! h. W; a& V* K
ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");
( Y7 N( o. Y0 I' N% D delete[] (BYTE*)Ym_pData;9 A; Y( S! @7 S) E
Ym_pData = pNewData;6 Z, H7 J+ @# ]1 S8 X3 c6 s
ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called)( R# w+ B4 v# G: A# @' ?- T4 E
m_nSize = nNewSize;
' q( H9 l/ c: m8 ^% A5 a m_nMaxSize = nNewMax;2 L1 F$ W9 E! M( A
}
' z1 h/ O1 H% _% @4 D3 R. ~- I SetIndexSize(nNewSize);
& x. Y+ b% Z% ?, w" F5 j: F, {6 P- G}
$ q# B3 r# ~$ V2 X$ d* ]2 D$ W3 y |