#ifndef SOPHIAR2_NAME_TRANSLATOR_HPP #define SOPHIAR2_NAME_TRANSLATOR_HPP #include "utility/string_map.hpp" #include #include namespace sophiar { template class name_translator { public: void register_item(std::string_view name, IndexType index) { assert(!name_map.contains(name)); assert(!index_map.contains(index)); name_map.insert(name, index); index_map.emplace(index, name); } IndexType translate(std::string_view name) const { assert(name_map.contains(name)); return name_map.query(name); } std::string_view translate(IndexType index) const { assert(index_map.contains(index)); return index_map.at(index); } private: string_map name_map; std::unordered_map index_map; }; } #endif //SOPHIAR2_NAME_TRANSLATOR_HPP