www.pudn.com > GOS.rar > KArray.h


// KArray.h: interface for the KArray class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#if !defined(AFX_KARRAY_H__F19FEDC1_6BDB_46F8_889C_1C0688F0AD0E__INCLUDED_) 
#define AFX_KARRAY_H__F19FEDC1_6BDB_46F8_889C_1C0688F0AD0E__INCLUDED_ 
 
#if _MSC_VER > 1000 
#pragma once 
#endif // _MSC_VER > 1000 
///////////////////////////////////////////////////////////////////////////// 
// KArray 
 
template 
class KArray 
{ 
public: 
// Construction 
	KArray(); 
 
// Attributes 
	int GetSize() const; 
	void SetSize(int nNewSize, int nGrowBy); 
 
// Operations 
	// Clean up 
	void FreeExtra(); 
	void RemoveAll(); 
 
	// Accessing elements 
	TYPE GetAt(int nIndex) const; 
	void SetAt(int nIndex, TYPE newElement); 
	TYPE& ElementAt(int nIndex); 
 
	// Direct Access to the element data (may return NULL) 
	const TYPE* GetData() const; 
	TYPE* GetData(); 
 
	// Potentially growing the array 
	void SetAtGrow(int nIndex, TYPE newElement); 
	int Add(TYPE newElement); 
	int Append(const KArray& src); 
	void Copy(const KArray& src); 
 
	// overloaded operator helpers 
	TYPE operator[](int nIndex) const; 
	TYPE& operator[](int nIndex); 
 
	// Operations that move elements around 
	void InsertAt(int nIndex, TYPE newElement, int nCount); 
	void RemoveAt(int nIndex, int nCount); 
	void InsertAt(int nStartIndex, KArray* pNewArray); 
	void InsertAt(int nIndex, TYPE newElement); 
	void RemoveAt(int nIndex); 
 
// Implementation 
protected: 
	TYPE* m_pData;   // the actual array of data 
	int m_nSize;     // # of elements (upperBound - 1) 
	int m_nMaxSize;  // max allocated 
	int m_nGrowBy;   // grow amount 
 
public: 
	~KArray(); 
}; 
 
#endif // !defined(AFX_KARRAY_H__F19FEDC1_6BDB_46F8_889C_1C0688F0AD0E__INCLUDED_)