52 lines
944 B
C++
52 lines
944 B
C++
#ifndef _List_H_
|
|
#define _List_H_
|
|
|
|
// 变长列表。仅用于存储指针
|
|
class List
|
|
{
|
|
public:
|
|
explicit List(int count = 0);
|
|
//List(void* items, uint count);
|
|
~List();
|
|
|
|
int Count() const;
|
|
|
|
// 添加单个元素
|
|
void Add(void* item);
|
|
|
|
// 添加多个元素
|
|
void Add(void** items, uint count);
|
|
|
|
// 删除指定位置元素
|
|
void RemoveAt(uint index);
|
|
|
|
// 删除指定元素
|
|
void Remove(const void* item);
|
|
|
|
void Clear();
|
|
|
|
// 查找指定项。不存在时返回-1
|
|
int FindIndex(const void* item);
|
|
|
|
// 释放所有指针指向的内存
|
|
List& DeleteAll();
|
|
|
|
// 返回内部指针
|
|
//const void** ToArray() const;
|
|
|
|
// 重载索引运算符[],返回指定元素的第一个
|
|
void* operator[](int i) const;
|
|
void*& operator[](int i);
|
|
|
|
private:
|
|
void** _Arr;
|
|
uint _Count;
|
|
uint _Capacity;
|
|
|
|
void* Arr[0x10];
|
|
|
|
bool CheckCapacity(int count);
|
|
};
|
|
|
|
#endif
|