2019-12-26 14:45:42 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2014-10-01 18:20:53 -04:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3209340)
#lockdown Nick.Penwarden
#rb none
==========================
MAJOR FEATURES + CHANGES
==========================
Change 3209340 on 2016/11/23 by Ben.Marsh
Convert UE4 codebase to an "include what you use" model - where every header just includes the dependencies it needs, rather than every source file including large monolithic headers like Engine.h and UnrealEd.h.
Measured full rebuild times around 2x faster using XGE on Windows, and improvements of 25% or more for incremental builds and full rebuilds on most other platforms.
* Every header now includes everything it needs to compile.
* There's a CoreMinimal.h header that gets you a set of ubiquitous types from Core (eg. FString, FName, TArray, FVector, etc...). Most headers now include this first.
* There's a CoreTypes.h header that sets up primitive UE4 types and build macros (int32, PLATFORM_WIN64, etc...). All headers in Core include this first, as does CoreMinimal.h.
* Every .cpp file includes its matching .h file first.
* This helps validate that each header is including everything it needs to compile.
* No engine code includes a monolithic header such as Engine.h or UnrealEd.h any more.
* You will get a warning if you try to include one of these from the engine. They still exist for compatibility with game projects and do not produce warnings when included there.
* There have only been minor changes to our internal games down to accommodate these changes. The intent is for this to be as seamless as possible.
* No engine code explicitly includes a precompiled header any more.
* We still use PCHs, but they're force-included on the compiler command line by UnrealBuildTool instead. This lets us tune what they contain without breaking any existing include dependencies.
* PCHs are generated by a tool to get a statistical amount of coverage for the source files using it, and I've seeded the new shared PCHs to contain any header included by > 15% of source files.
Tool used to generate this transform is at Engine\Source\Programs\IncludeTool.
[CL 3209342 by Ben Marsh in Main branch]
2016-11-23 15:48:37 -05:00
|
|
|
#include "CoreMinimal.h"
|
2019-01-10 17:26:53 -05:00
|
|
|
#include "Misc/EnumClassFlags.h"
|
2020-01-07 15:54:23 -05:00
|
|
|
#include "UObject/Field.h"
|
2021-03-05 19:27:14 -04:00
|
|
|
#include "UObject/UnrealType.h"
|
2019-01-10 17:26:53 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Flags controlling the behavior of struct serializer backends.
|
|
|
|
|
*/
|
|
|
|
|
enum class EStructSerializerBackendFlags
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* No special behavior.
|
|
|
|
|
*/
|
|
|
|
|
None = 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Write text in its complex exported format (eg, NSLOCTEXT(...)) rather than as a simple string.
|
|
|
|
|
* @note This is required to correctly support localization
|
|
|
|
|
*/
|
|
|
|
|
WriteTextAsComplexString = 1<<0,
|
|
|
|
|
|
2019-11-20 13:14:21 -05:00
|
|
|
/**
|
|
|
|
|
* Write TArray<uint8>/TArray<int> as byte string if possible (CBOR), starting at 4.25.
|
|
|
|
|
*/
|
|
|
|
|
WriteByteArrayAsByteStream = 1<<1,
|
|
|
|
|
|
2020-01-29 18:45:15 -05:00
|
|
|
/**
|
|
|
|
|
* Force the CBOR backend to write CBOR data in big endian (CBOR compliant endianness), available from 4.25. Caller must be opt-in.
|
|
|
|
|
* By default, the CBOR backend uses the endianness of the platform.
|
|
|
|
|
*/
|
|
|
|
|
WriteCborStandardEndianness = 1 << 2,
|
|
|
|
|
|
2022-02-11 15:17:57 -05:00
|
|
|
/**
|
|
|
|
|
* Support backward compatibility for LWC types by writing double properties as floats.
|
|
|
|
|
*/
|
|
|
|
|
WriteLWCTypesAsFloats = 1 << 3,
|
|
|
|
|
|
2019-01-10 17:26:53 -05:00
|
|
|
/**
|
|
|
|
|
* Legacy settings for backwards compatibility with code compiled prior to 4.22.
|
|
|
|
|
*/
|
|
|
|
|
Legacy = None,
|
|
|
|
|
|
|
|
|
|
/**
|
2022-02-11 15:17:57 -05:00
|
|
|
* Legacy settings for backwards compatibility with code compiled for 4.25 up to UE5.
|
|
|
|
|
*/
|
|
|
|
|
LegacyUE4 = WriteTextAsComplexString | WriteByteArrayAsByteStream | WriteLWCTypesAsFloats,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Default settings for code compiled for 5.0 onwards.
|
2019-01-10 17:26:53 -05:00
|
|
|
*/
|
2019-11-20 13:14:21 -05:00
|
|
|
Default = WriteTextAsComplexString | WriteByteArrayAsByteStream,
|
2019-01-10 17:26:53 -05:00
|
|
|
};
|
|
|
|
|
ENUM_CLASS_FLAGS(EStructSerializerBackendFlags);
|
|
|
|
|
|
2014-10-01 18:20:53 -04:00
|
|
|
|
2020-10-09 22:42:26 -04:00
|
|
|
/**
|
|
|
|
|
* Flags related to the current state being serialized.
|
|
|
|
|
*/
|
|
|
|
|
enum class EStructSerializerStateFlags
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Nothing special.
|
|
|
|
|
*/
|
|
|
|
|
None = 0,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether its serializing a single element from a container (array, set, map)
|
|
|
|
|
*/
|
|
|
|
|
WritingContainerElement = 1 << 0,
|
|
|
|
|
};
|
|
|
|
|
ENUM_CLASS_FLAGS(EStructSerializerStateFlags);
|
|
|
|
|
|
2015-09-09 13:45:13 -04:00
|
|
|
/**
|
|
|
|
|
* Structure for the write state stack.
|
|
|
|
|
*/
|
|
|
|
|
struct FStructSerializerState
|
|
|
|
|
{
|
2021-03-05 19:27:14 -04:00
|
|
|
FStructSerializerState() = default;
|
|
|
|
|
|
|
|
|
|
FStructSerializerState(void* InValuePtr, FProperty* InProperty, EStructSerializerStateFlags InFlags)
|
|
|
|
|
: ValueData(InValuePtr)
|
|
|
|
|
, ValueProperty(InProperty)
|
|
|
|
|
, FieldType(InProperty->GetClass())
|
|
|
|
|
, StateFlags(InFlags)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-09 13:45:13 -04:00
|
|
|
/** Holds a flag indicating whether the property has been processed. */
|
2019-06-07 11:22:52 -04:00
|
|
|
bool HasBeenProcessed = false;
|
2015-09-09 13:45:13 -04:00
|
|
|
|
2015-09-09 14:24:58 -04:00
|
|
|
/** Holds a pointer to the key property's data. */
|
2019-06-07 11:22:52 -04:00
|
|
|
const void* KeyData = nullptr;
|
2015-09-09 14:24:58 -04:00
|
|
|
|
|
|
|
|
/** Holds the key property's meta data (only used for TMap). */
|
2020-01-07 15:54:23 -05:00
|
|
|
FProperty* KeyProperty = nullptr;
|
2015-09-09 14:24:58 -04:00
|
|
|
|
2015-09-09 13:45:13 -04:00
|
|
|
/** Holds a pointer to the property value's data. */
|
2019-06-07 11:22:52 -04:00
|
|
|
const void* ValueData = nullptr;
|
2015-09-09 13:45:13 -04:00
|
|
|
|
|
|
|
|
/** Holds the property value's meta data. */
|
2020-01-07 15:54:23 -05:00
|
|
|
FProperty* ValueProperty = nullptr;
|
2015-09-09 13:45:13 -04:00
|
|
|
|
|
|
|
|
/** Holds a pointer to the UStruct describing the data. */
|
2019-06-07 11:22:52 -04:00
|
|
|
UStruct* ValueType = nullptr;
|
2020-01-07 15:54:23 -05:00
|
|
|
|
|
|
|
|
/** Holds a pointer to the field type describing the data. */
|
|
|
|
|
FFieldClass* FieldType = nullptr;
|
2020-10-09 22:42:26 -04:00
|
|
|
|
|
|
|
|
/** Holds the element index that is targeted if an array/set/map */
|
|
|
|
|
int32 ElementIndex = INDEX_NONE;
|
|
|
|
|
|
|
|
|
|
/** Flags related for the current state */
|
|
|
|
|
EStructSerializerStateFlags StateFlags = EStructSerializerStateFlags::None;
|
2015-09-09 13:45:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-10-01 18:20:53 -04:00
|
|
|
/**
|
|
|
|
|
* Interface for UStruct serializer backends.
|
|
|
|
|
*/
|
|
|
|
|
class IStructSerializerBackend
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Signals the beginning of an array.
|
|
|
|
|
*
|
2015-09-09 13:45:13 -04:00
|
|
|
* State.ValueProperty points to the property that holds the array.
|
|
|
|
|
*
|
|
|
|
|
* @param State The serializer's current state.
|
|
|
|
|
* @see BeginStructure, EndArray
|
2014-10-01 18:20:53 -04:00
|
|
|
*/
|
2015-09-09 13:45:13 -04:00
|
|
|
virtual void BeginArray(const FStructSerializerState& State) = 0;
|
2014-10-01 18:20:53 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Signals the beginning of a child structure.
|
|
|
|
|
*
|
2015-09-09 13:45:13 -04:00
|
|
|
* State.ValueProperty points to the property that holds the struct.
|
2014-10-01 18:20:53 -04:00
|
|
|
*
|
2015-09-09 13:45:13 -04:00
|
|
|
* @param State The serializer's current state.
|
|
|
|
|
* @see BeginArray, EndStructure
|
2014-10-01 18:20:53 -04:00
|
|
|
*/
|
2015-09-09 13:45:13 -04:00
|
|
|
virtual void BeginStructure(const FStructSerializerState& State) = 0;
|
2014-10-01 18:20:53 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Signals the end of an array.
|
|
|
|
|
*
|
2015-09-09 13:45:13 -04:00
|
|
|
* State.ValueProperty points to the property that holds the array.
|
|
|
|
|
*
|
|
|
|
|
* @param State The serializer's current state.
|
|
|
|
|
* @see BeginArray, EndStructure
|
2014-10-01 18:20:53 -04:00
|
|
|
*/
|
2015-09-09 13:45:13 -04:00
|
|
|
virtual void EndArray(const FStructSerializerState& State) = 0;
|
2014-10-01 18:20:53 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Signals the end of an object.
|
2015-09-09 13:45:13 -04:00
|
|
|
*
|
|
|
|
|
* State.ValueProperty points to the property that holds the struct.
|
|
|
|
|
*
|
|
|
|
|
* @param State The serializer's current state.
|
|
|
|
|
* @see BeginStructure, EndArray
|
2014-10-01 18:20:53 -04:00
|
|
|
*/
|
2015-09-09 13:45:13 -04:00
|
|
|
virtual void EndStructure(const FStructSerializerState& State) = 0;
|
2014-10-01 18:20:53 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Writes a comment to the output stream.
|
|
|
|
|
*
|
|
|
|
|
* @param Comment The comment text.
|
2015-09-09 13:45:13 -04:00
|
|
|
* @see BeginArray, BeginStructure, EndArray, EndStructure, WriteProperty
|
2014-10-01 18:20:53 -04:00
|
|
|
*/
|
2015-09-09 13:45:13 -04:00
|
|
|
virtual void WriteComment(const FString& Comment) = 0;
|
2014-10-01 18:20:53 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Writes a property to the output stream.
|
|
|
|
|
*
|
|
|
|
|
* Depending on the context, properties to be written can be either object properties or array elements.
|
|
|
|
|
*
|
2015-09-09 14:24:58 -04:00
|
|
|
* State.KeyProperty points to the key property that holds the data to write.
|
|
|
|
|
* State.KeyData points to the key property's data.
|
2015-09-09 13:45:13 -04:00
|
|
|
* State.ValueProperty points to the property that holds the value to write.
|
|
|
|
|
* State.ValueData points to the actual data to write.
|
|
|
|
|
* State.TypeInfo contains the data's type information
|
|
|
|
|
* State.ArrayIndex is the optional index if the data is a value in an array.
|
|
|
|
|
*
|
|
|
|
|
* @param State The serializer's current state.
|
|
|
|
|
* @see BeginArray, BeginStructure, EndArray, EndStructure, WriteComment
|
2014-10-01 18:20:53 -04:00
|
|
|
*/
|
2015-09-09 13:45:13 -04:00
|
|
|
virtual void WriteProperty(const FStructSerializerState& State, int32 ArrayIndex = 0) = 0;
|
2014-10-01 18:20:53 -04:00
|
|
|
|
2021-02-03 14:57:28 -04:00
|
|
|
/**
|
|
|
|
|
* Writes a POD Array property to the output stream.
|
|
|
|
|
* @note implementations will support only a Int8 or Byte array at the moment
|
|
|
|
|
*
|
|
|
|
|
* State.ValueProperty points to the property that holds the value to write. needs to be an ArrayProperty with a properly supported InnerProperty.
|
|
|
|
|
* State.ValueData points to the actual data to write. The array itself in this case
|
|
|
|
|
* State.TypeInfo contains the data's type information
|
|
|
|
|
*
|
|
|
|
|
* @param State The serializer's current state.
|
|
|
|
|
* @return true if the array was properly written entirely as a pod array, false is we need to fallback to per element serialization
|
|
|
|
|
* @see BeginArray, BeginStructure, EndArray, EndStructure, WriteComment
|
|
|
|
|
*/
|
|
|
|
|
virtual bool WritePODArray(const FStructSerializerState& State) { return false; };
|
|
|
|
|
|
2014-10-01 18:20:53 -04:00
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/** Virtual destructor. */
|
2014-10-24 12:00:50 -04:00
|
|
|
virtual ~IStructSerializerBackend() { }
|
2014-10-01 18:20:53 -04:00
|
|
|
};
|