//接上面
# N" i6 A& O+ J$ q$ Btemplate<class TYPE, class ARG_TYPE>, ]( J) W- V6 i9 {+ ^5 A- I6 w
YCArray<TYPE, ARG_TYPE>::~YCArray()* [4 k; e5 q1 J1 u8 L' m' l/ w
{6 j+ {+ e, M+ U- q" @& ~8 F; b0 {2 W- T
ASSERT_VALID(this); if (Ym_pData != NULL)* m5 P* Z! A8 N( V6 j7 s
{) ?" J8 w' u* a' m! U
DestructAllElement(0,m_nSize);
7 g* c8 ]4 r% G7 f6 S- Y //DestructElements<TYPE>(Ym_pData, m_nSize);
" s' b9 b$ k' @6 {6 T7 u9 l delete[] (BYTE*)Ym_pData;
o8 H. p- X4 K- P$ n a" V }1 s' C! Y1 b6 L* d1 l( M! \8 {6 V
}
7 e8 D N5 V) ~: utemplate<class TYPE, class ARG_TYPE>/ f4 B3 G$ r$ V' w7 e5 `, E
CString YCArray<TYPE, ARG_TYPE>::GetSign()
* _+ `9 ~/ ~+ x; r! j, l" ?4 X{
$ Z! n3 q- L r' S1 Z lock_sign=0;
. i( R1 d* n4 O# W return Sign;" @2 \2 }" B: r Y% Y: @& T. C; A
}
0 g" x# q- b0 F- P* _% p% T4 `template<class TYPE, class ARG_TYPE>5 t* H9 u }5 ?/ W; F
int YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign)
+ O2 n9 @ h T" n{
" a n5 ^7 ~/ D8 U$ r/ S int i=0;
0 H* m* P* R: w t6 b& R: d! ~ while(lock_sign&&i<MAXSIGNTIME){: L9 l' Q8 K2 B7 L1 f3 J! T
Sleep(1);# Q' K3 d% V5 O( S$ |2 W ?- C& R
i++;
1 A( Q C8 |, F. u$ T }9 i6 M# d1 c2 u6 H5 Z7 E' {2 e( \
lock_sign=1;8 |1 m# u% P/ i0 d$ A$ j/ W
Sign=sign;2 ^7 R' ]/ c6 J; P X/ }+ r9 e
return TRUE;, p& \8 q6 W# E. \/ P; }6 o/ l/ l$ A
}+ A4 S) ^0 H! ~+ @! F6 O
//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer2 z: C* ]$ g8 X% H/ [1 h
template<class TYPE, class ARG_TYPE>
- @8 e# {, d" E2 w% W4 a UBOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)
. r) d3 y6 G' s9 q- x, H/ T{$ |7 ]7 j4 @8 t, i3 F! d$ y* W! [$ I
if(strIndexNum < nNewSize){
0 n8 o1 ?6 c2 R5 f CString* tp = new CString[nNewSize];//新的buffer
) J G( u5 e8 h* I: k7 V for(int i=0;i<strIndexNum;i++){//把老索引复制过来
3 h8 y8 q1 s4 U5 F1 ^/ s tp = strIndex;
4 X) i2 z9 {" c% B4 O }
+ s2 c; ]9 w9 b y: J for(i=strIndexNum;i<nNewSize;i++){
1 h1 H H, D7 h: N- q2 I tp = "" ;
! }& M- e2 w7 |3 V& P! b) O( W } 5 b0 Y+ W* h; u$ O8 w' u+ ~
delete[] strIndex ;
) Y& d2 D+ r, S3 J w strIndex = tp ;
* U t- C% ~- r' g: M strIndexNum = nNewSize ;- e3 C- ~' `- g) b# W+ l
}else if(strIndexNum < nNewSize){& w' Z' [8 |( A" z" E
for(int i=nNewSize;i<strIndexNum;i++){% h# i4 K& U2 y; ?( z
strIndex = "" ;
8 s% K. Z3 k, l; N9 O w( L$ | }
2 g" E; X6 e+ W) j }
2 `, Q) m. Q$ {0 g3 t1 `' A return TRUE;
! O9 o. L6 N8 F D, C}6 [* N, o1 N+ B8 P0 E/ I* M
template<class TYPE, class ARG_TYPE>
- v1 t; I3 T+ aBOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/)
1 [( h/ m/ @8 m; H) J- L) B, ^{
U5 _* l3 ^; q. T( c* A( A r d$ o- y CString* tp = new CString[m_nSize+nCount];//新的buffer
" l: M6 [9 ?4 U% c: x for(int i=0;i<nIndex;i++){//把老索引复制过来+ Q2 g8 @- q' f& [8 t2 c
tp = strIndex;+ B6 c9 S( c, f3 O$ L
}int j =0 ;
+ U/ Q8 ^- v$ l6 m( L5 z* O) o3 ? for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来2 L/ C4 t8 ], A2 I9 C
tp = strIndex[nIndex+j];
: `# M9 N( K Y9 e j++;8 A+ F& D. V$ |% k; G3 u
}
' j! E. F1 x: L( y9 {8 z, { delete[] strIndex ;: y$ v+ L# ^7 O f( ?$ ]/ y: C
strIndex = tp ;
" v4 I; y# {' X return TRUE;
1 _; u: g6 t/ I% t5 O6 M}
C3 p# H' Z1 X) K1 W, m& w: dtemplate<class TYPE, class ARG_TYPE>
! a6 `0 r6 c% I' P9 e! u5 rBOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex)* t) s2 Y! v* n4 A
{//在 nIndex 后面添加一个 字符串索引
& r, I. f9 e/ d strIndex[nIndex] = cIndex ;
( H3 B% e) z# m3 a2 e( V9 `2 D! f8 o return TRUE;0 A0 j- F- X, E- J2 @. _
} y% S5 J! k) l- Q r' B
template<class TYPE, class ARG_TYPE>
o. h0 n+ m2 _+ ZBOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/)
1 }: q0 p: ~6 B* s) F{//需要在 m_nSize 变化之前调用!!
8 D' d2 X# v1 H# Q, C# z ASSERT(nIndex >= 0);
~/ a% ?8 a+ m2 x5 `4 E ASSERT(nCount >= 0);+ q8 c& x$ n0 B& |" X/ @
ASSERT(nIndex + nCount <= m_nSize);
5 Z8 o4 c; ~$ N( v Z' D5 V int j =0 ;
! T7 R n2 d; z n- L% M for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来. d& D& h4 A; }! e
strIndex[nIndex+j] = strIndex;$ |4 r4 O @$ F9 z: d" V6 n& F, Z! e
j++;
, a( K3 ?0 b0 x' T7 M, R) a# \ }
3 m0 `1 i! ^ a' \3 E return TRUE;0 a/ Z- L% o5 |
}% \2 d1 ^8 b$ y! @9 k6 ~; c: E' N) f& `
template<class TYPE, class ARG_TYPE>
5 K9 t( @) J+ E- }$ gBOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)
* L5 m* s" N X0 V: l+ m) c! Q{% v; e+ S& u( _! G t
int nIndex=this->GetIndex(cIndex);! F* I( w# l4 d8 Z% Y2 x7 K/ D
return this->DELIndex(nIndex,nCount);- S" M$ J' L: w3 N, m
}2 y) C% U( q5 i) m
template<class TYPE, class ARG_TYPE>7 ^ L2 `0 m. G* o$ Q' y- f
int YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex)9 N0 o1 U$ X3 u# P
{//得到 cIndex 的数字索引4 g5 h# Z& s9 C' R
int nPos = -1;
8 B; k4 X$ W' K' u* @; ~ for(int i=0;i<m_nSize;i++){& |9 T% k/ g. ?* ~$ W
if(strIndex == cIndex){+ `: c( Z6 }4 L2 S
nPos = i ;break;; D3 \, p! D. m# }, m
}
6 {* x$ M$ C; _/ e: y! T }
2 K8 @7 ]( j% q: ]4 @ return nPos;
7 }: |' b0 _4 i; m! p6 Z}
) d. S7 w4 l% O" btemplate<class TYPE, class ARG_TYPE>
6 ^, F- R# q6 U) r; D% FCString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex)
- ]8 Q; w! p2 w{//返回 nIndex 的字符串索引
4 g. p7 o) M7 C' v: [ return strIndex[nIndex];
3 x1 C9 t+ b, o0 V8 g) n. c7 t}" F* r: X# E3 @4 K: P# g
/////////////////////////////////////////////////////////////////////////////1 A8 ^& r: z5 X8 U7 V8 X4 N, E
// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE>
k3 ^5 h6 u+ W" WAFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const' C3 i& A4 T* D) J: s
{ return m_nSize; }
! @- D5 U* k- t% k3 @& O6 Qtemplate<class TYPE, class ARG_TYPE>
. i3 G( M& |, o, D/ z5 i4 \AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const
8 [' G2 p* Q3 i' e { return m_nSize-1; }
1 Q9 O$ q8 W f9 }/ P; U# ]template<class TYPE, class ARG_TYPE>$ j* z% w. b' P6 m+ M
AFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll()% x) q6 B9 h% D# [$ U" ]
{ SetSize(0, -1); }' P! ]! l* _& f* p
template<class TYPE, class ARG_TYPE>
3 f. N5 r, ~3 p' `% R9 R% \4 MAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const( o' \, F/ s7 X& |, v
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
+ @: r3 R) P! q3 H5 `! k return *Ym_pData[nIndex]; }
5 i$ Q* G* X6 W3 X, C% U ktemplate<class TYPE, class ARG_TYPE>
( J: H Y n; ?( }8 a5 p( JAFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)7 D/ q. V. s* |, t
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
% s- ]6 p8 m/ | e1 A *(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>
" M% U) I' Q' {1 U8 u* WAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex)
" H$ ?, H2 a6 ^8 c7 r! H- ` { ASSERT(nIndex >= 0 && nIndex < m_nSize);8 L! k9 T3 T4 R4 C O
return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>
/ f! r$ c' i7 R2 sTYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const& H, u0 P& \* f
{6 J+ v5 I" @3 l# ?& g; n5 ]
int nIndex=GetIndex(cIndex);
" C) X4 @9 _# ?( s* C3 ^0 W3 Y return GetAt(nIndex);
# m9 L9 z, t0 f% v}
1 F# A5 q2 _3 [3 e% v: z8 [* ]template<class TYPE, class ARG_TYPE>
7 v5 `3 O' n) e% Pvoid YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement)
( c. h4 A0 k8 i* U6 [1 _5 ^7 M( b{4 T8 ?) i; a9 `; H8 n" M
int nIndex=GetIndex(cIndex);0 `! e' G3 O: y" Y
return SetAt(nIndex, newElement);% L) g5 I2 }6 h2 J
}
5 J9 ^8 y% }+ e6 M' }template<class TYPE, class ARG_TYPE>7 L4 `! k' {; o& `+ F; p
TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)
" }6 Q g0 @! ~# l{1 g+ ]/ C5 T' m& s" d: e
int nIndex=GetIndex(cIndex);! m& @. L" }6 ]8 S1 U
return ElementAt(nIndex);
: w3 N" g8 \+ V# e7 P( \+ G9 y}
1 p/ B3 i" B5 D9 [8 F. Ztemplate<class TYPE, class ARG_TYPE>
% k# F1 E2 ?, h# [ ?/ g+ @AFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const4 b- D$ @" F' X8 ]
{ return (const TYPE**)Ym_pData; }
f7 P W# T& h7 g( S [/ a! y Gtemplate<class TYPE, class ARG_TYPE>
# h1 s7 Q# R/ F0 h2 p- MAFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData()+ e' Y# ^3 T l6 n
{ return (TYPE**)Ym_pData; }
; U$ E) j6 F. z6 s) Y( ~template<class TYPE, class ARG_TYPE>
0 Z( z- F' C5 m( ZAFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */)0 d1 R, y- ]2 _3 i; e) o
{ int nIndex = m_nSize;; V' [$ C) U) i3 [, c
SetAtGrow(nIndex, newElement);
8 s. q0 W! {$ u' r5 C, f SETIndex(cIndex,nIndex); r$ M* e( L9 Y$ N% o
return nIndex; }* H$ x) k- X2 s
template<class TYPE, class ARG_TYPE>, X/ z5 H c3 _, {
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const
" e- a4 E' \, O) f" w { return GetAt(nIndex); }4 r6 H4 j' H$ d* c
template<class TYPE, class ARG_TYPE>. X3 v* }! w H; n* J
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)
, Q6 x8 `, E. f0 \ { return ElementAt(nIndex); }
9 k" Q& u% P5 `9 g+ Xtemplate<class TYPE, class ARG_TYPE>" x; _0 [% b) m6 g* q
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const( R5 h2 T |- U) t
{' D. j. F1 g0 w' ?! s+ b
int nIndex=GetIndex(cIndex); return operator[](nIndex);
( X. A0 [) Y. A}
, ?1 l: O+ r1 P3 F# n- Jtemplate<class TYPE, class ARG_TYPE>4 H0 M3 M0 E7 E @
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)2 [+ b* f* s( r' p/ O) [" q
{
Q( w0 U3 ?, s. M3 i! c& Y$ h8 O5 U int nIndex=GetIndex(cIndex);6 A+ M/ }! \/ ]: p
return operator[](nIndex);: |: S9 I: J9 f H4 X8 b- R0 O! V! h* J
}! D3 s* ^2 t# D2 n5 `: |6 w
/*
$ [1 W+ S1 {! E/ L( Htemplate<class TYPE, class ARG_TYPE>
- R8 g& w8 ~6 r9 LAFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const
, b2 p8 e# T# P/ u4 ~; h{8 \5 t1 M0 n# I. J
int i,j;
" \0 R9 t! g' [9 r, M0 N for(i=0;i<tparr.GetSize();i++){
6 h' i M. ~' G# w/ ^' r7 W j = GetIndex(tparr.GetIndex(i));
. H( J- t) M- L2 k0 n+ e if(j>-1){
; g7 F* k/ G/ H, @& h" Z, K operator[](tparr.GetIndex(i)) = tparr;9 b# p, j J0 B$ Q% x5 N0 K( T" F$ j
}else{
2 V) U0 T2 `# ^ Add(tparr,tparr.GetIndex(i));! }7 T' p" i* y2 f( Z! D
}
3 d6 H$ }& C( z, j }" N1 V. S: \$ m) z, f
return this;
! \) k* Q1 Q* S) {8 H8 j' x9 p}! O7 {7 J1 i# }: E2 U4 T
*/
4 n! G4 V- J. M0 Y* u7 j7 D% Wtemplate<class TYPE, class ARG_TYPE>! O2 k- {; k/ t- X! f
AFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src)2 q4 h5 _5 ?5 }' O; r3 f( Y) q4 U
{1 t% b' k. c3 P9 E, H
ASSERT_VALID(this);
+ w* S' w! E7 H8 @) @" ]( M( a ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);" ~: o0 X- l& `- D" V% z. ]5 |
for(int i=0;i<m_nSize;i++){) k& d) i6 d( D% n! \3 l5 L
/*将此句修改为内存拷贝*///
# m% X7 g/ n( a. b( M *Ym_pData = *src.Ym_pData ;: O! U6 r' P( T' v/ B, o! z
//memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));
+ i7 S' `5 a. L R SETIndex(src.GetIndex(i),i);
0 m; V8 G, j% W) R6 v } W7 z% o) Z/ z+ x4 E% r
return *this;
; N8 {& f5 L% Z( B/ ]; [ W8 X}
5 `/ M# V/ ?3 E: O/////////////////////////////////////////////////////////////////////////////
: L/ j" a9 E Q6 C// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>
0 N0 D" i$ t; F& j; qYCArray<TYPE, ARG_TYPE>::YCArray()9 U" x( q# p! I" y. [& z: D0 Q8 {
{
; q6 L* y2 q- i' E( V Ym_pData = NULL;
3 i: w6 y4 |) \+ E strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
4 K* O% Q2 c0 ~+ _ strIndex=NULL;MAXSIGNTIME=10;
, B5 b! _* z3 h7 u2 ?7 b}9 v# Z# ?( z2 l$ N
template<class TYPE, class ARG_TYPE>/ }9 a/ R( F6 m0 }2 W1 O5 A
YCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp)" X; k5 I. i+ s( t, V
{1 X" X b" q- M# H) R
Ym_pData = NULL;
5 q, _9 m( z3 Z4 P$ U8 r+ _ strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
* H/ N" m$ i; x4 h strIndex=NULL;MAXSIGNTIME=10;6 W% K/ D1 a9 g) |- X/ y+ M: a
operator=(tp);8 g$ V: w0 D( {5 u2 D: p. x
} template<class TYPE, class ARG_TYPE>
( G- T* e5 w9 f7 I& G9 ]# i2 T- |; ^void YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy)
: y! B1 M2 i$ [9 H{7 B* e( M/ I4 C$ m. f5 Z: i
ASSERT_VALID(this);; O k8 y" t9 J( I& [ h# f( j8 F
ASSERT(nNewSize >= 0); if (nGrowBy != -1)
6 Y, F) X# a0 w9 I' a6 A m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){
: }: z6 S% H8 _. I0 W // shrink to nothing
2 r( k& z# J7 Z; L$ X0 S if (Ym_pData != NULL){7 `" o* i9 M* H3 L6 H0 W$ d" x
DestructAllElement(0,m_nSize);
2 w8 K) r' h! Y4 ]! O //DestructElements<TYPE>(Ym_pData, m_nSize);+ F; h# q, B3 x. P( P1 q
delete[] (BYTE*)Ym_pData;1 ^5 Z9 Q, n; \- L; @# r3 O' \
Ym_pData = NULL;' B$ \, D0 m) L: T
}
) k& c* u- M+ m2 v! o m_nSize = m_nMaxSize = 0;
( I' p9 t! R. }$ @8 Q( y } else if (Ym_pData == NULL){* a; V Z; M5 h9 l
// create one with exact size
/ e5 @1 l6 r3 P- ]* y! m#ifdef SIZE_T_MAX
/ r6 b; Z8 j, |+ M R2 E ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow
9 M# h2 b3 @! b0 }5 u#endif4 U# M& s/ B, M3 W
Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];
: C8 @, c9 P* T: P2 a" t. J$ y# d ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);
1 l8 F. {, S6 @$ k) i3 G& c' s m_nSize = m_nMaxSize = nNewSize;$ a) }% A1 N) z& b, E4 j
} else if (nNewSize <= m_nMaxSize){5 Y3 s8 E8 K2 Y0 }# Q1 p" ]* \. k
// it fits
3 i8 p1 \7 B5 K2 Y if (nNewSize > m_nSize)8 Z& p, b* Z" ]7 X
{
+ f6 c9 r$ k! A: n& C9 w' ~# O // initialize the new elements
$ f7 V p; Z) a; A8 F ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);
; N8 z. d' m1 b4 R }
) S7 N% a# \. }5 d. L m6 ]6 o else if (m_nSize > nNewSize)
3 X4 \4 b0 `2 N" r5 V \' D {8 _( z( @! d0 Q
// destroy the old elements
* u4 V( F# Q+ v% U. a DestructAllElement(nNewSize,m_nSize-nNewSize);3 h4 G! Z4 z" u* @7 q3 _1 k
//DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);
5 d5 ~. X% S* ~+ U2 ]' Q# P }, ?$ R2 L6 V* x2 j
m_nSize = nNewSize;' Q7 i+ I0 w4 x: k
}' [6 H2 e' m1 b' d- ?# N
else
$ ]( i: j1 V- [+ K7 s" @9 {# t6 D {# c4 l! p* Z0 q; w$ G
// otherwise, grow array
! j. w& U: i3 j$ \! H* f/ ?. Y+ M7 E int nGrowBy = m_nGrowBy;9 X4 g) J- M0 X% ~8 z
if (nGrowBy == 0)
- `* {* y" c4 I' Z2 V D# i {
* m( m# m1 R0 S4 }* }6 a // heuristically determine growth when nGrowBy == 0* y- W! H2 n6 y# b) s
// (this avoids heap fragmentation in many situations)& g. r/ l/ i! n
nGrowBy = m_nSize / 8;1 u9 k) R" W+ P) t7 e1 u
nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);* |8 U, y: u- _+ y1 |7 v
}
# k: N0 L5 W5 o8 ]0 h int nNewMax;* U! i6 z. {+ j6 [3 V# q0 Z
if (nNewSize < m_nMaxSize + nGrowBy): @2 p }& y) h9 P* P; A+ x. V
nNewMax = m_nMaxSize + nGrowBy; // granularity
6 W ]9 E. N7 x b else; M! t8 ~; N" }! g3 v
nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around
1 z2 H" n1 H9 e; ~3 g& }#ifdef SIZE_T_MAX* P2 j$ H5 C2 }/ C$ X/ P
ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow
$ D! y& s. T" }! }( A% K- Z#endif
* R- i0 g+ k9 D$ }7 N. H; x% E TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old
8 X0 I! I) b4 g" i memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements
" D0 |/ v( b+ q3 X! i3 W0 C ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");$ y, q g2 h: I7 ]( ?, u
delete[] (BYTE*)Ym_pData;
* D8 R3 W$ g9 b' y Ym_pData = pNewData;
; K J- h( X* [7 V ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called)
/ P1 D, g0 c8 Q5 Z2 v m_nSize = nNewSize;% }7 W" c9 \+ g3 I: s/ p. Z% H7 J
m_nMaxSize = nNewMax;, T" ?9 D2 x J- G& G
}( t e& X6 ]$ i6 Y
SetIndexSize(nNewSize);
" D. L/ r% _# E4 t5 B; C}/ ]( V8 w- e# r% ~0 H0 D4 H
|