//接上面 / y9 j% Q& P8 r6 \, n/ O
template<class TYPE, class ARG_TYPE>) e! }& T8 v1 M/ {" N
YCArray<TYPE, ARG_TYPE>::~YCArray()5 U. C& u: y m t5 v8 Z- V; U
{2 {$ l' v; s3 O1 Z8 S! m
ASSERT_VALID(this); if (Ym_pData != NULL)
+ w8 c1 c, X& [* W, q4 W {# u2 Z- l$ P7 E
DestructAllElement(0,m_nSize);- S; {7 j# O- e6 A; z
//DestructElements<TYPE>(Ym_pData, m_nSize);
6 ]( I$ @, T2 M+ P1 A delete[] (BYTE*)Ym_pData;4 O; I) y: s- _ r) j7 ]
}1 Y3 O- N8 D) Q) R# ~8 f* r' `: c
}
2 g. S, u/ a1 j- _3 i4 xtemplate<class TYPE, class ARG_TYPE>
1 f* [* O3 T* }4 ~" H8 tCString YCArray<TYPE, ARG_TYPE>::GetSign()5 L* `( F- i' a* S; s( m0 g$ o- L7 y
{" \, q2 [# d, E
lock_sign=0;
' g1 Q; d. t5 \6 A% [1 @ return Sign;& v" \# G3 a' H2 ?
}
& X9 `% p* I l0 Z2 Y- n, ltemplate<class TYPE, class ARG_TYPE>
! {+ X8 V9 Y3 a" I0 o2 S3 Wint YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign)! j3 d v9 Z' y8 t/ H1 }
{
7 {' J9 f5 E C7 i int i=0;
, n. N) z% t8 g0 W0 L while(lock_sign&&i<MAXSIGNTIME){, [/ g' a5 {2 k7 o+ P2 M7 Y7 @ h
Sleep(1);. f) M5 r8 N/ `* \; g! z' ]! H# y
i++;* R/ |9 }( z8 A! R* f: j
}
0 u8 g! U7 u- k' ~% u4 }3 X) L; `* A7 M lock_sign=1;& |% M& C1 ?) ]' g1 J
Sign=sign;& a0 R( l2 p- X" V3 j
return TRUE;
$ I; i4 M( G! ~) ?% T2 \}# m' P) o. {9 m* H2 C) O
//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer
- _* B/ z$ v1 \, K8 q6 A# E3 Otemplate<class TYPE, class ARG_TYPE>
+ E- A' V+ u2 t% S8 A: Z7 u) KBOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)
" t* r5 i8 W- F5 ~ D{
5 f. O$ K1 Q6 d" d if(strIndexNum < nNewSize){
7 c6 G- k' g0 H5 C CString* tp = new CString[nNewSize];//新的buffer1 ~- h+ ~" r5 F& v# m
for(int i=0;i<strIndexNum;i++){//把老索引复制过来8 i! z# u( w1 z) |
tp = strIndex;
/ i$ k1 n: f2 T; Y1 W$ z8 \ }$ H( f( q _+ J+ }( b
for(i=strIndexNum;i<nNewSize;i++){0 ]1 V% G. k1 Z
tp = "" ;* Y" V) n# H: ~% A! z: m
} % x. J$ B' K' d" ^; s: o$ h/ i
delete[] strIndex ;
) Q8 C, l* w' \( b8 [4 m( N9 v strIndex = tp ;+ }- v3 ^9 r9 v! }" v
strIndexNum = nNewSize ;4 x9 x9 S( k6 t7 {6 h6 t
}else if(strIndexNum < nNewSize){( ]4 E# r( o. [5 j0 N. ^' X
for(int i=nNewSize;i<strIndexNum;i++){
' Q6 a5 J ?+ X" U strIndex = "" ;
% \8 q1 q% \% ~9 ]. Z }' r6 R5 O3 B) n, S
}. Q2 h j4 b. a$ {
return TRUE;( @8 A' o1 W( X8 W3 c( H4 U
}: r) ]7 L) K3 l3 q( t
template<class TYPE, class ARG_TYPE>$ [6 K7 q0 b& K% _4 E7 \2 s$ W) l
BOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/)
' i* d# o$ f1 s0 T% s{
; ^* n2 X1 e1 a+ D) E5 V$ y CString* tp = new CString[m_nSize+nCount];//新的buffer/ r3 i! {( L2 k: d Q+ ?- X, r
for(int i=0;i<nIndex;i++){//把老索引复制过来1 B7 i8 f' w# ?
tp = strIndex;
7 K3 D8 p/ x4 ?5 }& a0 O$ P2 N }int j =0 ;. q0 z2 P _1 v2 n" d
for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
( {; x: J. |3 ]' y- S) R4 k, L4 y tp = strIndex[nIndex+j];2 x% G9 i5 q& g: z# G+ _5 @
j++;
5 p7 t# l, ~* V. B% I }
# [1 v0 B6 x/ R4 m8 X* d& f4 w delete[] strIndex ;2 X/ `/ t/ }4 }
strIndex = tp ;# M: r) Y& n! k& p
return TRUE;9 o8 ^+ B# X) b% r) _
}/ |2 J8 Z$ E; ~4 D
template<class TYPE, class ARG_TYPE>
: h1 l! I; i5 b5 K4 u( ~7 F6 {) |" CBOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex)
4 @( Y$ }- y q, i0 D{//在 nIndex 后面添加一个 字符串索引
8 S( U3 l2 s; t1 P! `% e strIndex[nIndex] = cIndex ;$ e7 {& [3 c1 M$ Z& ?0 f" v& }# e
return TRUE;
, j1 b/ K% C; z) l; e9 q" k}
3 M% f$ m* L/ S% g4 S: a- utemplate<class TYPE, class ARG_TYPE>& T8 r/ U( Z4 E, F4 l
BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/)
) O0 ^2 C" n$ w4 c{//需要在 m_nSize 变化之前调用!!, g0 J, `, k$ G! L# c8 t' P
ASSERT(nIndex >= 0);
) y4 O* _+ R. S ASSERT(nCount >= 0);
5 X& u4 \+ \7 @1 o6 F2 L ASSERT(nIndex + nCount <= m_nSize);' O8 \3 C4 P. H) ~7 O2 i
int j =0 ;
& |$ o- w3 i" K) n, j for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
: |% p0 q# V: u0 F( S* { strIndex[nIndex+j] = strIndex;, v0 z2 f+ ?/ Z- u3 d, w
j++;
, H2 f5 t- k) f! h/ G' [* E8 F' ? }, n& j A. d4 F1 |5 o
return TRUE;
! r, _) ?$ j8 E' R1 | i* R9 s}1 f( n) r. n, g; X3 g
template<class TYPE, class ARG_TYPE>
8 o- E. P# ^4 @ o ABOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)
8 M- r. l- E2 Y- b+ T4 s( V{
/ i1 ~9 [$ A1 p: |& L# g1 D3 W int nIndex=this->GetIndex(cIndex); m6 x1 n1 n' w" s) c0 w
return this->DELIndex(nIndex,nCount);
) w( p8 I; |- b, U3 U}6 p' h+ q5 [8 U8 y, \
template<class TYPE, class ARG_TYPE>
6 ]! i0 c* G2 ~# J& ]" Iint YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex)7 P. }5 m5 J- s+ j0 v) ^( e
{//得到 cIndex 的数字索引
. V+ j9 T+ ?- b0 Z int nPos = -1;% Q! H3 u8 v6 {0 o0 _
for(int i=0;i<m_nSize;i++){6 U e( A j# H, ?; U/ A. U3 m
if(strIndex == cIndex){
8 _1 `6 X; o/ m/ h6 R nPos = i ;break;
3 C- I9 f1 K9 `7 G) N$ n0 p0 O }" ]! H; N9 y, z2 ^ ^
}+ i' ]# s6 W& k2 i$ A/ B
return nPos;- t( y0 C* v4 U0 \. ~; _
}' V# L% t8 Z! q8 B4 ^
template<class TYPE, class ARG_TYPE>; X: {, Q% ?& _3 M
CString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex)
. I6 X, f, m; Y3 d' ?4 L{//返回 nIndex 的字符串索引( _, X$ H' A: L6 u8 n
return strIndex[nIndex];
9 j) U1 ~' F0 \* [7 z}
! T5 _/ c% E( o6 D A* |: X' U. U/////////////////////////////////////////////////////////////////////////////
; o0 m& X; s# i// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE>( j5 b) b! A9 u' E" M
AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const
3 y' s, N2 v0 s. a" j { return m_nSize; }& C1 s: r3 C: Y, D( y
template<class TYPE, class ARG_TYPE>
4 k1 u; C7 |% i9 h- g0 \AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const! S& M. t, q7 l" _# a* n+ B4 ~; N o
{ return m_nSize-1; }
/ R" q& y. N5 H" i& l% L5 ]template<class TYPE, class ARG_TYPE>* h6 ^) R- w* D1 q) M
AFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll()
+ {9 E. V7 Z0 w: m. n# [( z { SetSize(0, -1); }
7 A" M# w. T* H3 i' etemplate<class TYPE, class ARG_TYPE>: S, b! o) u% C/ c; |
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const! ]3 j, U0 R1 j, ?2 e" r' g) V7 R
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
; n2 B. V |) R6 G* d return *Ym_pData[nIndex]; }
/ e" F% a |) h+ T( p; S2 H# d' `template<class TYPE, class ARG_TYPE>& z( L1 M4 W* I; J4 ?9 q
AFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)
4 ?- l: W$ N1 b( f1 a* M { ASSERT(nIndex >= 0 && nIndex < m_nSize);
* Z8 U# P6 j9 N8 G/ M *(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>
' P- w0 Q, X OAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex)
0 l8 T+ Y+ |# Y3 w, z { ASSERT(nIndex >= 0 && nIndex < m_nSize);
1 C$ Z/ F; @2 h return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>
* { D* G" ?3 I4 nTYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const. \- `- r! k L
{* \' A) A$ `1 `& ^; b% j$ a0 w) U" X
int nIndex=GetIndex(cIndex);
' Y# J0 [4 Q8 M9 Z" ~9 Q3 o, B return GetAt(nIndex);; n1 ]' s" P8 t! Y
}6 J$ O3 Q* {6 D# W$ p3 ]& S7 e
template<class TYPE, class ARG_TYPE>
) ?. n- {7 S! O a2 e& Qvoid YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement)
' ~2 Y, L$ u& J& Y{
6 f: Z$ s% s5 e# ], R: M2 j+ Y int nIndex=GetIndex(cIndex);
h% |% ]' E4 | return SetAt(nIndex, newElement);! h+ X! ]% j) O
}& [4 [$ C# w+ y* w4 w# E
template<class TYPE, class ARG_TYPE>. @. T' v1 M1 K* v+ a* s# e
TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)
# D) Q- I# b1 a{
7 J: M. ~) X8 G f) k int nIndex=GetIndex(cIndex);7 z) C7 {' _. I3 @: o
return ElementAt(nIndex);. V. B) c1 o% ?) [1 n
}6 g1 b/ K4 G1 Z5 @
template<class TYPE, class ARG_TYPE>
3 u& Z; x$ X( M8 FAFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const
4 l9 }8 r5 {, t. t { return (const TYPE**)Ym_pData; }. m( \8 @3 O; e0 M- J2 d3 h
template<class TYPE, class ARG_TYPE>2 }8 C) O4 L s- `( c' A
AFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData() d( ^, S1 a D0 Q9 v0 ^
{ return (TYPE**)Ym_pData; }# j+ K. _/ K0 P# d
template<class TYPE, class ARG_TYPE>
8 f# R% b& _: ~3 F1 IAFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */)! W$ }' @$ Q" W4 y7 Z
{ int nIndex = m_nSize;: V F; _( H( g8 S" ?; ?- i# E2 T
SetAtGrow(nIndex, newElement);
; O* L' i2 u$ y$ N' u; w8 z SETIndex(cIndex,nIndex);
1 n; x c. t) v/ e& S9 U return nIndex; }
5 w2 [, Y# Q N9 B0 ?template<class TYPE, class ARG_TYPE>
" S" Q# G% }. l4 u- b6 O9 c" IAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const4 i; @/ J2 T, J3 P4 ~
{ return GetAt(nIndex); }2 y, J; g: l4 n6 Z B" o8 x+ a
template<class TYPE, class ARG_TYPE>8 N2 h- \+ C n/ u; w
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)1 i( L* S X& R- D
{ return ElementAt(nIndex); }" O6 S4 ]* L( y* C$ C1 P
template<class TYPE, class ARG_TYPE>
/ O0 r3 K! f7 R2 D% x! e4 gAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const. v( U) E6 Q* D4 p ^
{ s0 M$ d y$ ~8 M! |
int nIndex=GetIndex(cIndex); return operator[](nIndex);' D C4 z0 i _, Y' u3 c
}
+ t& T/ Z7 c0 r7 _template<class TYPE, class ARG_TYPE>* t+ J6 k, @5 X, p* j0 }5 ^2 |
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)9 E- M" ^, `2 l
{
9 z! G" j! O# A% n! @: T int nIndex=GetIndex(cIndex);
7 |7 @* \0 ^. ~3 Q; i; o return operator[](nIndex);
* ^6 {; [" B* p# q8 x' G}9 d2 F- u+ z* ~' g. f+ K( J
/*. g/ P8 H3 L) E
template<class TYPE, class ARG_TYPE>1 E' Y* n- o/ c8 V! K& O) F
AFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const) ~5 E* V+ E- g
{4 `% {; V! l; f# l! X. t
int i,j;
/ N% l) \ m7 i) N for(i=0;i<tparr.GetSize();i++){; E q) @1 ~/ G! X d p
j = GetIndex(tparr.GetIndex(i));
' N% C" @4 {1 R+ R0 j) R5 \/ @ if(j>-1){
! S/ j9 b, |0 Y0 ^ operator[](tparr.GetIndex(i)) = tparr;( L7 r, {* G. d
}else{" c" Y% ~* ]5 B9 l3 D/ Z; H
Add(tparr,tparr.GetIndex(i));
4 T w# D, S0 e4 Y9 U3 i }$ @2 t% h' g( v7 K4 l
}& a( F' W1 L0 C _; ]5 ?
return this;( M& p/ G& T4 _) B$ ?
}
3 {+ |1 ]- i C4 v*/5 W* k' t, t1 {5 p+ U; l
template<class TYPE, class ARG_TYPE>" E; {: W) q, q0 \
AFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src)* x6 J8 u% t/ {% H+ M: }+ h
{1 b! |4 t" S0 n1 t& {
ASSERT_VALID(this);
) K0 ~' i" S" ~& Y ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);
7 l4 @* J$ U0 N. `/ _/ x for(int i=0;i<m_nSize;i++){4 h. f5 U5 ?6 f+ \" t; m
/*将此句修改为内存拷贝*///; t8 A- P$ w- W% g1 z$ e, H/ ^' T! Y+ M3 G
*Ym_pData = *src.Ym_pData ;
8 \5 b, V/ y$ w( Y- e: k3 v //memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));
" K. o I$ T+ [0 {, G U+ y, W7 n SETIndex(src.GetIndex(i),i);
3 F6 k5 B) I* n( B& m+ |" M }
7 N( w& ?8 x, r, e% v# ~) A% p* } return *this;/ U: B, g( d* x, p
}- h; L+ K9 A. L/ ?" Y
/////////////////////////////////////////////////////////////////////////////
7 H& J- p( }% t0 u% l% f7 q// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>
S& c- k" j# S6 ~" g ~! i! b4 ~YCArray<TYPE, ARG_TYPE>::YCArray()
" S7 c$ U' k- y8 b5 U* i0 U6 R. x$ f{. D3 ^ S/ M2 S4 ^6 q% y$ [
Ym_pData = NULL;5 k9 t/ G! h9 k6 W* E( M
strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;$ _# r* y( K E6 m" u: q
strIndex=NULL;MAXSIGNTIME=10;
' k7 e! I# X0 F' n/ p9 J, x}
. q( D. T) K: G; S) g! N, ~, [template<class TYPE, class ARG_TYPE>; o' q( K7 C W
YCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp)
) H, |9 q1 `2 X; u( B{8 l# D) |7 i t) [
Ym_pData = NULL;. W/ W! K, n$ m9 J/ P
strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;4 h) P+ R9 m. z
strIndex=NULL;MAXSIGNTIME=10;! n+ F9 _& N- A( [( ]5 d( @4 d
operator=(tp);4 t& @4 U. Y6 [1 Q5 U
} template<class TYPE, class ARG_TYPE>5 q: Q* ~7 g- m4 Y4 D7 c( D
void YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy); B- ?. e) o: x, V8 H
{- _, X+ T. d) K( `3 M
ASSERT_VALID(this);% t! a. E1 I6 N' u% e
ASSERT(nNewSize >= 0); if (nGrowBy != -1)2 @( \8 |7 C$ U. D! b8 |& w9 q
m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){; v/ J1 Y/ f2 K& O! Q% R+ }/ \
// shrink to nothing
) f5 @: F$ _& s if (Ym_pData != NULL){
& ^8 Z" ^) Y$ ^0 M7 ~; r) K* a DestructAllElement(0,m_nSize);: {8 q, t: m' D9 S* f, Z
//DestructElements<TYPE>(Ym_pData, m_nSize);3 L! e6 v& d& n
delete[] (BYTE*)Ym_pData;- z0 m$ g: O: ?8 I+ K
Ym_pData = NULL;8 z$ X# l% ]; F& j
}' X3 U8 }, ]. Q/ A! m
m_nSize = m_nMaxSize = 0;
+ F, V1 z% c3 T5 t8 j5 o- q } else if (Ym_pData == NULL){
: g$ q0 q6 f( L3 c9 N/ ?* l // create one with exact size
! S: c( U E. p#ifdef SIZE_T_MAX1 N! `/ A5 s! N: T2 j1 V# E
ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow
+ d8 ^# d j8 E# }#endif2 Q( Y0 s; W/ _5 [
Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];
/ t- A7 f) V4 ?7 n$ Q ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);" ]& J3 @8 Z1 ~4 T2 u4 Q/ [1 k& D
m_nSize = m_nMaxSize = nNewSize;
" o9 B" M4 a( M: z: o: B; g } else if (nNewSize <= m_nMaxSize){8 N* A# F, {( \$ W8 m
// it fits9 R7 w7 M: Y+ h+ F( } p# q4 z
if (nNewSize > m_nSize)1 r& \. W, f3 ^; b: }
{
9 f/ ^% W- l" V) R% b. T& j) d // initialize the new elements# X+ Y0 B! N6 [
ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);
/ m6 N5 `; E6 K1 v }
6 w( Q! g- P3 T2 a: R8 X' d else if (m_nSize > nNewSize)
7 F" O! L0 \" T1 I {2 h& j- V1 W6 e! [
// destroy the old elements
+ r- D6 ]' u" B, y( W DestructAllElement(nNewSize,m_nSize-nNewSize);% B* |, B* _ _* N2 H4 x% @! n9 R
//DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);$ I! x. ] e0 q6 O/ y
}
V% K7 O2 z0 w2 M/ b& R t3 S/ Z m_nSize = nNewSize;
2 e2 t" v9 z) N8 T }+ h, L; B; Z# n2 t I0 ]3 D- \; _
else
0 g* `, q9 h, Y& h. v ~ {7 P' i6 D& \2 R$ Y W6 b; \
// otherwise, grow array1 Y, ^( j& e A% c& _" i+ h
int nGrowBy = m_nGrowBy;
% P) M2 ^$ |* y4 U" G if (nGrowBy == 0)
- ^9 q# o# X6 Z8 t; a {, Q* X$ }2 l( W! w4 S7 K
// heuristically determine growth when nGrowBy == 0
. r2 s8 a+ D. Q8 ] // (this avoids heap fragmentation in many situations)2 W, `3 [& H% u) Q
nGrowBy = m_nSize / 8;
2 i$ U# J' Q1 ]: } nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);) b0 v4 q ~, e# Z5 ^9 Z7 W6 Q
}* \1 _0 z- \6 `3 v! n( e
int nNewMax;3 c9 c# X! Q: Q5 h& n4 Z, E. [
if (nNewSize < m_nMaxSize + nGrowBy)' w6 s6 n8 ], k& z* Q
nNewMax = m_nMaxSize + nGrowBy; // granularity* N" x; P4 ^, _
else8 B4 M. _5 m- m
nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around
; W; r! E9 i# B0 C* Y& a" \#ifdef SIZE_T_MAX* n G& o7 s0 A7 h' ?
ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow
7 x9 k5 z. _4 B, S1 U$ S( j# ]1 I- P5 T#endif# ^8 R: f( F3 \* S1 M
TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old D/ J& M8 {0 W) k9 p/ b+ K
memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements
2 c6 B$ u( M4 J/ v* S, l! W ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");* Y+ s: \4 j7 U. w% g
delete[] (BYTE*)Ym_pData;
7 L) {4 |- P1 ^1 A8 ^" Y7 r5 y Ym_pData = pNewData;
$ d }+ r1 s# W ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called): H. F# Y3 G( W! k! t4 k+ ~
m_nSize = nNewSize;
- c6 i5 M; }1 `4 R: Y! w- F m_nMaxSize = nNewMax;
: R: u4 B& j8 z8 I* k t$ K }
& F6 P9 L, y& ]( h SetIndexSize(nNewSize);
3 l: e1 X0 l1 X0 v# E! c}( h5 p7 l+ G' E5 C. Q
|