//接上面 & }/ X7 L* X6 P0 s9 F; p
template<class TYPE, class ARG_TYPE>
7 B U& `' q2 Q, [0 JYCArray<TYPE, ARG_TYPE>::~YCArray()0 D! g+ i5 _$ }9 K7 d( \$ E, [
{' ~" N' b% [' Z6 d
ASSERT_VALID(this); if (Ym_pData != NULL)+ M% S/ m# G1 e" b: ^1 @. y( x
{, l$ ^# b6 a1 `+ z A0 K6 @
DestructAllElement(0,m_nSize);
5 ]3 ^; b/ V. F( E P //DestructElements<TYPE>(Ym_pData, m_nSize);
* Z( F* X+ w, g delete[] (BYTE*)Ym_pData;
* w7 v4 C/ X" H) [% N2 x: r+ ]0 f }
: c0 Z% d; V* }# j* }}. g9 t! f% K# r/ U
template<class TYPE, class ARG_TYPE>$ J$ V% ?+ H- B/ T# g4 S
CString YCArray<TYPE, ARG_TYPE>::GetSign()
( e `9 k/ q( ^0 j! g, j6 G2 l{
0 G; Z- w* S7 z) N a lock_sign=0;4 @* v# u8 C2 o# R& j0 [
return Sign;: u5 [ W: D& B7 @( G& V: y
}
: S, B+ x6 w/ ]* f& p3 X; Qtemplate<class TYPE, class ARG_TYPE>
# g% l8 f/ R% H. n. { U4 X9 E* z, }int YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign)
. ~3 T+ A% d; o6 x{
* g+ {! o- r( W4 I int i=0;" o% [4 e/ v1 ^& B+ L2 u2 D& V
while(lock_sign&&i<MAXSIGNTIME){
. O% \2 H t. n9 p3 S Sleep(1);
7 r! \: J f! ~0 U( v2 r i++;# m9 D% v- g% Y* j; L
}. \2 H: r7 m( Z$ ]3 `! {6 B1 C
lock_sign=1;
* s F0 T: a- h! r. B Sign=sign;
2 s5 e- G7 h# H' B4 E' k; g return TRUE;9 w6 ~' ?6 V* a8 p& T) ]& e
}# X/ Y o- h# X2 C) ^" \. d
//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer4 B3 J1 g$ W: [2 z/ M3 ^3 \) ?* a
template<class TYPE, class ARG_TYPE>3 S1 i% A1 X2 V# G
BOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)
* a3 [6 x/ `5 k& G% i% @! x6 `! U8 M{
6 x2 b& E& X! i6 Y if(strIndexNum < nNewSize){
+ g2 X" k8 }4 |. i. L, h* f% m CString* tp = new CString[nNewSize];//新的buffer/ l2 D% B: z, G4 U
for(int i=0;i<strIndexNum;i++){//把老索引复制过来
5 [! y. B. `' J tp = strIndex;
- V0 U. Z! q( X3 M }
* j( Q$ @6 n; h% @2 c9 j/ P0 C for(i=strIndexNum;i<nNewSize;i++){2 E6 D9 V1 s' ]/ C* j- m `9 Z
tp = "" ;
% c& h: [& D1 ?# i$ R' W/ p }
: n, ^& T( X! ~$ t/ d delete[] strIndex ;
6 m" f0 j9 t, U- a7 Y7 {5 w strIndex = tp ;( w- F( n, H% Y' Q5 E
strIndexNum = nNewSize ;% ^6 K( p) H' j! ]3 a% {0 [ t" @
}else if(strIndexNum < nNewSize){: Z+ h8 D+ B$ s4 {$ h4 U3 p
for(int i=nNewSize;i<strIndexNum;i++){
* \) _0 I$ b" ~+ I/ ]9 C/ L strIndex = "" ;
# M, \9 q% H) R. m/ r; U }
" n9 d: f' Z' r% h) K; } }# u/ f3 y# a" B
return TRUE;& h) ^) M1 E% i, d' x# k2 r
}+ m, V( \0 w1 l. M
template<class TYPE, class ARG_TYPE>
( r B# k0 [$ j7 `, G* H! dBOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/)/ m* A; [* R% n" g3 e
{3 N# i# f# z" J o8 J3 u' @2 B
CString* tp = new CString[m_nSize+nCount];//新的buffer
' g0 a6 L( d$ C* D for(int i=0;i<nIndex;i++){//把老索引复制过来& K0 G2 m' O0 s/ T) e2 S5 x
tp = strIndex;
& Y& V* _3 C0 f. y8 _" _ b8 L }int j =0 ;
8 K* r# ^. F9 e4 j. i' l for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来2 g% r. L) e$ w3 _1 n
tp = strIndex[nIndex+j];
. C Q# n/ S+ D8 Q j++;
8 F& I3 N- b( S7 y _+ y }0 z0 _. e7 A8 C% U1 `
delete[] strIndex ;
, t6 k i. A1 g strIndex = tp ;
( ^, d0 X3 V0 a' [ return TRUE;
9 k9 f2 A& t0 ^+ ^7 I8 z/ n7 b/ q}
* q7 J, l: I# H9 [template<class TYPE, class ARG_TYPE>
$ u: Y# K' d& jBOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex)+ ^% o- X& J$ ]3 o8 ^
{//在 nIndex 后面添加一个 字符串索引7 L" [' j5 l! z* A
strIndex[nIndex] = cIndex ; {& F7 r) `! g/ P7 k) C5 W4 ]6 s
return TRUE;: \9 L5 I; D% @' t9 q% a
}
, B/ V7 |7 E9 n, l& Ltemplate<class TYPE, class ARG_TYPE>5 z; y9 q% I; f; q: @; \# G9 {% [
BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/). L7 o+ V) X( m6 s" A
{//需要在 m_nSize 变化之前调用!!# X5 {* l p3 K5 Z4 ^+ U. q- C& R
ASSERT(nIndex >= 0);2 R) Q, @# U: Z8 J2 _
ASSERT(nCount >= 0);
* Q7 K1 {" C* ~" {" Y( v ASSERT(nIndex + nCount <= m_nSize);$ O4 J# P% j9 s; a3 P6 b$ P0 h
int j =0 ;/ [6 J/ A0 }7 E4 R
for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来4 z' Q8 O* O+ q! _7 q2 k" U4 ^
strIndex[nIndex+j] = strIndex;
8 h5 N. Y) ]7 R5 P5 z3 a j++;( b4 B: N# x3 k
}( V" f! s5 T, K8 P2 ]
return TRUE;
0 Y" p& h7 J3 L! G% g* f' @}8 y( v# Q) E$ p- g! _/ w% x
template<class TYPE, class ARG_TYPE>
0 c& U+ Z- B9 k+ _4 \% a; XBOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)5 ~* ^( A! L U+ H( `: f. e D6 I
{
+ P* [9 l3 P- b! k; F) f# ` int nIndex=this->GetIndex(cIndex);
' Z" M4 i* M; }( V3 u7 s) {9 n return this->DELIndex(nIndex,nCount);
6 X: W( C, X4 D6 ^}: p: B/ t& P3 `8 \& @$ U
template<class TYPE, class ARG_TYPE>
, l& H8 q- T+ b# jint YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex)
3 n8 i3 l* R# g0 ?3 e2 _% s{//得到 cIndex 的数字索引" ^) Z1 i; ?( r( v
int nPos = -1;
, ~1 k( H3 o; E; O$ t2 u$ T for(int i=0;i<m_nSize;i++){
# k6 F+ a+ ^5 U if(strIndex == cIndex){8 O& k! H2 i. d! X
nPos = i ;break;
1 _2 z6 L# W9 ^ }
# ~! r* C" i" B8 v1 N1 h6 @# M }
$ J7 t. y# @" D0 j# V return nPos;* |& N) R G3 _& w% C" h8 O
}
) Q2 h1 ^! i8 e: atemplate<class TYPE, class ARG_TYPE>; {4 s" @- O3 V. ]% G
CString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex)
) g7 ], i9 A$ C& K) b{//返回 nIndex 的字符串索引1 c% ~# q$ t5 |! g, O/ p
return strIndex[nIndex];
T" l& ?( ~8 f}" x# J. [7 O5 @! W Z$ V5 t; c+ g
/////////////////////////////////////////////////////////////////////////////1 g" H' g4 C9 Z8 \1 j3 @
// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE>
: Z! D, E0 j. Q: u9 @AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const- y& l+ T% v5 J. X3 { u; g4 M
{ return m_nSize; }
/ B8 Z; R. I) {8 Etemplate<class TYPE, class ARG_TYPE>
! ?3 U" Y* S4 f& T4 `7 G" EAFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const* z+ X" c2 p$ W: c0 d0 o
{ return m_nSize-1; }
8 I) U0 \: [! V2 [$ z/ ]+ q% A1 Etemplate<class TYPE, class ARG_TYPE>
- V1 R) _$ o0 X7 C7 Q/ k1 D: T$ C& yAFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll()
7 g# S, I5 x* h$ M3 R) r/ \ { SetSize(0, -1); }
7 w" J% I3 K8 P% K) ktemplate<class TYPE, class ARG_TYPE>) J$ K6 y8 _* q6 l! P( Q# H
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const
. t$ R! J7 s; K { ASSERT(nIndex >= 0 && nIndex < m_nSize);& c1 c( J/ b! _9 U
return *Ym_pData[nIndex]; }3 ?# ^) t, m% a: E
template<class TYPE, class ARG_TYPE>1 X; l, c, J4 y$ X7 K; f J
AFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)
K; C4 @/ v& X { ASSERT(nIndex >= 0 && nIndex < m_nSize);! |/ }8 q1 ~& K F' _
*(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>7 C x8 g G; K& z
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex)
- h* k/ E: r* _1 S { ASSERT(nIndex >= 0 && nIndex < m_nSize);6 Z1 @1 u8 G2 E9 _
return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>
8 z7 U: v5 |' e; Z: Z5 kTYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const. J& z' }$ U3 X- f# c1 f
{
& q5 C9 X) W: I3 a7 f7 x+ l$ ` int nIndex=GetIndex(cIndex); d4 \* G, D$ N6 x! U
return GetAt(nIndex);- w) s. R/ v* j" w, t
}0 I+ |/ F* K$ Q* e+ B$ O
template<class TYPE, class ARG_TYPE>
, ^, @; q/ Z6 wvoid YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement)
7 i1 n! u3 u1 j: @{
0 \5 [1 U9 r8 g, s int nIndex=GetIndex(cIndex);
0 t: b: h' Z' D" V7 k* V6 ^ return SetAt(nIndex, newElement);- y) V' \8 }! H" @5 I
}
( [5 w& x q: [template<class TYPE, class ARG_TYPE>/ Z5 m6 Z& ]4 p; z
TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)
# n$ \* m. U+ b: T0 t: a# ]* _{
. `2 D' J" W7 I: U) d" K2 b& R int nIndex=GetIndex(cIndex);$ B' O- w' `9 B- t w& }) r& |
return ElementAt(nIndex);
' V4 ~5 B. N/ h2 h4 e5 L2 Y}$ L, ?5 u3 ]- v
template<class TYPE, class ARG_TYPE>
; O( i. i9 @1 \' t: `& ?AFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const
6 K2 \ R# d0 X* P( m { return (const TYPE**)Ym_pData; }
9 t, _8 G+ h6 @& N; U& f, Qtemplate<class TYPE, class ARG_TYPE>% Q: B5 z7 x7 L M U
AFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData()
7 Y2 q% n) A0 T( x5 P8 j { return (TYPE**)Ym_pData; }6 S% I! C* {# c, c4 z) b
template<class TYPE, class ARG_TYPE>
0 q" e7 @, u8 }" x( b; ~7 z5 \AFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */)
. v; c: ^8 I+ e, C' P2 ` { int nIndex = m_nSize;5 `& _1 v5 C3 e$ W, V
SetAtGrow(nIndex, newElement);' l/ {8 f/ f3 _
SETIndex(cIndex,nIndex);
( F2 \8 m/ q: ]; z2 o; T5 J4 ^ return nIndex; }0 x. I7 }2 x1 {3 \/ P
template<class TYPE, class ARG_TYPE>% y" a, f* Z8 I3 e2 \5 S' ?9 W
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const$ U( R& M1 k N" Y, ^) `
{ return GetAt(nIndex); }( ?8 ~( f* Y; D }, }+ w/ ?
template<class TYPE, class ARG_TYPE>) X5 K! H# o, x4 t8 U
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)
( p3 T+ W1 Y5 |1 j* x2 s) q { return ElementAt(nIndex); }
7 Q* ^2 z1 a; O! htemplate<class TYPE, class ARG_TYPE> d7 z. W' E/ K% X- i& Q) d) `
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const+ E9 u a, W1 ?) H- k' C
{- A6 y$ W1 o2 K1 |
int nIndex=GetIndex(cIndex); return operator[](nIndex);2 h2 j; I+ e, Y: D5 C# b
}
% P; N z) c9 A& m* Wtemplate<class TYPE, class ARG_TYPE>
# r4 S& [3 Y7 gAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)
1 D+ P9 p' W( x3 s{$ c, I. Q2 X& K
int nIndex=GetIndex(cIndex);
' C2 w& t" s0 w return operator[](nIndex);$ H) K3 k# G5 D+ ~9 j( Y. V8 a/ }
}. X) z2 M- O- q$ Q: V& q
/*) F! A1 ~# Z* D, O2 }' A( L* m
template<class TYPE, class ARG_TYPE>% B a0 Q5 z( R- g: g( S# y D' a, x
AFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const' ^. k2 |1 i/ f
{5 {) j7 |9 ^4 s4 ]+ Y9 g' |
int i,j;/ S6 I1 S7 l# b, P+ L
for(i=0;i<tparr.GetSize();i++){/ g9 V, p/ J. v n+ d# ?9 V. F
j = GetIndex(tparr.GetIndex(i));
4 g6 e* r* H( x+ O) E if(j>-1){5 P/ x. U6 H9 b/ }5 l! d
operator[](tparr.GetIndex(i)) = tparr;
8 O% [% P9 V3 v" s, W }else{
2 b% n% p! |9 ^$ |8 f, s Add(tparr,tparr.GetIndex(i));& a; z: T$ }: g; n5 n. n7 L
}4 Y) z- J7 X8 M/ H$ a6 p, V$ y/ g
}/ Y, Q) F* V/ f; V" X6 I: {" Q
return this; a! P' c' |' u. ~1 u6 s
}9 j* ^- O. R( G2 v) d* k
*/
' q- p9 a+ l7 ^, A% K; R: n; @template<class TYPE, class ARG_TYPE>
b* B/ z. }1 d1 E6 d2 ~AFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src)
# y" o2 H& V3 [% V1 z{
+ _! F8 \8 r9 I9 ?0 M$ j. n2 b1 p, ? ASSERT_VALID(this);- {/ n& f: c8 k" C, m$ U
ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);
( G5 @6 q7 |. O e, v for(int i=0;i<m_nSize;i++){
" K. h7 a& w" E /*将此句修改为内存拷贝*///
0 C$ o& l- ]) [2 _; E% ~ *Ym_pData = *src.Ym_pData ;4 Z4 O6 I9 {! }3 r
//memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));
3 N" Z1 a% V7 V2 d5 I; r SETIndex(src.GetIndex(i),i);, u. w* F+ N$ Q7 _) a5 o
}
3 e3 s7 @( q! U; s9 u return *this;
% J; Z& u0 w7 N% ^}( }4 [! R8 {9 W, T' r# S( R- s
/////////////////////////////////////////////////////////////////////////////
6 R9 T- ?- v- \0 J T8 M1 q: q// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>
r3 x' u$ f% @5 iYCArray<TYPE, ARG_TYPE>::YCArray()
) }+ V {/ O% Q{
, ?" Y$ e8 C9 ] Ym_pData = NULL;
( \0 A+ M. N5 M) ?+ d! `) j( {- N( F strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;0 n/ L$ a1 G; m7 @ S% f1 ]! h1 P) A
strIndex=NULL;MAXSIGNTIME=10;
# D6 s3 R D4 Y$ J}! J( Y0 M( f$ o
template<class TYPE, class ARG_TYPE>
/ [5 x& _5 T7 X4 R( d9 @- k- WYCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp)0 }1 l# Y" w1 U
{8 T+ _) C: i3 P& _6 U, j- ^# ?
Ym_pData = NULL;
1 |: K. R5 @. ?/ M0 S strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
2 m G9 H% L5 b8 f; l% ~6 C5 M& t. @ strIndex=NULL;MAXSIGNTIME=10;
, E4 G: }$ P$ i/ t" u+ g- M operator=(tp);1 V0 E! x C& Z% y/ p, ?+ c+ o1 i; p
} template<class TYPE, class ARG_TYPE>
0 B3 u" b0 e8 C/ t1 mvoid YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy)# N3 i: C4 F( b+ {3 w
{
; o% `/ D) k" {3 N+ y" S. k$ s% G1 ?" E ASSERT_VALID(this);. i7 k& s) G% ]: f% ~( A
ASSERT(nNewSize >= 0); if (nGrowBy != -1)
. H( D4 _1 H' _1 y z# g$ e3 F m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){
5 `8 y7 P: g+ _' u. q) A // shrink to nothing
8 T& q/ }2 F- y' }' f$ N) P! { if (Ym_pData != NULL){
! m, f2 \7 D5 e DestructAllElement(0,m_nSize);
7 D8 t) }) n; i& { //DestructElements<TYPE>(Ym_pData, m_nSize);! k4 V2 p% P$ Z4 v$ E8 f1 r/ X% ^" V
delete[] (BYTE*)Ym_pData;
- ?8 q7 [/ u8 p# W Ym_pData = NULL;7 e; N n2 x; y8 A
}' C/ B& ]0 g6 f3 X6 Z" M
m_nSize = m_nMaxSize = 0;; E3 T9 r' | z% f U
} else if (Ym_pData == NULL){) V5 b" n" B9 p- I2 d- i
// create one with exact size
, u& K+ [" H% o/ U; `#ifdef SIZE_T_MAX
% f& g5 m9 q% f9 W6 l" c2 n2 o ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow
8 P$ w- k% U7 E/ z0 A; H+ R5 r#endif
1 w, x8 i. f8 |0 f Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];9 V; B: \9 }- @! y' `
ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);$ x: }- j' i* Z8 q5 k' Y* d& s
m_nSize = m_nMaxSize = nNewSize;3 E0 ^- Z6 w7 P% A- v u, j2 ?
} else if (nNewSize <= m_nMaxSize){/ [, a; b( [: A3 I* B
// it fits
& h3 o; S+ Z; ^$ o if (nNewSize > m_nSize)
t0 w3 e4 b6 | {
& b6 ?; ~3 \4 W* q // initialize the new elements
K$ x2 p, c9 w1 W* E% M* _7 U2 t ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);8 i3 [/ j& C, t& y$ R! e% u
}
N/ |" |, o( P6 h else if (m_nSize > nNewSize)& c, U- M6 Z. T X) ?
{
+ \' C2 P* I0 w5 i9 j7 T // destroy the old elements
3 Q9 K' b# g* p2 \5 `* ] DestructAllElement(nNewSize,m_nSize-nNewSize);: Q2 P$ I( V8 P* [+ t. A3 P
//DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);% ~( r" U8 O/ `
}
- X# c1 L& t, {2 W m_nSize = nNewSize;
5 p5 {" W$ `8 G; ]+ R }& [. h3 Q2 T: G' f6 @' |* N: G. K: g: n; B
else
+ X) u. U2 \7 u6 R* c* D V1 } {
/ ?2 I' G& ~7 U6 d3 G // otherwise, grow array4 q1 f/ S, m# F
int nGrowBy = m_nGrowBy;
( E/ I7 ^! ~* S: I; | if (nGrowBy == 0)1 [1 e! q% K* j2 S! q
{7 o }) |- R; j
// heuristically determine growth when nGrowBy == 0
4 o5 w' j( ]3 B' x) s4 Y" L // (this avoids heap fragmentation in many situations)9 d1 a2 c: v+ D
nGrowBy = m_nSize / 8;% Q- k/ a+ ?0 t0 n# v/ S* v
nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);! S, k8 S8 d* l
}
& f6 a0 ?$ a, t, P int nNewMax;8 L4 D% K) J9 C. J/ H/ |) g
if (nNewSize < m_nMaxSize + nGrowBy)
5 _7 S# u# N0 `! [8 ^/ s' y nNewMax = m_nMaxSize + nGrowBy; // granularity
9 K0 a- w+ `- t4 N( D& e) F% u5 Z else" q9 w" `& P# O- E
nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around
) T8 R; J% M7 ]6 H7 X#ifdef SIZE_T_MAX
( C0 m- r9 {; L$ N6 d ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow0 }( }9 y9 n8 G9 ~" ~
#endif
; ~; R. N+ v% c9 H& \ TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old9 i" [' y. F; C$ i# u
memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements; ]; |. M* V. B6 h: m* [) P6 @
ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");
/ x. d: ^5 J8 ^% e c3 F delete[] (BYTE*)Ym_pData;
6 d6 y, n+ r/ G) w Ym_pData = pNewData;
$ ]* U& K t$ n ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called)7 `7 [( m0 Z! L3 P- D8 K
m_nSize = nNewSize;
; p2 m" V A M, q8 r- F& w m_nMaxSize = nNewMax;
0 P+ N/ G* L( M l }# y2 A; l p: w5 H# U: [1 A7 g
SetIndexSize(nNewSize);4 I* M$ _! k& A9 B0 E
}
% o; j% W& c6 I) v! U1 \ |