UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMNameValueMap.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_VERSE_VM || defined(__INTELLISENSE__)
6
8#include "Misc/Optional.h"
12
13namespace Verse
14{
15// A helper struct that maps strings to VValues
16struct VNameValueMap
17{
18 VNameValueMap(FAllocationContext Context, uint32 Capacity)
19 : NameAndValues(Context, &VMutableArray::New(Context, 0, Capacity, EArrayType::VValue))
20 {
21 }
22
23 // We keep names at 2*Index and Values at 2*Index+1
25
26 uint32 Num() const
27 {
28 return NameAndValues->Num() / 2;
29 }
30
31 void Reset(FAllocationContext Context)
32 {
33 NameAndValues->Reset(Context);
34 }
35
37 {
38 checkSlow(Index < static_cast<int32>(Num()));
39 VValue Value = NameAndValues->GetValue(2 * Index);
40 return Value.StaticCast<VUniqueString>();
41 }
42
43 VValue GetValue(uint32 Index) const
44 {
45 checkSlow(Index < static_cast<int32>(Num()));
46 return NameAndValues->GetValue(2 * Index + 1);
47 }
48
49 template <typename CellType>
50 CellType& GetCell(uint32 Index) const
51 {
52 return GetValue(Index).StaticCast<CellType>();
53 }
54
55 void AddValue(FAllocationContext Context, VUniqueString& Name, VValue Value)
56 {
57 NameAndValues->AddValue(Context, VValue(Name));
58 NameAndValues->AddValue(Context, Value);
59 }
60
62 {
64 if (Index == INDEX_NONE)
65 {
66 return {};
67 }
68
69 VValue RemovedValue = NameAndValues->GetValue(2 * Index + 1);
70 NameAndValues->RemoveRange(2 * Index, 2);
71 return RemovedValue;
72 }
73
75 {
76 for (uint32 Index = 0, End = Num(); Index < End; ++Index)
77 {
78 if (GetName(Index).AsStringView().Equals(Name, SearchCase))
79 {
80 return Index;
81 }
82 }
83 return INDEX_NONE;
84 }
85
86 VValue Lookup(FUtf8StringView Name, ESearchCase::Type SearchCase = ESearchCase::CaseSensitive) const
87 {
88 uint32 Index = IndexOf(Name, SearchCase);
89 return Index != INDEX_NONE ? GetValue(Index) : VValue();
90 }
91
92 template <typename CellType>
94 {
95 VValue Value = Lookup(Name);
96 return Value.DynamicCast<CellType>();
97 }
98
99 template <typename CellType>
101 {
103 Name.AppendString(NameString);
104 VValue Value = Lookup(NameString, ESearchCase::IgnoreCase);
105 return Value.DynamicCast<CellType>();
106 }
107
108 template <typename TVisitor>
109 friend void Visit(TVisitor& Visitor, VNameValueMap& Value)
110 {
111 Visitor.Visit(Value.NameAndValues, TEXT("NamesAndValues"));
112 }
113};
114} // namespace Verse
115
116#endif // WITH_VERSE_VM
#define checkSlow(expr)
Definition AssertionMacros.h:332
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
T * New(FMemStackBase &Mem, int32 Count=1, int32 Align=DEFAULT_ALIGNMENT)
Definition MemStack.h:259
@ Num
Definition MetalRHIPrivate.h:234
decltype(auto) Visit(Func &&Callable, Variants &&... Args)
Definition TVariant.h:271
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition NameTypes.h:617
Definition StringBuilder.h:509
UE_REWRITE auto IndexOf(const RangeType &Range, const ValueType &Value)
Definition IndexOf.h:59
IMAGECORE_API const TCHAR * GetName(Type Format)
Definition ImageCore.cpp:1378
Type
Definition CString.h:21
@ IgnoreCase
Definition CString.h:26
@ CaseSensitive
Definition CString.h:23
@ Visitor
Definition XmppMultiUserChat.h:94
T::FDataType GetValue(const UBlackboardComponent &Blackboard, const FName &Name, FBlackboard::FKey &InOutCachedKey, const typename T::FDataType &DefaultValue)
Definition ValueOrBBKey.h:51
Definition Archive.h:36
U16 Index
Definition radfft.cpp:71
Definition Optional.h:131