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


C++ NameList::reserve方法代码示例

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


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

示例1: Execute

void EditQueueBinCommand::Execute()
{
	SNZBEditQueueRequest EditQueueRequest;
	if (!ReceiveRequest(&EditQueueRequest, sizeof(EditQueueRequest)))
	{
		return;
	}

	int iNrIDEntries = ntohl(EditQueueRequest.m_iNrTrailingIDEntries);
	int iNrNameEntries = ntohl(EditQueueRequest.m_iNrTrailingNameEntries);
	int iNameEntriesLen = ntohl(EditQueueRequest.m_iTrailingNameEntriesLen);
	int iAction = ntohl(EditQueueRequest.m_iAction);
	int iMatchMode = ntohl(EditQueueRequest.m_iMatchMode);
	int iOffset = ntohl(EditQueueRequest.m_iOffset);
	int iTextLen = ntohl(EditQueueRequest.m_iTextLen);
	bool bSmartOrder = ntohl(EditQueueRequest.m_bSmartOrder);
	unsigned int iBufLength = ntohl(EditQueueRequest.m_iTrailingDataLength);

	if (iNrIDEntries * sizeof(int32_t) + iTextLen + iNameEntriesLen != iBufLength)
	{
		error("Invalid struct size");
		return;
	}

	char* pBuf = (char*)malloc(iBufLength);

	// Read from the socket until nothing remains
	char* pBufPtr = pBuf;
	int NeedBytes = iBufLength;
	int iResult = 0;
	while (NeedBytes > 0)
	{
		iResult = recv(m_iSocket, pBufPtr, NeedBytes, 0);
		// Did the recv succeed?
		if (iResult <= 0)
		{
			error("invalid request");
			break;
		}
		pBufPtr += iResult;
		NeedBytes -= iResult;
	}
	bool bOK = NeedBytes == 0;

	if (iNrIDEntries <= 0 && iNrNameEntries <= 0)
	{
		SendBoolResponse(false, "Edit-Command failed: no IDs/Names specified");
		return;
	}

	if (bOK)
	{
		char* szText = iTextLen > 0 ? pBuf : NULL;
		int32_t* pIDs = (int32_t*)(pBuf + iTextLen);
		char* pNames = (pBuf + iTextLen + iNrIDEntries * sizeof(int32_t));

		IDList cIDList;
		NameList cNameList;

		if (iNrIDEntries > 0)
		{
			cIDList.reserve(iNrIDEntries);
			for (int i = 0; i < iNrIDEntries; i++)
			{
				cIDList.push_back(ntohl(pIDs[i]));
			}
		}

		if (iNrNameEntries > 0)
		{
			cNameList.reserve(iNrNameEntries);
			for (int i = 0; i < iNrNameEntries; i++)
			{
				cNameList.push_back(pNames);
				pNames += strlen(pNames) + 1;
			}
		}

		if (iAction < eRemoteEditActionPostMoveOffset)
		{
			bOK = g_pQueueCoordinator->GetQueueEditor()->EditList(
				iNrIDEntries > 0 ? &cIDList : NULL,
				iNrNameEntries > 0 ? &cNameList : NULL,
				(QueueEditor::EMatchMode)iMatchMode, bSmartOrder, (QueueEditor::EEditAction)iAction, iOffset, szText);
		}
		else
		{
			bOK = g_pPrePostProcessor->QueueEditList(&cIDList, (PrePostProcessor::EEditAction)iAction, iOffset);
		}
	}

	free(pBuf);

	if (bOK)
	{
		SendBoolResponse(true, "Edit-Command completed successfully");
	}
	else
	{
#ifndef HAVE_REGEX_H
//.........这里部分代码省略.........
开发者ID:Bootz,项目名称:nzbm,代码行数:101,代码来源:BinRpc.cpp


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