2021-03-30 18:22:10 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "MetasoundFrontendRegistryTransaction.h"
|
|
|
|
|
|
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
|
|
|
|
|
|
namespace Metasound
|
|
|
|
|
{
|
|
|
|
|
namespace Frontend
|
|
|
|
|
{
|
|
|
|
|
FRegistryTransactionID GetOriginRegistryTransactionID()
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FRegistryTransactionHistory::FRegistryTransactionHistory()
|
|
|
|
|
: Current(GetOriginRegistryTransactionID())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FRegistryTransactionID FRegistryTransactionHistory::Add(TUniquePtr<IRegistryTransaction>&& InRegistryTransaction)
|
|
|
|
|
{
|
|
|
|
|
FScopeLock Lock(&RegistryTransactionMutex);
|
|
|
|
|
|
|
|
|
|
if (ensure(InRegistryTransaction.IsValid()))
|
|
|
|
|
{
|
|
|
|
|
Current++;
|
|
|
|
|
|
|
|
|
|
IRegistryTransaction* RegistryTransactionPointer = InRegistryTransaction.Get();
|
|
|
|
|
int32 Index = RegistryTransactions.Num();
|
|
|
|
|
|
|
|
|
|
RegistryTransactions.Add(MoveTemp(InRegistryTransaction));
|
|
|
|
|
RegistryTransactionIndexMap.Add(Current, Index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FRegistryTransactionID FRegistryTransactionHistory::Add(const IRegistryTransaction& InRegistryTransaction)
|
|
|
|
|
{
|
|
|
|
|
return Add(InRegistryTransaction.Clone());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FRegistryTransactionID FRegistryTransactionHistory::GetCurrent() const
|
|
|
|
|
{
|
|
|
|
|
FScopeLock Lock(&RegistryTransactionMutex);
|
|
|
|
|
{
|
|
|
|
|
return Current;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TArray<const IRegistryTransaction*> FRegistryTransactionHistory::GetTransactions(FRegistryTransactionID InSince, FRegistryTransactionID* OutCurrent) const
|
|
|
|
|
{
|
|
|
|
|
FScopeLock Lock(&RegistryTransactionMutex);
|
|
|
|
|
{
|
|
|
|
|
TArray<const IRegistryTransaction*> Result;
|
|
|
|
|
|
|
|
|
|
if (nullptr != OutCurrent)
|
|
|
|
|
{
|
|
|
|
|
*OutCurrent = Current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32 Start = INDEX_NONE;
|
|
|
|
|
|
|
|
|
|
if (GetOriginRegistryTransactionID() == InSince)
|
|
|
|
|
{
|
|
|
|
|
Start = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (const int32* Pos = RegistryTransactionIndexMap.Find(InSince))
|
|
|
|
|
{
|
|
|
|
|
Start = *Pos + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (INDEX_NONE != Start)
|
|
|
|
|
{
|
|
|
|
|
const int32 Num = RegistryTransactions.Num();
|
|
|
|
|
|
|
|
|
|
if (ensure(Start <= Num))
|
|
|
|
|
{
|
|
|
|
|
const int32 OutNum = Num - Start;
|
|
|
|
|
if (OutNum > 0)
|
|
|
|
|
{
|
|
|
|
|
Result.Reserve(OutNum);
|
|
|
|
|
for (int32 i = Start; i < Num; i++)
|
|
|
|
|
{
|
|
|
|
|
Result.Add(RegistryTransactions[i].Get());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 16:46:19 -04:00
|
|
|
FRegistryTransactionPtr MakeAddNodeRegistryTransaction(const FNodeRegistryKey& InKey, const FNodeClassInfo& InInfo)
|
2021-03-30 18:22:10 -04:00
|
|
|
{
|
2021-06-09 18:20:38 -04:00
|
|
|
class FNodeRegistryTransaction : public IRegistryTransaction
|
2021-03-30 18:22:10 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2021-06-14 16:46:19 -04:00
|
|
|
FNodeRegistryTransaction(const FNodeRegistryKey& InKey, const FNodeClassInfo& InNodeClassInfo)
|
2021-03-30 18:22:10 -04:00
|
|
|
: NodeClassInfo(InNodeClassInfo)
|
2021-06-14 16:46:19 -04:00
|
|
|
, Key(InKey)
|
2021-03-30 18:22:10 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 16:46:19 -04:00
|
|
|
virtual ETransactionType GetTransactionType() const override
|
2021-05-27 14:45:41 -04:00
|
|
|
{
|
|
|
|
|
return ETransactionType::Add;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 16:46:19 -04:00
|
|
|
virtual TUniquePtr<IRegistryTransaction> Clone() const override
|
2021-05-27 14:45:41 -04:00
|
|
|
{
|
2021-06-09 18:20:38 -04:00
|
|
|
return MakeUnique<FNodeRegistryTransaction>(*this);
|
2021-05-27 14:45:41 -04:00
|
|
|
}
|
|
|
|
|
|
2021-06-14 16:46:19 -04:00
|
|
|
virtual const FNodeClassInfo* GetNodeClassInfo() const override
|
2021-05-27 14:45:41 -04:00
|
|
|
{
|
|
|
|
|
return &NodeClassInfo;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 16:46:19 -04:00
|
|
|
virtual const FNodeRegistryKey* GetNodeRegistryKey() const override
|
|
|
|
|
{
|
|
|
|
|
return &Key;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-27 14:45:41 -04:00
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
FNodeClassInfo NodeClassInfo;
|
2021-06-14 16:46:19 -04:00
|
|
|
FNodeRegistryKey Key;
|
2021-05-27 14:45:41 -04:00
|
|
|
};
|
|
|
|
|
|
2021-06-14 16:46:19 -04:00
|
|
|
return MakeUnique<FNodeRegistryTransaction>(InKey, InInfo);
|
2021-05-27 14:45:41 -04:00
|
|
|
}
|
|
|
|
|
|
2021-06-14 16:46:19 -04:00
|
|
|
FRegistryTransactionPtr MakeRemoveNodeRegistryTransaction(const FNodeRegistryKey& InKey, const FNodeClassInfo& InInfo)
|
2021-05-27 14:45:41 -04:00
|
|
|
{
|
2021-06-09 18:20:38 -04:00
|
|
|
class FNodeRegistryTransaction : public IRegistryTransaction
|
2021-05-27 14:45:41 -04:00
|
|
|
{
|
|
|
|
|
public:
|
2021-06-14 16:46:19 -04:00
|
|
|
FNodeRegistryTransaction(const FNodeRegistryKey& InKey, const FNodeClassInfo& InNodeClassInfo)
|
2021-05-27 14:45:41 -04:00
|
|
|
: NodeClassInfo(InNodeClassInfo)
|
2021-06-14 16:46:19 -04:00
|
|
|
, Key(InKey)
|
2021-05-27 14:45:41 -04:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 16:46:19 -04:00
|
|
|
virtual ETransactionType GetTransactionType() const override
|
2021-05-27 14:45:41 -04:00
|
|
|
{
|
|
|
|
|
return ETransactionType::Remove;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 16:46:19 -04:00
|
|
|
virtual TUniquePtr<IRegistryTransaction> Clone() const override
|
2021-03-30 18:22:10 -04:00
|
|
|
{
|
2021-06-09 18:20:38 -04:00
|
|
|
return MakeUnique<FNodeRegistryTransaction>(*this);
|
2021-03-30 18:22:10 -04:00
|
|
|
}
|
|
|
|
|
|
2021-06-14 16:46:19 -04:00
|
|
|
virtual const FNodeClassInfo* GetNodeClassInfo() const override
|
2021-03-30 18:22:10 -04:00
|
|
|
{
|
|
|
|
|
return &NodeClassInfo;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 16:46:19 -04:00
|
|
|
virtual const FNodeRegistryKey* GetNodeRegistryKey() const override
|
|
|
|
|
{
|
|
|
|
|
return &Key;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-30 18:22:10 -04:00
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
FNodeClassInfo NodeClassInfo;
|
2021-06-14 16:46:19 -04:00
|
|
|
FNodeRegistryKey Key;
|
2021-03-30 18:22:10 -04:00
|
|
|
};
|
|
|
|
|
|
2021-06-14 16:46:19 -04:00
|
|
|
return MakeUnique<FNodeRegistryTransaction>(InKey, InInfo);
|
2021-03-30 18:22:10 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|