MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/MaterialX / remapEnumeration

Method remapEnumeration

source/MaterialXGenMsl/MslSyntax.cpp:351–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349}
350
351bool 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
392MATERIALX_NAMESPACE_END

Callers

nothing calls this directly

Calls 7

splitStringFunction · 0.85
trimSpacesFunction · 0.85
findFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected