1 Star 0 Fork 0

Janisa/GUI

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
List.h 5.03 KB
一键复制 编辑 原始数据 按行查看 历史
Janisa 提交于 2024-07-09 19:24 +08:00 . 添加编译工程脚本
#pragma once
#include <windows.h>
#include <vector>
#include <helper.h>
template <typename T, class _Alloc = std::allocator<T>>
class List : public std::vector<T, _Alloc>
{
public:
List() {}
List(T *val, int len)
{
for (int i = 0; i < len; i++)
{
this->push_back(val[i]);
}
}
List(std::initializer_list<T> val)
{
for (int i = 0; i < val.size(); i++)
{
this->push_back(val.begin()[i]);
}
}
List(std::vector<T> val)
{
for (int i = 0; i < val.size(); i++)
{
this->push_back(val[i]);
}
}
~List() {}
T &operator[](int index)
{
return this->data()[index];
}
PROPERTY(int, Count);
GET(int, Count)
{
return this->size();
}
SET(int, Count)
{
this->resize(value);
}
void Add(T val)
{
this->push_back(val);
}
void Clear()
{
this->clear();
}
void AddRange(T *val, int len)
{
int ldx = this->Count;
this->resize(this->size() + len);
memcpy(&this->operator[](ldx), &val[0], sizeof(T) * len);
}
void AddRange(std::initializer_list<T> val)
{
int ldx = this->Count;
this->resize(this->size() + val.size());
memcpy(&this->data()[ldx], &val.begin()[0], sizeof(T) * val.size());
}
void AddRange(List<T> &val)
{
int ldx = this->Count;
this->resize(this->size() + val.size());
memcpy(&this->data()[ldx], &val[0], sizeof(T) * val.size());
}
void AddRange(List<T> *val)
{
int ldx = this->Count;
this->resize(this->size() + val->size());
memcpy(&this->data()[ldx], &val->data()[0], sizeof(T) * val->size());
}
void AddRange(std::vector<T> &val)
{
int ldx = this->Count;
this->resize(this->size() + val.size());
memcpy(&this->data()[ldx], &val[0], sizeof(T) * val.size());
}
void AddRange(std::vector<T> *val)
{
int ldx = this->Count;
this->resize(this->size() + val->size());
memcpy(&this->data()[ldx], &val->data()[0], sizeof(T) * val->size());
}
void Insert(int index, T val)
{
if (index >= this->size())
{
this->push_back(val);
}
else if (index >= 0)
{
this->insert(this->begin() + index, val);
}
}
void Insert(int index, std::initializer_list<T> &val)
{
if (index >= this->size())
{
this->AddRange(val);
}
else if (index >= 0)
{
this->insert(this->begin() + index, val.begin(), val.end() - 1);
}
}
void Insert(int index, std::vector<T> &val)
{
if (index >= this->size())
{
this->AddRange(val);
}
else if (index >= 0)
{
this->insert(this->begin() + index, val.begin(), val.end() - 1);
}
}
void Insert(int index, std::vector<T> *val)
{
if (index >= this->size())
{
this->AddRange(val);
}
else if (index >= 0)
{
this->insert(this->begin() + index, val->begin(), val->end() - 1);
}
}
void Insert(int index, List<T> &val)
{
if (index >= this->size())
{
this->AddRange(val);
}
else if (index >= 0)
{
this->insert(this->begin() + index, val.begin(), val.end() - 1);
}
}
void Insert(int index, List<T> *val)
{
if (index >= this->size())
{
this->AddRange(val);
}
else if (index >= 0)
{
this->insert(this->begin() + index, val->begin(), val->end() - 1);
}
}
void RemoveAt(int index)
{
if (index >= 0 && index < this->size())
{
this->erase(this->begin() + index);
}
}
int IndexOf(T &value)
{
for (int i = 0; i < this->Count; i++)
{
if (this->at(i) == value)
{
return i;
}
}
return -1;
}
bool Contains(T &value)
{
return IndexOf(value) >= 0;
}
int LastIndexOf(T &value)
{
for (int i = this->Count - 1; i >= 0; i--)
{
if (this->at(i) == value)
{
return i;
}
}
return -1;
}
int Remove(T item)
{
int num = 0;
for (int i = this->Count; i >= 0; i--)
{
if (this->data()[i] == item)
{
RemoveAt(i);
num += 1;
}
}
return num;
}
std::vector<T> &GetVector()
{
return *(std::vector<T> *)this;
}
T *Pointer()
{
return this->data();
}
T &get(int i)
{
return this->data()[i];
}
void set(int i, T val)
{
this->data()[i] = val;
}
T &First()
{
return this->data()[0];
}
T &Last()
{
return this->data()[this->size() - 1];
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/Janisa/gui.git
git@gitee.com:Janisa/gui.git
Janisa
gui
GUI
master

搜索帮助