MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ string_to_enum_or_throw_case_insensitive()

template<typename EnumType >
EnumType MayaFlux::Reflect::string_to_enum_or_throw_case_insensitive ( std::string_view  str,
std::string_view  context = "" 
)

Convert string to enum with exception on failure (case-insensitive)

Template Parameters
EnumTypeAny enum type
Parameters
strString to convert
contextOptional context for error message
Returns
Enum value
Exceptions
std::invalid_argumentif string is not valid enum

Definition at line 159 of file EnumReflect.hpp.

161{
162 auto result = string_to_enum_case_insensitive<EnumType>(str);
163 if (!result.has_value()) {
164 std::string error_msg = "Invalid enum value: '" + std::string(str) + "'";
165 if (!context.empty()) {
166 error_msg += " for " + std::string(context);
167 }
168
169 error_msg += ". Valid values are: ";
170 auto names = get_enum_names_lowercase<EnumType>();
171 for (size_t i = 0; i < names.size(); ++i) {
172 if (i > 0)
173 error_msg += ", ";
174 error_msg += names[i];
175 }
176
177 throw std::invalid_argument(error_msg);
178 }
179 return *result;
180}