当前位置: 首页>>代码示例>>C++>>正文


C++ TMap::GetKeys方法代码示例

本文整理汇总了C++中TMap::GetKeys方法的典型用法代码示例。如果您正苦于以下问题:C++ TMap::GetKeys方法的具体用法?C++ TMap::GetKeys怎么用?C++ TMap::GetKeys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TMap的用法示例。


在下文中一共展示了TMap::GetKeys方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BuildJsonStrFromMap

FORCEINLINE FString BuildJsonStrFromMap(TMap<FString, FString> Map)
{
	FString JsonStr;
	TSharedRef< TJsonWriter<TCHAR, TCondensedJsonPrintPolicy<TCHAR> > > JsonWriter = TJsonWriterFactory<TCHAR, TCondensedJsonPrintPolicy<TCHAR> >::Create(&JsonStr);
	// Close the writer and finalize the output such that JsonStr has what we want
	TArray<FString> keys;
	Map.GetKeys(keys);
	JsonWriter->WriteObjectStart();
	for (int32 k = 0; k < Map.Num(); k++)
	{
		JsonWriter->WriteValue(keys[k], Map[keys[k]]);
	}
	JsonWriter->WriteObjectEnd();
	JsonWriter->Close();

	return JsonStr;
}
开发者ID:chaiyuntian,项目名称:PhilipsHue,代码行数:17,代码来源:PhilipsHueBridge.cpp

示例2: DumpSharedMemoryUsage

void FPhysxSharedData::DumpSharedMemoryUsage(FOutputDevice* Ar)
{
	struct FSharedResourceEntry
	{
		uint64 MemorySize;
		uint64 Count;
	};

	struct FSortBySize
	{
		FORCEINLINE bool operator()( const FSharedResourceEntry& A, const FSharedResourceEntry& B ) const 
		{ 
			// Sort descending
			return B.MemorySize < A.MemorySize;
		}
	};

	TMap<FString, FSharedResourceEntry> AllocationsByType;

	uint64 OverallSize = 0;
	int32 OverallCount = 0;

	TMap<FString, TArray<PxBase*> > ObjectsByType;

	for (int32 i=0; i < (int32)SharedObjects->getNbObjects(); ++i)
	{
		PxBase& Obj = SharedObjects->getObject(i);
		FString TypeName = ANSI_TO_TCHAR(Obj.getConcreteTypeName());

		TArray<PxBase*>* ObjectsArray = ObjectsByType.Find(TypeName);
		if (ObjectsArray == NULL)
		{
			ObjectsByType.Add(TypeName, TArray<PxBase*>());
			ObjectsArray = ObjectsByType.Find(TypeName);
		}

		check(ObjectsArray);
		ObjectsArray->Add(&Obj);
	}

	TArray<FString> TypeNames;
	ObjectsByType.GetKeys(TypeNames);

	for (int32 TypeIdx=0; TypeIdx < TypeNames.Num(); ++TypeIdx)
	{
		const FString& TypeName = TypeNames[TypeIdx];
		
		TArray<PxBase*>* ObjectsArray = ObjectsByType.Find(TypeName);
		check(ObjectsArray);

		PxSerializationRegistry* Sr = PxSerialization::createSerializationRegistry(*GPhysXSDK);
		PxCollection* Collection = PxCreateCollection();
		
		for (int32 i=0; i < ObjectsArray->Num(); ++i)
		{
			Collection->add(*((*ObjectsArray)[i]));;
		}

		PxSerialization::complete(*Collection, *Sr);	// chase all other stuff (shared shaps, materials, etc) needed to serialize this collection

		FPhysXCountMemoryStream Out;
		PxSerialization::serializeCollectionToBinary(Out, *Collection, *Sr);

		Collection->release();
		Sr->release();

		OverallSize += Out.UsedMemory;
		OverallCount += ObjectsArray->Num();

		FSharedResourceEntry NewEntry;
		NewEntry.Count = ObjectsArray->Num();
		NewEntry.MemorySize = Out.UsedMemory;

		AllocationsByType.Add(TypeName, NewEntry);
	}

	Ar->Logf(TEXT(""));
	Ar->Logf(TEXT("Shared Resources:"));
	Ar->Logf(TEXT(""));

	AllocationsByType.ValueSort(FSortBySize());
	
	Ar->Logf(TEXT("%-10d %s (%d)"), OverallSize, TEXT("Overall"), OverallCount );
	
	for( auto It=AllocationsByType.CreateConstIterator(); It; ++It )
	{
		Ar->Logf(TEXT("%-10d %s (%d)"), It.Value().MemorySize, *It.Key(), It.Value().Count );
	}
}
开发者ID:zhaoyizheng0930,项目名称:UnrealEngine,代码行数:89,代码来源:PhysXSupport.cpp

示例3: ExtractFlipbooksFromSprites

void FPaperFlipbookHelpers::ExtractFlipbooksFromSprites(TMap<FString, TArray<UPaperSprite*> >& OutSpriteFlipbookMap, const TArray<UPaperSprite*>& Sprites, const TArray<FString>& InSpriteNames)
{
	OutSpriteFlipbookMap.Reset();

	// Local copy
	check((InSpriteNames.Num() == 0) || (InSpriteNames.Num() == Sprites.Num()));
	TArray<FString> SpriteNames = InSpriteNames;
	if (InSpriteNames.Num() == 0)
	{
		SpriteNames.Reset();
		for (int32 SpriteIndex = 0; SpriteIndex < Sprites.Num(); ++SpriteIndex)
		{
			check(Sprites[SpriteIndex] != nullptr);
			SpriteNames.Add(Sprites[SpriteIndex]->GetName());
		}
	}

	// Group them
	TMap<FString, UPaperSprite*> SpriteNameMap;
	TArray<UPaperSprite*> RemainingSprites;

	for (int32 SpriteIndex = 0; SpriteIndex < Sprites.Num(); ++SpriteIndex)
	{
		UPaperSprite* Sprite = Sprites[SpriteIndex];
		const FString SpriteName = SpriteNames[SpriteIndex];

		SpriteNameMap.Add(SpriteName, Sprite);

		int32 SpriteNumber = 0;
		FString SpriteBareString;
		if (ExtractSpriteNumber(SpriteName, /*out*/ SpriteBareString, /*out*/ SpriteNumber))
		{
			SpriteBareString = ObjectTools::SanitizeObjectName(SpriteBareString);
			OutSpriteFlipbookMap.FindOrAdd(SpriteBareString).Add(Sprite);
		}
		else
		{
			RemainingSprites.Add(Sprite);
		}
	}

	// Natural sort using the same method as above
	struct FSpriteSortPredicate
	{
		FSpriteSortPredicate() {}

		// Sort predicate operator
		bool operator()(UPaperSprite& LHS, UPaperSprite& RHS) const
		{
			FString LeftString;
			int32 LeftNumber;
			ExtractSpriteNumber(LHS.GetName(), /*out*/ LeftString, /*out*/ LeftNumber);

			FString RightString;
			int32 RightNumber;
			ExtractSpriteNumber(RHS.GetName(), /*out*/ RightString, /*out*/ RightNumber);

			return (LeftString == RightString) ? (LeftNumber < RightNumber) : (LeftString < RightString);
		}
	};

	// Sort sprites
	TArray<FString> Keys;
	OutSpriteFlipbookMap.GetKeys(Keys);
	for (auto SpriteName : Keys)
	{
		OutSpriteFlipbookMap[SpriteName].Sort(FSpriteSortPredicate());
	}

	// Create a flipbook from all remaining sprites
	// Not sure if this is desirable behavior, might want one flipbook per sprite
	if (RemainingSprites.Num() > 0)
	{
		RemainingSprites.Sort(FSpriteSortPredicate());

		const FString DesiredName = GetCleanerSpriteName(RemainingSprites[0]->GetName()) + TEXT("_Flipbook");
		const FString SanitizedName = ObjectTools::SanitizeObjectName(DesiredName);

		OutSpriteFlipbookMap.Add(SanitizedName, RemainingSprites);
	}
}
开发者ID:AndyHuang7601,项目名称:EpicGames-UnrealEngine,代码行数:81,代码来源:PaperFlipbookHelpers.cpp


注:本文中的TMap::GetKeys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。