#pragma once #include #include #include #include #include #include #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 { map> a; std::unordered_map>> b; map, std::set>> c; public: GameDatabase() = default; void Insert(ObjectId id, string name, size_t x, size_t y) { GameObject* d = new GameObject(); d->id = id; d->name = name; d->x = x; d->y = y; Remove(id); a[id] = *d; c[make_pair(x, y)].insert(d); b[name].insert(d); } void Remove(ObjectId id) { GameObject a1 = a[id]; a.erase(id); c[{a1.x, a1.y}].erase(&a1); b[a1.name].erase(&a1); } vector DataByPosition(size_t x, size_t y) const { vector a1; if (c.find({ x, y }) != c.end()) { std::set> c2 = c.at({ x, y }); for (auto a2 : c2) { a1.push_back(*a2); } } return a1; } vector DataByName(string name) const { vector a1; if (b.find(name) != b.end()) { std::set> b2 = b.at(name); for (auto a2 : b2) { (a1).push_back(*a2); } } return a1; } vector Data() const { vector a1; for (auto el : a) { a1.push_back(el.second); } return a1; } };