9 #include <unordered_map>
16 namespace onnxruntime {
18 template <
typename TEnum>
24 template <
typename TEnum>
26 const auto it = std::find_if(
27 mapping.begin(), mapping.end(),
28 [&
value](
const std::pair<TEnum, std::string>& entry) {
29 return entry.first ==
value;
38 template <
typename TEnum>
48 template <
typename TEnum>
51 const auto it = std::find_if(
52 mapping.begin(), mapping.end(),
53 [&name](
const std::pair<TEnum, std::string>& entry) {
54 return entry.second == name;
58 "Failed to map enum name to value: ", name);
63 template <
typename TEnum>
83 template <
typename ValueParserType>
87 value_parsers_.emplace(name, ValueParser{value_parser}).second,
88 "Provider option \"",
name,
"\" already has a value parser.");
104 template <
typename ValueType>
107 return AddValueParser(
128 template <
typename EnumType>
131 return AddValueParser(
142 for (
const auto& option : options) {
143 const auto&
name = option.first;
144 const auto& value_str = option.second;
145 const auto value_parser_it = value_parsers_.find(
name);
147 value_parser_it == value_parsers_.end(),
148 "Unknown provider option: \"",
name,
"\".");
150 const auto parse_status = value_parser_it->second(value_str);
153 "Failed to parse provider option \"",
name,
"\": ", parse_status.ErrorMessage());
160 using ValueParser = std::function<Status(const std::string&)>;
161 std::unordered_map<std::string, ValueParser> value_parsers_;
ProviderOptionsParser & AddValueParser(const std::string &name, ValueParserType value_parser)
GLsizei const GLchar *const * string
GLsizei const GLfloat * value
#define ORT_ENFORCE(condition,...)
Status Parse(const ProviderOptions &options) const
std::vector< std::pair< TEnum, std::string >> EnumNameMapping
ProviderOptionsParser & AddAssignmentToEnumReference(const std::string &name, const EnumNameMapping< EnumType > &mapping, EnumType &dest)
ProviderOptionsParser & AddAssignmentToReference(const std::string &name, ValueType &dest)
GLuint const GLchar * name
Status EnumToName(const EnumNameMapping< TEnum > &mapping, TEnum value, std::string &name)
#define ORT_RETURN_IF_NOT(condition,...)
std::unordered_map< std::string, std::string > ProviderOptions
Status NameToEnum(const EnumNameMapping< TEnum > &mapping, const std::string &name, TEnum &value)
Status ParseStringWithClassicLocale(std::string_view s, T &value)
#define ORT_RETURN_IF(condition,...)
#define ORT_THROW_IF_ERROR(expr)