//接上面
% {6 W+ J% y3 F1 j2 Rtemplate<class TYPE, class ARG_TYPE>
' F A1 i$ Y5 n* YYCArray<TYPE, ARG_TYPE>::~YCArray()
' l4 M3 }. n* L' `( g) y$ k{* c$ H% a9 U2 k; d) L' z
ASSERT_VALID(this); if (Ym_pData != NULL)
( _, x' L) b' {' P* c, @ {3 t5 L2 l$ z$ o% f
DestructAllElement(0,m_nSize);* {4 V+ ^/ Z+ D- C$ e# B3 g6 E
//DestructElements<TYPE>(Ym_pData, m_nSize);
. J3 w% K- D Y N) {( u delete[] (BYTE*)Ym_pData;) O+ `$ @% ?% R" b9 l6 `
}, |+ |3 r' E' U- }+ F9 D
}( g: W6 Y' y2 o7 i' o% y& V: o) ^
template<class TYPE, class ARG_TYPE>6 J1 b$ S2 M3 S# T4 g% i
CString YCArray<TYPE, ARG_TYPE>::GetSign()9 F, t+ l6 @5 }. a; v3 F
{5 r* \4 i% v6 }; V9 ~# P' C8 v
lock_sign=0;
4 Q. L6 A5 s; u: o return Sign;6 R1 w t0 e$ j3 k S
}2 H! [ I' z& u# d; m0 [
template<class TYPE, class ARG_TYPE>
# z* O, [$ c8 Y! I! b0 P5 |" `int YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign)
, p8 \' {( u; Q+ M{) ]5 ^7 q0 w2 Y& w* E( j& Q5 d
int i=0;
& A6 o) q% O" L! s. x while(lock_sign&&i<MAXSIGNTIME){$ ^# S0 n: `6 Z6 \; \1 z7 l! V; ]
Sleep(1);
- d$ B9 x* o" g' a# Q/ d0 M6 J8 a( f i++;
' [/ R: R, ]( v) E" w }# ^2 {& I G1 q- r% g- p F" ~
lock_sign=1;
' w) f* w( d7 Q Sign=sign;
' O& h7 F+ \, c0 z2 k# V4 _ return TRUE;+ F7 w- L( R* A; b
}/ N2 {2 K. u; w3 G, F' [+ S% r
//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer" {# k4 q0 R; s# E
template<class TYPE, class ARG_TYPE>$ D3 a, p3 k' H7 [2 {# p$ C
BOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)4 y4 K$ D g r9 l/ P, v: E
{2 h* H! v+ r' }& Q4 S
if(strIndexNum < nNewSize){! }/ ^9 ~$ r! P7 s
CString* tp = new CString[nNewSize];//新的buffer
2 h+ f5 `+ k2 A5 d' t, j for(int i=0;i<strIndexNum;i++){//把老索引复制过来
+ s; q4 A: L" t+ v: q, B tp = strIndex;
& ^4 n% G( D. @) G4 d7 K2 w }" }8 X8 `9 Q7 S3 t4 `- o, T
for(i=strIndexNum;i<nNewSize;i++){
6 E8 x v" e" o; ] tp = "" ;
: `/ S% u9 g6 [+ U; M4 y }
V/ ^; D. v/ d- d% }+ v delete[] strIndex ;
8 h8 I- F' @: ? strIndex = tp ;- \1 H: O8 P7 y7 W8 W1 c2 x
strIndexNum = nNewSize ;- U* V% ^3 t3 {) p; u9 W
}else if(strIndexNum < nNewSize){
8 P( T6 B: `! x. U+ B E for(int i=nNewSize;i<strIndexNum;i++){
; _. z6 f- n( u- d- r) T1 [ strIndex = "" ;
! u! D) } o+ e- P$ I! B }, z0 a" n' Y' _, N6 Y: T M
}
3 y3 Y7 n6 I( n" X. a return TRUE;
: h @ M* I& I7 g! w3 p}) m% y; u/ j% K$ b# G
template<class TYPE, class ARG_TYPE>. ^$ f' z* E e _
BOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/)$ q/ a7 J1 Y( I: c
{
( ^' R6 H+ J$ X2 Z4 A+ Z& _/ K9 `( d CString* tp = new CString[m_nSize+nCount];//新的buffer
; }8 b$ s2 ~4 k5 } for(int i=0;i<nIndex;i++){//把老索引复制过来
$ C( x9 _7 ] v4 D tp = strIndex;8 a/ c3 u @$ z7 ]. |
}int j =0 ;8 E* p9 _$ `* o/ s: A
for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来+ }* b4 ^1 U7 L. u9 Z% A0 z3 g
tp = strIndex[nIndex+j];
1 t9 K' W* f4 [ X9 d j++;
9 Q1 {& o/ I. u% H }
], W+ l R: e1 L delete[] strIndex ;1 k0 X( Z$ ^) J* H7 ^
strIndex = tp ;
( O# c! r8 `( a9 ? return TRUE;8 E2 P I; j$ ]( P7 m5 L
}
+ c) I2 t% ?- Ftemplate<class TYPE, class ARG_TYPE>
. B3 h F. J0 Q! T& B7 SBOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex)' ^5 ]# X: \3 `6 L% {9 [0 E* W6 y: k- s
{//在 nIndex 后面添加一个 字符串索引
8 ]' c6 p' o# Q, x2 h) m I strIndex[nIndex] = cIndex ; Z& x3 i1 H- ?! D
return TRUE;# g" c( \/ C- k, j3 K
}
2 k8 i- h6 H) y2 b' X# x- Ytemplate<class TYPE, class ARG_TYPE>+ ?& W% w' h0 ^ y8 L1 {7 h, ?1 T
BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/)
2 X4 C& i; c) l7 [2 w/ f{//需要在 m_nSize 变化之前调用!!
p/ _/ D; @# J! e! g t* Q" o! ~ ASSERT(nIndex >= 0);& k) C4 F. j# d u5 s6 S! C
ASSERT(nCount >= 0);7 y4 j! z4 {! g1 e+ I, H' ^
ASSERT(nIndex + nCount <= m_nSize);
$ s& b1 ^9 T8 U: O5 X int j =0 ; y8 k+ H& w) F5 A7 q$ r2 y. t
for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
! Y4 i$ T; a; b7 X- N% ]0 F9 \( k strIndex[nIndex+j] = strIndex;
! }" l5 ?1 C0 P! W: N. a j++;
1 V+ e' f* x% ~) C% N }" i2 C b6 M7 j! V8 \
return TRUE;
+ p1 x0 r3 j3 m. ^, v}- W2 H' e2 f3 q0 J' \' f; x5 r
template<class TYPE, class ARG_TYPE>
" y2 v3 H' ]: I& rBOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)$ _% ~2 p% g) z2 y1 c& O W
{
5 F9 j( h7 e. Y int nIndex=this->GetIndex(cIndex);
" c: T4 w& z- d4 s) r return this->DELIndex(nIndex,nCount); L% F; f% O( `; \, n1 G+ W
}- r' Q5 r* P2 _. u
template<class TYPE, class ARG_TYPE>. [& ]7 p3 R- z
int YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex)
& k& T2 q7 T. o9 _) B' U8 `{//得到 cIndex 的数字索引
$ h: }8 N6 _' k' |) Y int nPos = -1;" j6 K0 @- K& Z5 w2 Y+ r
for(int i=0;i<m_nSize;i++){4 U/ ]2 c/ g7 \( x! u
if(strIndex == cIndex){
$ ^9 J/ N; Y5 y3 Z: O8 s9 M nPos = i ;break;
, G \) f) X9 h# l% H2 [& ] }
9 |2 x/ I( M8 i$ g3 i! f) F+ | }
" } f+ w* K- K1 S4 ?: }: H return nPos;
- S2 m2 ^* F. N( b4 K}
! E. Y) n) ^% M5 ptemplate<class TYPE, class ARG_TYPE>
, s4 q y0 b5 D3 y& cCString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex)
+ }' M0 Q+ R/ s; b! U{//返回 nIndex 的字符串索引
' O' E. }& D [' w: v return strIndex[nIndex];
. g' b N3 D- H# |% } l}
& N$ i1 x% p+ V# C, b5 s% U////////////////////////////////////////////////////////////////////////////// c& h: w0 A; ^- ], v$ D
// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE>
- U( W$ M* [8 o2 VAFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const
- {' D; x9 y4 `, |! b { return m_nSize; }
O. X' S, d' M' C Ytemplate<class TYPE, class ARG_TYPE>
( K y/ @9 }/ n V3 kAFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const' r8 w" X- C$ i2 z, q7 ?
{ return m_nSize-1; }* U! Q, \3 @8 ~/ J
template<class TYPE, class ARG_TYPE>
, X$ a5 e$ n! P& R: ^. RAFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll()5 _. x6 M' R- K; L
{ SetSize(0, -1); }
, W. U2 |* i, a% v+ _ ?, {template<class TYPE, class ARG_TYPE>
9 G) b( G7 W4 u+ G" J# i( ZAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const' t% N! n2 X& J v
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);5 W/ M5 Z5 O1 ~$ y* y0 ~7 U
return *Ym_pData[nIndex]; }8 x. x! B' S& V7 |# d
template<class TYPE, class ARG_TYPE>
5 M7 h4 `, b# l. f. p2 U b7 pAFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)% r1 @0 n1 J9 P9 |1 z" E( x% O' ?
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
+ j) _1 H1 |$ ~) H/ Q K! k4 T! T# { *(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>" K# j+ }; B& v" k( ]5 W& }6 T; H/ {
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex)( F" s6 W0 K u$ z7 p' s
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);7 B% g9 W! H0 d$ f4 l0 U3 ?' Y. T
return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>
$ s& n. A! K% l& |TYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const
7 l i/ \8 |3 n) ~$ A{5 _" L4 f; ]2 K h: d8 M
int nIndex=GetIndex(cIndex);
0 ]2 U0 ~8 ^! W q! M9 g0 f return GetAt(nIndex);
) t" }( m2 E& k" `0 Q1 b& B( Y}
) C |) U3 ^$ Y V: I5 x: t* b+ ]2 f6 Otemplate<class TYPE, class ARG_TYPE>
9 \' Z$ j! y/ @2 z. Jvoid YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement). a7 N' ?4 ? H5 f# k
{
3 B5 r" u5 w3 ?3 [" K int nIndex=GetIndex(cIndex);+ y# f. O: @9 A3 V9 Y( A
return SetAt(nIndex, newElement);% a7 h0 t0 z0 D1 u5 y# ]
}
3 O! J; ]5 |3 D6 etemplate<class TYPE, class ARG_TYPE>8 e' ]+ N( m! ]# a+ ]3 n
TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)
/ X1 y3 l( P4 C0 ]& o{
4 L5 V J9 H8 i. Z. L" {# k int nIndex=GetIndex(cIndex);
- y0 z% D' o3 ?$ y2 L return ElementAt(nIndex);/ [, \ n; x; ~. n
}' ?8 m* |/ }( e; x
template<class TYPE, class ARG_TYPE>6 K5 O9 s1 q. {/ c* B8 A' j
AFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const, c# `4 v& S2 {" J; T$ [
{ return (const TYPE**)Ym_pData; }7 t. S d( n5 t. L& C
template<class TYPE, class ARG_TYPE>
* U- y8 ^4 l+ P2 y- A0 lAFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData()
+ D$ u+ ]" ?# { { return (TYPE**)Ym_pData; }
6 { `+ V( [* ]* B u1 c4 Utemplate<class TYPE, class ARG_TYPE>
t) J) h! d8 H6 M# G7 @ HAFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */); C/ o I$ S) s# z9 K3 c9 i
{ int nIndex = m_nSize;
) D4 M6 k/ J* n% U; y9 W SetAtGrow(nIndex, newElement);$ F- d$ [6 A0 K; D f
SETIndex(cIndex,nIndex);
8 i5 p1 x+ Z6 ~- H return nIndex; }
. \% R7 ]' G! ttemplate<class TYPE, class ARG_TYPE>2 I) n: M' W( r$ e* Q
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const
1 n9 v8 o. E# W( B7 v9 g% P { return GetAt(nIndex); }
) j) w9 }* n; @" |template<class TYPE, class ARG_TYPE>
9 H5 t7 k- p' Y, @& U6 lAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)
i7 {/ k9 e! W, t) ^ { return ElementAt(nIndex); }( m% \9 H4 Y9 C
template<class TYPE, class ARG_TYPE>
- ~7 t( s. x5 D$ d; t: @AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const3 K Y3 ^2 A9 V
{/ w( ?1 D3 Q+ g; F& Q; O
int nIndex=GetIndex(cIndex); return operator[](nIndex);
+ w' ^; z* n* g7 q}' B+ F% i, y* N+ t2 x# g
template<class TYPE, class ARG_TYPE>
2 h- `, ]( D) S3 [! B1 Q/ r! I; tAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)' T0 Y6 X) e/ X, k" |
{
, H8 f: T& G' Y8 i; b9 s int nIndex=GetIndex(cIndex);
2 W& K8 {9 R9 s return operator[](nIndex);
- j8 ~8 W2 q! \: ^}
: N) m+ L" t, Z- {% x3 I( R/*- |6 Q+ |1 @) E5 n/ U
template<class TYPE, class ARG_TYPE>. m" P# G; p* G, L
AFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const
+ B6 Z; P/ u% F/ {* s5 B% O{3 R+ |/ U* k+ ?& d9 a# g) ]
int i,j;; p& p! u, D' ~- [- t
for(i=0;i<tparr.GetSize();i++){
, N* H4 s0 @3 r7 q9 [2 m8 G j = GetIndex(tparr.GetIndex(i));' l+ ?4 k( a/ L. p. w2 r
if(j>-1){
7 p8 u4 c$ M$ S! {1 O, n operator[](tparr.GetIndex(i)) = tparr;
* b3 W" ]- w, }5 l2 l9 ]4 [: D }else{
9 [, j# f5 E- L Add(tparr,tparr.GetIndex(i));
9 \7 V; }- {( o% X) ]$ T) D" l/ _6 v6 u }
5 {- `% V6 N+ ]8 h( s }' b) V I& o8 S4 o# D4 i# q
return this;
2 W/ s8 w2 ~9 U6 ]7 d( y9 F}, c' g/ ]$ z: W: ~ B) C
*/
3 G1 u% a( L$ c8 C" t/ B0 itemplate<class TYPE, class ARG_TYPE>
% V. b. ?7 q E* ?7 n# u# W( Q: zAFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src)
# C: s: \8 A) ]8 G% {{
$ r" w( F! A( k A5 B6 @* j ASSERT_VALID(this);
1 b9 }* j3 [/ B3 w d: d% f ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);. z( Q4 G0 D, G; ~
for(int i=0;i<m_nSize;i++){
" R! U) C* r" ~1 v1 r /*将此句修改为内存拷贝*///
' f2 T# c ?4 E *Ym_pData = *src.Ym_pData ;9 K7 T' N) t' c& E2 q9 b( o
//memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));5 L4 r- ^; ?. j W
SETIndex(src.GetIndex(i),i);- h T2 P1 z* [2 W3 E' ^
}
9 S' g! }* }- S, v) D2 u return *this;
3 A& C# c9 C* [; a' }& Q}
* n1 Z: Y" U: i" f/////////////////////////////////////////////////////////////////////////////
) T( o! m2 ?5 n. m// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>" I2 {7 @* |( @* ?/ F# C
YCArray<TYPE, ARG_TYPE>::YCArray() J# C9 F% B' Y" [
{
: E/ f$ N J- [ Ym_pData = NULL;
6 }8 e5 ^4 C& s strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
! j2 W ]8 j; y6 Z8 t strIndex=NULL;MAXSIGNTIME=10;
' J, q" b: j% X% e- B# H}
2 p* S) c& i3 B* C5 {, o2 n6 Itemplate<class TYPE, class ARG_TYPE>
+ E4 T) z6 t5 N v9 F* BYCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp): P' {* o3 j% l8 k- b
{8 ?$ [- i- q& H! H
Ym_pData = NULL;6 I: C% W9 P" a
strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
, c6 I d% z# P, g6 b$ G strIndex=NULL;MAXSIGNTIME=10;
d4 B+ z) S, C8 V9 |1 r% n* D operator=(tp);
- S4 q x/ q. i* K! G* B} template<class TYPE, class ARG_TYPE>
5 }* D9 C3 @: z+ q& j8 b7 avoid YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy)
' I0 ^' z" n; m{
4 p9 G" x& J( I0 J9 p+ A8 j ASSERT_VALID(this);2 e# c3 u/ F4 h3 x: W2 Y
ASSERT(nNewSize >= 0); if (nGrowBy != -1)
2 i' J5 \, r a6 m, S$ v5 m m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){
5 [6 F$ J2 h4 F0 U \( _ // shrink to nothing
[0 p7 Q- p% A1 I7 f if (Ym_pData != NULL){. K7 f4 A& f1 E' r7 g: y2 a& ?
DestructAllElement(0,m_nSize);2 R0 y/ M; ?( m$ \5 w$ `- T; B+ O
//DestructElements<TYPE>(Ym_pData, m_nSize);* `9 M4 e$ K, q+ t+ M5 E
delete[] (BYTE*)Ym_pData;
( O2 c3 v$ r" s% V" ? Ym_pData = NULL;8 ]- X8 p# ~/ d8 S5 R' d) W
}$ w) e8 D8 }7 D% i
m_nSize = m_nMaxSize = 0;
8 K) y. X. l* h4 H0 D } else if (Ym_pData == NULL){) M* Z- T3 |1 i, A& L$ s2 ~
// create one with exact size, K `' w9 P$ R* _0 W4 n
#ifdef SIZE_T_MAX$ J- t& s8 O& V! n# ]: |
ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow0 g3 |' L0 B$ {$ {* j! o
#endif! N& ^/ c# `0 q; j9 V- e
Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];
. Z0 I& }! [/ s/ }: n ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);: w1 `% ]* G, K0 P* [) Q% h
m_nSize = m_nMaxSize = nNewSize;; e% H4 A3 j6 R, ~
} else if (nNewSize <= m_nMaxSize){
0 U" I5 V8 P( k" `) \; y // it fits5 y X! t6 c. T* ?/ }, T
if (nNewSize > m_nSize). b, |/ J$ c5 J9 i
{" E4 J! h" I% Q
// initialize the new elements
$ d, i% C- _3 E7 `2 M( B ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);
* T2 \9 w/ T* P4 ]7 q* m5 j }: O# C. }" N3 O* I
else if (m_nSize > nNewSize)& M! y! w5 x! Q% x& s A, S: M
{
. u4 r) o6 P+ D6 X' S ]! E5 ?- ]: i // destroy the old elements+ ?- x% Z; W3 v
DestructAllElement(nNewSize,m_nSize-nNewSize);" A7 d$ N9 A& B( ~* I& t
//DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);
* S6 W" J. l" ]6 ~3 q. z }/ n3 X. z8 |$ h9 `* F: X% c
m_nSize = nNewSize;9 y! C7 ?( _% |6 K
}
, ]3 J d4 i( z b' H/ L else
) G9 M8 ^8 e) {# J {7 M7 S g6 F0 N9 ]0 S& s0 i
// otherwise, grow array
+ X) k$ c* z0 o& h; }7 d int nGrowBy = m_nGrowBy;
/ F1 c) `7 m! ?) l if (nGrowBy == 0)
+ N n3 S, M! \* h" r$ U {1 z& L n) w( \3 G* Q) N1 ~& |
// heuristically determine growth when nGrowBy == 0" g$ k, _( P) r; Y/ r3 z2 z
// (this avoids heap fragmentation in many situations)
: J# s: \8 S/ U, W( m nGrowBy = m_nSize / 8;
) T: @% ]9 m) y- w9 K nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);% F m, m; b$ M6 R/ m$ V5 p' T
}
6 d7 ~- i$ V3 N; Q' U int nNewMax;$ X! n; ], r/ }* G. `
if (nNewSize < m_nMaxSize + nGrowBy)
- E" q7 _* x* c9 ~5 C. \8 I4 e nNewMax = m_nMaxSize + nGrowBy; // granularity" @0 V! e7 O( d* ?, L
else
) N+ z' _7 O, {6 F nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around; i* q$ x! L7 Q, @! R
#ifdef SIZE_T_MAX
8 Z8 \: t* Z1 `% n7 k- q' H ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow
d. P* k. i; L! K# Y7 u#endif2 L3 ? V( Z% m; `: x/ ~
TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old% C7 p1 a6 e g! p( ]1 ?- A
memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements
% l& \7 c9 ?, g ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");7 z' |/ c$ _9 ~4 z# w
delete[] (BYTE*)Ym_pData;, A, R0 p5 \$ E1 B- `) l
Ym_pData = pNewData;
# i* F- m' l& v' T ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called)7 _. ~9 x2 b, e
m_nSize = nNewSize; Q! Z8 i& X/ n3 D$ M
m_nMaxSize = nNewMax;$ I" T7 P) ?, g! F. a
}
% u1 Q) N9 v% v; S. ^ SetIndexSize(nNewSize);0 L$ L, a% f8 X' w9 {% v$ r
}
) Q+ n* o4 \, i! b |