Skip to content
Snippets Groups Projects
Select Git revision
  • 62366312fc2ea3746bc8d17b4b8f922d4fc48dda
  • 5.4 default protected
  • 5.5
  • dev/5.5
  • dev/5.4
  • dev/5.3_downgrade
  • feature/experimenttime_hack
  • 5.3 protected
  • _IntenSelect5.3
  • IntenSelect5.3
  • 4.27 protected
  • 4.26 protected
  • 5.0 protected
  • 4.22 protected
  • 4.21 protected
  • UE5.4-2024.1
  • UE5.4-2024.1-rc1
  • UE5.3-2023.1-rc3
  • UE5.3-2023.1-rc2
  • UE5.3-2023.1-rc
20 results

ClickBehaviour.cpp

Blame
  • DisplayClusterEventParameterHelper.h 2.80 KiB
    #pragma once
    
    #include "Serialization/MemoryReader.h"
    #include "Serialization/MemoryWriter.h"
    #include "type_traits"
    
    template <typename ParameterType, typename... RemainingParameterTypes>
    inline void SerializeParameters(FMemoryWriter* MemoryWriter, ParameterType&& Parameter,
    								RemainingParameterTypes&&... RemainingParameters)
    {
    	using NonConstType = typename std::remove_cv_t<typename TRemoveReference<ParameterType>::Type>;
    	// const_cast because the same operator (<<) is used for reading and writing
    	(*MemoryWriter) << const_cast<NonConstType&>(Parameter);
    	SerializeParameters(MemoryWriter, Forward<RemainingParameterTypes>(RemainingParameters)...);
    }
    
    inline void SerializeParameters(FMemoryWriter* MemoryWriter) {}
    
    // This is a wrapper function to recursively fill the argument tuple. This overload is only used if the index indicating
    // the currently handled attribute is less than the number of total attributes. I.e., if the attribute index is valid.
    template <int CurrentIndex, typename... ArgTypes>
    inline typename TEnableIf<(CurrentIndex < sizeof...(ArgTypes))>::Type
    FillArgumentTuple(FMemoryReader* MemoryReader, TTuple<ArgTypes...>* ArgumentTuple)
    {
    	// Read the "<<" as ">>" operator here. FArchive uses the same for both and decides based on an internal type on
    	// what to do. So this statement parses the bytes that were passed into reader and puts the parsed object into the
    	// tuple at index CurrentIndex.
    	(*MemoryReader) << ArgumentTuple->template Get<CurrentIndex>();
    
    	// Recursive call for the remaining attributes.
    	FillArgumentTuple<CurrentIndex + 1>(MemoryReader, Forward<TTuple<ArgTypes...>*>(ArgumentTuple));
    }
    
    // The overload that is called if we are "passed the end" of attributes.
    template <int CurrentIndex, typename... ArgTypes>
    inline typename TEnableIf<(CurrentIndex >= sizeof...(ArgTypes))>::Type
    FillArgumentTuple(FMemoryReader* MemoryReader, TTuple<ArgTypes...>* ArgumentTuple)
    {
    }
    
    template <typename RetType, typename... ArgTypes>
    inline RetType CallDelegateWithParameterMap(const TDelegate<RetType, ArgTypes...>& Delegate,
    											const TMap<FString, FString>& Parameters)
    {
    	// Create a tuple that holds all arguments. This assumes that all argument types are default constructible. However,
    	// all types that overload the FArchive "<<" operator probably are.
    	TTuple<typename std::remove_cv_t<typename TRemoveReference<ArgTypes>::Type>...> ArgumentTuple;
    
    	// This call will parse the string map and fill all values in the tuple appropriately.
    	FillArgumentTuple<0>(&ArgumentTuple, Parameters);
    
    	// The lambda function is only necessary because delegates do not overload the ()-operator but use the Execute()
    	// method instead. So, the lambda acts as a wrapper.
    	return ArgumentTuple.ApplyBefore([Delegate](ArgTypes&&... Arguments)
    									 { Delegate.Execute(Forward<ArgTypes>(Arguments)...); });
    }