UnrealVoxta 0.1.1
 
Loading...
Searching...
No Matches
SignalRValue.h
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2020-2022 Frozen Storm Interactive, Yoann Potinet
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#pragma once
26
27#include "CoreMinimal.h"
28
34{
35public:
49
54 Type(EValueType::Null)
55 {
56 Value.Emplace<NumberType>(0);
57 }
58
62 FSignalRValue(std::nullptr_t) :
63 Type(EValueType::Null)
64 {
65 Value.Emplace<NumberType>(0);
66 }
67
73 FSignalRValue(const int32 InValue) :
74 Type(EValueType::Number)
75 {
76 Value.Set<NumberType>(InValue);
77 }
78
84 FSignalRValue(const uint32 InValue) :
85 Type(EValueType::Number)
86 {
87 Value.Set<NumberType>(InValue);
88 }
89
95 FSignalRValue(const int64 InValue) :
96 Type(EValueType::Number)
97 {
98 Value.Set<NumberType>(InValue);
99 }
100
106 FSignalRValue(const uint64 InValue) :
107 Type(EValueType::Number)
108 {
109 Value.Set<NumberType>(InValue);
110 }
111
117 FSignalRValue(const float InValue) :
118 Type(EValueType::Number)
119 {
120 Value.Set<NumberType>(InValue);
121 }
122
128 FSignalRValue(const double InValue) :
129 Type(EValueType::Number)
130 {
131 Value.Set<NumberType>(InValue);
132 }
133
139 FSignalRValue(const TMap<FString, FSignalRValue>& InValue) :
140 Type(EValueType::Object)
141 {
142 Value.Set<TSharedPtr<ObjectType>>(MakeShared<ObjectType>(InValue));
143 }
144
150 FSignalRValue(TMap<FString, FSignalRValue>&& InValue) :
151 Type(EValueType::Object)
152 {
153 Value.Emplace<TSharedPtr<ObjectType>>(MakeShared<ObjectType>(MoveTemp(InValue)));
154 }
155
161 FSignalRValue(const TArray<FSignalRValue>& InValue) :
162 Type(EValueType::Array)
163 {
164 Value.Set<ArrayType>(InValue);
165 }
166
172 FSignalRValue(TArray<FSignalRValue>&& InValue) :
173 Type(EValueType::Array)
174 {
175 Value.Emplace<ArrayType>(MoveTemp(InValue));
176 }
177
183 FSignalRValue(const FString& InValue) :
184 Type(EValueType::String)
185 {
186 Value.Set<StringType>(InValue);
187 }
188
194 FSignalRValue(FString&& InValue) :
195 Type(EValueType::String)
196 {
197 Value.Emplace<StringType>(MoveTemp(InValue));
198 }
199
205 FSignalRValue(bool InValue) :
206 Type(EValueType::Boolean)
207 {
208 Value.Set<BooleanType>(InValue);
209 }
210
216 FSignalRValue(const TArray<uint8>& InValue) :
217 Type(EValueType::Binary)
218 {
219 Value.Set<BinaryType>(InValue);
220 }
221
227 FSignalRValue(TArray<uint8>&& InValue) :
228 Type(EValueType::Binary)
229 {
230 Value.Emplace<BinaryType>(MoveTemp(InValue));
231 }
232
238 FSignalRValue(const FSignalRValue& OtherValue)
239 {
240 Type = OtherValue.Type;
241 Value = OtherValue.Value;
242 }
243
249 FSignalRValue(FSignalRValue&& OtherValue) noexcept
250 {
251 Type = MoveTemp(OtherValue.Type);
252 Value = MoveTemp(OtherValue.Value);
253 }
254
258 ~FSignalRValue() = default;
259
268 {
269 Type = OtherValue.Type;
270 Value = OtherValue.Value;
271 return *this;
272 }
273
281 FSignalRValue& operator=(FSignalRValue&& OtherValue) noexcept
282 {
283 Type = MoveTemp(OtherValue.Type);
284 Value = MoveTemp(OtherValue.Value);
285 return *this;
286 }
287
289 FORCEINLINE bool IsNumber() const
290 {
291 return Type == EValueType::Number;
292 }
293
295 FORCEINLINE bool IsObject() const
296 {
297 return Type == EValueType::Object;
298 }
299
301 FORCEINLINE bool IsString() const
302 {
303 return Type == EValueType::String;
304 }
305
307 FORCEINLINE bool IsNull() const
308 {
309 return Type == EValueType::Null;
310 }
311
313 FORCEINLINE bool IsArray() const
314 {
315 return Type == EValueType::Array;
316 }
317
319 FORCEINLINE bool IsBoolean() const
320 {
321 return Type == EValueType::Boolean;
322 }
323
325 FORCEINLINE bool IsBinary() const
326 {
327 return Type == EValueType::Binary;
328 }
329
331 FORCEINLINE EValueType GetType() const
332 {
333 return Type;
334 }
335
337 FORCEINLINE int64 AsInt() const
338 {
339 check(Type == EValueType::Number);
340 return Value.Get<NumberType>();
341 }
342
344 FORCEINLINE uint64 AsUInt() const
345 {
346 check(Type == EValueType::Number);
347 return Value.Get<NumberType>();
348 }
349
351 FORCEINLINE float AsFloat() const
352 {
353 check(Type == EValueType::Number);
354 return Value.Get<NumberType>();
355 }
356
358 FORCEINLINE double AsDouble() const
359 {
360 check(Type == EValueType::Number);
361 return Value.Get<NumberType>();
362 }
363
365 FORCEINLINE double AsNumber() const
366 {
367 check(Type == EValueType::Number);
368 return Value.Get<NumberType>();
369 }
370
372 FORCEINLINE const TMap<FString, FSignalRValue>& AsObject() const
373 {
374 check(Type == EValueType::Object);
375 return *Value.Get<TSharedPtr<ObjectType>>();
376 }
377
379 FORCEINLINE const TArray<FSignalRValue>& AsArray() const
380 {
381 check(Type == EValueType::Array);
382 return Value.Get<ArrayType>();
383 }
384
386 FORCEINLINE const FString& AsString() const
387 {
388 check(Type == EValueType::String);
389 return Value.Get<StringType>();
390 }
391
393 FORCEINLINE bool AsBool() const
394 {
395 check(Type == EValueType::Boolean);
396 return Value.Get<BooleanType>();
397 }
398
400 FORCEINLINE const TArray<uint8>& AsBinary() const
401 {
402 check(Type == EValueType::Binary);
403 return Value.Get<BinaryType>();
404 }
405
406private:
407 EValueType Type;
408
409 using NumberType = double;
410 using ObjectType = TMap<FString, FSignalRValue>;
411 using ArrayType = TArray<FSignalRValue>;
412 using StringType = FString;
413 using BooleanType = bool;
414 using BinaryType = TArray<uint8>;
415 using FInternalValueVariant = TVariant<NumberType, TSharedPtr<ObjectType>, ArrayType, StringType, BooleanType, BinaryType>;
416
417 FInternalValueVariant Value;
418};
FORCEINLINE bool IsBinary() const
Definition SignalRValue.h:325
FORCEINLINE const TArray< uint8 > & AsBinary() const
Definition SignalRValue.h:400
FSignalRValue(const float InValue)
Create an object representing a EValueType::Number with the given float value.
Definition SignalRValue.h:117
EValueType
Enumeration of possible value types that can be stored in a FSignalRValue.
Definition SignalRValue.h:40
@ String
Definition SignalRValue.h:44
@ Boolean
Definition SignalRValue.h:46
@ Array
Definition SignalRValue.h:43
@ Object
Definition SignalRValue.h:42
@ Binary
Definition SignalRValue.h:47
@ Number
Definition SignalRValue.h:41
@ Null
Definition SignalRValue.h:45
FSignalRValue()
Create an object representing a EValueType::Null value.
Definition SignalRValue.h:53
FSignalRValue(const uint64 InValue)
Create an object representing a EValueType::Number with the given unsigned 64-bit integer value.
Definition SignalRValue.h:106
FSignalRValue(const TMap< FString, FSignalRValue > &InValue)
Create an object representing a EValueType::Object with the given map of string-values.
Definition SignalRValue.h:139
FSignalRValue(TArray< uint8 > &&InValue)
Create an object representing a EValueType::Binary with the given array of byte's.
Definition SignalRValue.h:227
FORCEINLINE bool IsArray() const
Definition SignalRValue.h:313
FSignalRValue(const FSignalRValue &OtherValue)
Copies an existing value.
Definition SignalRValue.h:238
FORCEINLINE const FString & AsString() const
Definition SignalRValue.h:386
FSignalRValue(TArray< FSignalRValue > &&InValue)
Create an object representing a EValueType::Array with the given array of values.
Definition SignalRValue.h:172
FSignalRValue(const TArray< FSignalRValue > &InValue)
Create an object representing a EValueType::Array with the given array of values.
Definition SignalRValue.h:161
FSignalRValue(TMap< FString, FSignalRValue > &&InValue)
Create an object representing a EValueType::Object with the given map of string-values.
Definition SignalRValue.h:150
~FSignalRValue()=default
Cleans up the resources associated with the value.
FORCEINLINE bool IsNumber() const
Definition SignalRValue.h:289
FSignalRValue(const TArray< uint8 > &InValue)
Create an object representing a EValueType::Binary with the given array of byte's.
Definition SignalRValue.h:216
FORCEINLINE int64 AsInt() const
Definition SignalRValue.h:337
FORCEINLINE bool AsBool() const
Definition SignalRValue.h:393
FSignalRValue & operator=(const FSignalRValue &OtherValue)
Copies an existing value.
Definition SignalRValue.h:267
FSignalRValue(const double InValue)
Create an object representing a EValueType::Number with the given double value.
Definition SignalRValue.h:128
FSignalRValue(const int32 InValue)
Create an object representing a EValueType::Number with the given integer value.
Definition SignalRValue.h:73
FORCEINLINE EValueType GetType() const
Definition SignalRValue.h:331
FORCEINLINE double AsNumber() const
Definition SignalRValue.h:365
FORCEINLINE bool IsObject() const
Definition SignalRValue.h:295
FSignalRValue(const FString &InValue)
Create an object representing a EValueType::String with the given string value.
Definition SignalRValue.h:183
FORCEINLINE const TArray< FSignalRValue > & AsArray() const
Definition SignalRValue.h:379
FORCEINLINE bool IsNull() const
Definition SignalRValue.h:307
FSignalRValue & operator=(FSignalRValue &&OtherValue) noexcept
Moves an existing value.
Definition SignalRValue.h:281
FORCEINLINE uint64 AsUInt() const
Definition SignalRValue.h:344
FORCEINLINE double AsDouble() const
Definition SignalRValue.h:358
FORCEINLINE const TMap< FString, FSignalRValue > & AsObject() const
Definition SignalRValue.h:372
FORCEINLINE bool IsBoolean() const
Definition SignalRValue.h:319
FSignalRValue(const int64 InValue)
Create an object representing a EValueType::Number with the given 64-bit integer value.
Definition SignalRValue.h:95
FORCEINLINE bool IsString() const
Definition SignalRValue.h:301
FSignalRValue(bool InValue)
Create an object representing a EValueType::Boolean with the given bool value.
Definition SignalRValue.h:205
FSignalRValue(FString &&InValue)
Create an object representing a EValueType::String with the given string value.
Definition SignalRValue.h:194
FORCEINLINE float AsFloat() const
Definition SignalRValue.h:351
FSignalRValue(FSignalRValue &&OtherValue) noexcept
Moves an existing value.
Definition SignalRValue.h:249
FSignalRValue(std::nullptr_t)
Create an object representing a EValueType::Null value.
Definition SignalRValue.h:62
FSignalRValue(const uint32 InValue)
Create an object representing a EValueType::Number with the given unsigned integer value.
Definition SignalRValue.h:84