Cesium for Unreal 2.15.0
Loading...
Searching...
No Matches
CesiumMetadataEnum.h
Go to the documentation of this file.
1// Copyright 2020-2024 CesiumGS, Inc. and Contributors
2
3#pragma once
4
5#include "Misc/Optional.h"
6#include "UObject/ObjectMacros.h"
7#include "CesiumMetadataEnum.generated.h"
8
9namespace CesiumGltf {
10struct Enum;
11struct Schema;
12struct Model;
13} // namespace CesiumGltf
14
15/**
16 * @brief Stores information on the values of an enum and the corresponding
17 * names of those values.
18 */
19USTRUCT(BlueprintType)
20struct CESIUMRUNTIME_API FCesiumMetadataEnum {
21 GENERATED_USTRUCT_BODY()
22
23public:
24 /**
25 * @brief Constructs an empty enum definition with no values.
26 */
27 FCesiumMetadataEnum() : _valueNames() {}
28 /**
29 * @brief Constructs an enum definition from a @ref CesiumGltf::Enum.
30 */
32 /**
33 * @brief Constructs an enum definition from an Unreal UENUM type.
34 *
35 * This can be useful when creating @ref FCesiumMetadataValue items directly
36 * from code, to avoid having to create a @ref CesiumGltf::Enum from scratch
37 * to create this enum definition from. It can also be useful for testing
38 * purposes.
39 *
40 * To call this method with an Unreal UENUM from C++, you can use the
41 * `StaticEnum` method like so:
42 * ```
43 * FCesiumMetadataEnum enumDefinition(StaticEnum<EExampleEnumType>());
44 * ```
45 */
46 FCesiumMetadataEnum(const UEnum* UnrealEnum);
47
48 /**
49 * @brief Attempts to return the name of a given value from this enum
50 * definition, returning the name if the value was found or an empty optional
51 * if not.
52 *
53 * @param Value The value to lookup in this enum definition.
54 */
55 TOptional<FString> GetName(int64_t Value) const;
56
57private:
58 TMap<int64_t, FString> _valueNames;
59};
60
61/**
62 * @brief Contains a set of enum definitions obtained from a @ref
63 * CesiumGltf::Schema.
64 */
65USTRUCT()
66struct CESIUMRUNTIME_API FCesiumMetadataEnumCollection {
67 GENERATED_USTRUCT_BODY()
68
69public:
70 /**
71 * @brief Creates a new @ref FCesiumMetadataEnumCollection without any enum
72 * definitions.
73 */
74 FCesiumMetadataEnumCollection() : _enumDefinitions() {}
75 /**
76 * @brief Creates a new @ref FCesiumMetadataEnumCollection with definitions
77 * obtained from the `enums` property of the given @ref CesiumGltf::Schema.
78 *
79 * In most cases, @ref FCesiumMetadataEnumCollection::GetOrCreateFromSchema
80 * should be used instead.
81 */
83
84 /**
85 * @brief Obtains the @ref FCesiumMetadataEnum corresponding to the given key.
86 *
87 * The input key should be one of the keys in the `enums` of the @ref
88 * CesiumGltf::Schema that this collection is based on.
89 */
90 TSharedPtr<FCesiumMetadataEnum> Get(const FString& InKey) const;
91
92 /**
93 * @brief Attempts to obtain a @ref FCesiumMetadataEnumCollection from the
94 * given schema if one has already been created, or creates one if not.
95 *
96 * This method utilizes a custom extension on the @ref CesiumGltf::Schema to
97 * prevent duplicate enum collections from being created for the same schema,
98 * avoiding unnecessary allocations.
99 *
100 * @param Schema The schema to create an enum collection from.
101 */
102 static TSharedRef<FCesiumMetadataEnumCollection>
104
105 /**
106 * @brief Attempts to obtain a @ref FCesiumMetadataEnumCollection from a
107 * schema attached to the given model, or returns an invalid `TSharedPtr` if
108 * no schema is present.
109 *
110 * This method is equivalent to looking up the schema from the model yourself
111 * and calling @ref FCesiumMetadataEnumCollection::GetOrCreateFromSchema.
112 *
113 * @param Model The model to lookup the schema from.
114 */
115 static TSharedPtr<FCesiumMetadataEnumCollection>
117
118private:
119 TMap<FString, TSharedRef<FCesiumMetadataEnum>> _enumDefinitions;
120};
TSharedPtr< FCesiumMetadataEnum > Get(const FString &InKey) const
Obtains the FCesiumMetadataEnum corresponding to the given key.
static TSharedRef< FCesiumMetadataEnumCollection > GetOrCreateFromSchema(CesiumGltf::Schema &Schema)
Attempts to obtain a FCesiumMetadataEnumCollection from the given schema if one has already been crea...
static TSharedPtr< FCesiumMetadataEnumCollection > GetOrCreateFromModel(const CesiumGltf::Model &Model)
Attempts to obtain a FCesiumMetadataEnumCollection from a schema attached to the given model,...
FCesiumMetadataEnumCollection(const CesiumGltf::Schema &Schema)
Creates a new FCesiumMetadataEnumCollection with definitions obtained from the enums property of the ...
FCesiumMetadataEnumCollection()
Creates a new FCesiumMetadataEnumCollection without any enum definitions.
FCesiumMetadataEnum(const UEnum *UnrealEnum)
Constructs an enum definition from an Unreal UENUM type.
TOptional< FString > GetName(int64_t Value) const
Attempts to return the name of a given value from this enum definition, returning the name if the val...
FCesiumMetadataEnum(const CesiumGltf::Enum &Enum)
Constructs an enum definition from a CesiumGltf::Enum.
FCesiumMetadataEnum()
Constructs an empty enum definition with no values.