Files
spark/src/lib/utils/parse_enum.h
T

27 lines
629 B
C++

#pragma once
#include "lib/utils/optional.h"
#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