#include #include #include #include namespace Cubed { std::unordered_map MapTable::id_to_name_map; std::unordered_map MapTable::name_to_id_map; const std::string& MapTable::get_name_from_id(unsigned id) { auto it = id_to_name_map.find(id); ASSERT_MSG(it != id_to_name_map.end(), "Id: " + std::to_string(id) + " is not exist"); return it->second; } unsigned MapTable::get_id_from_name(const std::string& name) { auto it = name_to_id_map.find(HASH::str(name)); ASSERT_MSG(it != name_to_id_map.end(), "Name " + name + " is not exist"); return it->second; } void MapTable::init_map() { id_to_name_map.reserve(MAX_BLOCK_NUM); name_to_id_map.reserve(MAX_BLOCK_NUM); for (int i = 0; i < MAX_BLOCK_NUM; i++) { id_to_name_map[i] = BLOCK_REISTER[i]; name_to_id_map[HASH::str(BLOCK_REISTER[i])] = i; } } }