Skip to content
Snippets Groups Projects

ENH: New functions getEnumNameFromValue() and getEnumValueFromName()

Merged Daniel Hornung requested to merge f-enum-utilities into f-consolidation
All threads resolved!
1 file
+ 4
3
Compare changes
  • Side-by-side
  • Inline
+ 4
3
@@ -63,7 +63,7 @@ auto getEnumValueFromName<Importance>(const std::string &name) -> Importance {
// caosdb::entity::importance_names.cend(),
// [name](const auto& entry){ return entry.second == name; });
// Workaround: plaint old iteration:
for (auto entry: caosdb::entity::importance_names) {
for (auto const &entry: caosdb::entity::importance_names) {
if (entry.second == name) {
return entry.first;
}
@@ -73,16 +73,17 @@ auto getEnumValueFromName<Importance>(const std::string &name) -> Importance {
template <>
auto getEnumValueFromName<AtomicDataType>(const std::string &name) -> AtomicDataType {
for (auto entry: caosdb::entity::atomicdatatype_names) {
for (auto const &entry: caosdb::entity::atomicdatatype_names) {
if (entry.second == name) {
return entry.first;
}
}
throw std::out_of_range(std::string("Could not find enum value for string '") + name + "'.");
}
template <>
auto getEnumValueFromName<Role>(const std::string &name) -> Role {
for (auto entry: caosdb::entity::role_names) {
for (auto const &entry: caosdb::entity::role_names) {
if (entry.second == name) {
return entry.first;
}
Loading