aboutsummaryrefslogtreecommitdiff
path: root/src/script/cpp_api/s_entity.h
diff options
context:
space:
mode:
authorWuzzy <almikes@aol.com>2016-02-27 14:48:10 +0100
committerest31 <MTest31@outlook.com>2016-03-25 10:54:14 +0100
commit25da0594eb09bb0e72816aaf8280573a668af00c (patch)
treeaeb0559d429ab44e776fca0b7dce7f8218141645 /src/script/cpp_api/s_entity.h
parent21c479688b4ee93c58f41d20f5c7555a41e4ad97 (generated by cgit v1.2.3 (git 2.39.1) at 2025-02-21 07:15:06 +0000 t; #include <iostream> #include <set> #include "irrlichttypes_bloated.h" #include "util/cpp11_container.h" class NameIdMapping { public: void serialize(std::ostream &os) const; void deSerialize(std::istream &is); void clear() { m_id_to_name.clear(); m_name_to_id.clear(); } void set(u16 id, const std::string &name) { m_id_to_name[id] = name; m_name_to_id[name] = id; } void removeId(u16 id) { std::string name; bool found = getName(id, name); if (!found) return; m_id_to_name.erase(id); m_name_to_id.erase(name); } void eraseName(const std::string &name) { u16 id; bool found = getId(name, id); if (!found) return; m_id_to_name.erase(id); m_name_to_id.erase(name); } bool getName(u16 id, std::string &result) const { UNORDERED_MAP<u16, std::string>::const_iterator i; i = m_id_to_name.find(id); if (i == m_id_to_name.end()) return false; result = i->second; return true; } bool getId(const std::string &name, u16 &result) const { UNORDERED_MAP<std::string, u16>::const_iterator i; i = m_name_to_id.find(name); if (i == m_name_to_id.end()) return false; result = i->second; return true; } u16 size() const { return m_id_to_name.size(); } private: UNORDERED_MAP<u16, std::string> m_id_to_name; UNORDERED_MAP<std::string, u16> m_name_to_id; }; #endif