Skip to content
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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

azrogers
Copy link
Contributor

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!

Copy link
Member

@kring kring left a 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!

@kring kring added this to the March 2025 Release milestone Feb 21, 2025
Copy link
Contributor

@j9liu j9liu left a 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

Copy link
Contributor

@j9liu j9liu left a 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.

Comment on lines +203 to +221
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;
}
}
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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:

Suggested change
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;
}

Copy link
Contributor

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.

Comment on lines +611 to +624
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);
}
}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
}

Comment on lines +721 to +734
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);
}
}
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
}

@azrogers
Copy link
Contributor Author

@j9liu Addressed your review comments. Was able to consolidate most of the constructors - I did have to add a pEnumDefinition parameter to some of the protected constructors that would never be enums, just so the templating worked out, but since the parameter is ignored I don't think it's a big deal.

@azrogers azrogers marked this pull request as ready for review February 25, 2025 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants