//接上面 + S" }& P/ M4 \4 ^
template<class TYPE, class ARG_TYPE> w8 R! {+ M$ I6 b7 S, B' i8 e
YCArray<TYPE, ARG_TYPE>::~YCArray()& |) e) M: F1 I5 F! A
{8 E, n+ h8 J7 s" p; Y
ASSERT_VALID(this); if (Ym_pData != NULL); X2 u" P# o( V: i- x
{) `7 G. H% w* k% N2 I
DestructAllElement(0,m_nSize);
S+ y n9 ]; X4 u //DestructElements<TYPE>(Ym_pData, m_nSize);
+ b7 i! e- e3 e$ _5 | delete[] (BYTE*)Ym_pData;1 C' M- L' K' [
}" l, H8 n& ?9 i& D5 s
}
* _% o0 L' S% ?" qtemplate<class TYPE, class ARG_TYPE>
# L2 C% `" J* T0 G5 P6 M- K% kCString YCArray<TYPE, ARG_TYPE>::GetSign()
0 d# _( }1 [) T9 j) S, b% {/ P{+ g% w8 W! W1 s6 I% C# h" V2 C4 `
lock_sign=0;3 ]8 Y) i- i/ O4 h+ d
return Sign;
/ G; m9 e, s; z, U o; x}9 c# x% ]9 A: `2 W* P. i% b
template<class TYPE, class ARG_TYPE>3 Y. }" I4 S+ z* l7 V' |6 [
int YCArray<TYPE, ARG_TYPE>::SetSign(CString& sign)" v- o* N, j3 r
{/ n$ ?: R9 A7 ~
int i=0;
; p* k+ ]7 `* | while(lock_sign&&i<MAXSIGNTIME){" m' K5 D0 i/ S% }: @: H+ Q- n& c
Sleep(1);
5 }6 E5 ?/ U4 b! e i++;
, v: i1 N: T& T/ ^2 U# j3 H! ] }! _6 W4 |7 H5 A, w& t) ]
lock_sign=1;( {7 w# f' N5 d9 Z
Sign=sign;
* t8 l- C9 Q2 @/ A return TRUE;
" |0 o1 p* |( C* w}. f3 E1 _, k f) D I2 q
//用与把 nindex 后的索引往后推 nCount ,自动调整好buffer
% P/ c- G' W) r3 e* w F4 \$ qtemplate<class TYPE, class ARG_TYPE>
) n# Q1 y( c# |) H( p, a2 M" j7 yBOOL YCArray<TYPE, ARG_TYPE>::SetIndexSize(int nNewSize)
& U6 ]" U1 x; z$ R4 U' w{
1 j3 R" s7 `* b. v/ Y if(strIndexNum < nNewSize){3 W0 W* y: n" _) G: O
CString* tp = new CString[nNewSize];//新的buffer0 n F! r3 |2 Z2 Y& A
for(int i=0;i<strIndexNum;i++){//把老索引复制过来
& K& n& U% b) A( {! K: x tp = strIndex;
$ m- c( Y) {3 Z2 _ }& o: Z2 H* l( A+ f1 j
for(i=strIndexNum;i<nNewSize;i++){
5 p6 ?( c; l* r# ]3 R+ ]; Y1 L( I tp = "" ;( M. a: r( o/ B+ m( F* c, T
}
$ J- E; b% U: k" E, d delete[] strIndex ;* ^$ ^, Q4 m/ J% \+ O/ j! o
strIndex = tp ; t4 E" y. V3 s( q
strIndexNum = nNewSize ; p; n) m0 ?0 M9 L% I
}else if(strIndexNum < nNewSize){ C- i- W% @5 }
for(int i=nNewSize;i<strIndexNum;i++){
& X9 o0 P" J5 z5 O0 j strIndex = "" ;+ K: n5 ]- R" Q! q( X: N e
}% T1 x0 E+ l1 z& ]7 ~
}8 j1 h; h* q6 x
return TRUE;
9 G. Z+ {7 O k7 q e}
$ P$ Q6 M# @) _9 N5 ^template<class TYPE, class ARG_TYPE>
7 @" E( P8 W9 C7 ^7 b! BBOOL YCArray<TYPE, ARG_TYPE>::INSERTIndex(int nIndex,int nCount /*=1*/)
9 U; J0 @2 t) r. c5 h$ Q3 t{% I7 m9 v' H# C( S- j5 H
CString* tp = new CString[m_nSize+nCount];//新的buffer
. w( v0 x4 O, u+ d for(int i=0;i<nIndex;i++){//把老索引复制过来 s/ c1 k% _3 C% \& c
tp = strIndex;2 E4 I P& s" `' }: j$ |) E% E
}int j =0 ;
* e/ w; M8 V2 m/ k$ y/ A. ^! N for(i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来
/ _, y3 s, Z4 d" b# ]! P tp = strIndex[nIndex+j];
- g! X& d' {1 v& Y1 |. J, v j++;
7 O. V* e9 a; J6 t# \2 u2 \1 f }
# h- y5 C+ x1 ~+ r0 x( S/ W delete[] strIndex ;( o3 C% O% ?' }% o
strIndex = tp ;
0 ~4 N9 c1 v6 s# y return TRUE;1 w0 | d2 ~) N
}
" Z) O- {: f& K# I/ c* Jtemplate<class TYPE, class ARG_TYPE>
+ k7 V2 t5 T# J/ j$ Y5 _2 eBOOL YCArray<TYPE, ARG_TYPE>::SETIndex(CString cIndex,int nIndex)5 o' k( n8 V; J" d0 L
{//在 nIndex 后面添加一个 字符串索引
+ W R m4 X+ F strIndex[nIndex] = cIndex ;
4 ~" ^: F1 l, }; T+ ^# l return TRUE;
+ K* [ E6 E1 U, b}; k4 u; J9 k5 K/ D7 _9 U* ^
template<class TYPE, class ARG_TYPE>
! V. n1 E2 E& b8 uBOOL YCArray<TYPE, ARG_TYPE>:ELIndex(int nIndex,int nCount /*=1*/)5 l; C, }) {9 t% T; [2 {" h2 p
{//需要在 m_nSize 变化之前调用!!% Q7 Z6 u; w9 M0 o
ASSERT(nIndex >= 0);
) G6 S- |9 k8 s4 `+ V' u ASSERT(nCount >= 0);; a& J" N8 }9 }* _5 V Z/ V6 H
ASSERT(nIndex + nCount <= m_nSize);5 {0 c" z3 Q) J5 f4 ]0 i
int j =0 ;& @, ~* H* y+ }! f0 ]
for(int i=nIndex+nCount;i<m_nSize;i++){//把老索引复制过来: e' H5 a5 N( i
strIndex[nIndex+j] = strIndex;0 ]: `: w, \) O( S+ n
j++;7 w* R% c$ Q# O( z
}
" G! F1 T9 W$ X2 _ return TRUE;
0 J6 h# B+ p5 p1 \8 ]9 G H}
3 N& a: d( x- s7 `: E C/ Qtemplate<class TYPE, class ARG_TYPE>
5 F0 j$ h$ P8 ^8 oBOOL YCArray<TYPE, ARG_TYPE>:ELIndex(CString cIndex,int nCount /*=1*/)
' P% U& g! h7 F' j{
5 S4 H' s- \4 ^7 S0 ]% ~: \7 m int nIndex=this->GetIndex(cIndex);* L u1 P( t2 W8 i& P
return this->DELIndex(nIndex,nCount);
2 z% D$ O: D8 m9 P4 n' f3 j}! W2 a% Q0 }2 H. f9 o! ?/ O
template<class TYPE, class ARG_TYPE>
, P8 |' V6 }( l8 hint YCArray<TYPE, ARG_TYPE>::GetIndex(CString cIndex)& ]+ Z0 ^" `5 v( S
{//得到 cIndex 的数字索引! V# w' y. ?( P* A
int nPos = -1;
$ z+ M1 f- p: r& c8 L7 r5 U( @) s for(int i=0;i<m_nSize;i++){
- }# e3 U9 B+ O# } if(strIndex == cIndex){
* ?6 M2 {/ Z! M nPos = i ;break;8 o! R* [8 Q3 I" J* x
}- T! n6 v6 k/ _! e J8 o
}+ F& L2 e/ ?/ P3 g
return nPos;
! `$ B' Q/ t6 U* ]. w& w}# x/ `* i8 O/ N) |2 N r/ p- ]
template<class TYPE, class ARG_TYPE>
% B- O4 j% G$ ?# ICString YCArray<TYPE, ARG_TYPE>::GetIndex(int nIndex). N8 v j5 S( h/ C1 Z
{//返回 nIndex 的字符串索引. z& J! T" r. F2 p' t
return strIndex[nIndex];
( ?& }5 Q0 O V}
7 ] k; I' q8 M* c7 k! L/////////////////////////////////////////////////////////////////////////////
0 k9 j4 k/ E* A9 G$ ]. r// YCArray<TYPE, ARG_TYPE> inline functions template<class TYPE, class ARG_TYPE># h; i, S& e" I3 c( P4 y
AFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetSize() const
3 m* a+ ]2 T( P* T9 O W! b { return m_nSize; }
) I6 g& l" U" @ n; y: [* l& qtemplate<class TYPE, class ARG_TYPE>
, v2 H) E3 j. ^" j% NAFX_INLINE int YCArray<TYPE, ARG_TYPE>::GetUpperBound() const, A& M9 d# q7 C
{ return m_nSize-1; }* H4 n6 X0 A0 W, B& w* ]
template<class TYPE, class ARG_TYPE>
3 R$ t2 L$ e" m* ZAFX_INLINE void YCArray<TYPE, ARG_TYPE>::RemoveAll()$ G- w0 n4 |) v8 A
{ SetSize(0, -1); }
7 j# ]# q% ~. `" `1 Atemplate<class TYPE, class ARG_TYPE>4 @! @6 Z5 o& C( @) f( b. B- m; m
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>::GetAt(int nIndex) const3 q8 N J6 X0 a. }$ f
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);
. {* T: _9 u) J1 j r8 s+ L return *Ym_pData[nIndex]; }
w) @6 ~# D- m utemplate<class TYPE, class ARG_TYPE>5 v+ ~, q, _" ~. ~: ?$ M3 V, l
AFX_INLINE void YCArray<TYPE, ARG_TYPE>::SetAt(int nIndex, ARG_TYPE newElement)
* g+ E6 c/ Y- {; }6 c4 z { ASSERT(nIndex >= 0 && nIndex < m_nSize);# y! G+ P m( ]
*(Ym_pData[nIndex]) = newElement; } template<class TYPE, class ARG_TYPE>
; u! {7 G( T w7 `. n+ Z& @' JAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(int nIndex)1 Q5 r# ^/ v7 O6 D! U5 F
{ ASSERT(nIndex >= 0 && nIndex < m_nSize);! v$ X7 @# z9 v/ s# r
return *Ym_pData[nIndex]; } template<class TYPE, class ARG_TYPE>' f9 }: [% x7 q( F! f* d' ^5 A
TYPE YCArray<TYPE, ARG_TYPE>::GetAt(CString cIndex) const
- a2 H4 [7 X, ^2 y& H{
" E+ M" [3 D: ]3 a& H& ` int nIndex=GetIndex(cIndex);
! T. d2 w/ X- S3 l. { return GetAt(nIndex);
9 t9 v3 r9 f3 t7 w' R) X+ b9 F}
# v) Q0 N1 g9 u7 J# A" j5 X* a6 E1 Gtemplate<class TYPE, class ARG_TYPE> N X }2 a5 F* a6 L- m4 k
void YCArray<TYPE, ARG_TYPE>::SetAt(CString cIndex, ARG_TYPE newElement)$ k% a7 G3 }3 R" k$ {3 K
{- i2 ? T; q5 b6 o K6 g
int nIndex=GetIndex(cIndex);
& ?! O. P# C- k9 a+ F return SetAt(nIndex, newElement);) X- i; W# O! {
}
9 f2 Z$ g) {- {# \3 x! E$ Ftemplate<class TYPE, class ARG_TYPE>9 s* h2 X- `9 G3 ?. w/ ]! h
TYPE& YCArray<TYPE, ARG_TYPE>::ElementAt(CString cIndex)
7 e c; u* t7 V* I l- P{9 `' d9 b, t6 J4 R7 E
int nIndex=GetIndex(cIndex);
- q) a) M! q$ E9 y# y return ElementAt(nIndex);
' x. R2 O- L! F) K}
- u$ m ~& @4 c+ ltemplate<class TYPE, class ARG_TYPE>) ? Q+ O3 u1 X) r. [4 h; h
AFX_INLINE const TYPE** YCArray<TYPE, ARG_TYPE>::GetData() const
# r! D$ a" `# M9 A. g# g { return (const TYPE**)Ym_pData; }7 J Q9 P. j. _2 H
template<class TYPE, class ARG_TYPE>
, [$ d7 j6 o1 n1 N' SAFX_INLINE TYPE** YCArray<TYPE, ARG_TYPE>::GetData(), |3 F( }3 F. n- @9 V
{ return (TYPE**)Ym_pData; }5 \3 W& e" w* S1 m7 a) R
template<class TYPE, class ARG_TYPE>
5 @+ h! N$ c, c1 f1 o0 }AFX_INLINE int YCArray<TYPE, ARG_TYPE>::Add(ARG_TYPE newElement,CString cIndex /* ="" */)
4 d9 ], Y+ F- h7 x" [! G, P { int nIndex = m_nSize;0 }$ o) s% \) j- b9 r5 q
SetAtGrow(nIndex, newElement);( k$ l3 [$ T# s' W5 j. d! p
SETIndex(cIndex,nIndex);0 k& _" _- x" g: Y
return nIndex; }$ f/ \+ I" c4 E6 x6 @
template<class TYPE, class ARG_TYPE>0 `/ @! [- @) a& |+ y4 o! D
AFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](int nIndex) const
5 O# h4 L5 @4 q2 H5 d) d: U0 _ { return GetAt(nIndex); }. C8 G. ?; s, T
template<class TYPE, class ARG_TYPE>
; i' e+ `: P8 l' u* MAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](int nIndex)
3 W: v3 L( E G! u! p4 i { return ElementAt(nIndex); }
W5 l( |+ ~6 F, y5 ~( ftemplate<class TYPE, class ARG_TYPE>
; \. `$ d6 k0 O' XAFX_INLINE TYPE YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex) const3 l% L) X; S$ j0 B$ q6 M
{
; E4 z! z4 _% g- Y; Z int nIndex=GetIndex(cIndex); return operator[](nIndex);
4 ]$ N! k3 a# b6 O}
) x3 N& l1 I# x4 I* `+ w4 V' wtemplate<class TYPE, class ARG_TYPE>
$ }3 b) I% J! a/ k& S9 \( m* k# {; lAFX_INLINE TYPE& YCArray<TYPE, ARG_TYPE>:perator[](CString cIndex)
S5 A, }% V7 [6 U! {{, @- |5 j) `/ f# u. M, ^. Y
int nIndex=GetIndex(cIndex);
+ B' H. ]7 H7 D8 R return operator[](nIndex);2 i7 f8 I2 {( I V8 x1 Z
}' p& ^/ A& R; S3 ^7 U k
/*
2 w& s1 N2 |/ ~( d' ^template<class TYPE, class ARG_TYPE>8 g" |0 K% \9 d: f
AFX_INLINE YCArray<TYPE,ARG_TYPE> YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& tparr) const
" C5 h' _8 p6 c/ b% |0 C{' _0 |2 X" A, l
int i,j;
) t! s' O: L1 o& P% K for(i=0;i<tparr.GetSize();i++){7 }$ ]4 ~% [/ L
j = GetIndex(tparr.GetIndex(i));
9 l- n3 q7 G4 v2 R if(j>-1){
# W/ I' z6 A' ] operator[](tparr.GetIndex(i)) = tparr;0 c/ K6 P- U* n7 t) Q
}else{5 a+ Z" l8 ]! N
Add(tparr,tparr.GetIndex(i));
`) G" I2 B$ ?% b# P- J }
* J" N0 o0 |9 ^7 p7 t" q7 L$ f }
* k% U Q) o' S( | return this;
% e b7 ]5 F8 d) j2 n* U$ U}
# {, i1 O) d0 e! d% z*/
) o" @! `& p, `; K P3 Vtemplate<class TYPE, class ARG_TYPE>" W( c1 v' T+ t* P$ }4 J! E* I
AFX_INLINE YCArray<TYPE,ARG_TYPE>& YCArray<TYPE, ARG_TYPE>:perator=(YCArray<TYPE,ARG_TYPE>& src)* ~3 }! H7 D8 Y
{- V! C' O" L, }2 U/ `$ r
ASSERT_VALID(this);
& t/ B. {* H% v4 c Q+ D6 h( W ASSERT(this != &src); // cannot append to itself SetSize(src.m_nSize);- T+ V; v- w0 F5 U$ w4 b7 ]0 N* A# Y/ j5 K/ h
for(int i=0;i<m_nSize;i++){
c+ f6 y6 I; ~/ j0 v: E- y. Y /*将此句修改为内存拷贝*///
; d" ~' ]' d6 M1 O% ]9 ? *Ym_pData = *src.Ym_pData ;
. l* ~% Q% e4 V! L9 c; l4 K //memcpy(Ym_pData,src.Ym_pData,sizeof(TYPE));( ~7 T1 z/ t1 G6 |4 {! _ t
SETIndex(src.GetIndex(i),i);
6 a" s6 d! T+ ^8 J }
9 ^& \1 l1 x" v: ]: g' ~9 { return *this;
1 ?+ s5 B% V9 c& L7 [# b: \}
! T& r3 D/ r# f/////////////////////////////////////////////////////////////////////////////: e/ b( w; ~$ b
// YCArray<TYPE, ARG_TYPE> out-of-line functions template<class TYPE, class ARG_TYPE>
" C" l6 t. I( KYCArray<TYPE, ARG_TYPE>::YCArray()& q* `, `- a3 }( ^9 P: s5 P# {9 k
{
' a. H/ u2 ^1 e% z0 s7 z Ym_pData = NULL;
. D- ?: C1 {- P strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;# I0 m& ~7 x1 P0 w# M& x1 b3 h) Y
strIndex=NULL;MAXSIGNTIME=10;8 H1 ~3 i" o& r$ L& o
}
5 j) m* K% Z6 x7 \0 a4 [& @template<class TYPE, class ARG_TYPE>
& ~; W r9 p7 O8 rYCArray<TYPE, ARG_TYPE>::YCArray(YCArray<TYPE, ARG_TYPE>& tp)
- h p+ ~+ _1 h{2 ^/ s0 E$ G) G4 U
Ym_pData = NULL;
4 Y+ P& u( \0 W strIndexNum = m_nSize = m_nMaxSize = m_nGrowBy = 0;5 U8 n0 i" b% F: i# _% y
strIndex=NULL;MAXSIGNTIME=10;
; `8 `! O, x, B. r( F5 S operator=(tp);
9 s- u" @5 F! n3 ^+ q} template<class TYPE, class ARG_TYPE>
4 J# _) C6 n, S$ \: X5 m# {void YCArray<TYPE, ARG_TYPE>::SetSize(int nNewSize, int nGrowBy)
' I4 S7 Q. K7 Y1 B{5 b* Q5 A# {7 Q' T; y
ASSERT_VALID(this);* m {( R! W/ @* f1 x
ASSERT(nNewSize >= 0); if (nGrowBy != -1)
5 r4 r0 `2 ~% i: d' m/ U m_nGrowBy = nGrowBy; // set new size if (nNewSize == 0){
) N$ U8 o0 f4 Y( `1 B // shrink to nothing/ X$ p2 T* `3 f) Z( \
if (Ym_pData != NULL){
" l+ v+ n* @$ J* z) }* y DestructAllElement(0,m_nSize);; T3 h. E2 _/ ?- W
//DestructElements<TYPE>(Ym_pData, m_nSize);: @6 L2 p9 \* H* a9 s% y
delete[] (BYTE*)Ym_pData;7 l, z' F6 @) C) _' _; b0 S+ M
Ym_pData = NULL;
. F" Q4 R$ G. ] } V9 }! o7 W7 @; H% v% F/ z7 a
m_nSize = m_nMaxSize = 0;
8 ]9 {8 J% P2 |0 Z# [* a+ G } else if (Ym_pData == NULL){
4 T+ Z! W" \2 B5 D // create one with exact size+ ]8 \/ C3 c" {/ t
#ifdef SIZE_T_MAX
/ U7 X+ R9 }0 V ASSERT(nNewSize <= SIZE_T_MAX/sizeof(TYPE*)); // no overflow
& Z6 }0 E% q5 c# Y#endif/ v6 o# ]$ G9 r$ {: ?+ E* c- {
Ym_pData = (TYPE**) new BYTE[nNewSize * sizeof(TYPE*)];
$ M- Q+ s; f0 c2 d6 {4 P ConstructAllElements(0,nNewSize);//ConstructElements<TYPE>(Ym_pData, nNewSize);
) j# P: J8 j: K% B/ j4 w$ o3 a1 e m_nSize = m_nMaxSize = nNewSize; {7 n, a3 H+ ~7 l6 Q+ S1 V
} else if (nNewSize <= m_nMaxSize){
- K: Z: |3 }" v. B // it fits
4 U( i8 m3 \# B8 ^ if (nNewSize > m_nSize)4 g4 z; ?7 S r% e2 B: F1 k
{
( b4 Y8 C5 w+ Q/ T: H // initialize the new elements
( R% `. A9 l( y. F' G# K1 r2 \1 C ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&Ym_pData[m_nSize], nNewSize-m_nSize);3 S/ p/ l( X$ e6 I1 R) w* D
}# c% _* b( `# E- q0 g0 _
else if (m_nSize > nNewSize)
: k# |# Q$ p$ D4 B {/ f4 B2 \% ~# _# t
// destroy the old elements4 l, R% E: y9 f& e, S% d3 y
DestructAllElement(nNewSize,m_nSize-nNewSize);' D8 u7 |7 t9 S! w
//DestructElements<TYPE>(&Ym_pData[nNewSize], m_nSize-nNewSize);& G6 B& a9 f" c& ?1 E
}5 L9 l1 ^. ]4 W2 o
m_nSize = nNewSize;* }. T, E! u/ O: {
}: v4 }; N5 f) s
else
0 Z1 c3 J( x- G8 C4 r! r {8 \" I7 X% P# T3 Y! w: |
// otherwise, grow array5 G, B" T! X, @! O) Y6 l) ]6 I* ?, ^
int nGrowBy = m_nGrowBy;5 T$ a7 M& M. x" J5 X
if (nGrowBy == 0)9 U$ t$ C+ _$ \$ o6 x# P$ ~
{$ o( W- P+ h* q( {# m8 {
// heuristically determine growth when nGrowBy == 09 L3 _* `$ W# _4 w/ T/ g
// (this avoids heap fragmentation in many situations)
5 }. l y. Y m+ a nGrowBy = m_nSize / 8;/ `% A7 S8 g! Y; n" F
nGrowBy = (nGrowBy < 4) ? 4 : ((nGrowBy > 1024) ? 1024 : nGrowBy);
( v% p* e) p" K: y4 k m1 F }" h& s W v: X' ~ @9 S' A
int nNewMax;
& I' { f5 `% N: o) g3 N if (nNewSize < m_nMaxSize + nGrowBy)
2 P, W4 T' `, F) |, k( i' n nNewMax = m_nMaxSize + nGrowBy; // granularity
% x4 k$ M7 U2 W2 U else
8 a& X; L( D: j- z nNewMax = nNewSize; // no slush ASSERT(nNewMax >= m_nMaxSize); // no wrap around6 k% R, t0 U$ [ y% ]) Q. N
#ifdef SIZE_T_MAX( ]3 G0 d$ h. d+ o8 H
ASSERT(nNewMax <= SIZE_T_MAX/sizeof(TYPE)); // no overflow& u I) y! L2 b# P
#endif
, R' }1 r" ]& d5 E2 K. n6 } TYPE** pNewData = (TYPE**) new BYTE[nNewMax * sizeof(TYPE*)];//TYPE* pNewData = (TYPE*) new BYTE[nNewMax * sizeof(TYPE)]; // copy new data from old
9 U- F: ^; k: V+ n& | Z8 \ memcpy(pNewData, Ym_pData, m_nSize * sizeof(TYPE*)); // construct remaining elements2 N- K7 ]9 R+ _2 M: @
ASSERT(nNewSize > m_nSize); //throw("/*wait for me --- yzhlinux*/");$ {" A& j9 p: ^5 M7 o
delete[] (BYTE*)Ym_pData;
/ a$ o% s6 b2 A$ p' G ?7 V Ym_pData = pNewData;
. x) Y! h. _; w4 h" Y7 ]" X ConstructAllElements(m_nSize,nNewSize-m_nSize);//ConstructElements<TYPE>(&pNewData[m_nSize], nNewSize-m_nSize); // get rid of old stuff (note: no destructors called)" i5 ?! e5 }1 |4 J2 q, T
m_nSize = nNewSize;
0 u0 n4 p5 y6 u- L2 F m_nMaxSize = nNewMax;% x2 P' k* |+ j6 r% `
}
( ]& H2 z4 t: @- C j( \ SetIndexSize(nNewSize);
0 {5 g* V3 g2 Z3 v: s/ b}3 P& O5 p7 D& ]( l4 q& w( F; W3 f
|