本文整理汇总了C++中TMap::FindOrAdd方法的典型用法代码示例。如果您正苦于以下问题:C++ TMap::FindOrAdd方法的具体用法?C++ TMap::FindOrAdd怎么用?C++ TMap::FindOrAdd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TMap
的用法示例。
在下文中一共展示了TMap::FindOrAdd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EvaluateTransformCurveData
/**
* Since we don't care about blending, we just change this decoration to OutCurves
* @TODO : Fix this if we're saving vectorcurves and blending
*/
void FRawCurveTracks::EvaluateTransformCurveData(USkeleton * Skeleton, TMap<FName, FTransform>&OutCurves, float CurrentTime, float BlendWeight) const
{
check (Skeleton);
// evaluate the curve data at the CurrentTime and add to Instance
for(auto CurveIter = TransformCurves.CreateConstIterator(); CurveIter; ++CurveIter)
{
const FTransformCurve& Curve = *CurveIter;
// if disabled, do not handle
if (Curve.GetCurveTypeFlag(ACF_Disabled))
{
continue;
}
FSmartNameMapping* NameMapping = Skeleton->SmartNames.GetContainer(USkeleton::AnimTrackCurveMappingName);
// Add or retrieve curve
FName CurveName;
// make sure it was added
if (ensure (NameMapping->GetName(Curve.CurveUid, CurveName)))
{
// note we're not checking Curve.GetCurveTypeFlags() yet
FTransform & Value = OutCurves.FindOrAdd(CurveName);
Value = Curve.Evaluate(CurrentTime, BlendWeight);
}
}
}
示例2: SortSearchResults
void FOnlineSessionSearchQos::SortSearchResults()
{
TMap<FString, int32> RegionCounts;
static const int32 MaxPerRegion = 5;
UE_LOG(LogQos, Verbose, TEXT("Sorting QoS results"));
for (int32 SearchResultIdx = 0; SearchResultIdx < SearchResults.Num();)
{
FString QosRegion;
FOnlineSessionSearchResult& SearchResult = SearchResults[SearchResultIdx];
if (!SearchResult.Session.SessionSettings.Get(SETTING_REGION, QosRegion) || QosRegion.IsEmpty())
{
UE_LOG(LogQos, Verbose, TEXT("Removed Qos search result, invalid region."));
SearchResults.RemoveAtSwap(SearchResultIdx);
continue;
}
int32& ResultCount = RegionCounts.FindOrAdd(QosRegion);
ResultCount++;
if (ResultCount > MaxPerRegion)
{
SearchResults.RemoveAtSwap(SearchResultIdx);
continue;
}
SearchResultIdx++;
}
for (auto& It : RegionCounts)
{
UE_LOG(LogQos, Verbose, TEXT("Region: %s Count: %d"), *It.Key, It.Value);
}
}
示例3: CopyKeys
void FGroupedKeyArea::CopyKeys(FMovieSceneClipboardBuilder& ClipboardBuilder, const TFunctionRef<bool(FKeyHandle, const IKeyArea&)>& KeyMask) const
{
const FIndexEntry* IndexEntry = GlobalIndex.Find(IndexKey);
if (!IndexEntry)
{
return;
}
// Since we are a group of nested key areas, we test the key mask for our key handles, and forward on the results to each key area
// Using ptr as map key is fine here as we know they will not change
TMap<const IKeyArea*, TSet<FKeyHandle>> AllValidHandles;
for (auto& Pair : IndexEntry->HandleToGroup)
{
if (!KeyMask(Pair.Key, *this) || !Groups.IsValidIndex(Pair.Value))
{
continue;
}
const FKeyGrouping& Group = Groups[Pair.Value];
for (const FKeyGrouping::FKeyIndex& KeyIndex : Group.Keys)
{
const IKeyArea& KeyArea = KeyAreas[KeyIndex.AreaIndex].Get();
AllValidHandles.FindOrAdd(&KeyArea).Add(KeyIndex.KeyHandle);
}
}
for (auto& Pair : AllValidHandles)
{
Pair.Key->CopyKeys(ClipboardBuilder, [&](FKeyHandle Handle, const IKeyArea&){
return Pair.Value.Contains(Handle);
});
}
}
示例4: InitSequencePlayer
void UUMGSequencePlayer::InitSequencePlayer( const UWidgetAnimation& InAnimation, UUserWidget& UserWidget )
{
Animation = &InAnimation;
UMovieScene* MovieScene = Animation->MovieScene;
// Cache the time range of the sequence to determine when we stop
TimeRange = MovieScene->GetTimeRange();
RuntimeBindings = NewObject<UMovieSceneBindings>(this);
RuntimeBindings->SetRootMovieScene( MovieScene );
UWidgetTree* WidgetTree = UserWidget.WidgetTree;
TMap<FGuid, TArray<UObject*> > GuidToRuntimeObjectMap;
// Bind to Runtime Objects
for (const FWidgetAnimationBinding& Binding : InAnimation.AnimationBindings)
{
UObject* FoundObject = Binding.FindRuntimeObject( *WidgetTree );
if( FoundObject )
{
TArray<UObject*>& Objects = GuidToRuntimeObjectMap.FindOrAdd(Binding.AnimationGuid);
Objects.Add(FoundObject);
}
}
for( auto It = GuidToRuntimeObjectMap.CreateConstIterator(); It; ++It )
{
RuntimeBindings->AddBinding( It.Key(), It.Value() );
}
}
示例5: GetTrackKeyForTime
void UFaceFXMatineeControl::GetTrackKeyForTime(float InTime, TArray<TPair<int32, const FFaceFXTrackKey*>>& OutResult, TArray<FFaceFXSkelMeshComponentId>* OutNoTracks) const
{
//build a list of all keys for all skelmesh component ids
TMap<int32, TArray<const FFaceFXTrackKey*>> SkelMeshTracks;
TMap<int32, FFaceFXSkelMeshComponentId> SkelMeshIds;
for(const FFaceFXTrackKey& Key : Keys)
{
SkelMeshTracks.FindOrAdd(Key.SkelMeshComponentId.Index).Add(&Key);
if(OutNoTracks && !SkelMeshIds.Contains(Key.SkelMeshComponentId.Index))
{
SkelMeshIds.Add(Key.SkelMeshComponentId.Index, Key.SkelMeshComponentId);
}
}
//then generate the pair results for each skelmesh component
for(auto It = SkelMeshTracks.CreateConstIterator(); It; ++It)
{
const TArray<const FFaceFXTrackKey*>& SkelMeshKeys = It.Value();
const int32 IndexMax = SkelMeshKeys.Num()-1;
int32 Index = INDEX_NONE;
for(; Index < IndexMax && SkelMeshKeys[Index+1]->Time <= InTime; ++Index);
if(Index != INDEX_NONE)
{
OutResult.Add(TPairInitializer<int32, const FFaceFXTrackKey*>(Index, SkelMeshKeys[Index]));
}
else if(OutNoTracks)
{
OutNoTracks->Add(SkelMeshIds.FindChecked(It.Key()));
}
}
}
示例6: CreateTextures
void FSlateRHIResourceManager::CreateTextures( const TArray< const FSlateBrush* >& Resources )
{
DECLARE_SCOPE_CYCLE_COUNTER(TEXT("Loading Slate Textures"), STAT_Slate, STATGROUP_LoadTime);
TMap<FName,FNewTextureInfo> TextureInfoMap;
const uint32 Stride = GPixelFormats[PF_R8G8B8A8].BlockBytes;
for( int32 ResourceIndex = 0; ResourceIndex < Resources.Num(); ++ResourceIndex )
{
const FSlateBrush& Brush = *Resources[ResourceIndex];
const FName TextureName = Brush.GetResourceName();
if( TextureName != NAME_None && !Brush.HasUObject() && !Brush.IsDynamicallyLoaded() && !ResourceMap.Contains(TextureName) )
{
// Find the texture or add it if it doesnt exist (only load the texture once)
FNewTextureInfo& Info = TextureInfoMap.FindOrAdd( TextureName );
Info.bSrgb = (Brush.ImageType != ESlateBrushImageType::Linear);
// Only atlas the texture if none of the brushes that use it tile it and the image is srgb
Info.bShouldAtlas &= ( Brush.Tiling == ESlateBrushTileType::NoTile && Info.bSrgb && AtlasSize > 0 );
// Texture has been loaded if the texture data is valid
if( !Info.TextureData.IsValid() )
{
uint32 Width = 0;
uint32 Height = 0;
TArray<uint8> RawData;
bool bSucceeded = LoadTexture( Brush, Width, Height, RawData );
Info.TextureData = MakeShareable( new FSlateTextureData( Width, Height, Stride, RawData ) );
const bool bTooLargeForAtlas = (Width >= 256 || Height >= 256 || Width >= AtlasSize || Height >= AtlasSize );
Info.bShouldAtlas &= !bTooLargeForAtlas;
if( !bSucceeded || !ensureMsgf( Info.TextureData->GetRawBytes().Num() > 0, TEXT("Slate resource: (%s) contains no data"), *TextureName.ToString() ) )
{
TextureInfoMap.Remove( TextureName );
}
}
}
}
// Sort textures by size. The largest textures are atlased first which creates a more compact atlas
TextureInfoMap.ValueSort( FCompareFNewTextureInfoByTextureSize() );
for( TMap<FName,FNewTextureInfo>::TConstIterator It(TextureInfoMap); It; ++It )
{
const FNewTextureInfo& Info = It.Value();
FName TextureName = It.Key();
FString NameStr = TextureName.ToString();
checkSlow( TextureName != NAME_None );
FSlateShaderResourceProxy* NewTexture = GenerateTextureResource( Info );
ResourceMap.Add( TextureName, NewTexture );
}
}
示例7: EnumerateChunkPartInventory
void FBuildPatchAppManifest::EnumerateChunkPartInventory(const TArray<FGuid>& ChunksRequired, TMap<FGuid, TArray<FFileChunkPart>>& ChunkPartsAvailable) const
{
ChunkPartsAvailable.Empty();
// Use a set to optimize
TSet<FGuid> ChunksReqSet(ChunksRequired);
// For each file in the manifest, check what chunks it is made out of, and grab details for the ones in ChunksRequired
for (auto FileManifestIt = Data->FileManifestList.CreateConstIterator(); FileManifestIt && !FBuildPatchInstallError::HasFatalError(); ++FileManifestIt)
{
const FFileManifestData& FileManifest = *FileManifestIt;
uint64 FileOffset = 0;
for (auto ChunkPartIt = FileManifest.FileChunkParts.CreateConstIterator(); ChunkPartIt && !FBuildPatchInstallError::HasFatalError(); ++ChunkPartIt)
{
const FChunkPartData& ChunkPart = *ChunkPartIt;
if (ChunksReqSet.Contains(ChunkPart.Guid))
{
TArray<FFileChunkPart>& FileChunkParts = ChunkPartsAvailable.FindOrAdd(ChunkPart.Guid);
FFileChunkPart FileChunkPart;
FileChunkPart.Filename = FileManifest.Filename;
FileChunkPart.ChunkPart = ChunkPart;
FileChunkPart.FileOffset = FileOffset;
FileChunkParts.Add(FileChunkPart);
}
FileOffset += ChunkPart.Size;
}
}
}
示例8: Append
void Append(const FNodeClassCounter& Other)
{
for (auto Iterator : Other.NodeClassUsage)
{
uint32& Count = NodeClassUsage.FindOrAdd(Iterator.Key);
Count += Iterator.Value;
}
}
示例9: UpdateDestructibleChunkTM
void UDestructibleComponent::UpdateDestructibleChunkTM(const TArray<const PxRigidActor*>& ActiveActors)
{
//We want to consolidate the transforms so that we update each destructible component once by passing it an array of chunks to update.
//This helps avoid a lot of duplicated work like marking render dirty, computing inverse world component, etc...
TMap<UDestructibleComponent*, TArray<FUpdateChunksInfo> > ComponentUpdateMapping;
//prepare map to update destructible components
TArray<PxShape*> Shapes;
for (const PxRigidActor* RigidActor : ActiveActors)
{
if (const FDestructibleChunkInfo* DestructibleChunkInfo = FPhysxUserData::Get<FDestructibleChunkInfo>(RigidActor->userData))
{
if (GApexModuleDestructible->owns(RigidActor) && DestructibleChunkInfo->OwningComponent.IsValid())
{
Shapes.AddUninitialized(RigidActor->getNbShapes());
int32 NumShapes = RigidActor->getShapes(Shapes.GetData(), Shapes.Num());
for (int32 ShapeIdx = 0; ShapeIdx < Shapes.Num(); ++ShapeIdx)
{
PxShape* Shape = Shapes[ShapeIdx];
int32 ChunkIndex;
if (NxDestructibleActor* DestructibleActor = GApexModuleDestructible->getDestructibleAndChunk(Shape, &ChunkIndex))
{
const physx::PxMat44 ChunkPoseRT = DestructibleActor->getChunkPose(ChunkIndex);
const physx::PxTransform Transform(ChunkPoseRT);
if (UDestructibleComponent* DestructibleComponent = Cast<UDestructibleComponent>(FPhysxUserData::Get<UPrimitiveComponent>(DestructibleActor->userData)))
{
if (DestructibleComponent->IsRegistered())
{
TArray<FUpdateChunksInfo>& UpdateInfos = ComponentUpdateMapping.FindOrAdd(DestructibleComponent);
FUpdateChunksInfo* UpdateInfo = new (UpdateInfos)FUpdateChunksInfo(ChunkIndex, P2UTransform(Transform));
}
}
}
}
Shapes.Empty(Shapes.Num()); //we want to keep largest capacity array to avoid reallocs
}
}
}
//update each component
for (auto It = ComponentUpdateMapping.CreateIterator(); It; ++It)
{
UDestructibleComponent* DestructibleComponent = It.Key();
TArray<FUpdateChunksInfo>& UpdateInfos = It.Value();
if (DestructibleComponent->IsFracturedOrInitiallyStatic())
{
DestructibleComponent->SetChunksWorldTM(UpdateInfos);
}
else
{
//if we haven't fractured it must mean that we're simulating a destructible and so we should update our ComponentToWorld based on the single rigid body
DestructibleComponent->SyncComponentToRBPhysics();
}
}
}
示例10: LoadTexture
void FSlateD3DTextureManager::CreateTextures( const TArray< const FSlateBrush* >& Resources )
{
TMap<FName,FNewTextureInfo> TextureInfoMap;
for( int32 ResourceIndex = 0; ResourceIndex < Resources.Num(); ++ResourceIndex )
{
const FSlateBrush& Brush = *Resources[ResourceIndex];
const FName TextureName = Brush.GetResourceName();
if( TextureName != NAME_None && !ResourceMap.Contains(TextureName) )
{
// Find the texture or add it if it doesn't exist (only load the texture once)
FNewTextureInfo& Info = TextureInfoMap.FindOrAdd( TextureName );
Info.bSrgb = (Brush.ImageType != ESlateBrushImageType::Linear);
// Only atlas the texture if none of the brushes that use it tile it
Info.bShouldAtlas &= (Brush.Tiling == ESlateBrushTileType::NoTile && Info.bSrgb );
if( !Info.TextureData.IsValid())
{
uint32 Width = 0;
uint32 Height = 0;
TArray<uint8> RawData;
bool bSucceeded = LoadTexture( Brush, Width, Height, RawData );
const uint32 Stride = 4; // RGBA
Info.TextureData = MakeShareable( new FSlateTextureData( Width, Height, Stride, RawData ) );
const bool bTooLargeForAtlas = (Width >= 256 || Height >= 256);
Info.bShouldAtlas &= !bTooLargeForAtlas;
if( !bSucceeded )
{
TextureInfoMap.Remove( TextureName );
}
}
}
}
TextureInfoMap.ValueSort( FCompareFNewTextureInfoByTextureSize() );
for( TMap<FName,FNewTextureInfo>::TConstIterator It(TextureInfoMap); It; ++It )
{
const FNewTextureInfo& Info = It.Value();
FName TextureName = It.Key();
FString NameStr = TextureName.ToString();
FSlateShaderResourceProxy* NewTexture = GenerateTextureResource( Info );
ResourceMap.Add( TextureName, NewTexture );
}
}
示例11: GetHistogramCategories
void FVisualLoggerHelpers::GetHistogramCategories(const FVisualLogEntry& EntryItem, TMap<FString, TArray<FString> >& OutCategories)
{
for (const auto& CurrentSample : EntryItem.HistogramSamples)
{
auto& DataNames = OutCategories.FindOrAdd(CurrentSample.GraphName.ToString());
if (DataNames.Find(CurrentSample.DataName.ToString()) == INDEX_NONE)
{
DataNames.Add(CurrentSample.DataName.ToString());
}
}
}
示例12: ScopedContextOverride
TOptional<ECurrentState> FAutoReimportManager::ProcessAdditions(const FTimeLimit& TimeLimit)
{
// Override the global feedback context while we do this to avoid popping up dialogs
TGuardValue<FFeedbackContext*> ScopedContextOverride(GWarn, FeedbackContextOverride.Get());
TGuardValue<bool> ScopedAssetChangesGuard(bGuardAssetChanges, true);
FeedbackContextOverride->GetContent()->SetMainText(GetProgressText());
TMap<FString, TArray<UFactory*>> Factories;
TArray<FString> FactoryExtensions;
FactoryExtensions.Reserve(16);
// Get the list of valid factories
for (TObjectIterator<UClass> It ; It ; ++It)
{
UClass* CurrentClass = (*It);
if (CurrentClass->IsChildOf(UFactory::StaticClass()) && !(CurrentClass->HasAnyClassFlags(CLASS_Abstract)))
{
UFactory* Factory = Cast<UFactory>(CurrentClass->GetDefaultObject());
if (Factory->bEditorImport && Factory->ImportPriority >= 0)
{
FactoryExtensions.Reset();
Factory->GetSupportedFileExtensions(FactoryExtensions);
for (const auto& Ext : FactoryExtensions)
{
auto& Array = Factories.FindOrAdd(Ext);
Array.Add(Factory);
}
}
}
}
for (auto& Pair : Factories)
{
Pair.Value.Sort([](const UFactory& A, const UFactory& B) { return A.ImportPriority > B.ImportPriority; });
}
const IAssetRegistry& Registry = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry").Get();
for (auto& Monitor : DirectoryMonitors)
{
Monitor.ProcessAdditions(Registry, TimeLimit, PackagesToSave, Factories, *FeedbackContextOverride);
yield TOptional<ECurrentState>();
}
return ECurrentState::ProcessModifications;
}
示例13: ExpandFrontierTowardsTarget
// DEPRECATED
void ADEPRECATED_VolumeAdaptiveBuilder::ExpandFrontierTowardsTarget(UDoNNavigationVolumeComponent* current, UDoNNavigationVolumeComponent* neighbor, DoNNavigation::PriorityQueue<UDoNNavigationVolumeComponent*> &frontier, TMap<UDoNNavigationVolumeComponent*, FVector> &entryPointMap, bool &goalFound, UDoNNavigationVolumeComponent* start, UDoNNavigationVolumeComponent* goal, FVector origin, FVector destination, TMap<UDoNNavigationVolumeComponent*, int>& VolumeVsCostMap, bool DrawDebug, TMap<UDoNNavigationVolumeComponent*, TArray<UDoNNavigationVolumeComponent*>> &PathVolumeSolutionMap)
{
if (DrawDebug)
{
DisplayDebugVolume(current, FColor::Red);
DisplayDebugVolume(neighbor, FColor::Blue);
}
float SegmentDist = 0;
FVector nextEntryPoint;
TArray<UDoNNavigationVolumeComponent*> PathSolutionSoFar = PathVolumeSolutionMap.FindOrAdd(current);
nextEntryPoint = NavEntryPointsForTraversal(*entryPointMap.Find(current), current, neighbor, SegmentDist, DrawDebug);
entryPointMap.Add(neighbor, nextEntryPoint);
if (nextEntryPoint == *entryPointMap.Find(current)) // i.e. no traversal solution exists
{
if (DrawDebug)
{
DisplayDebugVolume(current, FColor::Red);
DisplayDebugVolume(neighbor, FColor::Blue);
}
UE_LOG(LogTemp, Log, TEXT("Skipping neighbor due to lack of traversal solution"));
return;
}
//int new_cost = *VolumeVsCostMap.Find(current) + graph.cost(current, next);
int new_cost = *VolumeVsCostMap.Find(current) + SegmentDist;
if (!VolumeVsCostMap.Contains(neighbor) || new_cost < *VolumeVsCostMap.Find(neighbor))
{
PathSolutionSoFar.Add(neighbor);
PathVolumeSolutionMap.Add(neighbor, PathSolutionSoFar);
VolumeVsCostMap.Add(neighbor, new_cost);
float heuristic = FVector::Dist(nextEntryPoint, destination);
int priority = new_cost + heuristic;
if (DrawDebug)
{
DrawDebugLine(GetWorld(), nextEntryPoint, destination, FColor::Red, true, -1.f, 0, 10.f);
FString priorityText = FString::Printf(TEXT("Priority: %d"), priority);
UE_LOG(LogTemp, Log, TEXT("%s"), *priorityText);
}
frontier.put(neighbor, priority);
}
}
示例14:
FText UK2Node_InputKey::GetMenuCategory() const
{
static TMap<FName, FNodeTextCache> CachedCategories;
const FName KeyCategory = InputKey.GetMenuCategory();
const FText SubCategoryDisplayName = FText::Format(LOCTEXT("EventsCategory", "{0} Events"), EKeys::GetMenuCategoryDisplayName(KeyCategory));
FNodeTextCache& NodeTextCache = CachedCategories.FindOrAdd(KeyCategory);
if (NodeTextCache.IsOutOfDate(this))
{
// FText::Format() is slow, so we cache this to save on performance
NodeTextCache.SetCachedText(FEditorCategoryUtils::BuildCategoryString(FCommonEditorCategory::Input, SubCategoryDisplayName), this);
}
return NodeTextCache;
}
示例15: RegisterNets
virtual void RegisterNets(FKismetFunctionContext& Context, UEdGraphNode* Node)
{
FNodeHandlingFunctor::RegisterNets(Context, Node);
const FString BaseNetName = Context.NetNameMap->MakeValidName(Node);
// Create a term to store a bool that determines if we're in the first execution of the node or not
FBPTerminal* FirstRunTerm = Context.CreateLocalTerminal();
FirstRunTerm->Type.PinCategory = CompilerContext.GetSchema()->PC_Boolean;
FirstRunTerm->Source = Node;
FirstRunTerm->Name = BaseNetName + TEXT("_FirstRun");
FirstRunTermMap.Add(Node, FirstRunTerm);
UK2Node_MultiGate* GateNode = Cast<UK2Node_MultiGate>(Node);
// If there is already a data node from expansion phase
if (!GateNode || !GateNode->DataNode)
{
FBPTerminal* DataTerm = Context.CreateLocalTerminal();
DataTerm->Type.PinCategory = CompilerContext.GetSchema()->PC_Int;
DataTerm->Source = Node;
DataTerm->Name = BaseNetName + TEXT("_Data");
DataTermMap.Add(Node, DataTerm);
}
FFunctionScopedTerms& FuncLocals = FunctionTermMap.FindOrAdd(Context.Function);
// Create a local scratch bool for run-time if there isn't already one
if (!FuncLocals.GenericBoolTerm)
{
FuncLocals.GenericBoolTerm = Context.CreateLocalTerminal();
FuncLocals.GenericBoolTerm->Type.PinCategory = CompilerContext.GetSchema()->PC_Boolean;
FuncLocals.GenericBoolTerm->Source = Node;
FuncLocals.GenericBoolTerm->Name = BaseNetName + TEXT("_ScratchBool");
}
// Create a local scratch int for run-time index tracking if there isn't already one
if (!FuncLocals.IndexTerm)
{
FuncLocals.IndexTerm = Context.CreateLocalTerminal();
FuncLocals.IndexTerm->Type.PinCategory = CompilerContext.GetSchema()->PC_Int;
FuncLocals.IndexTerm->Source = Node;
FuncLocals.IndexTerm->Name = BaseNetName + TEXT("_ScratchIndex");
}
}