Skip to content

Commit 3f4e777

Browse files
committed
Add ToString to CesiumPropertyArray and CesiumMetadataValueType
1 parent 8c2fd03 commit 3f4e777

File tree

5 files changed

+141
-26
lines changed

5 files changed

+141
-26
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2020-2025 CesiumGS, Inc. and Contributors
2+
3+
#include "CesiumMetadataValueType.h"
4+
5+
#include <Cesium3DTiles/ClassProperty.h>
6+
7+
using namespace CesiumGltf;
8+
9+
FCesiumMetadataValueType::FCesiumMetadataValueType()
10+
: Type(ECesiumMetadataType::Invalid),
11+
ComponentType(ECesiumMetadataComponentType::None),
12+
bIsArray(false) {}
13+
14+
FCesiumMetadataValueType::FCesiumMetadataValueType(
15+
ECesiumMetadataType InType,
16+
ECesiumMetadataComponentType InComponentType,
17+
bool IsArray)
18+
: Type(InType), ComponentType(InComponentType), bIsArray(IsArray) {}
19+
20+
FString FCesiumMetadataValueType::ToString() const {
21+
if (Type == ECesiumMetadataType::Invalid) {
22+
return TEXT("Invalid Type");
23+
}
24+
25+
TArray<FString> strings;
26+
strings.Reserve(3);
27+
28+
if (ComponentType != ECesiumMetadataComponentType::None) {
29+
strings.Emplace(MetadataComponentTypeToString(ComponentType));
30+
}
31+
32+
strings.Emplace(MetadataTypeToString(Type));
33+
34+
if (bIsArray) {
35+
strings.Emplace("Array");
36+
}
37+
38+
return FString::Join(strings, TEXT(" "));
39+
}

Source/CesiumRuntime/Private/CesiumPropertyArrayBlueprintLibrary.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ FCesiumMetadataValue UCesiumPropertyArrayBlueprintLibrary::GetValue(
6666
Array._valueView);
6767
}
6868

69+
FString UCesiumPropertyArrayBlueprintLibrary::ToString(
70+
UPARAM(ref) const FCesiumPropertyArray& Array) {
71+
TArray<FString> results;
72+
73+
const int64 size = UCesiumPropertyArrayBlueprintLibrary::GetArraySize(Array);
74+
for (int64 i = 0; i < size; i++) {
75+
FCesiumMetadataValue value =
76+
UCesiumPropertyArrayBlueprintLibrary::GetValue(Array, i);
77+
results.Add(
78+
UCesiumMetadataValueBlueprintLibrary::GetString(value, FString("")));
79+
}
80+
81+
return "[" + FString::Join(results, TEXT(", ")) + "]";
82+
}
83+
6984
PRAGMA_DISABLE_DEPRECATION_WARNINGS
7085
ECesiumMetadataTrueType_DEPRECATED
7186
UCesiumPropertyArrayBlueprintLibrary::GetTrueComponentType(

Source/CesiumRuntime/Private/Tests/CesiumPropertyArray.spec.cpp

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,32 @@ void FCesiumPropertyArraySpec::Define() {
225225
});
226226
});
227227

228-
Describe("UCesiumPropertyArrayBlueprintLibrary::GetString", [this]() {
229-
It("handles an int array correctly", [this]() {
228+
Describe("ToString", [this]() {
229+
It("handles bool elements", [this]() {
230+
std::vector<bool> values{true, false, false, true, true};
231+
// Extraneous bool constructor is needed to avoid implicit conversion
232+
// under the hood.
233+
TArray<FCesiumMetadataValue> valuesArray{
234+
FCesiumMetadataValue(bool(values[0])),
235+
FCesiumMetadataValue(bool(values[1])),
236+
FCesiumMetadataValue(bool(values[2])),
237+
FCesiumMetadataValue(bool(values[3])),
238+
FCesiumMetadataValue(bool(values[4]))};
239+
240+
FCesiumPropertyArray array(std::move(valuesArray));
241+
TestEqual(
242+
"size",
243+
UCesiumPropertyArrayBlueprintLibrary::GetSize(array),
244+
int64(values.size()));
245+
246+
FString expected("[true, false, false, true, true]");
247+
TestEqual(
248+
"ToString",
249+
UCesiumPropertyArrayBlueprintLibrary::ToString(array),
250+
expected);
251+
});
252+
253+
It("handles int elements", [this]() {
230254
std::vector<int32> values{1, 2, 3, -1};
231255
CesiumGltf::PropertyArrayCopy<int32> arrayView = std::vector(values);
232256
FCesiumPropertyArray array(arrayView);
@@ -235,15 +259,14 @@ void FCesiumPropertyArraySpec::Define() {
235259
UCesiumPropertyArrayBlueprintLibrary::GetSize(array),
236260
int64(values.size()));
237261

238-
for (size_t i = 0; i < values.size(); i++) {
239-
TestEqual(
240-
"GetString",
241-
UCesiumPropertyArrayBlueprintLibrary::GetString(array, i),
242-
FString(UTF8_TO_TCHAR(std::to_string(values[i]).c_str())));
243-
}
262+
FString expected("[1, 2, 3, -1]");
263+
TestEqual(
264+
"ToString",
265+
UCesiumPropertyArrayBlueprintLibrary::ToString(array),
266+
expected);
244267
});
245268

246-
It("handles an enum array correctly", [this]() {
269+
It("handles enum elements", [this]() {
247270
TSharedPtr<FCesiumMetadataEnum> enumDef = MakeShared<FCesiumMetadataEnum>(
248271
StaticEnum<ECesiumMetadataBlueprintType>());
249272
std::vector<int32> values{
@@ -263,12 +286,31 @@ void FCesiumPropertyArraySpec::Define() {
263286
UCesiumPropertyArrayBlueprintLibrary::GetSize(array),
264287
int64(values.size()));
265288

266-
for (size_t i = 0; i < values.size(); i++) {
267-
TestEqual(
268-
"GetString",
269-
UCesiumPropertyArrayBlueprintLibrary::GetString(array, i),
270-
FString(UTF8_TO_TCHAR(valueNames[i].c_str())));
271-
}
289+
FString expected("[Boolean, Byte, Integer, Integer64]");
290+
TestEqual(
291+
"ToString",
292+
UCesiumPropertyArrayBlueprintLibrary::ToString(array),
293+
expected);
294+
});
295+
296+
It("handles string elements", [this]() {
297+
std::vector<std::string_view> values{"Test", "These", "Strings"};
298+
TArray<FCesiumMetadataValue> valuesArray{
299+
FCesiumMetadataValue(values[0]),
300+
FCesiumMetadataValue(values[1]),
301+
FCesiumMetadataValue(values[2])};
302+
303+
FCesiumPropertyArray array(std::move(valuesArray));
304+
TestEqual(
305+
"size",
306+
UCesiumPropertyArrayBlueprintLibrary::GetSize(array),
307+
int64(values.size()));
308+
309+
FString expected("[Test, These, Strings]");
310+
TestEqual(
311+
"ToString",
312+
UCesiumPropertyArrayBlueprintLibrary::ToString(array),
313+
expected);
272314
});
273315
});
274316
}

Source/CesiumRuntime/Public/CesiumMetadataValueType.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
// Copyright 2020-2024 CesiumGS, Inc. and Contributors
1+
// Copyright 2020-2025 CesiumGS, Inc. and Contributors
22

33
#pragma once
44

5-
#include "CesiumGltf/Enum.h"
6-
#include "CesiumGltf/PropertyArrayView.h"
7-
#include "CesiumGltf/PropertyType.h"
8-
#include "CesiumGltf/PropertyTypeTraits.h"
95
#include "CesiumMetadataEnum.h"
6+
#include <CesiumGltf/Enum.h>
7+
#include <CesiumGltf/PropertyArrayView.h>
8+
#include <CesiumGltf/PropertyType.h>
9+
#include <CesiumGltf/PropertyTypeTraits.h>
10+
1011
#include "CesiumMetadataValueType.generated.h"
1112

13+
namespace Cesium3DTiles {
14+
struct ClassProperty;
15+
}
16+
1217
/**
1318
* The Blueprint type that can losslessly represent values of a given property.
1419
*/
@@ -139,16 +144,12 @@ USTRUCT(BlueprintType)
139144
struct CESIUMRUNTIME_API FCesiumMetadataValueType {
140145
GENERATED_USTRUCT_BODY()
141146

142-
FCesiumMetadataValueType()
143-
: Type(ECesiumMetadataType::Invalid),
144-
ComponentType(ECesiumMetadataComponentType::None),
145-
bIsArray(false) {}
147+
FCesiumMetadataValueType();
146148

147149
FCesiumMetadataValueType(
148150
ECesiumMetadataType InType,
149151
ECesiumMetadataComponentType InComponentType,
150-
bool IsArray = false)
151-
: Type(InType), ComponentType(InComponentType), bIsArray(IsArray) {}
152+
bool IsArray = false);
152153

153154
/**
154155
* The type of the metadata property or value.
@@ -186,6 +187,12 @@ struct CESIUMRUNTIME_API FCesiumMetadataValueType {
186187
return Type != ValueType.Type || ComponentType != ValueType.ComponentType ||
187188
bIsArray != ValueType.bIsArray;
188189
}
190+
191+
/**
192+
* Prints the type in the format "(Component Type) (Type) (Array)".
193+
* For example, "Int16 Scalar", "Float32 Mat4 Array", "String Array".
194+
*/
195+
FString ToString() const;
189196
};
190197

191198
template <typename T>

Source/CesiumRuntime/Public/CesiumPropertyArrayBlueprintLibrary.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,18 @@ class CESIUMRUNTIME_API UCesiumPropertyArrayBlueprintLibrary
7373
static FCesiumMetadataValue
7474
GetValue(UPARAM(ref) const FCesiumPropertyArray& Array, int64 Index);
7575

76+
/**
77+
* Prints the contents of the array to a human-readable string in the format
78+
* "[A, B, C, ... Z]".
79+
* @param Array The array.
80+
* @return A string capturing the contents of the array.
81+
*/
82+
UFUNCTION(
83+
BlueprintCallable,
84+
BlueprintPure,
85+
Category = "Cesium|Metadata|PropertyArray")
86+
static FString ToString(UPARAM(ref) const FCesiumPropertyArray& Array);
87+
7688
PRAGMA_DISABLE_DEPRECATION_WARNINGS
7789
/**
7890
* Gets the best-fitting Blueprints type for the elements of this array.

0 commit comments

Comments
 (0)