Cgrowablearray declaration in DXUTmisc.h
1 //--------------------------------------------------------------------------------------2 //A growable Array.3 //--------------------------------------------------------------------------------------4Template<typename type>classCgrowablearray5 {6 Public:7 Cgrowablearray ()8 {9M_pdata = NULL; M_nsize =0; M_nmaxsize =0;Ten } OneCgrowablearray (ConstCgrowablearray <TYPE>&a) A { - for(inti =0; i < a.m_nsize; i++) Add (A.m_pdata[i]); - } the~Cgrowablearray () - { - RemoveAll (); - } + - Consttype&operator[](intNIndex)Const + { A returnGetAt (nIndex); at } -type&operator[](intNIndex) - { - returnGetAt (nIndex); - } - incgrowablearray&operator=(ConstCgrowablearray <TYPE>&a) - { to if( This= = &a)return* This; RemoveAll (); for(inti =0; I <a.m_nsize; +i++) Add (A.m_pdata[i]);return* This; - } the *HRESULT SetSize (intnnewmaxsize); $HRESULT Add (Consttype&value);Panax NotoginsengHRESULT Insert (intNIndex,Consttype&value); -HRESULT SetAt (intNIndex,Consttype&value); thetype& GetAt (intNIndex)Const + { AASSERT (NIndex >=0&& NIndex < m_nsize);returnM_pdata[nindex]; the } + intGetSize ()Const - { $ returnm_nsize; $ } -type*GetData () - { the returnm_pdata; - }Wuyi BOOLContains (Consttype&value) the { - return( -1!=IndexOf (value)); Wu } - About intIndexOf (Consttype&value) $ { - return(M_nsize >0) ? IndexOf (Value,0, m_nsize):-1; - } - intIndexOf (Consttype& value,intIStart) A { + returnIndexOf (value, IStart, M_nsize-IStart); the } - intIndexOf (Consttype& value,intNIndex,intnnumelements); $ the intLastIndexOf (Consttype&value) the { the return(M_nsize >0) ? LastIndexOf (value, M_nsize-1, m_nsize):-1; the } - intLastIndexOf (Consttype& value,intNIndex) in { the returnLastIndexOf (value, NIndex, NIndex +1 ); the } About intLastIndexOf (Consttype& value,intNIndex,intnnumelements); the theHRESULT Remove (intnIndex); the voidRemoveAll () + { -SetSize (0 ); the }Bayi voidReset () the { theM_nsize =0; - } - the protected: theType* m_pdata;//The actual array of data the intM_nsize;//# of elements (upperBound-1) the intM_nmaxsize;//Max Allocated - theHRESULT setsizeinternal (intNnewmaxsize);//This version of doesn ' t call ctor or Dtor. the};
View Code
Cgrowablearray Parsing _ Dxut Container