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


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

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


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

示例1: GenerateUnique

int CMarkovWordGenerator::GenerateUnique (int iCount, TArray<CString> *retArray)

//	GenerateUnique
//
//	Generates an array of unique words

	{
	int i;
	TMap<CString, DWORD> Generated;

	for (i = 0; i < iCount; i++)
		{
		int iTriesLeft = 500;

		while (iTriesLeft > 0)
			{
			//	Generate a random word

			CString sWord = Generate();

			//	Lookup the word in our map. If we found it,
			//	try again.

			if (Generated.Find(sWord))
				{
				iTriesLeft--;
				continue;
				}

			//	If it is unique, add it

			Generated.Insert(sWord, 1);
			break;
			}

		//	If we couldn't find a unique word, then quit

		if (iTriesLeft == 0)
			break;
		}

	//	Add the entries that we generated to the output array

	CMapIterator j;
	Generated.Reset(j);
	int iGeneratedCount = 0;
	while (Generated.HasMore(j))
		{
		DWORD *pDummy;
		CString sWord = Generated.GetNext(j, &pDummy);
		retArray->Insert(sWord);
		iGeneratedCount++;
		}

	return iGeneratedCount;
	}
开发者ID:Sdw195,项目名称:Transcendence,代码行数:56,代码来源:CMarkovWordGenerator.cpp

示例2: AddFile

void LumpRemapper::AddFile(const char* extension, FResourceFile *file, Type type)
{
	LumpRemapper *iter = remaps.CheckKey(extension);
	if(iter == NULL)
	{
		LumpRemapper remaper(extension);
		remaper.AddFile(file, type);
		remaps.Insert(extension, remaper);
		return;
	}
	iter->AddFile(file, type);
}
开发者ID:JohnnyonFlame,项目名称:ecwolf,代码行数:12,代码来源:lumpremap.cpp

示例3: LoadMap

void LumpRemapper::LoadMap(const char* extension, const char* name, const char* data, unsigned int length)
{
	LumpRemapper *iter = remaps.CheckKey(extension);
	if(iter == NULL)
	{
		LumpRemapper remaper(extension);
		remaper.LoadMap(name, data, length);
		remaps.Insert(extension, remaper);
		return;
	}

	iter->LoadMap(name, data, length);
}
开发者ID:JohnnyonFlame,项目名称:ecwolf,代码行数:13,代码来源:lumpremap.cpp

示例4: Insert

void CStatCounterArray::Insert (const CString &sStat, int iCount, const CString &sSection, const CString &sSort)

//	Insert
//
//	Adds the given stat. If the stat already exists (by name) the counts are added

	{
	if (iCount == 0)
		return;

	ASSERT(!sStat.IsBlank());
	ASSERT(!sSection.IsBlank());

	//	First look for the section

	TMap<CString, SEntry> *pSection = m_Array.Find(sSection);
	if (pSection == NULL)
		pSection = m_Array.Insert(sSection);

	//	Next look for the entry

	SEntry *pEntry = pSection->Find(sStat);
	if (pEntry == NULL)
		{
		pEntry = pSection->Insert(sStat);
		pEntry->iCount = iCount;
		pEntry->sSort = sSort;
		}
	else
		{
		if (iCount > pEntry->iCount)
			pEntry->sSort = sSort;

		pEntry->iCount += iCount;
		}
	}
开发者ID:Sdw195,项目名称:Transcendence,代码行数:36,代码来源:CPlayerGameStats.cpp

示例5: TestIntervalTree

void CTestRangeMap::TestIntervalTree(void) const
{
    Filling("CIntervalTree");

    typedef CIntervalTree TMap;
    typedef TMap::const_iterator TMapCI;

    TMap m;

    // fill
    for ( int count = 0; count < m_RangeNumber; ) {
        TRange range = RandomRange();
        m.Insert(range, CConstRef<CObject>(0));
        ++count;
        Added(range);
    }
    
    if ( m_PrintSize ) {
        Filled(m.Size());
        Stat(m.Stat());
    }

    for ( TMapCI i = m.AllIntervals(); i; ++i ) {
        FromAll(i.GetInterval());
    }

    size_t scannedCount = 0;
    for ( int count = 0; count < m_ScanCount; ++count ) {
        for ( int pos = 0; pos <= m_Length + 2*m_RangeLength;
              pos += m_ScanStep ) {
            TRange range(pos, pos + m_ScanLength - 1);
            
            StartFrom(range);
            
            for ( TMapCI i = m.IntervalsOverlapping(range); i; ++i ) {
                From(range, i.GetInterval());
                ++scannedCount;
            }
        }
    }
    PrintTotalScannedNumber(scannedCount);

    End();
}
开发者ID:,项目名称:,代码行数:44,代码来源:

示例6: COOP_PotentiallyStoreUVDPickup

//*****************************************************************************
//
void COOP_PotentiallyStoreUVDPickup ( const PClass *pType )
{
	// [BB] The current game mode doesn't need voodoo dolls, so no need to store any pickups.
	if ( COOP_VoodooDollsSelectedByGameMode() == false )
		return;

	// [BB] There is no ingame joining in such gamemodes, so no need to store any pickups.
	if ( GAMEMODE_GetFlags( GAMEMODE_GetCurrentMode( )) & GMF_MAPRESETS )
		return;

	// [BB] Nothing to store.
	if ( pType == NULL )
		return;

	// [BB] We only store weapons and keys since they might be crucial to finish a map.
	if ( ( pType->IsDescendantOf( RUNTIME_CLASS( AWeapon )) == false )
		&& ( pType->IsDescendantOf( RUNTIME_CLASS( AKey )) == false ) )
		return;

	const FName pickupName = pType->TypeName.GetChars();
	if ( UVDpickupMap.CheckKey( pickupName ) == false )
		UVDpickupMap.Insert( pickupName, 1 );
}
开发者ID:WChrisK,项目名称:Zandronum,代码行数:25,代码来源:cooperative.cpp

示例7: WordGenerator

void WordGenerator (CXMLElement *pCmdLine)
{
    int i;

    //	Load input file

    CString sFilespec = pCmdLine->GetAttribute(CONSTLIT("input"));
    if (sFilespec.IsBlank())
    {
        printf("ERROR: input filename expected.\n");
        return;
    }

    CFileReadBlock InputFile(sFilespec);
    if (InputFile.Open() != NOERROR)
    {
        printf("ERROR: Unable to open file: %s\n", sFilespec.GetASCIIZPointer());
        return;
    }

    //	"Novel" means that we only generate words that are not
    //	in the input file.

    bool bNovelWordsOnly = pCmdLine->GetAttributeBool(NOVEL_ATTRIB);

    //	Build up a word generator

    CMarkovWordGenerator Generator;
    TMap<CString, DWORD> InputWords;

    //	Read each line of the file

    char *pPos = InputFile.GetPointer(0);
    char *pEndPos = pPos + InputFile.GetLength();
    while (pPos < pEndPos)
    {
        //	Skip whitespace

        while (pPos < pEndPos && (strIsWhitespace(pPos) || *pPos < ' '))
            pPos++;

        //	Parse the line

        char *pStart = pPos;
        while (pPos < pEndPos && *pPos != '\r' && *pPos != '\n' && *pPos >= ' ')
            pPos++;

        CString sWord(pStart, pPos - pStart);

        //	Add the word to the generator

        if (!sWord.IsBlank())
        {
            Generator.AddSample(strTrimWhitespace(sWord));

            //	If we are looking for novel words we need to keep a map
            //	of all words in the input file.

            if (bNovelWordsOnly)
                InputWords.Insert(sWord);
        }
    }

    //	If we have a count, then output a list of random words

    int iCount;
    if (pCmdLine->FindAttributeInteger(COUNT_ATTRIB, &iCount))
    {
        if (iCount > 0)
        {
            TArray<CString> Result;
            Generator.GenerateUnique(iCount, &Result);

            for (i = 0; i < Result.GetCount(); i++)
                if (InputWords.Find(Result[i]))
                {
                    Result.Delete(i);
                    i--;
                }

            Result.Sort();

            for (i = 0; i < Result.GetCount(); i++)
                printf("%s\n", Result[i].GetASCIIZPointer());
        }
    }

    //	Otherwise, output the generator as XML

    else
    {
        CMemoryWriteStream Output;
        if (Output.Create() != NOERROR)
        {
            printf("ERROR: Out of memory.\n");
            return;
        }

        if (Generator.WriteAsXML(&Output) != NOERROR)
        {
//.........这里部分代码省略.........
开发者ID:Ttech,项目名称:Transcendence,代码行数:101,代码来源:Words.cpp

示例8: AddCreator

void FxGlobalFunctionCall::AddCreator(FName methodname, Creator creator)
{
	CreatorMap.Insert(methodname, creator);
}
开发者ID:BenJamesbabala,项目名称:ViZDoom,代码行数:4,代码来源:thingdef_function.cpp

示例9: path


//.........这里部分代码省略.........
		ReadSheetFont(folderdata, FixedWidth, FontHeight, Scale);
		Type = Folder;
	}
	else
	{
		if (nametemplate != nullptr)
		{
			if (!iwadonly)
			{
				for (i = 0; i < lcount; i++)
				{
					int position = lfirst + i;
					mysnprintf(buffer, countof(buffer), nametemplate, i + start);

					lump = TexMan.CheckForTexture(buffer, ETextureType::MiscPatch);
					if (doomtemplate && lump.isValid() && i + start == 121)
					{ // HACKHACK: Don't load STCFN121 in doom(2), because
					  // it's not really a lower-case 'y' but a '|'.
					  // Because a lot of wads with their own font seem to foolishly
					  // copy STCFN121 and make it a '|' themselves, wads must
					  // provide STCFN120 (x) and STCFN122 (z) for STCFN121 to load as a 'y'.
						if (!TexMan.CheckForTexture("STCFN120", ETextureType::MiscPatch).isValid() ||
							!TexMan.CheckForTexture("STCFN122", ETextureType::MiscPatch).isValid())
						{
							// insert the incorrectly named '|' graphic in its correct position.
							position = 124;
						}
					}
					if (lump.isValid())
					{
						Type = Multilump;
						if (position < minchar) minchar = position;
						if (position > maxchar) maxchar = position;
						charMap.Insert(position, TexMan.GetTexture(lump));
					}
				}
			}
			else
			{
				FTexture *texs[256] = {};
				if (lcount > 256 - start) lcount = 256 - start;
				for (i = 0; i < lcount; i++)
				{
					TArray<FTextureID> array;
					mysnprintf(buffer, countof(buffer), nametemplate, i + start);

					TexMan.ListTextures(buffer, array, true);
					for (auto entry : array)
					{
						FTexture *tex = TexMan.GetTexture(entry, false);
						if (tex && tex->SourceLump >= 0 && Wads.GetLumpFile(tex->SourceLump) <= Wads.GetIwadNum() && tex->UseType == ETextureType::MiscPatch)
						{
							texs[i] = tex;
						}
					}
				}
				if (doomtemplate)
				{
					// Handle the misplaced '|'.
					if (texs[121 - '!'] && !texs[120 - '!'] && !texs[122 - '!'] && !texs[124 - '!'])
					{
						texs[124 - '!'] = texs[121 - '!'];
						texs[121 - '!'] = nullptr;
					}
				}
开发者ID:coelckers,项目名称:gzdoom,代码行数:66,代码来源:font.cpp

示例10: ReadSheetFont

void FFont::ReadSheetFont(TArray<FolderEntry> &folderdata, int width, int height, const DVector2 &Scale)
{
	// all valid lumps must be named with a hex number that represents the Unicode character index for its first character,
	TArray<TexPart> part(1, true);
	TMap<int, FTexture*> charMap;
	int minchar = INT_MAX;
	int maxchar = INT_MIN;
	for (auto &entry : folderdata)
	{
		char *endp;
		auto base = ExtractFileBase(entry.name);
		auto position = strtoll(base.GetChars(), &endp, 16);
		if ((*endp == 0 || (*endp == '.' && position >= 0 && position < 0xffff)))	// Sheet fonts may fill in the low control chars.
		{
			auto lump = TexMan.CheckForTexture(entry.name, ETextureType::MiscPatch);
			if (lump.isValid())
			{
				auto tex = TexMan.GetTexture(lump);
				int numtex_x = tex->GetWidth() / width;
				int numtex_y = tex->GetHeight() / height;
				int maxinsheet = int(position) + numtex_x * numtex_y - 1;
				if (minchar > position) minchar = int(position);
				if (maxchar < maxinsheet) maxchar = maxinsheet;

				for (int y = 0; y < numtex_y; y++)
				{
					for (int x = 0; x < numtex_x; x++)
					{
						part[0].OriginX = -width * x;
						part[0].OriginY = -height * y;
						part[0].Image = tex->GetImage();
						FMultiPatchTexture *image = new FMultiPatchTexture(width, height, part, false, false);
						FImageTexture *tex = new FImageTexture(image, "");
						tex->SetUseType(ETextureType::FontChar);
						tex->bMultiPatch = true;
						tex->Width = width;
						tex->Height = height;
						tex->_LeftOffset[0] = 
						tex->_LeftOffset[1] = 
						tex->_TopOffset[0] = 
						tex->_TopOffset[1] = 0;
						tex->Scale = Scale;
						tex->bMasked = true;
						tex->bTranslucent = -1;
						tex->bWorldPanning = true;
						tex->bNoDecals = false;
						tex->SourceLump = -1;	// We do not really care.
						TexMan.AddTexture(tex);
						charMap.Insert(int(position) + x + y * numtex_x, tex);
					}
				}
			}
		}
	}


	FirstChar = minchar;
	bool map1252 = false;
	if (minchar < 0x80 && maxchar >= 0xa0) // should be a settable option, but that'd probably cause more problems than it'd solve.
	{
		if (maxchar < 0x2122) maxchar = 0x2122;
		map1252 = true;
	}
	LastChar = maxchar;
	auto count = maxchar - minchar + 1;
	Chars.Resize(count);
	int fontheight = 0;

	for (int i = 0; i < count; i++)
	{
		auto lump = charMap.CheckKey(FirstChar + i);
		if (lump != nullptr)
		{
			FTexture *pic = *lump;

			auto b = pic->Get8BitPixels(false);

			Chars[i].OriginalPic = pic;
			Chars[i].TranslatedPic = new FImageTexture(new FFontChar1(pic->GetImage()), "");
			Chars[i].TranslatedPic->CopySize(pic);
			Chars[i].TranslatedPic->SetUseType(ETextureType::FontChar);
			TexMan.AddTexture(Chars[i].TranslatedPic);
		}
		Chars[i].XMove = width;
	}

	if (map1252)
	{
		// Move the Windows-1252 characters to their proper place.
		for (int i = 0x80; i < 0xa0; i++)
		{
			if (win1252map[i - 0x80] != i && Chars[i - minchar].TranslatedPic != nullptr && Chars[win1252map[i - 0x80] - minchar].TranslatedPic == nullptr)
			{
				std::swap(Chars[i - minchar], Chars[win1252map[i - 0x80] - minchar]);
			}
		}
	}

	SpaceWidth = width;
}
开发者ID:coelckers,项目名称:gzdoom,代码行数:100,代码来源:font.cpp


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