//接上面
$ i: T* P3 [2 W, vtemplate<class TYPE, class ARG_TYPE>( v/ K$ s$ b/ @, w) i4 Q
YCArray<TYPE, ARG_TYPE>::~YCArray()* o) P9 L" q" t2 x+ F3 E
{! @6 M/ O% O" d" Z/ E
ASSERT_VALID(this); if (Ym_pData != NULL)
/ o. }1 @% `6 g( s1 v# E {: l) ]6 G! E Z/ }) z
DestructAllElement(0,m_nSize);
( i- D5 j* I: V# T# w$ ^ //DestructElements<TYPE>(Ym_pData, m_nSize);
6 Z5 e i2 A9 w* p, l delete[] (BYTE*)Ym_pData;0 s, {5 G) H# Y* w
}
- J' d0 \( D7 l8 a/ h0 @}0 Y8 R! P5 a, R# n
template<class TYPE, class ARG_TYPE>
/ y3 X3 J3 x$ V. ~: N; e3 a# GCString YCArray<TYPE, ARG_TYPE>::GetSign()
* k% [/ N' a" a2 e{
" `# ~% w2 s' f- w; d# o9 h lock_sign=0;- w' |# A* I4 `# z$ \/ V( V
return Sign;' i) t* e7 a3 b1 Y; w
}
2 c, b# Z7 v! ~9 b" C, ktemplate<class TYPE, class ARG_TYPE>
3 O! x4 y5 Z2 e c. ]int YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign)
. o0 `. \" r3 I1 t) t& @{ I0 Y$ F* e7 _, X% Y; A: A
int i=0;% Q0 J X2 t5 l: R3 n3 [
while(lock_sign&&i<MAXSIGNTIME){$ h: N, H' }/ \& T) b
Sleep(1);
& ]& d- X& A0 o' b7 P/ X i++;
' m& ], U7 j* ?5 _' q& Y: D. V1 v }
/ y: r6 u0 J7 D' F/ O4 }. B lock_sign=1;
9 y. H$ E" q; W4 } Sign=sign;
8 H& W7 A0 ^% O4 T+ w& p# f return TRUE;
0 y$ {: g1 j4 Y- x& c}
$ ^' o+ ~+ `& l% s//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer; v/ `4 K* a7 L
template<class TYPE, class ARG_TYPE>
" L% M1 f5 U3 ?" H- v! sBOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)2 K2 s( G7 _9 i4 m
{
3 F3 ~) C. N& a$ {9 Y( ` if(strIndexNum < nNewSize){( W5 ^+ c' V% }8 Z+ `6 X* A
CString* tp = new CString[nNewSize];//新的buffer
* x$ l/ l. ]. J6 C2 g. P( L for(int i=0;i<strIndexNum;i++){//把老索引复制过来' Z% ], a! e; X" i8 \! S2 z0 Z. t
tp = strIndex;4 E% p5 h9 w( F* ]* m
}; i$ ~$ U0 u" {% q2 B" z* S
for(i=strIndexNum;i<nNewSize;i++){
. k& o( h7 b7 p! m$ Y+ C% \1 | tp = "" ;* L' n, E/ w+ N) k& ]( a: {
}
. [' L9 \ T0 l! H4 h6 J/ a0 G delete[] strIndex ;4 C: @# G* k: t
strIndex = tp ;
( F4 A2 T! `( R* D- q" ]5 b strIndexNum = nNewSize ;4 j6 K; b$ J2 w0 e1 O
}else if(strIndexNum < nNewSize){
# l3 U8 u4 L* \% W0 b for(int i=nNewSize;i<strIndexNum;i++){
8 G. B9 [: ]: b% { strIndex = "" ;4 C# a/ J3 I' D3 ?5 K4 d7 P0 }
}
4 M# w6 S, W$ S7 p }3 g" @; E. v8 Y2 }+ k5 q X
return TRUE;
+ M2 t6 b" i6 L$ ?}6 U, Y% c7 U& i& R* G$ i
template<class TYPE, class ARG_TYPE>
" d9 [5 X6 v5 ]5 q" sBOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/)
4 b) B& d/ P# Y8 i{% `1 W; U, k9 m1 d
CString* tp = new CString[m_nSize+nCount];//新的buffer
- R9 |! t) {" B. c, b+ M for(int i=0;i<nIndex;i++){//把老索引复制过来4 q" E/ x2 }4 z! M- l* Q. |
tp = strIndex;
/ w( n# M1 A* ^- T& m+ o }int j =0 ;
& F* n! C& ~6 H$ e4 [ for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
; [# r5 v+ ^1 r* p2 S2 Y tp = strIndex[nIndex+j];
5 H. P: B+ M. w9 o j++;9 U' L) e& p( b! a" T
}6 K0 e% O S% q t' Q5 ^1 w; I
delete[] strIndex ;
( a" ~* f4 x6 l$ x( q' v- C strIndex = tp ;3 ~) T0 C& c7 ~0 z5 l' K9 k* S
return TRUE;
# l/ q0 ]( p+ w3 `1 {}6 f- J& s6 x1 d) w/ u
template<class TYPE, class ARG_TYPE>/ S# w0 K5 x5 `" P
BOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex)3 N4 {; @0 ]' H4 E# e, d
{//在 nIndex 后面添加一个 字符串索引
" ]- Y9 e" W1 e+ z4 W2 ~ strIndex[nIndex] = cIndex ;
9 ~- f6 ]3 c( g- t8 u return TRUE;
2 c" F7 b) ~: F' @0 _7 m; b6 X}* ]8 x4 C; P+ w* w* T
template<class TYPE, class ARG_TYPE>! |0 u$ ?4 O, G* t7 b
BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/)
1 N8 S# W5 y6 k! C0 l2 k{//需要在 m_nSize 变化之前调用!! U$ j0 j1 b5 n: m3 A m5 Q7 ?$ C
ASSERT(nIndex >= 0);
) I3 d% I9 K7 b- [8 J' V2 z# | ASSERT(nCount >= 0);
$ j3 J# \. `. P+ m7 G ASSERT(nIndex + nCount <= m_nSize);
& q8 t; T, O$ A P/ I: i1 D int j =0 ;
4 J H% z1 Q$ r for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
# y% v* }8 D1 c( [5 N strIndex[nIndex+j] = strIndex;6 u* q$ L- F8 k: F; E$ s5 S& o
j++;! J4 e2 o7 K1 u0 q
}
5 K- }% k( \6 U% \2 r9 { return TRUE;
# z; O7 [& Y) p2 ?# l5 a. n9 a+ B2 f}0 ^0 K7 A" L) s5 L/ `* I
template<class TYPE, class ARG_TYPE>
* z! l: W- A( ?9 J$ W4 IBOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)7 ?1 A$ R _' N) I
{
- n+ @- M0 F# p6 @9 M int nIndex=this->GetIndex(cIndex);
8 h4 P% m4 B, v0 p+ D O return this->DELIndex(nIndex,nCount);
* h7 n. @ v4 C. B}
9 g: a" o' ^# W/ d% m. ?( mtemplate<class TYPE, class ARG_TYPE>: Z8 J# {! o. `4 \
int YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex)
' Y! O4 ]$ M8 B# \/ a0 K$ Z) y{//得到 cIndex 的数字索引 a. j! P) R+ K# o# q% w; {3 ^ X
int nPos = -1;& C/ u) s: P5 Q2 @
for(int i=0;i<m_nSize;i++){
8 U$ v- }; y! F1 M6 |2 V if(strIndex == cIndex){) {& t; J: \/ z+ M3 Y! [+ v
nPos = i ;break;6 t) v+ J3 p' p8 \; Z
}) m9 ]/ f8 E) F6 @8 B: m
}
' t# j& l1 ^- n5 O0 G2 f return nPos;
, ?) ~% [& v* C1 U& H6 B2 C}
: b, r! I' S( R. Dtemplate<class TYPE, class ARG_TYPE>) g0 t% u- j3 G$ E6 c- F7 d# K
CString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex)* H) \7 R8 l* u6 j* X
{//返回 nIndex 的字符串索引 e/ R* g+ G) M
return strIndex[nIndex];
2 o5 m+ ]2 _- x9 n U7 C/ e}
6 z7 F( g3 v3 [ r) U; d+ D; ]/////////////////////////////////////////////////////////////////////////////6 P1 e# t4 u$ S$ i7 @; s
// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE>
# {% `4 o% p8 \7 a( Y7 ^AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const% N* P2 r7 C5 o. ? p
{ return m_nSize; }
I# m X9 n: m5 dtemplate<class TYPE, class ARG_TYPE>
3 v& ^$ g3 n# r( R4 DAFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const, j1 }' E) Z9 |' l: K
{ return m_nSize-1; }0 K2 O2 e# F# m; b1 V" s
template<class TYPE, class ARG_TYPE># O9 _. R) k5 z' S& m2 ~: {
AFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll()
9 ]* q, ~+ s% d2 F { SetSize(0, -1); }
- A7 v, J/ ~8 Q# {template<class TYPE, class ARG_TYPE>
/ v, p7 O8 ^( T$ E- {+ _9 ?8 ?AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const# x$ P5 [' m: W! l/ e) V
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);8 R, Q, }7 F6 H" F, c
return *Ym_pData[nIndex]; }
) c2 e5 S& `& H: d% e. m- h# utemplate<class TYPE, class ARG_TYPE>
) Q: i7 ~9 x0 bAFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)
1 S- U) \3 ~! W6 w* w/ A1 o7 } { ASSERT(nIndex >= 0 && nIndex < m_nSize);4 }4 _" m* C. a3 K0 i
*(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>- d: f# g. e2 K3 I
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex) ] F1 Q' p4 `. s' M, S
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);; O& z; d$ D7 _5 k
return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>+ v) ~% J0 c5 Q6 s
TYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const' W- N1 N) k+ Q6 \1 m8 P% {
{
# c: V& ]* a2 r int nIndex=GetIndex(cIndex);
* s9 {& {4 ^( o return GetAt(nIndex);0 J% W( Q. j# `/ X# {1 D0 o; y
}
6 o* [& H: M, ^( ztemplate<class TYPE, class ARG_TYPE>
3 o6 O* } _% Z6 C& F! Y ovoid YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement)2 _7 `/ v) {7 ~' g3 H- z
{
- O+ }! f6 X# b% D7 u int nIndex=GetIndex(cIndex);
8 H3 l" i' r) n5 y% H6 y return SetAt(nIndex, newElement);
3 Q. f8 _; Z4 {3 u% `% u}6 }4 g& ~/ j* @
template<class TYPE, class ARG_TYPE>
- k* J2 ^9 H6 f/ n3 ^ tTYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)+ s: }% T. G* c
{9 y4 B% _8 g! d& {. t
int nIndex=GetIndex(cIndex);
6 a+ V3 a3 T$ |% A7 h. U2 Z return ElementAt(nIndex);
$ {% x. z/ G2 c) U* J}
$ ^% z+ |$ m" Rtemplate<class TYPE, class ARG_TYPE>
4 R5 B- ?% Z! y, k+ s! [7 \) ^AFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const
$ J5 _1 S: _* X) q4 R9 m# S# ^ { return (const TYPE**)Ym_pData; }
. u5 T. c9 W$ Y6 N+ U! b( gtemplate<class TYPE, class ARG_TYPE>
/ z9 R0 f) B( `7 ?+ e, L6 KAFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData()
& ]4 [2 ^8 j- ?- z2 W" h { return (TYPE**)Ym_pData; }
% w) _6 ^: G6 ^; |& Y* {template<class TYPE, class ARG_TYPE>
s% C8 z5 ~, o( L0 d4 G* BAFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */)
5 Q* K- ]/ s; k' ^0 o9 y+ m { int nIndex = m_nSize;6 r+ e2 P# A% R. c
SetAtGrow(nIndex, newElement);" I p! }; ~$ a6 ` n. h0 ]! {
SETIndex(cIndex,nIndex);
2 N" v( {- `, p- w) ~8 ? return nIndex; }$ m; `& R' Y1 u, h; i f
template<class TYPE, class ARG_TYPE>
' H0 k9 H2 q& c! pAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const. m/ [4 a0 C5 K/ G
{ return GetAt(nIndex); }+ ~ e: q. x/ q: W6 T
template<class TYPE, class ARG_TYPE>; x5 h# v* M' T |0 ~
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)
4 X9 @4 a; K% ^& u, l) K9 |" E { return ElementAt(nIndex); }: r2 M, I* H( {3 ~; q
template<class TYPE, class ARG_TYPE>
4 J5 L! w8 o5 s% V% uAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const
9 _# b5 G2 j0 q$ s6 g; g{- q* X9 S1 j& k( K2 X
int nIndex=GetIndex(cIndex); return operator[](nIndex);
" G# M; A) w6 k2 i4 S}
: c- w) {5 v7 d9 ttemplate<class TYPE, class ARG_TYPE>
& }! \: q( D ^' T( L2 mAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)7 R( r+ F5 e! G' j) R+ F! S+ d' D
{
! `6 V; K6 S- m g5 @& S1 g int nIndex=GetIndex(cIndex);$ y/ F- F7 O) p6 v- {( g
return operator[](nIndex);
3 f0 V% o% k; M) _7 [}+ Q4 w$ {* S8 f( a+ i* @. \3 \* e
/*, L( C2 i3 j2 Z
template<class TYPE, class ARG_TYPE>
9 j1 e* v- E; m% C/ o# FAFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const' ^. ?+ | g' K+ t
{3 c7 U- K) _! w
int i,j;
$ x. b) F3 ]& r, h4 C for(i=0;i<tparr.GetSize();i++){
6 |/ o! G' H! Y4 f" ~, ^ j = GetIndex(tparr.GetIndex(i));( z' z* I/ o( [4 K% [. U3 a7 a9 e
if(j>-1){8 @# h3 R( h5 |% y& z# q, E$ [" I
operator[](tparr.GetIndex(i)) = tparr;
& A* J9 \5 @+ r) Q; D* p } }else{
5 ?; w1 O9 y% s7 p Add(tparr,tparr.GetIndex(i));
1 j, ]) e; q; k1 |4 [ }
a/ ^8 _2 w$ k* ?7 w0 G, N }
0 p2 J$ K9 v$ F( {4 S: t% @ return this;: l8 R6 A3 s# o" Q) Q
}
8 `& Q7 A& f; f$ K& \3 E1 ?8 g3 S*/( h2 O; O5 S- L2 s6 O1 k
template<class TYPE, class ARG_TYPE>
( y. z0 i6 x- Y) ?5 zAFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src)
" N4 a4 p; R1 A. U$ s/ Q8 Y0 S, m{6 n+ b+ X& K: d+ Q* {
ASSERT_VALID(this);
/ h8 _! ]4 P0 W6 c, V5 H* A ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);
; ]/ e' u* W; l8 @ for(int i=0;i<m_nSize;i++){" \6 _/ {5 M @: V" x. N
/*将此句修改为内存拷贝*///
$ l4 v8 k- y6 Q3 @4 H *Ym_pData = *src.Ym_pData ;
, W- G1 Y2 p, X, l9 L //memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));
" ~, u4 x4 \8 m0 U, O0 j+ _ SETIndex(src.GetIndex(i),i);
* M, A6 w* y0 |: g }
' D. R0 K* q; J! A. V% E) B! C return *this;
J+ K. y, V6 u2 A3 ^9 x! p. g. U}
' ?+ t5 ^+ P1 G! m! w. d/ x/////////////////////////////////////////////////////////////////////////////
+ J! _* V$ h# S4 M4 ?// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>
7 b3 X* |0 T/ v9 u3 VYCArray<TYPE, ARG_TYPE>::YCArray()2 d, L0 k+ t7 G# ]0 f' e9 c/ Q
{
. b7 X- I9 S9 t" ^( n: L Ym_pData = NULL;
( v4 ?4 K# T* V7 | z strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
! I' |( `8 w0 l, K; T# A strIndex=NULL;MAXSIGNTIME=10;
1 I$ ]; y) ~% \6 {}
; V9 I/ v- |3 ?- otemplate<class TYPE, class ARG_TYPE>, X1 a0 G- F7 J/ u6 K
YCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp)
_& _; l x7 f{5 d' l9 t8 G6 G, o7 l7 Z+ y F
Ym_pData = NULL;& q3 n0 _! ~8 y7 I' ^/ ^6 K
strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;+ T1 f8 b9 @2 ~8 l
strIndex=NULL;MAXSIGNTIME=10;
& C; L( Y. S% g3 J" S6 L3 T operator=(tp);$ ^' ]: q, j k
} template<class TYPE, class ARG_TYPE>
8 p. U' [! P; w7 ?void YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy)# l' e. D& d8 W
{
4 i' p& L0 @: k ASSERT_VALID(this);
; w) U/ z$ h4 T$ T ASSERT(nNewSize >= 0); if (nGrowBy != -1)# c" `- l7 n6 V& x5 b( d/ |# g4 X
m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){- ?- f! f# n9 o8 @
// shrink to nothing
: F( T" b2 } S0 o4 W if (Ym_pData != NULL){4 W/ }# |" h- @' _ x; a
DestructAllElement(0,m_nSize);, F2 y: N0 A5 f) G% _
//DestructElements<TYPE>(Ym_pData, m_nSize);! \3 Q" D6 s$ P5 ~/ |
delete[] (BYTE*)Ym_pData;
) n" R5 W3 F- v Ym_pData = NULL;
- k) z- E! O. x, ?/ z& C }
1 J5 _4 c2 ~+ l G; q# i m_nSize = m_nMaxSize = 0;
. x+ d6 N0 }) Y3 Y0 m } else if (Ym_pData == NULL){ D8 X6 l, d, U. b# i6 Y
// create one with exact size+ M5 K- L/ U" p* K2 p
#ifdef SIZE_T_MAX
1 D+ {7 `$ W) A7 s/ ]1 m& { ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow
, W) [! T% B% ~+ X#endif
( g3 j9 e; E. d Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];- D* z: I/ ~7 U
ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);
; G$ S' Y. w! t' N m_nSize = m_nMaxSize = nNewSize;
+ L8 ^0 S9 j# E2 t/ l } else if (nNewSize <= m_nMaxSize){
7 i* Z, E6 W2 q+ q& }; E; C/ M // it fits k9 o- f5 n/ ~5 ~. V. m6 n
if (nNewSize > m_nSize)
8 u- j n, @8 P4 @ {
" f; H. F& d, [$ Z- z/ [ // initialize the new elements
u, |0 V5 s, A J% @3 A& { ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);
/ c2 f. b) t1 k- I }
, J( W! G9 q3 Q# X$ z! ?( S else if (m_nSize > nNewSize)
, w' w: g; D4 h4 M& Q- V" u {* X2 I& N2 D5 e" h0 t, v. A
// destroy the old elements
( }0 _8 q; |2 R* E) Y! n DestructAllElement(nNewSize,m_nSize-nNewSize);
- w, z) |0 _$ j //DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);# _7 l6 S# H5 \4 s3 w: L
}' y" W+ G8 J5 j: F4 K
m_nSize = nNewSize;% a, Z4 {9 A0 Q3 q
}$ {* a( B9 J4 ^# J2 E
else& r& _4 O: I: C7 X: P Z+ \0 c. g7 T
{
3 D) |3 {! R* e, c/ j5 r4 U // otherwise, grow array5 g3 J8 J ?+ v! w9 x* R c8 u2 V
int nGrowBy = m_nGrowBy;# [3 ~% a) J4 f
if (nGrowBy == 0)! I' Q3 e3 q/ G* _+ ]
{
4 q. ~5 |9 |* T5 V // heuristically determine growth when nGrowBy == 0
! g* z7 o/ i: P8 f: W, R! W' Z // (this avoids heap fragmentation in many situations)
3 a6 ^0 x# l' q3 s' r, \ nGrowBy = m_nSize / 8; h( K1 T# }# R) o: I7 {6 ]/ i8 X( I
nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);9 N: z0 G2 E; l+ ]& `3 c$ x+ W
}: y I9 V# U' x5 q. M- r* I
int nNewMax;* x. O, i2 m* v
if (nNewSize < m_nMaxSize + nGrowBy)7 r1 f" m8 F6 u O
nNewMax = m_nMaxSize + nGrowBy; // granularity
# h; C# W7 r7 I else
- q* }# j+ @6 N- z6 y. r nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around( g) f8 j2 b" J
#ifdef SIZE_T_MAX. _0 ~# H. T) F$ a x
ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow
! U! ?4 y+ B# T& ~#endif
% K1 i- F5 J8 K+ ] u TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old( x3 d( F, k' q4 `, ^' ~ S) M
memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements3 g7 G' i: r! O
ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");4 z: v" N; o3 I. W
delete[] (BYTE*)Ym_pData;
, y$ b; ?/ U I- F" g" |2 n4 I Ym_pData = pNewData;
+ ~( \ E: X, a2 D, l; H ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called)1 B; h4 @6 Q1 t( T: I+ K8 X& g
m_nSize = nNewSize;
* h/ f8 e8 q- C5 `. h4 S m_nMaxSize = nNewMax;" ~, [! S6 A( A; }6 D
}
" R4 H/ \% w9 s0 B. e' b SetIndexSize(nNewSize);
" s; u' g3 ^$ D- g' N$ z+ K}+ p/ G' v2 s3 G" M" g" W
|