Files
spark/src/lib/utils/parse_enum.h
T
John Colvin 6dce2fcde1 refactor: Remove redundant optional.h
It was from a time when Windows std didn't provide the 'optional' header
2024-08-29 10:24:22 -04:00

28 lines
619 B
C++

#pragma once
#include <optional>
#include <string>
namespace bts {
inline std::string uppercase_copy(const std::string &cs) {
std::string s = cs;
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
return s;
}
template <class T, class T2>
std::optional<T>
parse_enum(const std::string &value, const std::string &prefix, T2 parse) {
auto temp = value;
T result;
if (temp.find(prefix) == std::string::npos) {
temp = prefix + "_" + temp;
}
if (parse(temp, &result)) {
return {result};
} else {
return std::nullopt;
}
}
} // namespace bts