//接上面
7 b2 x' i5 A8 a. W& S' }template<class TYPE, class ARG_TYPE>
* m" T) G& v% c5 }YCArray<TYPE, ARG_TYPE>::~YCArray()
; r3 ~; ?4 D) ^+ a* b; ^2 S{
2 |5 k) D* _" L2 z* t) V ASSERT_VALID(this); if (Ym_pData != NULL)
+ k6 F2 Y9 [" r! ` {
) m1 e: K y* n" ]4 U DestructAllElement(0,m_nSize);! D! j0 B! X7 j5 V, u n
//DestructElements<TYPE>(Ym_pData, m_nSize);. t3 z2 v, N" Q1 t# u/ q! o6 r
delete[] (BYTE*)Ym_pData;
' @0 E* ^4 j7 b1 E5 P H }
7 L, W8 Q8 o' H& G9 W7 @}
" {9 h6 f6 S8 j2 `- a, ~template<class TYPE, class ARG_TYPE>0 A( y: f" p* f' G& W/ n0 @
CString YCArray<TYPE, ARG_TYPE>::GetSign(). Y. m7 Z1 F1 X# H: n, J5 v
{
8 B5 j( ~7 A4 W8 }/ Y lock_sign=0;# Y% Q) s2 Q* A% S
return Sign;* P$ T1 ?- B/ q3 ^
}/ P% J t! d4 R9 ?$ v; u4 y
template<class TYPE, class ARG_TYPE>, E0 A8 N1 d3 p1 U0 H* ?
int YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign)
) d4 e. l0 N9 r8 n/ }{
2 N8 |9 G5 e9 c1 J3 N int i=0;
9 j4 p" D) x9 g/ ^6 g2 n' ?+ H while(lock_sign&&i<MAXSIGNTIME){
! D4 ^6 J" S1 C Sleep(1);
, ^# r9 A6 o6 d i++;) X; Q0 P2 e" k# m( s
}
I% W! k$ [& M1 Y lock_sign=1;
" p" m7 O7 m2 N) k* O) c Sign=sign;
* z0 ?, B9 ?) W( g return TRUE;8 `; Z7 B1 k! A$ ], N
}3 f& S8 M; ~& L! i& m
//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer
* C2 ^+ e7 o2 F+ h9 J" M9 B& Ctemplate<class TYPE, class ARG_TYPE> l- ]5 }' I6 E: ^
BOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)
. l9 w+ ~2 I! \) e% T* d2 W8 d/ G: W{
1 p/ Q2 d% M- M; a* ~/ V! i3 a# J2 w if(strIndexNum < nNewSize){# m' [& M# H6 H, c" ~
CString* tp = new CString[nNewSize];//新的buffer6 X3 g! P# b* c l) j/ d4 C
for(int i=0;i<strIndexNum;i++){//把老索引复制过来/ C# O. d: i$ s6 v3 T
tp = strIndex;/ _" f7 [8 m8 S1 z2 G8 Q
}
6 U% M$ X5 n' O for(i=strIndexNum;i<nNewSize;i++){6 O6 b% ] \! D2 Z* R
tp = "" ;
- M2 R! B: x+ m M* F% W5 ]- l } / m, b5 ?+ T5 D0 I
delete[] strIndex ;% ?1 m9 \( T* E% [" j$ s6 j
strIndex = tp ;
, @# s; U' k% Y8 z# O. s strIndexNum = nNewSize ;8 M; U% e1 l y
}else if(strIndexNum < nNewSize){2 C* m- Q7 i9 {3 ]
for(int i=nNewSize;i<strIndexNum;i++){& m9 g3 s5 E. L) t4 \8 o$ b g7 k
strIndex = "" ;+ J3 {- t4 y0 g" T, r7 M
}- V$ m8 S/ T( }: [1 [0 C
}6 j& l- z7 R& }5 `" B B
return TRUE;
M( i) [& w$ B" j9 d) p}3 v7 |2 U1 _- r* K$ S1 Z
template<class TYPE, class ARG_TYPE>- p- T- s# ]+ { W/ Z
BOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/)7 z8 s6 r, e3 H
{: M. m; R2 _! C" O
CString* tp = new CString[m_nSize+nCount];//新的buffer! B. G+ w' z0 F6 I) j5 U% Q
for(int i=0;i<nIndex;i++){//把老索引复制过来
9 P7 |2 |/ W, _ tp = strIndex;
1 u- R* t6 ~* {( L' ]4 U9 J- `! r0 y }int j =0 ;- @' ~, _% z# L& B" P, V
for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来# ?' o3 y+ G2 R. P. i
tp = strIndex[nIndex+j];
# X/ P& k' L, T j++;
8 T8 {# N' U* q }) Z/ i2 y v( W# W+ {
delete[] strIndex ;+ J+ n# N( Y, F1 ?' Z4 {
strIndex = tp ;
7 x# U$ A7 K0 g: o5 R# |, t0 y* F return TRUE;
$ v" c8 E- H! t$ d}
. H3 b( ?& w: O6 J* Itemplate<class TYPE, class ARG_TYPE>( X1 x# l, h6 r
BOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex)9 L7 h4 y/ f2 \( J
{//在 nIndex 后面添加一个 字符串索引
. B/ n: x$ z8 j5 Y" K strIndex[nIndex] = cIndex ;
9 f% l" {7 w6 @( P& _ { return TRUE; _% R& ?5 c+ t7 q) a
}1 p* \4 e! N8 T, }' \
template<class TYPE, class ARG_TYPE>6 B; m6 [; L9 U; [8 F
BOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/)
% W* m1 @+ o; f& E. d" W5 ~( s{//需要在 m_nSize 变化之前调用!!: }- p& U, l/ C) q4 B/ v
ASSERT(nIndex >= 0);
s, ], H1 k$ |. f/ Y, m4 L7 ^6 I ASSERT(nCount >= 0);
( p# f/ p7 p, |; B4 } ASSERT(nIndex + nCount <= m_nSize);
, k' S O) t$ n$ V4 K! z int j =0 ;& p$ }7 b0 `2 o- k2 X( u T
for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来( Y4 D+ D* |3 `# E3 e3 I+ Q
strIndex[nIndex+j] = strIndex;
1 z6 S' F' R3 |/ A( R0 S j++;4 D, m- m/ M* G- l3 e, F; l
}
9 N7 S! @! b+ Y& S return TRUE;
5 G* R1 |0 I9 q/ F+ H}6 z% a. L1 E/ A/ I+ |
template<class TYPE, class ARG_TYPE>
! w0 S6 Q3 D9 Z9 B$ E* gBOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)( K4 `6 w' t7 g2 v
{
: I4 @/ h5 ]8 H$ s i int nIndex=this->GetIndex(cIndex);7 |# V% W* |6 a' Y6 Y( X6 U o6 U
return this->DELIndex(nIndex,nCount);. x( M/ O/ K' _, B
}6 S% C2 N9 K, C! |
template<class TYPE, class ARG_TYPE>; U- g. l$ G( \$ l0 m
int YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex)# D) _7 y: \3 {( U# m+ L
{//得到 cIndex 的数字索引
\+ l f' p: c0 T! e/ Z$ b7 U' l int nPos = -1;
; k: E6 Q) d: K; f b# q# V# d7 Z for(int i=0;i<m_nSize;i++){% U' r/ ^: J3 F) k
if(strIndex == cIndex){
7 L d- G3 C' H. u) w nPos = i ;break;8 h) o; W+ p% P6 U* D) p2 X+ S" R
}
7 Y$ ~% g/ Y, O$ q, X3 ^+ b: ` }$ F0 L5 M4 G* g1 G" H" C8 L
return nPos;
1 \& R; P: n9 k: W/ ~& [}( T& ^3 m: a/ a: s( D" q0 R a
template<class TYPE, class ARG_TYPE>$ \5 Z6 }) r7 T: Y% G& h3 ^8 e$ N% P
CString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex)6 {. W3 ] K$ K# m$ n' ^
{//返回 nIndex 的字符串索引5 Y, r& t! y" _9 j: F
return strIndex[nIndex];' d, S; }1 J$ S0 n
}, U9 a- O# g6 ^; ]( V
/////////////////////////////////////////////////////////////////////////////
' i" I7 U& [; p- P* F% {// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE>
1 F- ^9 O) {: T; G: i! UAFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const' h) Q7 y( F5 O/ ?/ f
{ return m_nSize; }& s' L0 u( E2 t0 O( g
template<class TYPE, class ARG_TYPE>" ~$ h- @0 z, y1 \( r9 e
AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const! Q4 z. H) b* `: Q
{ return m_nSize-1; }% y/ U2 G, e) U. b1 q! P
template<class TYPE, class ARG_TYPE>
! [; e3 H% i/ T7 p; PAFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll()1 ^- M4 v( f f8 H N+ h' j
{ SetSize(0, -1); }
$ ^9 \; N% O4 G- K% Q" [template<class TYPE, class ARG_TYPE>
' q- [" Z+ [/ X) n+ ~- K, @AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const8 e: j1 ~( k8 G- U2 [% [
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);0 R0 l; A. Y" {
return *Ym_pData[nIndex]; }
& L2 E! l2 V% t* Q ntemplate<class TYPE, class ARG_TYPE>
a' F' ]- v) ]7 K( ZAFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)
" B2 z9 B' Y! h4 t0 ]6 Z/ f7 t: S3 c# C { ASSERT(nIndex >= 0 && nIndex < m_nSize);
4 j4 v/ S' V; p4 I3 Q *(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>
6 u9 x% Z, C$ qAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex)
2 d/ X0 H# j/ u/ a+ x3 z/ J { ASSERT(nIndex >= 0 && nIndex < m_nSize);# u8 C$ u2 N. |# }& l: U# x
return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>
! Z" @8 [- r( k+ a x7 HTYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const" J$ {- L1 y9 Z, j. [
{
% t8 b2 h; E `0 L; ^ int nIndex=GetIndex(cIndex);( Q1 ^% I7 B3 \
return GetAt(nIndex);( w/ R1 s' F7 c$ u
}5 f: }) x8 C1 `
template<class TYPE, class ARG_TYPE>5 e* W1 L. Y, v6 Q2 f0 e, c
void YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement)
) s( T& p- n `# ^& j) O8 O{
3 x+ O! k8 L' _1 c6 Q8 W int nIndex=GetIndex(cIndex);
6 e( ]' x" Z2 D return SetAt(nIndex, newElement);
+ E% {4 R Z3 B5 c4 |}* h* b' L! j3 E1 l ^7 v
template<class TYPE, class ARG_TYPE>
$ d7 E' m6 D8 X& h3 aTYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)+ H5 r+ ` `- V
{
7 v2 k6 ~3 B9 K0 ? int nIndex=GetIndex(cIndex);
! x- E2 @0 ] U$ N/ m# t7 o: v, | return ElementAt(nIndex);' O3 H; q# M1 u- s
}7 B5 m2 \' T: {4 n/ [
template<class TYPE, class ARG_TYPE>
# G3 g- t2 D+ V& xAFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const
0 a+ H# k* m$ K7 Q1 G# X { return (const TYPE**)Ym_pData; }
" S) b' R/ S8 X# {: S8 u5 ^( I! Vtemplate<class TYPE, class ARG_TYPE>2 g; j$ v; t8 a& w/ g" v
AFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData()
# I7 E- A+ U# G/ ~! K1 Z4 E0 }$ v7 }. e { return (TYPE**)Ym_pData; }
, s1 l# k/ X& btemplate<class TYPE, class ARG_TYPE>
% i: r* g% w# z( s5 Y- T8 {$ }AFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */)
2 S; S- m) F& \/ `0 R, z { int nIndex = m_nSize;
1 C9 W' y0 D- {6 D) ]8 D SetAtGrow(nIndex, newElement);" T5 K: m0 N9 v) `0 ]' t2 s
SETIndex(cIndex,nIndex);4 ^( L! T9 h S! L
return nIndex; }" ]' @' H2 c7 R" k3 y
template<class TYPE, class ARG_TYPE>
5 r1 X; a9 {" `2 DAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const8 r+ q# A7 T. [( ?0 e0 a- X, E
{ return GetAt(nIndex); }
& G" T0 e, w( K2 A# |. ~1 M" y+ \6 w! Ktemplate<class TYPE, class ARG_TYPE>, m7 q+ T& F0 Q* e. @
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)
{, I9 i9 a8 r3 K2 u9 F c { return ElementAt(nIndex); }
# ~8 u! O+ `: h# P& R( }7 H" {, E Gtemplate<class TYPE, class ARG_TYPE>% e8 N' b0 J1 I
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const' G& O, |" W/ Z2 K
{4 s2 a. l4 K/ q' j$ x
int nIndex=GetIndex(cIndex); return operator[](nIndex);
$ s( f. k5 ^1 I3 [8 H: s}& q; k, d" B) i9 q) @/ T
template<class TYPE, class ARG_TYPE>- H/ \6 s8 ~: C& ~3 m0 T
AFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)
% m- P' k. I7 T7 ?2 _! _! t{& x8 A; b1 [) A9 r: Z3 c0 q7 M
int nIndex=GetIndex(cIndex);' e L9 ~* U: }0 l
return operator[](nIndex);/ U% X5 A+ G$ L0 r' P- [# Z( t
}! J% l% R, [2 u* k* I: z
/*. e8 {+ Z0 _: y7 y, e J. s- _
template<class TYPE, class ARG_TYPE>, m+ H, J" D0 ?
AFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const
+ z" c% a) h- B9 d+ h{
, e" x+ w$ W1 ?# o/ |) H int i,j;
3 S3 z' ?7 T) H; J/ n/ y" t for(i=0;i<tparr.GetSize();i++){
- C p3 }4 G6 N! s0 Y$ X j = GetIndex(tparr.GetIndex(i));
7 g9 L- Y3 k0 N7 A) C ? if(j>-1){4 I. D. I- A0 z' v' [& V/ K
operator[](tparr.GetIndex(i)) = tparr;
3 ~$ O! s( m5 q7 {$ u# Q' \& _ U }else{
) g0 s/ W$ V: W6 D1 a( w# l" a Add(tparr,tparr.GetIndex(i));- L& G0 `, N% M, q
}! z7 v$ O$ f; e- y; a# x1 J* I
}
Y9 V) t7 T6 O* x return this;
- }) ~, @6 u) c" `. K: Q/ J I* w$ b}" B/ H3 L" u8 b( `
*/
+ M) y2 { {, I- I/ b/ i2 W( ltemplate<class TYPE, class ARG_TYPE>
$ J% m; N6 t% K, Z# k1 S4 t3 r0 a' DAFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src) o$ ^+ Z. k8 G+ v
{. G2 g. N8 {, s1 d( f* c0 q1 @
ASSERT_VALID(this);
/ w$ ]& D7 U5 G4 X2 T ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);
1 d4 b/ q9 U' B# T2 q for(int i=0;i<m_nSize;i++){
7 S8 y8 c$ o9 f# m( F& Q1 i /*将此句修改为内存拷贝*///
. D/ w9 F; b& O3 g *Ym_pData = *src.Ym_pData ;6 A2 u1 E5 K. U% ]
//memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));. G9 b) s9 o% I
SETIndex(src.GetIndex(i),i);
3 T p% m( N6 c$ N+ W }7 e: F9 J% n5 [7 C. s) X( h
return *this;
0 A* T4 ^) Z* Z8 a* _2 Z z2 R}
. m" m- d& n" g# A' {" H/////////////////////////////////////////////////////////////////////////////
3 N. b# F3 o; u& q$ [// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>
% m/ Q( J8 @* o4 U kYCArray<TYPE, ARG_TYPE>::YCArray()8 R6 [5 i6 [( e* [6 ?
{
/ L* x" i! m: c2 t Ym_pData = NULL;
, c9 \& |# K, W$ B strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
0 ^6 C, s& x" e- x8 D5 q strIndex=NULL;MAXSIGNTIME=10;7 Z5 X, N) I; d% w& o9 i& s; O
}
" o; L0 g5 N A, j/ Y4 l$ Mtemplate<class TYPE, class ARG_TYPE>
2 a& f# A# d0 W- N- M' JYCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp)
6 C6 w; i6 X6 P# Z; Z{
; q% y. u6 Y# J2 w/ X- L Ym_pData = NULL;
9 \$ `" z- v7 `: V. O ? strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;
( Q: Z' \; [: u/ ]* l4 Y$ r7 K/ ]( M strIndex=NULL;MAXSIGNTIME=10;
: V9 U% g5 l( n! z/ e2 r/ E: A operator=(tp);
1 l# Q0 |3 R- H% h1 P7 p; ^} template<class TYPE, class ARG_TYPE>
. R- t* F" N8 _ u ?7 yvoid YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy)
/ t/ a Q/ y' \ R{
# n8 T% [; G4 t& O m ASSERT_VALID(this);. }- G8 I2 g# x5 A
ASSERT(nNewSize >= 0); if (nGrowBy != -1). ]) {# r9 k+ l
m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){) [0 L' K# v' C$ f) O
// shrink to nothing$ o8 {) U0 x% S9 i: a
if (Ym_pData != NULL){
2 ?' M( T8 W+ U& v DestructAllElement(0,m_nSize);) w' _* z' H+ K% A& Y& t
//DestructElements<TYPE>(Ym_pData, m_nSize);
& ]. l, p1 q. ]# b; q! L3 h delete[] (BYTE*)Ym_pData;2 Z! @& Z: N' A- L6 [* Z. l
Ym_pData = NULL;" k3 x5 n) o( e6 a$ m1 l/ j& i& D3 V$ X
}( }4 e N8 D4 [3 r. T' a
m_nSize = m_nMaxSize = 0;
& X f& ? W) I* c/ Y, ?- J) V } else if (Ym_pData == NULL){
( X3 Z0 F' q: A z, ~; T! ~, ?3 r, c // create one with exact size" c9 ^+ Q9 k1 ?+ a
#ifdef SIZE_T_MAX X2 b/ b, ]; G; j! f
ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow% t8 O% [" Y9 U9 W) N* H6 U7 |9 Z
#endif
+ o$ h+ ?: ^8 N1 P9 R Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];
3 r g4 D+ M* r, p5 U- q ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);
* ?$ T- J. ~1 D2 Y/ U9 L2 @9 n m_nSize = m_nMaxSize = nNewSize;
$ U$ \% w* \- i } else if (nNewSize <= m_nMaxSize){
* u# Z( K3 T/ q7 }: L! `6 ~ // it fits0 d( v/ E1 ^* Q( O7 Q5 h
if (nNewSize > m_nSize)
' v& Q3 G [8 \( J# n8 j5 p {9 T# |* s. W6 b
// initialize the new elements
% `; g/ G$ T! F( S$ r1 D+ m8 x ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);
! }+ o- ]& v2 _2 y3 O5 `# A }
U% \9 T7 p" G, f4 \ else if (m_nSize > nNewSize)
" U0 X d; o. F, ~. L* B- J$ m+ o/ K {0 ?1 ~5 Y/ c! N/ O) R
// destroy the old elements
1 B- b x1 y' _6 Q7 S5 N DestructAllElement(nNewSize,m_nSize-nNewSize);
7 ~# k v0 _* n1 |: ? //DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);& g. L# V* O; f' _* h
}
/ a; w2 _" {9 g m_nSize = nNewSize;1 l3 B" N& s5 ]9 @: O
}
* ~% q2 h4 @" E else
% r0 l# w2 T# y# f {- X1 C1 J$ c* Q" K4 p: h2 A+ p' r- V
// otherwise, grow array! R! i" O+ \. u% K4 Q
int nGrowBy = m_nGrowBy;
/ E2 f. m8 g; B if (nGrowBy == 0)
+ G9 M1 ~* w! _! l/ Y {
$ a4 d7 O/ T* t/ P // heuristically determine growth when nGrowBy == 0
$ R3 {/ F/ s8 b0 l2 k# q // (this avoids heap fragmentation in many situations)
* x' \( S7 G: X: C! {% Y nGrowBy = m_nSize / 8;, k" u! _: h7 S- [. D: ~
nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);6 t3 V2 V# i. l2 H4 E$ z! X
}6 r" z3 ~0 k2 ?. ?6 W7 Q/ @1 z6 \
int nNewMax;8 b4 n: R' Z- F/ I" A, P
if (nNewSize < m_nMaxSize + nGrowBy)( j8 E% z4 a' Z5 B
nNewMax = m_nMaxSize + nGrowBy; // granularity
; ?$ ?$ N, h! \2 F! E5 g else
: N, T% D5 C7 ] n [, ^+ r nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around
2 T6 U# M1 ~, Z6 @0 w2 [3 ~#ifdef SIZE_T_MAX! ]! f, a3 \# H7 x
ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow
* I8 I8 Q9 [* R2 t, q% n#endif
, C: {0 F! G% `# l& s TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old
0 |9 F* C1 X: b5 C memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements
2 l" a) ]/ P; X* E, Z+ r6 t/ n/ _* C ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");4 j" s1 y' N3 Q4 T- ]
delete[] (BYTE*)Ym_pData;! c. G0 t6 V0 u. V( Z
Ym_pData = pNewData;
% m T2 Z8 g/ l9 n+ r3 H ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called)
! R* H* [6 h# D m_nSize = nNewSize;
& O* L7 k2 g6 S1 ~& G m_nMaxSize = nNewMax;
F9 V1 P/ `: Y }
0 C' R H% w$ M; P% I SetIndexSize(nNewSize);
' T4 F. M! W% c1 |' E}) b. |* L% ^! | h& g8 W
|