1 Star 0 Fork 0

younisd/ygopro-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
effectset.h 2.18 KB
一键复制 编辑 原始数据 按行查看 历史
salix5 提交于 2021-09-16 22:54 . partial revert in effect_set_v
/*
* effectset.h
*
* Created on: 2011-10-8
* Author: Argon
*/
#ifndef EFFECTSET_H_
#define EFFECTSET_H_
#include <stdlib.h>
#include <array>
#include <vector>
#include <algorithm>
class effect;
bool effect_sort_id(const effect* e1, const effect* e2);
struct effect_set {
effect_set()
: count(0), container{ nullptr } {}
void add_item(effect* peffect) {
if(count >= 64) return;
container[count++] = peffect;
}
void remove_item(int index) {
if(index >= count)
return;
if(index == count - 1) {
count--;
return;
}
for(int i = index; i < count - 1; ++i)
container[i] = container[i + 1];
count--;
}
void clear() {
count = 0;
}
int size() const {
return count;
}
void sort() {
if(count < 2)
return;
std::sort(container.begin(), container.begin() + count, effect_sort_id);
}
effect* const& get_last() const {
return container[count - 1];
}
effect*& get_last() {
return container[count - 1];
}
effect* const& operator[] (int index) const {
return container[index];
}
effect*& operator[] (int index) {
return container[index];
}
effect* const& at(int index) const {
return container[index];
}
effect*& at(int index) {
return container[index];
}
private:
std::array<effect*, 64> container;
int count;
};
struct effect_set_v {
effect_set_v() {}
void add_item(effect* peffect) {
container.push_back(peffect);
}
void remove_item(int index) {
if(index >= (int)container.size())
return;
container.erase(container.begin() + index);
}
void clear() {
container.clear();
}
int size() const {
return (int)container.size();
}
void sort() {
int count = (int)container.size();
if(count < 2)
return;
std::sort(container.begin(), container.begin() + count, effect_sort_id);
}
effect* const& get_last() const {
return container.back();
}
effect*& get_last() {
return container.back();
}
effect* const& operator[] (int index) const {
return container[index];
}
effect*& operator[] (int index) {
return container[index];
}
effect* const& at(int index) const {
return container[index];
}
effect*& at(int index) {
return container[index];
}
private:
std::vector<effect*> container;
};
#endif //EFFECTSET_H_
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/younisd/ygopro-core.git
git@gitee.com:younisd/ygopro-core.git
younisd
ygopro-core
ygopro-core
master

搜索帮助