//接上面
* p; x. n [! y9 \9 x7 `) vtemplate<class TYPE, class ARG_TYPE>
6 n- R3 O- }+ M- \. H! Z NYCArray<TYPE, ARG_TYPE>::~YCArray()
6 f( G9 @/ i- G; F- [{
5 _7 m X5 c: j" I) x. M ASSERT_VALID(this); if (Ym_pData != NULL)4 T3 R: |) ~3 |. |" J: [5 F
{
$ V- W0 ?" R- P+ q7 X DestructAllElement(0,m_nSize);2 |' u$ k' _1 M' r8 [. K2 L# F
//DestructElements<TYPE>(Ym_pData, m_nSize);4 K" y" U4 [1 D4 V k) m3 r, q5 u
delete[] (BYTE*)Ym_pData;4 I4 t, |# q) K$ X; ~
}
% R9 \ @% J; b4 i1 I% O}
2 `% {3 m8 K3 O1 Otemplate<class TYPE, class ARG_TYPE>
( o' Y, c Q4 P5 `( ^2 n* zCString YCArray<TYPE, ARG_TYPE>::GetSign()- u* m6 U& w9 d4 P
{
, A; y9 l( c5 B& i lock_sign=0;& s& y# }0 B8 b5 M7 V3 W
return Sign;
% R1 j' m1 K/ d) d; s" Y4 j) b/ P- u}
) B4 P$ x+ b# W0 A( ztemplate<class TYPE, class ARG_TYPE>
9 g6 B, o* e I6 p9 G/ C" ?+ dint YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign)
5 t7 `, D$ T* f H{
: k G0 Y0 I9 ?# d int i=0;
3 _9 I3 z8 \# g: |+ D- \. @+ b' U; | while(lock_sign&&i<MAXSIGNTIME){' s$ Y$ R2 W+ b$ D. ^ R( ]; l: _! A( R
Sleep(1);$ C( {. y% K( s# ?+ _
i++;( b* J/ R; X9 j
}
& \" k9 K6 g% T& A0 @8 L7 [ lock_sign=1;
% C5 e2 O& E4 L4 f5 [0 }9 G Sign=sign;
- n) {$ p$ L2 V return TRUE;( K: k6 a* `* B, n
} `" }1 k, ~7 b3 h7 `, _
//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer( @$ y! n& l J; T( t8 v$ b, ?3 p
template<class TYPE, class ARG_TYPE> n( I9 E3 E0 y" C$ }
BOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)* S; \/ k* a4 b& Y( v
{
* F( ~ S! S- z if(strIndexNum < nNewSize){% N1 u2 R9 p$ C
CString* tp = new CString[nNewSize];//新的buffer; P6 Z, r4 |: U8 L+ g2 x
for(int i=0;i<strIndexNum;i++){//把老索引复制过来
; H8 X5 G% A7 s6 @ tp = strIndex;
& H1 K( k7 d% G- o7 P }
# ]( S/ u5 B- F7 ?& E# [ for(i=strIndexNum;i<nNewSize;i++){. ?: m' m6 S0 V0 W, B. ]
tp = "" ;
# \8 {4 F/ |: ? }
8 M4 X8 \$ @5 N! Z: t2 N; R0 n delete[] strIndex ;* d8 W: e0 z J
strIndex = tp ;0 ?8 ^. S$ n4 N9 O
strIndexNum = nNewSize ;9 H. d% j1 p# M/ K1 l2 ]
}else if(strIndexNum < nNewSize){, v, T9 d1 l$ R( O& q
for(int i=nNewSize;i<strIndexNum;i++){/ v5 m6 O+ d8 f, M& F7 G* @7 r
strIndex = "" ;( l" a( O/ M- _+ R& h5 E: ^
}7 C4 a- M( ^- V" F4 w
}* Q$ n' y/ w* p6 r3 s: Y
return TRUE;
; `; b# O, ?$ p7 T5 w" t3 f}8 v+ q; E8 h4 {( e6 @) L
template<class TYPE, class ARG_TYPE>
7 U* C/ q$ d0 Q! f) W- u9 MBOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/). D% f) Y. F: S. \) Z, P# x- f
{
8 t3 G4 d# Y2 n. M0 K CString* tp = new CString[m_nSize+nCount];//新的buffer
* h* y( d; s: {3 u3 ^ for(int i=0;i<nIndex;i++){//把老索引复制过来
/ k% S8 i" v& s0 z' \5 n/ q tp = strIndex;' L4 x1 ]) c5 N ^$ P
}int j =0 ;
. w- D8 G' O$ P2 N# D$ t; W for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
9 h) o% q/ \+ c7 I9 ] tp = strIndex[nIndex+j];
1 F& t# g$ b4 ]) T+ C j++;
. s. U( b1 m. T9 T2 V ^2 [' g% { }& e( N8 u! l3 ?0 w% w2 F) d: p
delete[] strIndex ;
% h9 Q2 w; M' \1 c strIndex = tp ;# B& A) l. G4 e+ o9 j% b' I+ y0 }
return TRUE;; Q1 G) y4 T/ ] S5 v
}/ q" T' ?7 w6 B3 F' ^! ^
template<class TYPE, class ARG_TYPE>/ g( J) T8 }; X/ {
BOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex)4 { Y: z6 B. x0 k. W6 x
{//在 nIndex 后面添加一个 字符串索引$ t- u4 E) r4 D2 }: M
strIndex[nIndex] = cIndex ; b3 H; f9 q2 {7 P, L- k
return TRUE;8 B4 _& e' L! `% B5 W& |9 j
}& c1 m$ a$ x9 S+ O9 _6 A
template<class TYPE, class ARG_TYPE>2 i# V! a- V4 @& V6 m0 s5 r4 I& I" i
BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/), l, o4 r/ s6 d( W3 W8 X: s' f
{//需要在 m_nSize 变化之前调用!!9 D# d" O( U- b2 Y5 q, y" ~5 ^ o
ASSERT(nIndex >= 0);2 M' E j! u2 s0 i; u) A
ASSERT(nCount >= 0);( _. P* ]* T5 L( g4 q- I# b
ASSERT(nIndex + nCount <= m_nSize);
2 ~* \8 e/ f9 }" J6 \ ]3 p int j =0 ;/ F. s8 d1 \* J" W& {
for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
/ H$ f5 o- f: E# P7 x L strIndex[nIndex+j] = strIndex;% Z' P4 K7 e: c9 @5 ^6 `2 O
j++;+ ], q3 {% M, A o2 j- t M8 G
}
3 f- q; E3 m& ?1 f2 j return TRUE;
7 q) c& ?6 ?/ ~! z1 X2 p! p}
! @9 Y( J2 @. ptemplate<class TYPE, class ARG_TYPE>
* p+ w( l0 t, G' n, T0 {# t3 P7 fBOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)' n3 R$ Z i( x* H# j5 v+ w& @" {
{8 e+ K( D, l( N0 ^8 V
int nIndex=this->GetIndex(cIndex);% ], j$ p6 g8 Y w4 |' ~
return this->DELIndex(nIndex,nCount);
) k1 i$ Y- v( N/ f* V1 d! W}7 D6 S9 e2 T9 Q2 ~
template<class TYPE, class ARG_TYPE>
) ]* ]( I' l0 r* f( `0 d0 t1 |int YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex)0 j7 l" g& y$ C8 X! G
{//得到 cIndex 的数字索引
0 n# t" [& u. f* {. f6 [1 ~" K int nPos = -1; N+ ~4 R1 j5 z2 q
for(int i=0;i<m_nSize;i++){7 |$ J, a1 E6 g0 ?
if(strIndex == cIndex){0 N, k8 l$ K) m: k/ e3 V
nPos = i ;break;% O& y) ~' L) p: c4 A
}
1 R; ^5 z& O! l% o5 [ }
8 }& q: h r8 Z# `( \7 i return nPos;- m* S+ m. P: s2 v
}/ N4 l* B( f5 G+ o0 F
template<class TYPE, class ARG_TYPE>3 H8 t' u) |* t' L! u) S2 h
CString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex): }- H9 e/ V2 o$ P1 P$ L) Y
{//返回 nIndex 的字符串索引
9 v4 l- C' C6 _# J6 N. I return strIndex[nIndex];
# o B2 {; m& J}
. U7 }" q+ R& D6 T8 y/////////////////////////////////////////////////////////////////////////////' J8 B6 Z" V, w% y
// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE>
& R' M5 [5 \5 C' @1 [AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const. e/ a& _* {0 ~+ R9 I
{ return m_nSize; }
; C4 F9 d2 C# @0 P' N; vtemplate<class TYPE, class ARG_TYPE>7 S3 A' J) P7 K1 I5 }9 l8 O
AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const" f/ K% x7 U4 @- Y
{ return m_nSize-1; }
; K+ \( T3 ~2 a& K" N: Rtemplate<class TYPE, class ARG_TYPE>1 c7 _$ X o: g2 W; F r# X
AFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll()
& t+ f Y( V" m8 E { SetSize(0, -1); }0 c9 C; P k3 M8 u
template<class TYPE, class ARG_TYPE>
0 p i4 k I5 h4 v6 w4 `AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const
$ b2 D# t _) T+ ` { ASSERT(nIndex >= 0 && nIndex < m_nSize);' h- W0 W* i* z' e0 f8 d- ~
return *Ym_pData[nIndex]; }
; C7 F: [( I" `9 Y1 m: x atemplate<class TYPE, class ARG_TYPE>
9 M4 H8 M3 S ~! V1 m, n# a- wAFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)
1 a9 n* H" z5 I5 q' j, u9 I { ASSERT(nIndex >= 0 && nIndex < m_nSize);
! K4 L1 V) l, w D7 h *(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>% a0 q9 e% Y1 y5 Z8 I; L2 K
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex)( s; B5 Z, ^! r1 X" @. O5 F, Y
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
h9 n& @7 Y; s, V return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>( b# w5 ] q9 U9 }$ q) @7 K
TYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const( r2 m' X! @/ r* F) L0 C- C( ^
{
$ p% g! S, B' W6 b5 Y8 { int nIndex=GetIndex(cIndex);
3 Z( Y7 ?1 v E T2 w* Z) W return GetAt(nIndex);9 a% k1 d- ]+ M' W$ y8 B
}
' v7 J# ~8 L( f% W4 J+ W8 p5 itemplate<class TYPE, class ARG_TYPE>
9 g. W) n9 Z7 qvoid YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement)
" z7 a; A/ z& q# m; U' j{3 K. ?8 K( L, a5 d) B$ D1 x( [
int nIndex=GetIndex(cIndex);6 ~, J* W1 i/ ^: n* _/ x
return SetAt(nIndex, newElement);6 O3 y3 S, R1 m. X
}
. c' e2 B# u1 j& R+ I9 Y4 Ttemplate<class TYPE, class ARG_TYPE>* ]7 w4 R$ Z- o; g# u) D
TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)+ @% ~! [2 I9 A/ t/ z/ p' ^7 i
{( i: |, V) B) a' n$ q) u- p
int nIndex=GetIndex(cIndex);+ \, t. o& f* ?9 U e$ l
return ElementAt(nIndex);1 j( f3 b: |8 S8 `
}
' \; e) e, C Y9 C/ s$ S* z. Ztemplate<class TYPE, class ARG_TYPE>
1 G. A L1 T7 u: nAFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const
% N. m! i" W, H1 A, Q9 F { return (const TYPE**)Ym_pData; }* s! J& ^% _2 Y9 N
template<class TYPE, class ARG_TYPE>
! l5 Y. ~: W! [; h; N. \. d+ dAFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData()2 ~0 `8 N+ E4 T. k. Q5 b9 Y
{ return (TYPE**)Ym_pData; }
8 R" M+ _8 A" qtemplate<class TYPE, class ARG_TYPE>
, l( y: q7 M9 B; n5 RAFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */), V' o$ I. h: q$ e$ ^# l( h
{ int nIndex = m_nSize;
7 v. V& w& v: c ` SetAtGrow(nIndex, newElement);
6 V* O8 a/ c5 G; L SETIndex(cIndex,nIndex);2 h: d4 R. j- B3 t$ q2 G, `) k
return nIndex; }; o& m) B2 l- X/ U# P$ U0 D
template<class TYPE, class ARG_TYPE>- s$ h7 K. u$ g
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const
* s6 |( X1 A. h/ y- p7 V9 r { return GetAt(nIndex); }
/ t9 C' M( d. {# l& l. W. dtemplate<class TYPE, class ARG_TYPE>
7 [% w2 g+ S6 iAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)
1 U' c8 Z" c, a7 M) z { return ElementAt(nIndex); }/ A1 V2 @0 j4 H9 I2 W- t
template<class TYPE, class ARG_TYPE>
" f0 x- M# d5 O6 |9 m$ _AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const# ?5 o1 Z; i q6 Y
{3 j+ C0 L3 ] m
int nIndex=GetIndex(cIndex); return operator[](nIndex);
; X7 q& f% i' w$ E5 C+ x, R- y- E}
' h9 r+ c" N+ h4 C, ktemplate<class TYPE, class ARG_TYPE>6 s$ n9 y8 c" Z8 D: \ \
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)
% M) l+ u- e; }& Q! u C8 u{- l* Q$ r3 I1 T; R. o5 H2 \; [
int nIndex=GetIndex(cIndex);+ L/ k4 K8 p. F; u7 f: G% P
return operator[](nIndex);
( y: ^* B1 M% V/ d; ~) a8 I}' ?3 }1 S6 ?( P9 S5 P# I8 G2 N4 n
/*
|' P) f! p* |* f% E. _4 {* j' gtemplate<class TYPE, class ARG_TYPE>7 i" H( U, {3 ^- s2 |& I
AFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const
4 r) ]2 w% U- y+ B% N8 W{
3 F9 O2 w! l, K int i,j;! o4 D6 N' ~7 T6 i# q
for(i=0;i<tparr.GetSize();i++){) d6 o B/ c/ s3 R: L W
j = GetIndex(tparr.GetIndex(i));
, _/ F8 t9 z) e! R, h4 { if(j>-1){
0 A7 c, l- q- m4 s! s/ w# } operator[](tparr.GetIndex(i)) = tparr;! M/ T V2 t+ \9 E( c
}else{/ ~* m& u' |: A, \& F4 G1 B
Add(tparr,tparr.GetIndex(i));# P' z L: n& |) Q
}6 P4 Y) j- j- H6 D8 r3 B
}
& ?' E; K8 S1 z! `& ]% x+ y return this;
! u# r5 u$ |7 G4 u3 g3 `* }& S}4 n# c R ?' J$ g. y- ]( ~
*/: ?1 \! {( q$ A6 X* k
template<class TYPE, class ARG_TYPE>3 H; i; u3 b, ^9 v$ p
AFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src)
/ h) {4 m+ i A. {- v{" J2 H& c% I. s0 w
ASSERT_VALID(this);
+ t% U, e/ y/ [8 {* b ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);
4 D% O1 J0 n: X$ Q( i+ c" m q for(int i=0;i<m_nSize;i++){9 c# T4 M6 t) H2 n; W0 H
/*将此句修改为内存拷贝*///9 I2 L: V( D- t3 w! J. z. u
*Ym_pData = *src.Ym_pData ;3 F7 I# A. Y: P, n; A* W
//memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));3 H* L2 M n% c( }
SETIndex(src.GetIndex(i),i);' g4 ^" ~( a' s& {$ ?. x6 C
}
& E; `# H0 D6 A return *this;0 V- h: \$ g, M M( b& Z# x, w% x2 P
}- i: u* |1 J2 Y1 r( `
/////////////////////////////////////////////////////////////////////////////
6 Z) W# c' I! R0 w6 g// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>6 w, F5 H$ ]6 | O" P1 \
YCArray<TYPE, ARG_TYPE>::YCArray()
2 h; x# ]: n% H d{: [% `5 Y+ m6 H8 v4 Y6 B
Ym_pData = NULL;7 a: u4 Y$ M( x. q
strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
0 p8 N" A4 B8 Y+ V+ J: J! a3 V, S strIndex=NULL;MAXSIGNTIME=10;
5 [1 S. H% F0 p' D}" L6 k5 m+ T! Z2 W) S7 V
template<class TYPE, class ARG_TYPE>
3 h1 V1 z% s' }& p& g/ ~1 G2 kYCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp)
/ y) E3 c9 N5 a* r V! h& {{' T7 P9 V2 Z8 _* y# ~
Ym_pData = NULL;& e8 `4 S( h: ]
strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;; v" [! E" F G! M1 y
strIndex=NULL;MAXSIGNTIME=10; O+ }7 Z" a0 S) z* A- `
operator=(tp);0 c7 t0 k: k' m9 n
} template<class TYPE, class ARG_TYPE>0 S+ i8 I0 ?, a0 y$ i. U
void YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy)
" j) ^; _% k2 _ e{
" ~4 t# {6 r/ F1 B9 }. w' L ASSERT_VALID(this);4 ?% x- M! Q0 U8 U2 Q
ASSERT(nNewSize >= 0); if (nGrowBy != -1)
" n5 [: Z2 ~7 m1 P j0 d( S5 o m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){
4 K) ^# x$ q4 t+ J+ X" b1 C1 I# E3 g // shrink to nothing
- r2 ~* J* Y4 Y% s if (Ym_pData != NULL){
! p- v: j0 X: K DestructAllElement(0,m_nSize);, [4 r* ]3 G* f6 y. J
//DestructElements<TYPE>(Ym_pData, m_nSize);
! I5 x. `% }; g5 O( ]( Z delete[] (BYTE*)Ym_pData;( x H) j' L; z2 z5 p6 G8 d
Ym_pData = NULL;4 k; i4 @0 N- j( B q4 h
}" Q$ I1 g# X: I* `( V
m_nSize = m_nMaxSize = 0;% j; H+ F2 P" Z
} else if (Ym_pData == NULL){
! m+ h7 w- p$ w s; h // create one with exact size- u. u+ r" z* h
#ifdef SIZE_T_MAX5 ~; H4 _1 v; K# l% W) x( I* w
ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow4 @. {& M" D4 I2 F* |
#endif* v- {' T8 o7 i4 {4 `5 v: S4 M) ~
Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];8 Z6 Y, F: W* Q) [4 R8 x3 k
ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);6 x% X( S& G) |- |
m_nSize = m_nMaxSize = nNewSize;
4 Q: W. i; }) X& B& k6 ?& {) F ] } else if (nNewSize <= m_nMaxSize){8 [! ~1 g7 [, g& A
// it fits5 ~2 u: J) i6 e4 q3 z* _
if (nNewSize > m_nSize)
- s+ _* V8 ]* n( d9 P' D {: _5 q) e7 y0 ^" l6 z" b
// initialize the new elements5 ?7 V: F P/ d# L4 }+ E# B
ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);4 Y9 e* v3 [% Q4 E) ~+ B7 d' I- u y
}) K; V) A8 w/ }" [1 V5 x
else if (m_nSize > nNewSize)
5 w) N7 b' Z9 i; C' V2 X {7 |7 r- m( ]5 B4 R$ C: W8 O0 D
// destroy the old elements# b& j) P5 O: q L. J
DestructAllElement(nNewSize,m_nSize-nNewSize);
' b- V. g# c* D1 h' b //DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);
* h/ F' n# `5 q* y }. d, `2 L \4 x- {" F6 V6 Z
m_nSize = nNewSize;; L. {# G' x( b2 [" c2 q# I
}* s* E2 J' Z% O% U
else
) H" A9 f+ y) i {
5 ^2 {$ w+ E4 d7 `; X$ ]# s0 _4 C // otherwise, grow array
# f6 `2 I6 b B6 ^( g; h int nGrowBy = m_nGrowBy;& X5 Y' \3 g( Z& l5 p8 ^
if (nGrowBy == 0)* c5 l; [) `: M! h- H4 _2 \) v% @
{
+ a+ X" ^+ d7 N4 k8 f6 { // heuristically determine growth when nGrowBy == 0
/ l3 }6 D4 E% u4 v // (this avoids heap fragmentation in many situations), S: h. }4 q0 X" Y- C m8 O
nGrowBy = m_nSize / 8;
3 s7 P8 J( N1 i nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);
+ d6 A' D) A5 N$ w }
! y/ r, y, v- y5 m: L int nNewMax;
. i; y1 j4 j( f( M/ D, i% i/ h X if (nNewSize < m_nMaxSize + nGrowBy)0 |# b! T8 f3 ~- J6 u' A" K0 u8 y$ B
nNewMax = m_nMaxSize + nGrowBy; // granularity! P7 M6 [' s, O8 j9 {8 J
else
. h9 j% g' A$ D& \ nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around' R% W- n L- {/ z
#ifdef SIZE_T_MAX0 [; x3 C! m. ?! O! [! }' D# A
ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow2 y) y) U! ^& t" s
#endif+ J$ B8 ?6 K/ }+ q# f
TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old3 u# W5 L6 o A
memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements7 o6 R2 K4 K8 @
ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");, t7 C8 p9 N/ B) S! n
delete[] (BYTE*)Ym_pData;
1 }! L4 J+ c* Z( ^8 A6 `1 o Ym_pData = pNewData;8 C, r9 t, a( B: k' Q+ n
ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called)2 N" B' u& f3 U3 a/ q* a
m_nSize = nNewSize;
5 x4 ]$ J4 z w- c/ H m_nMaxSize = nNewMax;
) b$ {" Z% e4 a }
! F" m/ T. ?! w) G, G4 C+ p8 b6 u( J SetIndexSize(nNewSize);7 r% s3 A4 J) L* h! D- l
}
3 o. {, q) j& i0 x) Y& \2 S9 e |