| 349 | } |
| 350 | |
| 351 | bool MslSyntax::remapEnumeration(const string& value, TypeDesc type, const string& enumNames, std::pair<TypeDesc, ValuePtr>& result) const |
| 352 | { |
| 353 | // Early out if not an enum input. |
| 354 | if (enumNames.empty()) |
| 355 | { |
| 356 | return false; |
| 357 | } |
| 358 | |
| 359 | // Don't convert already supported types |
| 360 | if (type != Type::STRING) |
| 361 | { |
| 362 | return false; |
| 363 | } |
| 364 | |
| 365 | // Early out if no valid value provided |
| 366 | if (value.empty()) |
| 367 | { |
| 368 | return false; |
| 369 | } |
| 370 | |
| 371 | // For MSL we always convert to integer, |
| 372 | // with the integer value being an index into the enumeration. |
| 373 | result.first = Type::INTEGER; |
| 374 | result.second = nullptr; |
| 375 | |
| 376 | StringVec valueElemEnumsVec = splitString(enumNames, ","); |
| 377 | for (size_t i = 0; i < valueElemEnumsVec.size(); i++) |
| 378 | { |
| 379 | valueElemEnumsVec[i] = trimSpaces(valueElemEnumsVec[i]); |
| 380 | } |
| 381 | auto pos = std::find(valueElemEnumsVec.begin(), valueElemEnumsVec.end(), value); |
| 382 | if (pos == valueElemEnumsVec.end()) |
| 383 | { |
| 384 | throw ExceptionShaderGenError("Given value '" + value + "' is not a valid enum value for input."); |
| 385 | } |
| 386 | const int index = static_cast<int>(std::distance(valueElemEnumsVec.begin(), pos)); |
| 387 | result.second = Value::createValue<int>(index); |
| 388 | |
| 389 | return true; |
| 390 | } |
| 391 | |
| 392 | MATERIALX_NAMESPACE_END |
nothing calls this directly
no test coverage detected