//接上面
& d j! J$ z9 M2 i9 ?template<class TYPE, class ARG_TYPE>$ R8 h$ z( U" a6 _2 F! M
YCArray<TYPE, ARG_TYPE>::~YCArray()# b: c0 O+ q5 J: i! Z" |
{
$ _' l: M9 x- u" A9 O) b4 r ASSERT_VALID(this); if (Ym_pData != NULL)$ ~ k0 e! d1 [5 W7 U: E4 l
{$ X: k% i4 [9 X/ ^: m- I" h0 o
DestructAllElement(0,m_nSize);" D1 c- Q* [; }4 @/ P0 y7 ^
//DestructElements<TYPE>(Ym_pData, m_nSize);4 Y. m* n# v) L
delete[] (BYTE*)Ym_pData;' ?2 a- p. z; g' B- g
}
' N( Q4 h6 x) z$ Y7 z& C1 i}
/ v9 S* v* ~4 ?( X3 `; k* {0 ]template<class TYPE, class ARG_TYPE>3 p- G; m, p! D, B8 X
CString YCArray<TYPE, ARG_TYPE>::GetSign()
2 T% l/ K( b! }4 U, y& s{7 g* b Q+ _ t( Q( P2 ~1 x
lock_sign=0;
4 O8 Z) V' F/ Y! i# z return Sign;
3 }, R0 y8 k- v2 C0 ?" r/ ?}+ J* B1 C. ~0 T$ z$ D* \& } [) L; Z
template<class TYPE, class ARG_TYPE>4 u0 _6 N. a8 ]2 u. t8 g' F
int YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign)
* V5 `5 T7 j+ z& @; Q) @{7 S8 H9 ~# }2 W- L" t
int i=0;& G* C) B! Q) N7 x
while(lock_sign&&i<MAXSIGNTIME){- |; w& |2 r2 _5 U: |; L; x
Sleep(1);, w8 \& ?( g) [. ?+ C5 B3 _3 Z
i++;
! {% d% m1 U' L, d }
. r" q) \+ }! O( J( ]5 @ lock_sign=1;
7 W5 U7 O- A8 A O" }- B Sign=sign;% @+ L: u! X/ ]
return TRUE;
* {& f7 @8 q$ O: f# O. [5 K} c3 |8 r, d# b5 O2 i, ?% |
//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer
# g- A$ B- }2 f7 E, Ntemplate<class TYPE, class ARG_TYPE>
% L; v1 H7 }2 v$ \3 ~' mBOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)/ E+ m D8 F. z7 y5 a. R( g: H4 Z& C
{2 |0 S& q3 o5 M6 V, `8 A
if(strIndexNum < nNewSize){7 j. m* |- Q" ~
CString* tp = new CString[nNewSize];//新的buffer9 s' c z$ H" s9 ~3 D; Q8 G
for(int i=0;i<strIndexNum;i++){//把老索引复制过来
5 ~# H+ X s$ a5 O- s! a2 d tp = strIndex;
! @& ]2 Z h- n) ^ }! p" r$ j0 W; G# c
for(i=strIndexNum;i<nNewSize;i++){
- ~& E u) F/ a8 Z5 G6 ^0 _1 \7 O tp = "" ; i) V" g: _7 L$ `' ^% A6 F8 S
}
/ O) O* c. O6 x" [ delete[] strIndex ;
* U' v1 A. ~7 u strIndex = tp ;' H/ H! u5 }+ U5 o2 m0 G" A
strIndexNum = nNewSize ;
5 P. i0 ]$ D( _ l; X6 A2 ^/ { }else if(strIndexNum < nNewSize){
9 g4 i5 f, Z5 v6 Z4 R$ y+ ~1 N for(int i=nNewSize;i<strIndexNum;i++){
' ]) I; j% J- [4 n! W U( y strIndex = "" ;# Y6 j, r8 d9 J+ z2 r! X
}
" P+ i8 B/ d- O [$ U& p9 ~1 { }9 m+ S" s! z* U4 p
return TRUE;
! p; h0 \& X, W" _; @}
4 X ?# f9 m! Htemplate<class TYPE, class ARG_TYPE>
1 m) W0 T9 @5 t/ E4 R4 ~BOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/) O0 ]( }9 Z7 @; b6 @, m0 b
{7 `4 m" I( [# f5 `: v
CString* tp = new CString[m_nSize+nCount];//新的buffer
' f* \' v$ h4 J+ u for(int i=0;i<nIndex;i++){//把老索引复制过来9 p- T+ K5 n9 b. K4 b
tp = strIndex;
7 m1 T1 V: ?4 U% z& ~: c }int j =0 ;
3 s* U& e( _) x4 r3 M3 l6 Q1 F( B for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来! A+ m+ Y' Y& l) l
tp = strIndex[nIndex+j];) `- `6 l$ @1 S7 F
j++;& z' m5 d! Q- h" v! e5 T; g
}0 S2 V. u$ F) w7 Z6 T; L
delete[] strIndex ;2 S7 m& {& F9 Y8 X1 V
strIndex = tp ;+ L) Q3 V7 F5 x; l. g
return TRUE;* R! M" x+ r) ]7 z+ s/ w R
}
( P% x6 j. `7 L0 a8 l7 Ctemplate<class TYPE, class ARG_TYPE>
( u$ Z9 L" R8 f# }: [BOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex)
* {- M% e' W V( U{//在 nIndex 后面添加一个 字符串索引: m' Z% s& W, F: H
strIndex[nIndex] = cIndex ;
) @/ m- h& f- ]! N/ m8 k$ R return TRUE;
1 O) n, w ]$ J* O}# F4 d. ]3 Z* @
template<class TYPE, class ARG_TYPE>
$ ^: U3 _, n5 GBOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/)
X! n) P2 n, `! `8 E{//需要在 m_nSize 变化之前调用!!8 |2 q+ D& I5 m6 ?/ |4 Z0 j6 ~
ASSERT(nIndex >= 0);
5 `. @" B$ l+ X7 K/ w ASSERT(nCount >= 0);
6 S, {' I3 @! j! l ASSERT(nIndex + nCount <= m_nSize);4 k2 S a6 z8 |8 v8 s% M
int j =0 ;
# \* Y, }. b7 O; Y( J for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来# L* N5 o& M1 k: G/ k6 a
strIndex[nIndex+j] = strIndex;
8 |: w5 }, O, d j++;
' N2 A$ x3 Z$ z }$ Y% G0 ?& S8 T/ @
return TRUE;! j3 R" ]) Z [7 g) _& ^) K$ l% @
}
( @& k3 X E8 N$ itemplate<class TYPE, class ARG_TYPE>
& F! Q7 O3 j9 d+ P+ x8 c$ OBOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)
9 c0 \1 o8 L# P3 J' M3 Q0 U u{# f |% {. i) g7 D- a
int nIndex=this->GetIndex(cIndex);
- ~; t4 J: y/ ]" N& X1 o- E5 V/ N3 H- { return this->DELIndex(nIndex,nCount);7 }4 D7 ]9 d9 G, c8 _
}
* M8 Y H% m0 Vtemplate<class TYPE, class ARG_TYPE>- \( Q, Y2 f- s) y( t
int YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex)
# w# q# |' e+ _0 A6 U) v{//得到 cIndex 的数字索引
9 c O5 Q1 e6 A* _" [3 B' ^) ^ int nPos = -1;/ K9 L" t2 M n& b+ T
for(int i=0;i<m_nSize;i++){
2 w* x/ e% |1 Z" ?) _9 L if(strIndex == cIndex){) a& }, O8 U. ~8 H8 h
nPos = i ;break;( G4 F* Y( Y; E; J
}6 ~* D. p. B1 z: i' [
}
1 n3 K0 p3 S G4 b6 l; Q return nPos;
3 p% s; g3 I% k, h}& I: H- x5 z# N, r, [2 U# U6 d, A- q
template<class TYPE, class ARG_TYPE>
) N1 w' o, {6 b e6 Y" }CString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex)
" V+ ?4 x; T2 H) h( K5 b{//返回 nIndex 的字符串索引
. G& @( L" P) ]0 J+ m+ R$ N return strIndex[nIndex];
+ @, U8 o! q) N; Q3 Y! ^' ~}
3 U" }) Z# Z9 K' Y/////////////////////////////////////////////////////////////////////////////
, x& m" u0 a. O* X! h) W// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE>1 P+ J* d! Y+ j4 g. ?3 W0 V
AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const9 `1 b2 z# C# n) [2 V) I# {; h) b$ B
{ return m_nSize; }
) z# a( O- k& e' ~7 N' Stemplate<class TYPE, class ARG_TYPE>( z& O# l; ]3 W8 Y1 e9 d! I. B, ~7 h
AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const$ c9 v: S! H- @. J
{ return m_nSize-1; }8 v% ^+ B6 r9 S1 W3 r; x
template<class TYPE, class ARG_TYPE>
* G% J1 z$ b' ?0 W9 t# \; HAFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll() |4 K! _% j: b0 @, U4 J
{ SetSize(0, -1); }
) C W3 P, U2 P: |+ Wtemplate<class TYPE, class ARG_TYPE>! Q4 P3 |( u7 r
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const
. c% z( X- M3 \( W { ASSERT(nIndex >= 0 && nIndex < m_nSize);
# e3 x2 E5 j) e9 |) ^6 I return *Ym_pData[nIndex]; }
1 |5 {: L( o5 x! s$ g) ctemplate<class TYPE, class ARG_TYPE>0 ]8 |! i8 d0 R" K8 h1 ]9 ?! u
AFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)
; V. _* E4 n2 f { ASSERT(nIndex >= 0 && nIndex < m_nSize);
# n. ~9 \$ C" z0 Y *(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>
! ?8 A" g7 g# V/ k( \$ j4 E: k TAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex)
% k/ d% e e0 v" b8 r# F A { ASSERT(nIndex >= 0 && nIndex < m_nSize);
$ N$ [5 I- W5 ^) A return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>
7 u. p- g: c% i. z J. N7 c3 bTYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const
3 F( K- T( y, I2 X0 q) ^{
: n ?5 v+ Q! c/ [ int nIndex=GetIndex(cIndex);
[8 \+ D: n0 C return GetAt(nIndex);! v& Z3 g( [. H
}
4 a& G, q1 v* \6 `template<class TYPE, class ARG_TYPE>
; {8 P2 w* r! j6 r5 ]) }* s$ Dvoid YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement)
) R( ~( j( ~; f7 g6 w3 |! G# Y% N{
7 T2 E) d3 A+ m5 a; ~6 {: B% G int nIndex=GetIndex(cIndex);
7 E$ m/ l9 n1 p1 c5 x& S return SetAt(nIndex, newElement);% G9 m, p) F5 X! b" z
}
1 ]! c$ P' F% `, z0 |template<class TYPE, class ARG_TYPE>
% S% A! }2 J+ l6 KTYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)1 ^8 n9 O! T6 u
{
4 K$ Z# J$ I+ F4 C int nIndex=GetIndex(cIndex);
2 J. H7 D. @5 Z return ElementAt(nIndex);
# z6 h' |8 Y6 G# k; d) V. g}
" O% E9 @9 u; ^- m3 R8 Y+ etemplate<class TYPE, class ARG_TYPE>
7 A$ L5 K* Q3 a0 k3 q0 S( I2 bAFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const% ~( G2 t5 ~0 n( q
{ return (const TYPE**)Ym_pData; }
5 Z; K1 F K4 q f2 mtemplate<class TYPE, class ARG_TYPE>& {. S* y/ Z2 z$ \6 d) L
AFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData()% a% l! K* Q; i0 A# l9 X) y
{ return (TYPE**)Ym_pData; }
! z n% B2 Z6 {template<class TYPE, class ARG_TYPE>
) q6 V9 y. y( h, p6 N; r. eAFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */), a. M- J+ w. z9 u, i6 q" L7 ^
{ int nIndex = m_nSize;
: l" ^9 e0 I& k* ^5 u" g- @) ^ SetAtGrow(nIndex, newElement);
0 z( x% l8 b! t1 Q" C SETIndex(cIndex,nIndex);/ y8 O4 |& [8 k* l x$ J! }
return nIndex; }* {5 X5 B0 W6 p% |6 H0 b2 Q+ \
template<class TYPE, class ARG_TYPE>
& F+ o# l) o7 k/ U1 e. l9 R# n! ZAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const* a ]0 ?% T3 S1 T/ e% n1 A
{ return GetAt(nIndex); }8 _ h) W$ y& K$ _! P$ H4 h! ]+ B
template<class TYPE, class ARG_TYPE>
6 @& {9 |) j0 n0 P8 f. m2 i/ vAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)9 z: \# r o+ s5 i! S, h% w! V
{ return ElementAt(nIndex); }) w/ _0 y1 l$ \4 e
template<class TYPE, class ARG_TYPE>/ \& ?) m4 ~ W, B5 T3 `0 Q# i
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const
( X- {, e; V0 c0 A4 j9 ] b{; E$ r7 m Z4 c' t( O/ j: J
int nIndex=GetIndex(cIndex); return operator[](nIndex);5 Z, ?; k7 s6 Q! F! x4 C
}- j- g; Z) e, V5 J, `# k% _$ ]/ s
template<class TYPE, class ARG_TYPE>
& s& {5 c5 \5 Z( _4 o/ j/ rAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)
5 z+ n& e* C8 R2 v/ t4 S{
0 K0 C' O h. I2 K4 x' x! E int nIndex=GetIndex(cIndex);; u$ A+ ^( i( X* d' \
return operator[](nIndex);
, z. S0 c7 a6 f% p \! @# J}
3 z) {$ b6 q) m& F; X6 c/*& U- a$ O. Q6 Z! r9 u0 E. Q
template<class TYPE, class ARG_TYPE>
6 M- i% A7 r# E4 Z0 WAFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const4 g3 z+ W4 `( d, h8 A! _
{
! l- x8 o! N; Q! {: {2 h int i,j;/ ^6 M2 D C1 \2 `
for(i=0;i<tparr.GetSize();i++){: X9 g7 `/ A% i$ _
j = GetIndex(tparr.GetIndex(i));# |* F8 A ^6 t4 C. R9 A7 [( P
if(j>-1){
8 j: f( o: J0 g. l, V8 [; s operator[](tparr.GetIndex(i)) = tparr;
! g; V6 _! n: r" s3 J% t- g- _) K* `. w }else{
! F* f# ]& e- ~8 s! W Add(tparr,tparr.GetIndex(i));
) y; }# c$ _# w }+ |& ]$ w) h" |6 T
}& [9 h+ |. }! }7 J2 c
return this;3 a5 i6 {2 {1 T; `" {' `
}
x3 u) B% @+ i p! |0 M*/( z, J1 U5 f+ A. s3 P
template<class TYPE, class ARG_TYPE>% d8 x& Y& O; Y
AFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src): P- U% i2 r1 S
{; z' x5 t8 W5 `6 M$ D" J
ASSERT_VALID(this);$ F7 l8 S! K' f8 T, J- }" l0 F9 o
ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);3 @& I: U; J) h. n* `1 [; I2 i
for(int i=0;i<m_nSize;i++){. P% s2 r# g( N* H
/*将此句修改为内存拷贝*///
# {1 |4 l7 D/ H; U *Ym_pData = *src.Ym_pData ;
9 i2 \. k2 X+ S //memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));# _0 o. N+ v A8 r9 A
SETIndex(src.GetIndex(i),i); ~5 ?$ P- V$ E7 R4 W9 S" p
}/ l+ y9 e7 ?6 E1 o4 I5 S5 W
return *this;
7 E9 a' z5 D5 Z5 Q8 a b}
5 i- k5 z! l3 ^5 C3 \. X0 {8 o' g/////////////////////////////////////////////////////////////////////////////
% s9 v6 J& h9 J// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>
; o4 \- e4 w9 {3 a! PYCArray<TYPE, ARG_TYPE>::YCArray()7 \- Q7 t( h# E; {) I
{
; i1 \7 r- _ W" p0 e. r0 i Ym_pData = NULL;
# I; s0 ~& [4 x1 W strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;; J0 [' e3 A% v6 x0 H+ P, D
strIndex=NULL;MAXSIGNTIME=10;! r4 a4 G, Q6 Z# z a5 a5 Z! p
}
7 o; k/ D( r0 s) d2 s3 e& Btemplate<class TYPE, class ARG_TYPE>
7 L# L$ g. @* i+ L; HYCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp)
4 N- \! r. N1 S, X! M- B4 q{6 E, K' w# H* ~8 C+ G& E2 {" _
Ym_pData = NULL;' B: I9 I |: e0 j1 W/ D
strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;) Y3 @. q/ `! D9 Z3 t; r& l( N; `7 Y
strIndex=NULL;MAXSIGNTIME=10;) _ v u( @5 J) q; b$ A3 n, f
operator=(tp);0 w3 `! S u7 M$ J5 X/ [6 z- \
} template<class TYPE, class ARG_TYPE>' B' l% O' Q7 W5 s9 }
void YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy)0 Z( S( c: f! @; [0 x
{
+ W, ] @" F% C9 \ ASSERT_VALID(this);) }8 D3 n3 s, q5 T! x" `7 U/ B
ASSERT(nNewSize >= 0); if (nGrowBy != -1)
; ~* Y$ p0 l7 ` m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){5 U# Q7 C' q6 P/ X( o. M4 N
// shrink to nothing
7 i7 E5 Y$ R; E: ~0 L$ z if (Ym_pData != NULL){5 e6 E& L0 w& _* D$ Q- g. [
DestructAllElement(0,m_nSize);
9 D% C! t* ^, p# M7 p9 R4 _3 v4 f+ E //DestructElements<TYPE>(Ym_pData, m_nSize);) t4 Y p6 a) A, r
delete[] (BYTE*)Ym_pData;+ _3 }5 |% }. D" Y
Ym_pData = NULL;
: A' B* q* m7 L" @ }
8 s, i+ i& D/ c( M4 m6 {' f m_nSize = m_nMaxSize = 0;- u; @. [, F' m4 K0 `( k( W% y3 O
} else if (Ym_pData == NULL){8 Z0 y0 y+ t" A
// create one with exact size, p- \! m2 j7 y! G' V+ j
#ifdef SIZE_T_MAX
" L7 r" F% O) B* \9 x' \ ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow
: m2 Y+ k4 ?* g. R }#endif4 W ~) @, Z; L5 @- Q: s, e/ E
Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];* Y8 _4 Z! o% _# F5 M3 I r, n
ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);
* O+ Y; k0 v5 H, J+ d. C2 a m_nSize = m_nMaxSize = nNewSize;
- ^# c5 d) @) H. J } else if (nNewSize <= m_nMaxSize){
* ?/ ?9 i# y, r' {* Y% Q; j // it fits" \( Z o# B6 e5 C$ _
if (nNewSize > m_nSize)+ V+ T* _" l" |2 _
{$ \! W3 V2 _, }& Z, h( | _
// initialize the new elements+ z% X# Y: j( c, s6 m* B! I) T
ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);
9 H3 p& ~0 K: j: A/ @( C7 d4 S3 b }" B# D+ k# e2 u& U
else if (m_nSize > nNewSize)
! i$ q" n) p% F5 P& [2 E {- A7 K- k" W) ?! d& h! v
// destroy the old elements
5 ^( V7 E* b- _9 F3 J DestructAllElement(nNewSize,m_nSize-nNewSize);
\# H" F; P+ t2 `% U //DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);
% j( W, G9 @# A0 C: C+ F }) V" v- d. O2 ]6 r
m_nSize = nNewSize;
" [' f2 ]% O! h; X4 Z }4 R) c5 R& O, F1 W& Y0 q5 C
else2 ?. j( o& O* ^4 C1 H6 W9 z1 L
{8 I' F9 y4 B0 ~2 I B: E) d6 | ?8 v
// otherwise, grow array
" h0 k1 J% w$ w" Y4 c int nGrowBy = m_nGrowBy;: d4 X- H+ c) n3 j- ]
if (nGrowBy == 0)
* {; @! G& f$ y9 ^9 N {
0 G! ` g. J+ ~. @6 ]+ r- R // heuristically determine growth when nGrowBy == 0
& l2 P1 u" U3 H2 O0 f // (this avoids heap fragmentation in many situations)
/ S+ m* M2 H* U, r1 a nGrowBy = m_nSize / 8;
1 ^9 d y$ E) V3 q* s6 f+ l" m nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);4 q( s" n; k; R3 a
}0 R8 ~9 i! Y9 @6 n; B# A
int nNewMax;
4 N" N. m. q9 t( B; s& I if (nNewSize < m_nMaxSize + nGrowBy): ~# j" [6 g$ b0 M
nNewMax = m_nMaxSize + nGrowBy; // granularity
9 [4 u, e& I' L. m0 c else0 P8 ?/ V+ s% J
nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around
3 h, g+ I6 P6 V0 O2 E; V#ifdef SIZE_T_MAX
4 Z# H5 \' N- ? ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow
9 r, ^: }1 w" @1 L/ s6 a, O, w8 X#endif
8 u, |. H" c5 y* c. z3 h5 l TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old
' x3 }5 P3 \, I memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements0 ~: r) l$ |& |3 W1 f
ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");7 F- Q, m. n3 ^: e% t. b
delete[] (BYTE*)Ym_pData; C1 `9 j( @+ T/ U% B- U
Ym_pData = pNewData;
2 K I: p7 }( [- B8 W' g ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called)
; Y% `5 o+ b6 V# W m_nSize = nNewSize;, }' x) \( ^$ {0 H1 B, R( p$ Y
m_nMaxSize = nNewMax;9 S0 h9 J- {& W
}5 m3 l0 _5 p! g$ p" C; W
SetIndexSize(nNewSize);) r/ ^! S0 \' k5 L7 F4 O% J; l8 e$ c
}' b3 i! T8 P1 A: W% W
|