Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
MemStackUtility.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
5#include "Misc/MemStack.h"
6#include "Misc/StringBuilder.h"
7#include "Containers/ArrayView.h"
8#include "Containers/StringView.h"
9
10namespace UE
11{
12namespace MemStack
13{
14
15inline const TCHAR* AllocateString(FMemStackBase& Allocator, const TCHAR* String, int32 Length)
16{
17 TCHAR* Result = New<TCHAR>(Allocator, Length + 1);
18 FMemory::Memcpy(Result, String, Length * sizeof(TCHAR));
19 Result[Length] = 0;
20 return Result;
21}
22
23inline const TCHAR* AllocateString(FMemStackBase& Allocator, FStringView String)
24{
25 return AllocateString(Allocator, String.GetData(), String.Len());
26}
27
28inline FStringView AllocateStringView(FMemStackBase& Allocator, FStringView String)
29{
30 return FStringView(AllocateString(Allocator, String), String.Len());
31}
32
33inline const TCHAR* AllocateString(FMemStackBase& Allocator, const FStringBuilderBase& StringBuilder)
34{
35 return AllocateString(Allocator, StringBuilder.GetData(), StringBuilder.Len());
36}
37
38template <typename FormatType, typename... ArgTypes>
39inline const TCHAR* AllocateStringf(FMemStackBase& Allocator, const FormatType& Format, ArgTypes... Args)
40{
44}
45
46template <typename FormatType, typename... ArgTypes>
47inline FStringView AllocateStringViewf(FMemStackBase& Allocator, const FormatType& Format, ArgTypes... Args)
48{
52}
53
54template<typename T>
56{
57 T* Data = nullptr;
58 if (View.Num() > 0)
59 {
60 Data = new(Allocator) T[View.Num()];
61 for (int32 i = 0; i < View.Num(); ++i)
62 {
63 Data[i] = View[i];
64 }
65 }
66 return MakeArrayView(Data, View.Num());
67}
68
69} // namespace MemStack
70} // namespace UE
TArrayView< T > AllocateArrayView(FMemStackBase &Allocator, TArrayView< T > View)
const TCHAR * AllocateString(FMemStackBase &Allocator, FStringView String)
const TCHAR * AllocateStringf(FMemStackBase &Allocator, const FormatType &Format, ArgTypes... Args)
FStringView AllocateStringView(FMemStackBase &Allocator, FStringView String)
const TCHAR * AllocateString(FMemStackBase &Allocator, const FStringBuilderBase &StringBuilder)
FStringView AllocateStringViewf(FMemStackBase &Allocator, const FormatType &Format, ArgTypes... Args)
const TCHAR * AllocateString(FMemStackBase &Allocator, const TCHAR *String, int32 Length)
Definition Vector.h:40
static FORCEINLINE void * Memcpy(void *Dest, const void *Src, SIZE_T Count)