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;
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;
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"));
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();
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();
200 std::set<std::string> result;
201 std::for_each(m_table.begin(), m_table.end(), Insert(result));
208 return m_help.begin();
A mapper from emums to string values. - usefull for names flags.
const char * get_help(T value) const
THelpMap::const_iterator get_help_end() const
std::map< T, std::pair< std::string, std::string > > THelpMap
const char * get_name(T value) const
TDictMap(const Table *table, bool last_is_default=false)
THelpMap::const_iterator get_help_begin() const
T get_value(const char *name) const
const std::set< std::string > get_name_set() const
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
#define NS_MIA_END
conveniance define to end the mia namespace
const T value
parameter value
const char *const name
parameter name
const char *const help
help text