#pragma once #include #include bool operator>(const GameObject& a, const GameObject& b) { return a.id > b.id; } template class Compare> class DereferenceCompare { Compare comp; public: bool operator()(const Tp* const a, const Tp* const b) const { return comp(*a, *b); } }; class GameDatabase { public: map> ID; map, set>> pos; unordered_map>> title; GameDatabase() = default; void Insert(ObjectId id, string name, size_t x, size_t y) { GameObject chk{ id, name, x, y }; if (ID.find(id) != ID.end()) { Remove(id); } ID.insert({ id, chk }); auto add = &ID.at(id); pos[{x, y}].insert(add); title[name].insert(add); } void Remove(ObjectId id) { if (ID.find(id) != ID.end()) { GameObject* del = &ID.find(id)->second; pos.find({ del->x, del->y })->second.erase(del); title.find({ del->name })->second.erase(del); ID.erase(ID.find(id)); } } vector DataByName(string name) const { vector res; auto it = title.find(name); if (it == title.end()) { return res; } for (auto x : it->second) { res.push_back(*x); } return res; } vector DataByPosition(size_t x, size_t y) const { vector res; auto it = pos.find({ x, y }); if (it == pos.end()) { return res; } for (auto x : it->second) { res.push_back(*x); } return res; } vector Data() const { vector res; for (auto x : ID) { res.push_back(x.second); } return res; } };