summaryrefslogtreecommitdiff
path: root/common/array.h
blob: 2cb4764303693dc729c7555033b07706d9100b40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef _ARRAY_H_
#define _ARRAY_H_

template <class T>
class PtrArray
{
public:
	PtrArray(int nSize = 0);
	~PtrArray();

	typedef int (*LC_PTRARRAY_COMPARE_FUNC)(const T* a, const T* b, void* data);

	int GetSize() const
		{ return m_nLength; }

	T* RemoveIndex(int nIndex);
	T* RemovePointer(T* pObj);
	void RemoveAll();
	void Add(T* pObj);
	void AddSorted(T* pObj, LC_PTRARRAY_COMPARE_FUNC pFunc, void* pData);
	void InsertAt(int nIndex, T* pObj);
	int FindIndex(T* Obj) const;
	void Sort(LC_PTRARRAY_COMPARE_FUNC SortFunc, void* SortData);

	PtrArray<T>& operator=(const PtrArray<T>& Array);
	PtrArray<T>& operator+=(const PtrArray<T>& Array);
	T* operator [](int nIndex) const
		{ return m_pData[nIndex]; }

protected:
	void Expand(int nGrow);

	T** m_pData;
	int m_nLength;
	int m_nAlloc;
};

template <class T>
class ObjArray
{
public:
	ObjArray(int Size = 0, int Grow = 16);
	~ObjArray();

	typedef int (*LC_OBJARRAY_COMPARE_FUNC)(const T& A, const T& B, void* SortData);

	int GetSize() const
		{ return m_Length; }

	void RemoveIndex(int Index);
	void RemoveAll();
	void Add(const T& Obj);
	void AddSorted(const T& Obj, LC_OBJARRAY_COMPARE_FUNC Func, void* SortData);
	void InsertAt(int Index, const T& Obj);

	T& operator [](int Index) const
		{ return m_Data[Index]; }

protected:
	void Expand(int Grow);

	T* m_Data;
	int m_Length;
	int m_Alloc;
	int m_Grow;
};

#include "array.cpp"

#endif // _ARRAY_H_