//接上面
& B% ^' i J0 R5 itemplate<class TYPE, class ARG_TYPE>
) x: q+ R1 A6 L8 v7 k- f1 MYCArray<TYPE, ARG_TYPE>::~YCArray(); W" d4 ]1 a* Q$ D& p; U
{
6 I6 y' k, `0 v+ q6 j7 J ASSERT_VALID(this); if (Ym_pData != NULL)" `* K. V1 ?* [( c0 J" E) ?1 l. x
{
! y7 w9 z& D4 H5 ? DestructAllElement(0,m_nSize);- v5 A5 s* l; X$ C4 f
//DestructElements<TYPE>(Ym_pData, m_nSize);
8 g+ j$ ~% L0 v% n delete[] (BYTE*)Ym_pData;2 }* X$ V: t$ u0 _1 m
}
: H& J( e/ k, v$ |5 D" a5 x, |5 R}
* D$ p1 k) r4 a- R$ M( @6 k: D ~4 ~* Htemplate<class TYPE, class ARG_TYPE># M D$ K' y3 f3 Y
CString YCArray<TYPE, ARG_TYPE>::GetSign()
" \( O3 s( {/ Z b, |$ |{' e! U3 _0 |* i' g, B
lock_sign=0;
! U2 Q, F/ c9 U( E# D; T( H return Sign;
* X9 H* z' F* y/ b}) D9 g" R0 l/ \7 Y( _5 h
template<class TYPE, class ARG_TYPE>
' ]$ ^) G" }, |8 a$ o, O4 Z* |- mint YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign)
L& z3 W3 ]. e- M{1 J! ~( I# r2 ?2 j T/ S+ c ~
int i=0;
+ Z4 S. }6 M- z8 c" f/ A! i8 T& i while(lock_sign&&i<MAXSIGNTIME){+ u9 a. z! Z: s$ r: c) z, ^" l
Sleep(1);
' @# O M- ]5 }$ o5 N# Y0 F1 j! y% Y i++;1 [7 D: J; c1 ^
}
3 X! w7 Z8 H8 O2 Q! {6 @: Q lock_sign=1;
! s5 n8 a4 ?/ \/ A9 H h Sign=sign;( {. k) }9 Q8 E
return TRUE;/ O8 B1 o6 t$ u/ J' z
}' h0 W7 k A/ D) b
//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer
7 h& U8 G Z* s$ Vtemplate<class TYPE, class ARG_TYPE>2 c" @% a, Q! K& |6 ^
BOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)
/ ]" e( {" t0 N/ `{
! g6 u( F$ K _# t2 i% v% s- r1 G if(strIndexNum < nNewSize){. u. e3 z1 D+ a0 N- X. w
CString* tp = new CString[nNewSize];//新的buffer
I* H! e; X4 t6 t j/ k" _ for(int i=0;i<strIndexNum;i++){//把老索引复制过来
% p3 Y: \& ?! R7 V% O tp = strIndex;6 O# D% I( u5 u0 w' w$ g
}- o: E6 r3 T9 b' S0 G+ r
for(i=strIndexNum;i<nNewSize;i++){
: P0 ?4 @) Z) {, X+ D) W" d$ D% ] c& B tp = "" ;
W7 i7 q! Z% G; K) S }
5 G; P6 _$ A3 q0 k' Y" [ delete[] strIndex ;
% A9 f' U9 j' m/ j$ [ d% ~) c strIndex = tp ;
5 V6 N+ z) s% F! w0 ~) d! Q strIndexNum = nNewSize ;
7 v, L) G3 M: k$ @, c1 R, m: D }else if(strIndexNum < nNewSize){9 S/ |* ?) l, \2 O2 G+ E g
for(int i=nNewSize;i<strIndexNum;i++){
/ \/ q7 X# T% n6 y strIndex = "" ;
& a5 Q/ \: \1 Z3 J; W2 ^ }
2 [; x4 D' R9 ? }, d/ H/ d) g3 i( c3 I, r
return TRUE;# F3 Y6 K& `1 c8 c- [
}
C8 z$ |0 S0 stemplate<class TYPE, class ARG_TYPE>( Y/ s( v! ` _6 L) S
BOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/)
$ M8 M" A! N8 U1 A- \* S7 Q{
+ s2 q2 x! b' P CString* tp = new CString[m_nSize+nCount];//新的buffer
# g( z% ?1 X) ]/ H9 C for(int i=0;i<nIndex;i++){//把老索引复制过来
$ ]' G* v3 H3 K* `6 F, Q. U tp = strIndex;& l* C9 {; G& \8 [+ \
}int j =0 ;3 b9 c9 p- L7 Y2 Q: m4 `
for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
( j, n7 ^8 f0 ^6 f. D- Z) o tp = strIndex[nIndex+j]; O$ |5 L% C# b% M: x$ _
j++;
9 a; i6 m9 G$ N% o }
& g( k8 e; s: w3 g3 ` delete[] strIndex ;
9 T2 m- Q* I0 {) _ strIndex = tp ;/ z9 t) z4 ^1 ]7 a* R" ^7 v
return TRUE;
5 q; D4 `1 |1 o# C0 j" {5 G}8 W# e2 K, h) L/ C# v. H8 r
template<class TYPE, class ARG_TYPE>* i$ `! C' t$ A! G
BOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex). x* F6 d8 w R3 j3 P% y% S
{//在 nIndex 后面添加一个 字符串索引
# D+ |6 u) w Y) z* i/ Z strIndex[nIndex] = cIndex ;. h U6 ?& n w
return TRUE;# E5 x+ c* J. n) R# O+ K0 W
}+ ^+ H$ b/ w ]( D- ?9 b4 E, m
template<class TYPE, class ARG_TYPE>' w, r6 g5 b* J% m. Y; C
BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/)
4 A% W; b6 Q7 A* A" ?, [0 s7 T6 g{//需要在 m_nSize 变化之前调用!!
3 j/ j1 \% \2 w% v* w/ r ASSERT(nIndex >= 0);
( ~5 O6 ~. B8 R0 b! o ASSERT(nCount >= 0);9 W# G- Q: ?3 I/ L
ASSERT(nIndex + nCount <= m_nSize);, ?9 d, s1 r8 o* @, G* G
int j =0 ;
/ H6 ?$ E% r' m, y# k+ _/ Y; l for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
9 p0 `" f- J9 K/ j0 U0 m3 K strIndex[nIndex+j] = strIndex;
) L2 S( L" b' G9 f& O" } j++;+ \7 [8 _. w; t
}1 a( |& [# \+ z# u1 T I
return TRUE;" l. M# l, Y- s6 f% ]8 q# Q8 X/ T' D
}
5 b7 h$ p/ Q+ U3 Y& Ltemplate<class TYPE, class ARG_TYPE>
! D7 `# a$ D4 U" ?& i; NBOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)5 g8 x+ S$ }, x3 I
{3 [4 F" D1 D R5 z
int nIndex=this->GetIndex(cIndex);4 o# B, P, L) w' g+ Y$ m. h* X
return this->DELIndex(nIndex,nCount);/ O3 _. I9 w& R/ @. Y/ C' |# P
}
( Q2 ]* Z* U3 c$ }1 p; M( ztemplate<class TYPE, class ARG_TYPE>
; n; ~' E8 W0 I" Z5 \int YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex). `8 N) {1 g8 S. q6 m. `$ O E
{//得到 cIndex 的数字索引
8 w- i. z; c r7 c" P' X" I4 m6 K int nPos = -1;( V7 f2 r$ h( t' {" ]* i
for(int i=0;i<m_nSize;i++){" R) b2 q1 h& ~' }% `' l1 @
if(strIndex == cIndex){9 r( O% |/ ~ M' i S8 u8 d9 G
nPos = i ;break;! |' q! w; x- \9 b1 S P
}) c8 i3 F9 D2 o. e* l0 s% v
}
0 K6 O6 M4 D' t% A& w return nPos;
3 p" B. e' l) v! C, [9 Q$ ^# \9 w0 N}+ s& ^' O% t, z3 g
template<class TYPE, class ARG_TYPE>
; i8 W+ L7 ]& V+ B* F- U) i' B VCString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex)
) _ [! _8 P& B* X/ t9 }8 U{//返回 nIndex 的字符串索引
- O& ^0 ? s- p4 P( @* [ return strIndex[nIndex];
4 w. P1 D0 n4 o; U/ f}' V3 C X+ V0 _' C( f
/////////////////////////////////////////////////////////////////////////////
- }& ^' Q9 T: }7 J; u+ Y6 B// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE>
! A6 [6 f1 Z7 b2 f) v' \! mAFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const# e( g$ S0 ?: N5 n7 n1 v4 t9 i
{ return m_nSize; }& g- ~4 p8 `( O; J
template<class TYPE, class ARG_TYPE>* `# @* \* H. P6 i6 r' v
AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const
% W5 a6 \( U7 F3 k0 x: b4 D0 O { return m_nSize-1; }
2 _4 o( U* S) I+ ltemplate<class TYPE, class ARG_TYPE>
' l" F7 T$ a. ?3 L wAFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll()
) m! |2 c, _ l( W3 J$ y { SetSize(0, -1); }
5 s6 k. \2 B0 G- \4 T+ u0 Xtemplate<class TYPE, class ARG_TYPE>3 e) h$ D6 O- n
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const
% v# A* u- T8 j; w f4 d { ASSERT(nIndex >= 0 && nIndex < m_nSize);
$ b' \0 ]; `# E! p; c W* G1 v" t return *Ym_pData[nIndex]; }
$ s, D8 F: f( Atemplate<class TYPE, class ARG_TYPE>, D( H+ x8 F2 M! {4 `
AFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)) a: _' V% q9 O a) N0 }
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);+ a/ y8 }: k g5 G2 h' l, X
*(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>) F$ Q3 Y# N& H) [) {. z
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex)& {7 Z1 w) Z) M O. p T) l
{ ASSERT(nIndex >= 0 && nIndex < m_nSize); B6 A3 @' x# H' X0 c5 d; b
return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>
1 d; n9 i7 ` B3 h" ?6 H; cTYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const
: D3 @1 z( ^$ X( H, }6 W- c{. a/ R- m; M" u! V8 K
int nIndex=GetIndex(cIndex);7 n T% i3 R- g: `8 P ^
return GetAt(nIndex);9 d s& S7 J; T4 o& A6 ^; a
}
2 t+ C9 k! _4 K7 a- }template<class TYPE, class ARG_TYPE>9 `9 p8 S" ^9 L
void YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement)
" B$ K- Y4 m/ ]: L: g{
/ H8 ]/ C$ E/ E% U int nIndex=GetIndex(cIndex);
& ]& `& l6 X E* p) P9 J return SetAt(nIndex, newElement); K) x. x$ N( s$ C% \6 E
}
) z. U# m& Q3 N, K* P) O/ O1 Jtemplate<class TYPE, class ARG_TYPE>
" a, m7 y. N0 a+ R1 F% S" wTYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)( `! M0 S5 x8 x: _
{
% _( c* d) l! f. f; D int nIndex=GetIndex(cIndex);' s7 y8 V) A/ M' I
return ElementAt(nIndex);0 u1 r) O: M1 ]+ I
}
8 h6 O! p" H& x; `1 M* @6 ptemplate<class TYPE, class ARG_TYPE>
0 }7 H* l4 _* ^* M- M( {0 xAFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const0 C3 |. L; D: T6 C0 M: }
{ return (const TYPE**)Ym_pData; }
) i7 ]2 _" \* w% b9 t1 S+ d, Btemplate<class TYPE, class ARG_TYPE>' A- e& [7 O `( T- r2 {9 i
AFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData()
( Y' O2 l9 d7 z3 y, d4 {$ s { return (TYPE**)Ym_pData; }5 y+ A& x$ O- {
template<class TYPE, class ARG_TYPE>( o' s7 }: E1 `* s. C
AFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */)
; L* T/ M5 f' w' L { int nIndex = m_nSize;/ A- h! E U- f0 H7 S
SetAtGrow(nIndex, newElement);) Z* p9 g- u) v2 w" v8 L6 s# t
SETIndex(cIndex,nIndex);
" M5 d/ J7 ]) Y0 q/ o* q4 H! I return nIndex; }6 N) }' e2 o, J
template<class TYPE, class ARG_TYPE>0 \" @2 Y3 L* z( }; g% r0 m3 g
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const- r8 S) u2 t6 v" n
{ return GetAt(nIndex); }, P Z {1 \/ I ]' h A: |/ {
template<class TYPE, class ARG_TYPE>
9 z3 J7 f0 `; C4 q, b* gAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)
9 N4 o7 M0 n. m( M O+ b" h { return ElementAt(nIndex); }
+ ]1 W) L( N" a1 wtemplate<class TYPE, class ARG_TYPE>& W) v/ N+ O% ^
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const
* P S, i& |" m+ V9 w" p{" W- E$ S4 a' e( M' O2 H
int nIndex=GetIndex(cIndex); return operator[](nIndex);
$ c4 {& z* C* @}
% e! X! Z1 O; q# x; g" T i; stemplate<class TYPE, class ARG_TYPE>4 u' t. s9 s1 R& W- W
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)3 l" b$ y' ~ _
{
' u3 f3 O) G3 U; Z. E& r int nIndex=GetIndex(cIndex); D" r% ~; t1 p+ `- a
return operator[](nIndex);
4 W2 ~1 |) B! C8 N}
! @. k/ E( A& f' s' V/*6 W; E' \6 x7 P8 |; F
template<class TYPE, class ARG_TYPE>4 p, c' }5 Y6 g; l: d1 Y( Y
AFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const
. O" Q/ Y U& E1 m; P6 }{
: |, ^5 T7 Q. j k D U* k int i,j;- G! k/ R% H2 v2 G* s$ \3 F P+ G
for(i=0;i<tparr.GetSize();i++){) S( N1 `' v0 g' A9 ^0 ]
j = GetIndex(tparr.GetIndex(i));/ @# H% W, f/ M M8 `- N: z
if(j>-1){% W5 m8 a% e$ \$ T+ E0 F, w; y- \: |
operator[](tparr.GetIndex(i)) = tparr;: m1 ^8 h( E( \
}else{
9 G* G& }+ |5 B* x Add(tparr,tparr.GetIndex(i));
, J. x5 X& g0 x% _# y }& q/ y6 C% C3 C1 }4 v. r: p
}2 C$ }! t! \0 z( p2 C: i V
return this;
3 D8 \0 q9 t& [* S}
/ L2 S+ r' G+ |. O2 H! t( |+ o*/
% s5 K$ f. M" t+ b; Ptemplate<class TYPE, class ARG_TYPE>! x6 M' q5 x% S) y+ j6 b
AFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src)% A) {& e, v$ A( L Z
{
: j4 \4 k" h @0 J3 I9 e; x ASSERT_VALID(this);
" H$ A/ ]/ x$ `+ B ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);
# J2 q! I# H" t; O for(int i=0;i<m_nSize;i++){
+ V8 S0 M/ |, [ /*将此句修改为内存拷贝*///
6 V/ a1 p7 d, ^# Y w8 w7 Y) H *Ym_pData = *src.Ym_pData ;! K& E7 K+ B; `. I- v6 y
//memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));- V2 v4 C5 d4 T
SETIndex(src.GetIndex(i),i);, R2 J$ @; |/ t4 R* t
}
3 ]# O j) o1 K" m e! s return *this;4 _7 k$ K& R9 r) V: ?! ?: s
}
2 X8 A* R) j0 Z/////////////////////////////////////////////////////////////////////////////
# _- j6 e' s4 m( q// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>9 }% a3 `' B# a$ I+ w+ G
YCArray<TYPE, ARG_TYPE>::YCArray()6 ?' q" O3 e3 c9 v% D) b
{
0 I. W( k) m( }; w- a. p$ `' m Ym_pData = NULL;: i8 f+ n, ~" p. c9 C
strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
1 I- A/ j. t: D* V' Z' d) B' R strIndex=NULL;MAXSIGNTIME=10;5 A- }' W% F# ^* P3 o- W& u, x, X
}
0 a/ o) p0 R; P) G2 }' M2 itemplate<class TYPE, class ARG_TYPE>5 I+ }& ~& P% j: Y1 @' Q5 C
YCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp)
% |5 Q" q1 G& k7 p) `' j* q" z{
5 T$ y( z. N7 o" L, J6 z Ym_pData = NULL;
( T! T0 z3 I4 B/ }- _2 W0 | strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
1 w$ L, N2 q8 @: J" \- } strIndex=NULL;MAXSIGNTIME=10;
% Z: } g. e! T+ } operator=(tp);; G2 T* a. P( H- e5 j
} template<class TYPE, class ARG_TYPE>
/ @, R! a: c/ L* }3 u" n1 {void YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy)6 P2 P) Y4 T* a. l
{" E. @3 e# z+ D6 K" P
ASSERT_VALID(this);( Z j& f' v8 g: |8 } U, o
ASSERT(nNewSize >= 0); if (nGrowBy != -1) R- g g5 V$ e! H5 n+ Y
m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){
2 K) A5 o% R8 z1 k! Z p // shrink to nothing' x& V. e5 s# ]6 }2 C, w3 n9 o U' g
if (Ym_pData != NULL){
; |) r7 ~( y% S- o* b! [6 z7 K DestructAllElement(0,m_nSize);9 }9 I0 o1 @" S( Y: y
//DestructElements<TYPE>(Ym_pData, m_nSize);8 M% Z4 O8 L8 y( z, y' R
delete[] (BYTE*)Ym_pData;
3 `. o4 b1 C" }7 G, p: S Ym_pData = NULL;
5 f7 U# o; E9 w1 b! C N }2 b' G; {7 E' z5 n. z( ^) X2 O" I1 a
m_nSize = m_nMaxSize = 0;
% c1 @4 k* {5 d } else if (Ym_pData == NULL){
4 \% `. b, D9 L; h1 r // create one with exact size
$ p0 n6 I5 [" i7 T#ifdef SIZE_T_MAX
# o3 f) w5 x. n- x0 q ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow
% Z' E5 h- {$ z% U/ A# C: ~#endif8 b y. R1 A5 D# z* p2 ]) J
Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];3 ^/ z+ V( s4 C1 w1 e/ T/ T Z8 J
ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);
3 C6 f2 g0 M7 I% o$ A7 C0 ]" l m_nSize = m_nMaxSize = nNewSize;* m# r) L8 g* q8 w$ W$ _) J
} else if (nNewSize <= m_nMaxSize){) _- g- Z% d8 ~1 F: _; y( f& ^8 b3 Y
// it fits0 |; W6 m$ ]( f7 g0 @) `7 W5 p
if (nNewSize > m_nSize)
% v. `& h5 V0 s i, m1 e* r5 N0 h; P {
: z' u2 U* Q5 k( k% E: Z // initialize the new elements& T( x/ j* `+ v( J1 ^
ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);) h7 p' p, s+ W# R* V `
}4 Y- {) T2 F; m8 g* H. ~( _; z
else if (m_nSize > nNewSize)
- I, G2 o: a! D& e {8 ]( B0 v5 _) w; X6 O7 j
// destroy the old elements
" ?) d4 n( @0 { DestructAllElement(nNewSize,m_nSize-nNewSize);
0 J [% U1 k0 _0 k, U$ F //DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);% L( N* M- X. H* _* c
}5 R8 u7 P. [( a8 D3 j1 _/ w3 `: v
m_nSize = nNewSize;
# Z z; C% T4 y/ f, ? }
" c) T0 Q3 c* C; V( m5 [0 a4 D' T$ S else0 p8 D3 \; L5 ^5 q! m k
{# f! {& M. W6 x: h
// otherwise, grow array
* a7 d( Q* R, u) q Y# \ int nGrowBy = m_nGrowBy;
% Y: p. _! Y7 I7 g" S/ u if (nGrowBy == 0)
" H* ?0 u" s, Q7 p {. E: m! k7 u0 W4 [! N. C
// heuristically determine growth when nGrowBy == 0" w0 w K' p! I- ^$ e7 K# D/ C
// (this avoids heap fragmentation in many situations) j: U, c7 d7 y% a- A1 P( E
nGrowBy = m_nSize / 8;8 Q& W/ J0 c- _9 l
nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);
4 Q" X& a) \, z9 b; e+ y [9 B }
, N8 W. r$ d( |$ o( t int nNewMax;8 u# M: s* y3 _5 A4 _9 H2 t! {
if (nNewSize < m_nMaxSize + nGrowBy)
4 ]+ B+ w. I* K1 F( U nNewMax = m_nMaxSize + nGrowBy; // granularity
/ m& C8 m% S; N' P else
# x% c0 }$ c* g# T6 W nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around/ t7 [7 y: @( D6 K, \9 l0 Q
#ifdef SIZE_T_MAX0 I5 }% _# ^' z- }
ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow
- T, o, }4 R, D, c% E0 x#endif9 m/ ?$ [% ~$ T1 p
TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old, Q9 ^3 d0 i) W2 M/ C
memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements+ P0 x& M3 v: f
ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");- J7 B# _& ^3 i
delete[] (BYTE*)Ym_pData;
/ }, o. ?- g* l Ym_pData = pNewData;
* n( x) g9 h- y: }9 c: f: z5 z6 F0 z ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called)
* b; I# y. ~, `% _* A9 ~7 [/ n m_nSize = nNewSize;6 k! Y) E0 Q$ i+ z& C" v, H
m_nMaxSize = nNewMax;+ @3 Y9 ^4 h8 z
}' m. w' {6 X" s9 }4 M
SetIndexSize(nNewSize);' H, |4 y0 d" Q, E! _
}0 V, L! e$ [7 |1 P3 N# }
|