| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #ifndef SOPHIAR2_NAME_TRANSLATOR_HPP
- #define SOPHIAR2_NAME_TRANSLATOR_HPP
- #include "utility/string_map.hpp"
- #include <string>
- #include <unordered_map>
- namespace sophiar {
- template<typename IndexType>
- 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<IndexType> name_map;
- std::unordered_map<IndexType, std::string> index_map;
- };
- }
- #endif //SOPHIAR2_NAME_TRANSLATOR_HPP
|