Skip to content

Commit 2c3090a

Browse files
committed
Additional array/value cleanup
1 parent 1a7bb6f commit 2c3090a

File tree

3 files changed

+43
-112
lines changed

3 files changed

+43
-112
lines changed

Source/CesiumRuntime/Private/CesiumMetadataValue.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ UCesiumMetadataValueBlueprintLibrary::GetTrueComponentType(
7272
return CesiumMetadataValueTypeToTrueType(type);
7373
}
7474

75+
PRAGMA_ENABLE_DEPRECATION_WARNINGS
76+
7577
bool UCesiumMetadataValueBlueprintLibrary::GetBoolean(
7678
UPARAM(ref) const FCesiumMetadataValue& Value,
7779
bool DefaultValue) {
@@ -84,8 +86,6 @@ bool UCesiumMetadataValueBlueprintLibrary::GetBoolean(
8486
Value._value);
8587
}
8688

87-
PRAGMA_ENABLE_DEPRECATION_WARNINGS
88-
8989
uint8 UCesiumMetadataValueBlueprintLibrary::GetByte(
9090
UPARAM(ref) const FCesiumMetadataValue& Value,
9191
uint8 DefaultValue) {
@@ -276,13 +276,7 @@ FString UCesiumMetadataValueBlueprintLibrary::GetString(
276276
} else {
277277
if constexpr (CesiumGltf::IsMetadataInteger<ValueType>::value) {
278278
if (Value._pEnumDefinition.IsValid()) {
279-
TOptional<FString> MaybeName =
280-
Value._pEnumDefinition->GetName(value);
281-
if (MaybeName.IsSet()) {
282-
return MaybeName.GetValue();
283-
} else {
284-
return DefaultValue;
285-
}
279+
return Value._pEnumDefinition->GetName(value).Get(DefaultValue);
286280
}
287281
}
288282

@@ -298,7 +292,6 @@ FString UCesiumMetadataValueBlueprintLibrary::GetString(
298292

299293
FCesiumPropertyArray UCesiumMetadataValueBlueprintLibrary::GetArray(
300294
UPARAM(ref) const FCesiumMetadataValue& Value) {
301-
// TOptional.Get() == value_or
302295
return Value._arrayValue.Get(FCesiumPropertyArray());
303296
}
304297

Source/CesiumRuntime/Private/CesiumPropertyArrayBlueprintLibrary.cpp

Lines changed: 36 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ UCesiumPropertyArrayBlueprintLibrary::GetElementBlueprintType(
1010
return CesiumMetadataValueTypeToBlueprintType(array._elementType);
1111
}
1212

13-
ECesiumMetadataBlueprintType
14-
UCesiumPropertyArrayBlueprintLibrary::GetBlueprintComponentType(
15-
UPARAM(ref) const FCesiumPropertyArray& array) {
16-
return CesiumMetadataValueTypeToBlueprintType(array._elementType);
17-
}
18-
1913
FCesiumMetadataValueType
2014
UCesiumPropertyArrayBlueprintLibrary::GetElementValueType(
2115
UPARAM(ref) const FCesiumPropertyArray& array) {
@@ -27,11 +21,6 @@ int64 UCesiumPropertyArrayBlueprintLibrary::GetArraySize(
2721
return swl::visit([](const auto& view) { return view.size(); }, array._value);
2822
}
2923

30-
int64 UCesiumPropertyArrayBlueprintLibrary::GetSize(
31-
UPARAM(ref) const FCesiumPropertyArray& array) {
32-
return swl::visit([](const auto& view) { return view.size(); }, array._value);
33-
}
34-
3524
FCesiumMetadataValue UCesiumPropertyArrayBlueprintLibrary::GetValue(
3625
UPARAM(ref) const FCesiumPropertyArray& array,
3726
int64 index) {
@@ -54,140 +43,86 @@ FCesiumMetadataValue UCesiumPropertyArrayBlueprintLibrary::GetValue(
5443
array._value);
5544
}
5645

46+
PRAGMA_DISABLE_DEPRECATION_WARNINGS
47+
48+
ECesiumMetadataBlueprintType
49+
UCesiumPropertyArrayBlueprintLibrary::GetBlueprintComponentType(
50+
UPARAM(ref) const FCesiumPropertyArray& array) {
51+
return CesiumMetadataValueTypeToBlueprintType(array._elementType);
52+
}
53+
5754
ECesiumMetadataTrueType_DEPRECATED
5855
UCesiumPropertyArrayBlueprintLibrary::GetTrueComponentType(
5956
UPARAM(ref) const FCesiumPropertyArray& array) {
6057
return CesiumMetadataValueTypeToTrueType(array._elementType);
6158
}
6259

60+
int64 UCesiumPropertyArrayBlueprintLibrary::GetSize(
61+
UPARAM(ref) const FCesiumPropertyArray& array) {
62+
return swl::visit([](const auto& view) { return view.size(); }, array._value);
63+
}
64+
6365
bool UCesiumPropertyArrayBlueprintLibrary::GetBoolean(
6466
UPARAM(ref) const FCesiumPropertyArray& array,
6567
int64 index,
6668
bool defaultValue) {
67-
return swl::visit(
68-
[index, defaultValue](const auto& v) -> bool {
69-
if (index < 0 || index >= v.size()) {
70-
return defaultValue;
71-
}
72-
auto value = v[index];
73-
return CesiumGltf::MetadataConversions<bool, decltype(value)>::convert(
74-
value)
75-
.value_or(defaultValue);
76-
},
77-
array._value);
69+
return UCesiumMetadataValueBlueprintLibrary::GetBoolean(
70+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index),
71+
defaultValue);
7872
}
7973

8074
uint8 UCesiumPropertyArrayBlueprintLibrary::GetByte(
8175
UPARAM(ref) const FCesiumPropertyArray& array,
8276
int64 index,
8377
uint8 defaultValue) {
84-
return swl::visit(
85-
[index, defaultValue](const auto& v) -> uint8 {
86-
if (index < 0 || index >= v.size()) {
87-
return defaultValue;
88-
}
89-
auto value = v[index];
90-
return CesiumGltf::MetadataConversions<uint8, decltype(value)>::convert(
91-
value)
92-
.value_or(defaultValue);
93-
},
94-
array._value);
78+
return UCesiumMetadataValueBlueprintLibrary::GetByte(
79+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index),
80+
defaultValue);
9581
}
9682

9783
int32 UCesiumPropertyArrayBlueprintLibrary::GetInteger(
9884
UPARAM(ref) const FCesiumPropertyArray& array,
9985
int64 index,
10086
int32 defaultValue) {
101-
return swl::visit(
102-
[index, defaultValue](const auto& v) -> int32 {
103-
if (index < 0 || index >= v.size()) {
104-
return defaultValue;
105-
}
106-
auto value = v[index];
107-
return CesiumGltf::MetadataConversions<int32, decltype(value)>::convert(
108-
value)
109-
.value_or(defaultValue);
110-
},
111-
array._value);
87+
return UCesiumMetadataValueBlueprintLibrary::GetInteger(
88+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index),
89+
defaultValue);
11290
}
11391

11492
int64 UCesiumPropertyArrayBlueprintLibrary::GetInteger64(
11593
UPARAM(ref) const FCesiumPropertyArray& array,
11694
int64 index,
11795
int64 defaultValue) {
118-
return swl::visit(
119-
[index, defaultValue](const auto& v) -> int64 {
120-
if (index < 0 || index >= v.size()) {
121-
return defaultValue;
122-
}
123-
auto value = v[index];
124-
return CesiumGltf::MetadataConversions<int64_t, decltype(value)>::
125-
convert(value)
126-
.value_or(defaultValue);
127-
},
128-
array._value);
96+
return UCesiumMetadataValueBlueprintLibrary::GetInteger64(
97+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index),
98+
defaultValue);
12999
}
130100

131101
float UCesiumPropertyArrayBlueprintLibrary::GetFloat(
132102
UPARAM(ref) const FCesiumPropertyArray& array,
133103
int64 index,
134104
float defaultValue) {
135-
return swl::visit(
136-
[index, defaultValue](const auto& v) -> float {
137-
if (index < 0 || index >= v.size()) {
138-
return defaultValue;
139-
}
140-
auto value = v[index];
141-
return CesiumGltf::MetadataConversions<float, decltype(value)>::convert(
142-
value)
143-
.value_or(defaultValue);
144-
},
145-
array._value);
105+
return UCesiumMetadataValueBlueprintLibrary::GetFloat(
106+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index),
107+
defaultValue);
146108
}
147109

148110
double UCesiumPropertyArrayBlueprintLibrary::GetFloat64(
149111
UPARAM(ref) const FCesiumPropertyArray& array,
150112
int64 index,
151113
double defaultValue) {
152-
return swl::visit(
153-
[index, defaultValue](const auto& v) -> double {
154-
auto value = v[index];
155-
return CesiumGltf::MetadataConversions<double, decltype(value)>::
156-
convert(value)
157-
.value_or(defaultValue);
158-
},
159-
array._value);
114+
return UCesiumMetadataValueBlueprintLibrary::GetFloat64(
115+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index),
116+
defaultValue);
160117
}
161118

162119
FString UCesiumPropertyArrayBlueprintLibrary::GetString(
163120
UPARAM(ref) const FCesiumPropertyArray& array,
164121
int64 index,
165122
const FString& defaultValue) {
166-
return swl::visit(
167-
[index, defaultValue, &EnumDefinition = array._pEnumDefinition](
168-
const auto& v) -> FString {
169-
if (index < 0 || index >= v.size()) {
170-
return defaultValue;
171-
}
172-
auto value = v[index];
173-
using ValueType = decltype(value);
174-
175-
if constexpr (CesiumGltf::IsMetadataInteger<ValueType>::value) {
176-
if (EnumDefinition.IsValid()) {
177-
TOptional<FString> MaybeName = EnumDefinition->GetName(value);
178-
if (MaybeName.IsSet()) {
179-
return MaybeName.GetValue();
180-
}
181-
}
182-
}
183-
184-
auto maybeString =
185-
CesiumGltf::MetadataConversions<std::string, ValueType>::convert(
186-
value);
187-
if (!maybeString) {
188-
return defaultValue;
189-
}
190-
return UnrealMetadataConversions::toString(*maybeString);
191-
},
192-
array._value);
123+
return UCesiumMetadataValueBlueprintLibrary::GetString(
124+
UCesiumPropertyArrayBlueprintLibrary::GetValue(array, index),
125+
defaultValue);
193126
}
127+
128+
PRAGMA_ENABLE_DEPRECATION_WARNINGS

Source/CesiumRuntime/Public/CesiumMetadataValue.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,10 @@ class CESIUMRUNTIME_API UCesiumMetadataValueBlueprintLibrary
732732
*
733733
* String properties are returned as-is.
734734
*
735-
* Scalar values are converted to a string with `std::to_string`.
735+
* Scalar values are converted to a string with `std::to_string`. However,
736+
* if the scalar value represents an enum, it will be looked up in property's
737+
* enum definition. If the value exists in the definition, its string name
738+
* will be returned. Otherwise, the default value is returned.
736739
*
737740
* Boolean properties are converted to "true" or "false".
738741
*

0 commit comments

Comments
 (0)