21 #ifndef mia_core_dictmap_hh
22 #define mia_core_dictmap_hh
51 typedef std::map<T, std::pair<std::string, std::string>>
THelpMap;
71 TDictMap(
const Table *table,
bool last_is_default =
false);
110 typedef std::map<std::string, T> TMap;
111 typedef std::map<T, std::string> TBackMap;
113 bool m_last_is_default;
115 TBackMap m_back_table;
120 Insert( std::set<std::string>& result ): m_result(result)
123 void operator() (
const typename TMap::value_type& v)
125 m_result.insert(v.first);
128 std::set<std::string>& m_result;
133 template <
typename T>
135 m_last_is_default(last_is_default)
138 const Table *t = table;
141 if (!m_table.insert(
typename TMap::value_type(t->
name, t->
value)).second)
142 throw std::invalid_argument(std::string(
"TDictMap<T>::TDictMap:'") +
143 std::string(t->
name) +
144 std::string(
"' already present"));
146 m_back_table.insert(
typename TBackMap::value_type(t->
value, t->
name));
147 m_help.insert(
typename THelpMap::value_type(t->
value,
148 std::pair<std::string, std::string>(t->
name, t->
help ? t->
help :
"")));
152 m_default = t->
value;
155 template <
typename T>
158 typename TMap::const_iterator i = m_table.find(name);
160 if (i == m_table.end()) {
161 if (!m_last_is_default)
162 throw std::invalid_argument(std::string(
"TDictMap<T>::get_value: unknown key '") +
163 std::string(name) + std::string(
"' provided"));
171 template <
typename T>
174 auto i = m_back_table.find(value);
176 if (i == m_back_table.end()) {
177 if (!m_last_is_default || (m_default != value))
178 throw create_exception<std::invalid_argument>(
"TDictMap<T>::get_name: unknown value ", value,
" provided");
183 return i->second.c_str();
186 template <
typename T>
189 auto i = m_help.find(value);
191 if (i == m_help.end())
192 throw create_exception<std::invalid_argument>(
"TDictMap<T>::get_help: unknown value ", value,
" provided");
194 return i->second.second.c_str();
197 template <
typename T>
200 std::set<std::string> result;
201 std::for_each(m_table.begin(), m_table.end(), Insert(result));
205 template <
typename T>
208 return m_help.begin();
211 template <
typename T>