21 #ifndef mia_core_dictmap_hh 22 #define mia_core_dictmap_hh 50 typedef std::map<T, std::pair<std::string, std::string> >
THelpMap;
109 typedef std::map<std::string, T> TMap;
110 typedef std::map<T, std::string> TBackMap;
112 bool m_last_is_default;
114 TBackMap m_back_table;
119 Insert( std::set<std::string>& result ):m_result(result) {
121 void operator() (
const typename TMap::value_type& v) {
122 m_result.insert(v.first);
125 std::set<std::string>& m_result;
130 template <
typename T>
132 m_last_is_default(last_is_default)
135 const Table *t = table;
137 if (!m_table.insert(
typename TMap::value_type(t->name, t->value)).second)
138 throw std::invalid_argument(std::string(
"TDictMap<T>::TDictMap:'") +
139 std::string(t->name) +
140 std::string(
"' already present"));
141 m_back_table.insert(
typename TBackMap::value_type(t->value, t->name));
142 m_help.insert(
typename THelpMap::value_type(t->value,
143 std::pair<std::string, std::string>(t->name, t->help ? t->help :
"")));
146 m_default = t->value;
149 template <
typename T>
152 typename TMap::const_iterator i = m_table.find(name);
153 if (i == m_table.end()) {
154 if (!m_last_is_default)
155 throw std::invalid_argument(std::string(
"TDictMap<T>::get_value: unknown key '")+
156 std::string(name) + std::string(
"' provided"));
163 template <
typename T>
166 auto i = m_back_table.find(value);
168 if (i == m_back_table.end()) {
169 if (!m_last_is_default || (m_default != value))
170 throw create_exception<std::invalid_argument>(
"TDictMap<T>::get_name: unknown value ", value,
" provided");
174 return i->second.c_str();
177 template <
typename T>
180 auto i = m_help.find(value);
181 if (i == m_help.end())
182 throw create_exception<std::invalid_argument>(
"TDictMap<T>::get_help: unknown value ", value,
" provided");
183 return i->second.second.c_str();
186 template <
typename T>
189 std::set<std::string> result;
190 std::for_each(m_table.begin(),m_table.end(), Insert(result));
194 template <
typename T>
197 return m_help.begin();
200 template <
typename T>
const char *const name
parameter name
std::map< T, std::pair< std::string, std::string > > THelpMap
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
const char * get_name(T value) const
const char *const help
help text
THelpMap::const_iterator get_help_begin() const
THelpMap::const_iterator get_help_end() const
TDictMap(const Table *table, bool last_is_default=false)
const std::set< std::string > get_name_set() const
const T value
parameter value
T get_value(const char *name) const
const char * get_help(T value) const
A mapper from emums to string values. - usefull for names flags.
#define NS_MIA_END
conveniance define to end the mia namespace