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

Regenerate classes for EXT_feature_metadata #369

Merged
merged 3 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void checkScalarProperty(
size_t expectedTotalInstances) {
const ClassProperty& property = metaClass.properties.at(propertyName);
REQUIRE(property.type == expectedPropertyType);
REQUIRE(property.componentType.isNull());
REQUIRE(property.componentType == std::nullopt);
REQUIRE(property.componentCount == std::nullopt);

MetadataFeatureTableView view(&model, &featureTable);
Expand Down Expand Up @@ -62,7 +62,7 @@ static void checkArrayProperty(
size_t expectedTotalInstances) {
const ClassProperty& property = metaClass.properties.at(propertyName);
REQUIRE(property.type == "ARRAY");
REQUIRE(property.componentType.getString() == expectedComponentType);
REQUIRE(property.componentType == expectedComponentType);
if (expectedComponentCount > 0) {
REQUIRE(
property.componentCount.value() ==
Expand Down
79 changes: 77 additions & 2 deletions CesiumGltf/include/CesiumGltf/ClassProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,75 @@ struct CESIUMGLTF_API ClassProperty final
: public CesiumUtility::ExtensibleObject {
static inline constexpr const char* TypeName = "ClassProperty";

/**
* @brief Known values for The property type. If `ENUM` is used, then
* `enumType` must also be specified. If `ARRAY` is used, then `componentType`
* must also be specified. `ARRAY` is a fixed-length array when
* `componentCount` is defined, and variable-length otherwise.
*/
struct Type {
inline static const std::string INT8 = "INT8";

inline static const std::string UINT8 = "UINT8";

inline static const std::string INT16 = "INT16";

inline static const std::string UINT16 = "UINT16";

inline static const std::string INT32 = "INT32";

inline static const std::string UINT32 = "UINT32";

inline static const std::string INT64 = "INT64";

inline static const std::string UINT64 = "UINT64";

inline static const std::string FLOAT32 = "FLOAT32";

inline static const std::string FLOAT64 = "FLOAT64";

inline static const std::string BOOLEAN = "BOOLEAN";

inline static const std::string STRING = "STRING";

inline static const std::string ENUM = "ENUM";

inline static const std::string ARRAY = "ARRAY";
};

/**
* @brief Known values for When `type` is `ARRAY` this indicates the type of
* each component of the array. If `ENUM` is used, then `enumType` must also
* be specified.
*/
struct ComponentType {
inline static const std::string INT8 = "INT8";

inline static const std::string UINT8 = "UINT8";

inline static const std::string INT16 = "INT16";

inline static const std::string UINT16 = "UINT16";

inline static const std::string INT32 = "INT32";

inline static const std::string UINT32 = "UINT32";

inline static const std::string INT64 = "INT64";

inline static const std::string UINT64 = "UINT64";

inline static const std::string FLOAT32 = "FLOAT32";

inline static const std::string FLOAT64 = "FLOAT64";

inline static const std::string BOOLEAN = "BOOLEAN";

inline static const std::string STRING = "STRING";

inline static const std::string ENUM = "ENUM";
};

/**
* @brief The name of the property, e.g. for display purposes.
*/
Expand All @@ -34,8 +103,11 @@ struct CESIUMGLTF_API ClassProperty final
* specified. If `ARRAY` is used, then `componentType` must also be specified.
* `ARRAY` is a fixed-length array when `componentCount` is defined, and
* variable-length otherwise.
*
* Known values are defined in {@link Type}.
*
*/
std::string type;
std::string type = Type::INT8;

/**
* @brief An enum ID as declared in the `enums` dictionary. This value must be
Expand All @@ -46,8 +118,11 @@ struct CESIUMGLTF_API ClassProperty final
/**
* @brief When `type` is `ARRAY` this indicates the type of each component of
* the array. If `ENUM` is used, then `enumType` must also be specified.
*
* Known values are defined in {@link ComponentType}.
*
*/
CesiumUtility::JsonValue componentType;
std::optional<std::string> componentType;

/**
* @brief The number of components per element for `ARRAY` elements.
Expand Down
26 changes: 25 additions & 1 deletion CesiumGltf/include/CesiumGltf/Enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ namespace CesiumGltf {
struct CESIUMGLTF_API Enum final : public CesiumUtility::ExtensibleObject {
static inline constexpr const char* TypeName = "Enum";

/**
* @brief Known values for The type of the integer enum value.
*/
struct ValueType {
inline static const std::string INT8 = "INT8";

inline static const std::string UINT8 = "UINT8";

inline static const std::string INT16 = "INT16";

inline static const std::string UINT16 = "UINT16";

inline static const std::string INT32 = "INT32";

inline static const std::string UINT32 = "UINT32";

inline static const std::string INT64 = "INT64";

inline static const std::string UINT64 = "UINT64";
};

/**
* @brief The name of the enum, e.g. for display purposes.
*/
Expand All @@ -30,8 +51,11 @@ struct CESIUMGLTF_API Enum final : public CesiumUtility::ExtensibleObject {

/**
* @brief The type of the integer enum value.
*
* Known values are defined in {@link ValueType}.
*
*/
std::string valueType = "UINT16";
std::string valueType = ValueType::UINT16;

/**
* @brief An array of enum values. Duplicate names or duplicate integer values
Expand Down
20 changes: 18 additions & 2 deletions CesiumGltf/include/CesiumGltf/FeatureTableProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <CesiumUtility/ExtensibleObject.h>

#include <cstdint>
#include <string>

namespace CesiumGltf {
/**
Expand All @@ -17,6 +16,20 @@ struct CESIUMGLTF_API FeatureTableProperty final
: public CesiumUtility::ExtensibleObject {
static inline constexpr const char* TypeName = "FeatureTableProperty";

/**
* @brief Known values for The type of values in `arrayOffsetBufferView` and
* `stringOffsetBufferView`.
*/
struct OffsetType {
inline static const std::string UINT8 = "UINT8";

inline static const std::string UINT16 = "UINT16";

inline static const std::string UINT32 = "UINT32";

inline static const std::string UINT64 = "UINT64";
};

/**
* @brief The index of the buffer view containing property values. The data
* type of property values is determined by the property definition: When
Expand All @@ -40,8 +53,11 @@ struct CESIUMGLTF_API FeatureTableProperty final
/**
* @brief The type of values in `arrayOffsetBufferView` and
* `stringOffsetBufferView`.
*
* Known values are defined in {@link OffsetType}.
*
*/
std::string offsetType = "UINT32";
std::string offsetType = OffsetType::UINT32;

/**
* @brief The index of the buffer view containing offsets for variable-length
Expand Down
14 changes: 7 additions & 7 deletions CesiumGltf/include/CesiumGltf/MetadataFeatureTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class MetadataFeatureTableView {

PropertyType type = convertStringToPropertyType(pClassProperty->type);
PropertyType componentType = PropertyType::None;
if (pClassProperty->componentType.isString()) {
componentType = convertStringToPropertyType(
pClassProperty->componentType.getString());
if (pClassProperty->componentType.has_value()) {
componentType =
convertStringToPropertyType(pClassProperty->componentType.value());
}

if (type != PropertyType::Array) {
Expand All @@ -108,7 +108,7 @@ class MetadataFeatureTableView {
getArrayPropertyViewImpl(
propertyName,
*pClassProperty,
type,
componentType,
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'm pretty sure this used to be a bug.

std::forward<Callback>(callback));
}
}
Expand Down Expand Up @@ -395,18 +395,18 @@ class MetadataFeatureTableView {
MetadataPropertyView<MetadataArrayView<T>> getPrimitiveArrayPropertyValues(
const ClassProperty& classProperty,
const FeatureTableProperty& featureTableProperty) const {
if (classProperty.type != "ARRAY") {
if (classProperty.type != ClassProperty::Type::ARRAY) {
return createInvalidPropertyView<MetadataArrayView<T>>(
MetadataPropertyViewStatus::InvalidTypeMismatch);
}

if (!classProperty.componentType.isString()) {
if (!classProperty.componentType.has_value()) {
return createInvalidPropertyView<MetadataArrayView<T>>(
MetadataPropertyViewStatus::InvalidTypeMismatch);
}

const PropertyType componentType =
convertStringToPropertyType(classProperty.componentType.getString());
convertStringToPropertyType(classProperty.componentType.value());
if (TypeToPropertyType<T>::value != componentType) {
return createInvalidPropertyView<MetadataArrayView<T>>(
MetadataPropertyViewStatus::InvalidTypeMismatch);
Expand Down
2 changes: 1 addition & 1 deletion CesiumGltf/include/CesiumGltf/ModelEXT_feature_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct CESIUMGLTF_API ModelEXT_feature_metadata final
std::optional<Schema> schema;

/**
* @brief A uri to an external schema file.
* @brief The URI (or IRI) of the external schema file.
*/
std::optional<std::string> schemaUri;

Expand Down
7 changes: 3 additions & 4 deletions CesiumGltf/src/MetadataFeatureTableView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ MetadataPropertyView<std::string_view>
MetadataFeatureTableView::getStringPropertyValues(
const ClassProperty& classProperty,
const FeatureTableProperty& featureTableProperty) const {
if (classProperty.type != "STRING") {
if (classProperty.type != ClassProperty::Type::STRING) {
return createInvalidPropertyView<std::string_view>(
MetadataPropertyViewStatus::InvalidTypeMismatch);
}
Expand Down Expand Up @@ -235,13 +235,12 @@ MetadataPropertyView<MetadataArrayView<std::string_view>>
MetadataFeatureTableView::getStringArrayPropertyValues(
const ClassProperty& classProperty,
const FeatureTableProperty& featureTableProperty) const {
if (classProperty.type != "ARRAY") {
if (classProperty.type != ClassProperty::Type::ARRAY) {
return createInvalidPropertyView<MetadataArrayView<std::string_view>>(
MetadataPropertyViewStatus::InvalidTypeMismatch);
}

if (!classProperty.componentType.isString() ||
classProperty.componentType.getString() != "STRING") {
if (classProperty.componentType != ClassProperty::ComponentType::STRING) {
return createInvalidPropertyView<MetadataArrayView<std::string_view>>(
MetadataPropertyViewStatus::InvalidTypeMismatch);
}
Expand Down
Loading