Files
UnrealEngineUWP/Engine/Source/Developer/DerivedDataCache/Public/DerivedDataValueId.h
devin doucette bf8230db59 DDC: Fixes to the cache record and cache value refactor
#rb Zousar.Shaker
#rnx
#preflight 61d93c241a3fd09dcbefcfb8

#ROBOMERGE-AUTHOR: devin.doucette
#ROBOMERGE-SOURCE: CL 18560428 in //UE5/Release-5.0/... via CL 18560448
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v899-18417669)

[CL 18560457 by devin doucette in ue5-release-engine-test branch]
2022-01-10 11:20:18 -05:00

110 lines
2.6 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreTypes.h"
#include "Containers/StringFwd.h"
#include "Memory/MemoryView.h"
#include "String/BytesToHex.h"
#define UE_API DERIVEDDATACACHE_API
class FCbObjectId;
struct FIoHash;
namespace UE::DerivedData
{
/** A 12-byte value that uniquely identifies a value in the context that it was created. */
struct FValueId
{
public:
using ByteArray = uint8[12];
/** Construct a null ID. */
FValueId() = default;
/** Construct an ID from an array of 12 bytes. */
inline explicit FValueId(const ByteArray& Id);
/** Construct an ID from a view of 12 bytes. */
UE_API explicit FValueId(FMemoryView Id);
/** Construct an ID from a Compact Binary Object ID. */
UE_API FValueId(const FCbObjectId& Id);
/** Returns the ID as a Compact Binary Object ID. */
UE_API operator FCbObjectId() const;
/** Construct an ID from a non-zero hash. */
[[nodiscard]] UE_API static FValueId FromHash(const FIoHash& Hash);
/** Construct an ID from a non-empty name. */
[[nodiscard]] UE_API static FValueId FromName(FUtf8StringView Name);
[[nodiscard]] UE_API static FValueId FromName(FWideStringView Name);
/** Returns a reference to the raw byte array for the ID. */
inline const ByteArray& GetBytes() const { return Bytes; }
/** Returns a view of the raw byte array for the ID. */
inline FMemoryView GetView() const { return MakeMemoryView(Bytes); }
/** Whether this is null. */
inline bool IsNull() const;
/** Whether this is not null. */
inline bool IsValid() const { return !IsNull(); }
/** Reset this to null. */
inline void Reset() { *this = FValueId(); }
/** A null ID. */
static const FValueId Null;
private:
alignas(uint32) ByteArray Bytes{};
};
inline const FValueId FValueId::Null;
inline FValueId::FValueId(const ByteArray& Id)
{
FMemory::Memcpy(Bytes, Id, sizeof(ByteArray));
}
inline bool operator==(const FValueId& A, const FValueId& B)
{
return A.GetView().EqualBytes(B.GetView());
}
inline bool operator!=(const FValueId& A, const FValueId& B)
{
return !A.GetView().EqualBytes(B.GetView());
}
inline bool operator<(const FValueId& A, const FValueId& B)
{
return A.GetView().CompareBytes(B.GetView()) < 0;
}
inline uint32 GetTypeHash(const FValueId& Id)
{
return *reinterpret_cast<const uint32*>(Id.GetView().GetData());
}
/** Convert the ID to a 24-character hex string. */
template <typename CharType>
inline TStringBuilderBase<CharType>& operator<<(TStringBuilderBase<CharType>& Builder, const FValueId& Id)
{
UE::String::BytesToHexLower(Id.GetBytes(), Builder);
return Builder;
}
inline bool FValueId::IsNull() const
{
return *this == FValueId();
}
} // UE::DerivedData
#undef UE_API