-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENUM metadata support, treating them as scalars rather than using a container type #1112
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few comments below, but overall this looks reasonable to me. I'm going to look at the Unreal implementation next, though, so that could change my opinion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@azrogers I haven't done a full review, but I at least wanted to check the areas that Kevin commented on. I'll do another pass early next week
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@azrogers Thank you for responding quickly to feedback and putting effort into these changes!
My one remaining reservation is about the way that we handle the constructors with pEnumDefinition
. There is a silent assumption that if we call the constructor that includes the enum definition parameter -- even if nullptr
-- that the property must have been an enum. I feel like this isn't right; we could be handling the inputs more generally, starting with PropertyView
then working its way up into PropertyTablePropertyView
, etc.
Let me know what you think -- overall I think it's going to reduce duplication.
if (enumDefinitionIt == this->_pEnumDefinitions->end()) { | ||
callback( | ||
propertyId, | ||
PropertyTablePropertyView<uint8_t>( | ||
PropertyTablePropertyViewStatus::ErrorInvalidEnum)); | ||
return; | ||
} else { | ||
componentType = convertStringToPropertyComponentType( | ||
enumDefinitionIt->second.valueType); | ||
|
||
if (componentType == PropertyComponentType::Float32 || | ||
componentType == PropertyComponentType::Float64) { | ||
callback( | ||
propertyId, | ||
PropertyTablePropertyView<uint8_t>( | ||
PropertyTablePropertyViewStatus::ErrorInvalidEnum)); | ||
return; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be nitpicky, but can be flatten the if else
here so there's less indentation? It helps with readability at the end of the day
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how it can be flattened?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I just meant the outer if/else statement. Like this:
if (enumDefinitionIt == this->_pEnumDefinitions->end()) { | |
callback( | |
propertyId, | |
PropertyTablePropertyView<uint8_t>( | |
PropertyTablePropertyViewStatus::ErrorInvalidEnum)); | |
return; | |
} else { | |
componentType = convertStringToPropertyComponentType( | |
enumDefinitionIt->second.valueType); | |
if (componentType == PropertyComponentType::Float32 || | |
componentType == PropertyComponentType::Float64) { | |
callback( | |
propertyId, | |
PropertyTablePropertyView<uint8_t>( | |
PropertyTablePropertyViewStatus::ErrorInvalidEnum)); | |
return; | |
} | |
} | |
if (enumDefinitionIt == this->_pEnumDefinitions->end()) { | |
callback( | |
propertyId, | |
PropertyTablePropertyView<uint8_t>( | |
PropertyTablePropertyViewStatus::ErrorInvalidEnum)); | |
return; | |
} | |
componentType = convertStringToPropertyComponentType( | |
enumDefinitionIt->second.valueType); | |
if (componentType == PropertyComponentType::Float32 || | |
componentType == PropertyComponentType::Float64) { | |
callback( | |
propertyId, | |
PropertyTablePropertyView<uint8_t>( | |
PropertyTablePropertyViewStatus::ErrorInvalidEnum)); | |
return; | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with all the others.
if (enumDefinitionIt == this->_pEnumDefinitions->end()) { | ||
return PropertyTexturePropertyView<T, Normalized>( | ||
PropertyTexturePropertyViewStatus::ErrorInvalidEnum); | ||
} else { | ||
componentType = convertStringToPropertyComponentType( | ||
enumDefinitionIt->second.valueType); | ||
pEnumDefinition = &enumDefinitionIt->second; | ||
|
||
if (componentType == PropertyComponentType::Float32 || | ||
componentType == PropertyComponentType::Float64) { | ||
return PropertyTexturePropertyView<T, Normalized>( | ||
PropertyTexturePropertyViewStatus::ErrorInvalidEnum); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we flatten this if
/else
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, I don't see how this can be flattened. We can't do the lookup unless it's an enum value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (enumDefinitionIt == this->_pEnumDefinitions->end()) { | |
return PropertyTexturePropertyView<T, Normalized>( | |
PropertyTexturePropertyViewStatus::ErrorInvalidEnum); | |
} else { | |
componentType = convertStringToPropertyComponentType( | |
enumDefinitionIt->second.valueType); | |
pEnumDefinition = &enumDefinitionIt->second; | |
if (componentType == PropertyComponentType::Float32 || | |
componentType == PropertyComponentType::Float64) { | |
return PropertyTexturePropertyView<T, Normalized>( | |
PropertyTexturePropertyViewStatus::ErrorInvalidEnum); | |
} | |
} | |
if (enumDefinitionIt == this->_pEnumDefinitions->end()) { | |
return PropertyTexturePropertyView<T, Normalized>( | |
PropertyTexturePropertyViewStatus::ErrorInvalidEnum); | |
} | |
componentType = convertStringToPropertyComponentType( | |
enumDefinitionIt->second.valueType); | |
pEnumDefinition = &enumDefinitionIt->second; | |
if (componentType == PropertyComponentType::Float32 || | |
componentType == PropertyComponentType::Float64) { | |
return PropertyTexturePropertyView<T, Normalized>( | |
PropertyTexturePropertyViewStatus::ErrorInvalidEnum); | |
} | |
if (enumDefinitionIt == this->_pEnumDefinitions->end()) { | ||
return PropertyTexturePropertyView<PropertyArrayView<T>, Normalized>( | ||
PropertyTexturePropertyViewStatus::ErrorInvalidEnum); | ||
} else { | ||
componentType = convertStringToPropertyComponentType( | ||
enumDefinitionIt->second.valueType); | ||
pEnumDefinition = &enumDefinitionIt->second; | ||
|
||
if (componentType == PropertyComponentType::Float32 || | ||
componentType == PropertyComponentType::Float64) { | ||
return PropertyTexturePropertyView<PropertyArrayView<T>, Normalized>( | ||
PropertyTexturePropertyViewStatus::ErrorInvalidEnum); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we flatten this if
/else
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, how would you flatten it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (enumDefinitionIt == this->_pEnumDefinitions->end()) { | |
return PropertyTexturePropertyView<PropertyArrayView<T>, Normalized>( | |
PropertyTexturePropertyViewStatus::ErrorInvalidEnum); | |
} else { | |
componentType = convertStringToPropertyComponentType( | |
enumDefinitionIt->second.valueType); | |
pEnumDefinition = &enumDefinitionIt->second; | |
if (componentType == PropertyComponentType::Float32 || | |
componentType == PropertyComponentType::Float64) { | |
return PropertyTexturePropertyView<PropertyArrayView<T>, Normalized>( | |
PropertyTexturePropertyViewStatus::ErrorInvalidEnum); | |
} | |
} | |
if (enumDefinitionIt == this->_pEnumDefinitions->end()) { | |
return PropertyTexturePropertyView<PropertyArrayView<T>, Normalized>( | |
PropertyTexturePropertyViewStatus::ErrorInvalidEnum); | |
} | |
componentType = convertStringToPropertyComponentType( | |
enumDefinitionIt->second.valueType); | |
pEnumDefinition = &enumDefinitionIt->second; | |
if (componentType == PropertyComponentType::Float32 || | |
componentType == PropertyComponentType::Float64) { | |
return PropertyTexturePropertyView<PropertyArrayView<T>, Normalized>( | |
PropertyTexturePropertyViewStatus::ErrorInvalidEnum); | |
} | |
@j9liu Addressed your review comments. Was able to consolidate most of the constructors - I did have to add a |
This is an alternative version of #1085, implementing enums by leveraging our existing scalar metadata support rather than implementing them as an entirely new container type. This requires some changes to the assumptions we're currently making in the metadata system, chief among them the breaking of the connection between C++ type and
PropertyType
. However, it does simplify the implementation and reduce the amount of copy-and-paste necessary to support enums. Please review and discuss which approach you prefer!