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


C++ Queue::Size方法代码示例

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


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

示例1: FreeMemory

void HuffmanEncodingTree::FreeMemory( void )
{
	if ( root == 0 )
		return ;
		
	// Use an in-order traversal to delete the tree
	DataStructures::Queue<HuffmanEncodingTreeNode *> nodeQueue;
	
	HuffmanEncodingTreeNode *node;
	
	nodeQueue.Push( root );
	
	while ( nodeQueue.Size() > 0 )
	{
		node = nodeQueue.Pop();
		
		if ( node->left )
			nodeQueue.Push( node->left );
			
		if ( node->right )
			nodeQueue.Push( node->right );
			
		delete node;
	}
	
	// Delete the encoding table
	for ( int i = 0; i < 256; i++ )
		delete [] encodingTable[ i ].encoding;
		
	root = 0;
}
开发者ID:Kaperstone,项目名称:open-samp,代码行数:31,代码来源:DS_HuffmanEncodingTree.cpp

示例2: FreeMemory

void HuffmanEncodingTree::FreeMemory( void )
{
	if ( root == 0 )
		return ;

	// Use an in-order traversal to delete the tree
	DataStructures::Queue<HuffmanEncodingTreeNode *> nodeQueue;

	HuffmanEncodingTreeNode *node;

	nodeQueue.Push( root, _FILE_AND_LINE_  );

	while ( nodeQueue.Size() > 0 )
	{
		node = nodeQueue.Pop();

		if ( node->left )
			nodeQueue.Push( node->left, _FILE_AND_LINE_  );

		if ( node->right )
			nodeQueue.Push( node->right, _FILE_AND_LINE_  );

		RakNet::OP_DELETE(node, _FILE_AND_LINE_);
	}

	// Delete the encoding table
	for ( int i = 0; i < 256; i++ )
		rakFree_Ex(encodingTable[ i ].encoding, _FILE_AND_LINE_ );

	root = 0;
}
开发者ID:Aasagi,项目名称:DICEProgrammingChallenge,代码行数:31,代码来源:DS_HuffmanEncodingTree.cpp

示例3: ExecuteDefaultResult

	virtual void ExecuteDefaultResult(RakNet::Lobby2Message *message) {
		message->DebugPrintf();
		if (message->resultCode==RakNet::REC_SUCCESS && executionPlan.Size())
		{
			AutoExecutionPlanNode aepn = executionPlan.Pop();
			ExecuteCommand(aepn.operation, RakNet::RakString("user%i", aepn.instanceNumber), aepn.instanceNumber);
		}
	}
开发者ID:Darrenbydesign,项目名称:HoloToolkit,代码行数:8,代码来源:Lobby2ClientSample.cpp

示例4: AddFilesFromDirectory

void FileList::AddFilesFromDirectory(const char *applicationDirectory, const char *subDirectory, bool writeHash, bool writeData, bool recursive, FileListNodeContext context)
{



	DataStructures::Queue<char*> dirList;
	char root[260];
	char fullPath[520];
	_finddata_t fileInfo;
	intptr_t dir;
	FILE *fp;
	char *dirSoFar, *fileData;
	dirSoFar=(char*) rakMalloc_Ex( 520, _FILE_AND_LINE_ );
	RakAssert(dirSoFar);

	if (applicationDirectory)
		strcpy(root, applicationDirectory);
	else
		root[0]=0;

	int rootLen=(int)strlen(root);
	if (rootLen)
	{
		strcpy(dirSoFar, root);
		if (FixEndingSlash(dirSoFar))
			rootLen++;
	}
	else
		dirSoFar[0]=0;
	
	if (subDirectory)
	{
		strcat(dirSoFar, subDirectory);
		FixEndingSlash(dirSoFar);
	}
	for (unsigned int flpcIndex=0; flpcIndex < fileListProgressCallbacks.Size(); flpcIndex++)
		fileListProgressCallbacks[flpcIndex]->OnAddFilesFromDirectoryStarted(this, dirSoFar);
	// RAKNET_DEBUG_PRINTF("Adding files from directory %s\n",dirSoFar);
	dirList.Push(dirSoFar, _FILE_AND_LINE_ );
	while (dirList.Size())
	{
		dirSoFar=dirList.Pop();
		strcpy(fullPath, dirSoFar);
		// Changed from *.* to * for Linux compatibility
		strcat(fullPath, "*");


                dir=_findfirst(fullPath, &fileInfo );
		if (dir==-1)
		{
			_findclose(dir);
			rakFree_Ex(dirSoFar, _FILE_AND_LINE_ );
			unsigned i;
			for (i=0; i < dirList.Size(); i++)
				rakFree_Ex(dirList[i], _FILE_AND_LINE_ );
			return;
		}

//		RAKNET_DEBUG_PRINTF("Adding %s. %i remaining.\n", fullPath, dirList.Size());
		for (unsigned int flpcIndex=0; flpcIndex < fileListProgressCallbacks.Size(); flpcIndex++)
			fileListProgressCallbacks[flpcIndex]->OnDirectory(this, fullPath, dirList.Size());

        do
		{
                    // no guarantee these entries are first...
                    if (strcmp("." , fileInfo.name) == 0 ||
                        strcmp("..", fileInfo.name) == 0)
                    {
                        continue;
                    }
                    
			if ((fileInfo.attrib & (_A_HIDDEN | _A_SUBDIR | _A_SYSTEM))==0)
			{
				strcpy(fullPath, dirSoFar);
				strcat(fullPath, fileInfo.name);
				fileData=0;

				for (unsigned int flpcIndex=0; flpcIndex < fileListProgressCallbacks.Size(); flpcIndex++)
					fileListProgressCallbacks[flpcIndex]->OnFile(this, dirSoFar, fileInfo.name, fileInfo.size);

				if (writeData && writeHash)
				{
					fp = fopen(fullPath, "rb");
					if (fp)
					{
						fileData= (char*) rakMalloc_Ex( fileInfo.size+HASH_LENGTH, _FILE_AND_LINE_ );
						RakAssert(fileData);
						fread(fileData+HASH_LENGTH, fileInfo.size, 1, fp);
						fclose(fp);

						unsigned int hash = SuperFastHash(fileData+HASH_LENGTH, fileInfo.size);
						if (RakNet::BitStream::DoEndianSwap())
							RakNet::BitStream::ReverseBytesInPlace((unsigned char*) &hash, sizeof(hash));
						memcpy(fileData, &hash, HASH_LENGTH);

						//					sha1.Reset();
						//					sha1.Update( ( unsigned char* ) fileData+HASH_LENGTH, fileInfo.size );
						//					sha1.Final();
						//					memcpy(fileData, sha1.GetHash(), HASH_LENGTH);
						// File data and hash
//.........这里部分代码省略.........
开发者ID:BrianHarris,项目名称:RakNet,代码行数:101,代码来源:FileList.cpp

示例5: if

void StatisticsHistory::TimeAndValueQueue::ResizeSampleSet( int maxSamples, DataStructures::Queue<StatisticsHistory::TimeAndValue> &histogram, SHDataCategory dataCategory, Time timeClipStart, Time timeClipEnd )
{
	histogram.Clear(_FILE_AND_LINE_);
	if (maxSamples==0)
		return;
	Time timeRange = GetTimeRange();
	if (timeRange==0)
		return;
	if (maxSamples==1)
	{
		StatisticsHistory::TimeAndValue tav;
		tav.time = timeRange;
		tav.val = GetRecentSum();
		histogram.Push(tav, _FILE_AND_LINE_);
		return;
	}
	Time interval = timeRange / maxSamples;
	if (interval==0)
		interval=1;
	unsigned int dataIndex;
	Time timeBoundary;
	StatisticsHistory::TimeAndValue currentSum;
	Time currentTime;
	SHValueType numSamples;
	Time endTime;
	
	numSamples=0;
	endTime = values[values.Size()-1].time;
	dataIndex=0;
	currentTime=values[0].time;
	currentSum.val=0;
	currentSum.time=values[0].time + interval / 2;
	timeBoundary = values[0].time + interval;
	while (timeBoundary <= endTime)
	{
		while (dataIndex < values.Size() && values[dataIndex].time <= timeBoundary)
		{
			currentSum.val += values[dataIndex].val;
			dataIndex++;
			numSamples++;
		}

		if (dataCategory==DC_CONTINUOUS)
		{
			if (dataIndex > 0 &&
				dataIndex < values.Size() &&
				values[dataIndex-1].time < timeBoundary &&
				values[dataIndex].time > timeBoundary)
			{
				SHValueType interpolatedValue = Interpolate(values[dataIndex-1], values[dataIndex], timeBoundary);
				currentSum.val+=interpolatedValue;
				numSamples++;
			}

			if (numSamples > 1)
			{
				currentSum.val /= numSamples;
			}
		}

		histogram.Push(currentSum, _FILE_AND_LINE_);
		currentSum.time=timeBoundary + interval / 2;
		timeBoundary += interval;
		currentSum.val=0;
		numSamples=0;
	}

	
	if ( timeClipStart!=0 && histogram.Size()>=1)
	{
		timeClipStart = histogram.Peek().time+timeClipStart;
		if (histogram.PeekTail().time < timeClipStart)
		{
			histogram.Clear(_FILE_AND_LINE_);
		}
		else if (histogram.Size()>=2 && histogram.Peek().time < timeClipStart)
		{
			StatisticsHistory::TimeAndValue tav;

			do
			{
				tav = histogram.Pop();

				if (histogram.Peek().time == timeClipStart)
				{
					break;
				}
				else if (histogram.Peek().time > timeClipStart)
				{
					StatisticsHistory::TimeAndValue tav2;
					tav2.val = StatisticsHistory::TimeAndValueQueue::Interpolate(tav, histogram.Peek(), timeClipStart);
					tav2.time=timeClipStart;
					histogram.PushAtHead(tav2, 0, _FILE_AND_LINE_);
					break;
				}
			} while (histogram.Size()>=2);
		}
	}

	if ( timeClipEnd!=0 && histogram.Size()>=1)
//.........这里部分代码省略.........
开发者ID:jochao,项目名称:HoloToolkit,代码行数:101,代码来源:StatisticsHistory.cpp

示例6: if

bool RPC4::CallBlocking( const char* uniqueID, RakNet::BitStream * bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, RakNet::BitStream *returnData )
{
	RakNet::BitStream out;
	out.Write((MessageID) ID_RPC_PLUGIN);
	out.Write((MessageID) ID_RPC4_CALL);
	out.WriteCompressed(uniqueID);
	out.Write(true); // Blocking
	if (bitStream)
	{
		bitStream->ResetReadPointer();
        out.AlignWriteToByteBoundary();
		out.Write(bitStream);
	}
	RakAssert(returnData);
	RakAssert(rakPeerInterface);
	ConnectionState cs;
	cs = rakPeerInterface->GetConnectionState(systemIdentifier);
	if (cs!=IS_CONNECTED && cs!=IS_LOOPBACK)
		return false;

	SendUnified(&out,priority,reliability,orderingChannel,systemIdentifier,false);

	returnData->Reset();
	blockingReturnValue.Reset();
	gotBlockingReturnValue=false;
	Packet *packet;
	DataStructures::Queue<Packet*> packetQueue;
	while (gotBlockingReturnValue==false)
	{
		// TODO - block, filter until gotBlockingReturnValue==true or ID_CONNECTION_LOST or ID_DISCONNECTION_NOTIFICXATION or ID_RPC_REMOTE_ERROR/RPC_ERROR_FUNCTION_NOT_REGISTERED
		RakSleep(30);

		packet=rakPeerInterface->Receive();

		if (packet)
		{
			if (
				(packet->data[0]==ID_CONNECTION_LOST || packet->data[0]==ID_DISCONNECTION_NOTIFICATION) &&
				((systemIdentifier.rakNetGuid!=UNASSIGNED_RAKNET_GUID && packet->guid==systemIdentifier.rakNetGuid) ||
				(systemIdentifier.systemAddress!=UNASSIGNED_SYSTEM_ADDRESS && packet->systemAddress==systemIdentifier.systemAddress))
				)
			{
				// Push back to head in reverse order
				rakPeerInterface->PushBackPacket(packet,true);
				while (packetQueue.Size())
					rakPeerInterface->PushBackPacket(packetQueue.Pop(),true);
				return false;
			}
			else if (packet->data[0]==ID_RPC_REMOTE_ERROR && packet->data[1]==RPC_ERROR_FUNCTION_NOT_REGISTERED)
			{
				RakNet::RakString functionName;
				RakNet::BitStream bsIn(packet->data,packet->length,false);
				bsIn.IgnoreBytes(2);
				bsIn.Read(functionName);
				if (functionName==uniqueID)
				{
					// Push back to head in reverse order
					rakPeerInterface->PushBackPacket(packet,true);
					while (packetQueue.Size())
						rakPeerInterface->PushBackPacket(packetQueue.Pop(),true);
					return false;
				}
				else
				{
					packetQueue.PushAtHead(packet,0,_FILE_AND_LINE_);
				}
			}
			else
			{
				packetQueue.PushAtHead(packet,0,_FILE_AND_LINE_);
			}
		}
	}

	returnData->Read(blockingReturnValue);
	return true;
}
开发者ID:DevCortez,项目名称:vaultmp,代码行数:77,代码来源:RPC4Plugin.cpp

示例7: main


//.........这里部分代码省略.........
					// Connection lost normally
					printf("ID_ALREADY_CONNECTED\n");
					break;
				case ID_CONNECTION_BANNED: // Banned from this server
					printf("We are banned from this server.\n");
					break;			
				case ID_CONNECTION_ATTEMPT_FAILED:
					printf("Connection attempt failed\n");
					break;
				case ID_NO_FREE_INCOMING_CONNECTIONS:
					// Sorry, the server is full.  I don't do anything here but
					// A real app should tell the user
					printf("ID_NO_FREE_INCOMING_CONNECTIONS\n");
					break;
				case ID_INVALID_PASSWORD:
					printf("ID_INVALID_PASSWORD\n");
					break;
				case ID_CONNECTION_LOST:
					// Couldn't deliver a reliable packet - i.e. the other system was abnormally
					// terminated
					printf("ID_CONNECTION_LOST\n");
					break;
				case ID_CONNECTION_REQUEST_ACCEPTED:
					// This tells the rakPeer1 they have connected
					printf("ID_CONNECTION_REQUEST_ACCEPTED\n");
					int j;
					for (j=0; j < NUM_CONNECTIONS; j++)
						lobby2Client[j].SetServerAddress(packet->systemAddress);
					if (i==NUM_CONNECTIONS-1)
					{
						PrintCommands(&messageFactory);
						printf("Enter instance number 1 to %i followed by command number.\n", NUM_CONNECTIONS);

						if (executionPlan.Size())
						{
							/// Execute the first command now that both clients have connected.
							AutoExecutionPlanNode aepn = executionPlan.Pop();
							ExecuteCommand(aepn.operation, RakNet::RakString("user%i", aepn.instanceNumber), aepn.instanceNumber);
						}
					}
					break;
				case ID_LOBBY2_SERVER_ERROR:
					{
						RakNet::BitStream bs(packet->data,packet->length,false);
						bs.IgnoreBytes(2); // ID_LOBBY2_SERVER_ERROR and error code
						printf("ID_LOBBY2_SERVER_ERROR: ");
						if (packet->data[1]==RakNet::L2SE_UNKNOWN_MESSAGE_ID)
						{
							unsigned int messageId;
							bs.Read(messageId);
							printf("L2SE_UNKNOWN_MESSAGE_ID %i", messageId);
						}
						else
							printf("Unknown");
						printf("\n");				
					}

					break;
				}
			}
		}
		
		
		// This sleep keeps RakNet responsive
		RakSleep(30);
开发者ID:Darrenbydesign,项目名称:HoloToolkit,代码行数:66,代码来源:Lobby2ClientSample.cpp

示例8: Send

void FileListTransfer::Send(FileList *fileList, RakPeerInterface *rakPeer, PlayerID recipient, unsigned short setID, PacketPriority priority, char orderingChannel, bool compressData)
{
	RakNet::BitStream outBitstream, encodedData;
	HuffmanEncodingTree tree;
	unsigned int frequencyTable[ 256 ];
	unsigned int i,j;
	unsigned totalCompressedLength, totalLength;
	DataStructures::Queue<FileListNode> compressedFiles;
	FileListNode n;

	if (compressData)
	{
		memset(frequencyTable,0,256*sizeof(unsigned int));

		for (i=0; i < fileList->fileList.Size(); i++)
		{
			for (j=0; j < fileList->fileList[i].dataLength; j++)
			{
				++frequencyTable[(unsigned char)(fileList->fileList[i].data[j])];
			}
		}

		tree.GenerateFromFrequencyTable(frequencyTable);

		// Compress all the files, so we know the total compressed size to be sent
		totalCompressedLength=totalLength=0;
		for (i=0; i < fileList->fileList.Size(); i++)
		{
			encodedData.Reset();
			// Why send compressed chunks if we are not sending the whole file?
			assert(fileList->fileList[i].fileLength==fileList->fileList[i].fileLength);
			tree.EncodeArray((unsigned char*)fileList->fileList[i].data, fileList->fileList[i].dataLength, &encodedData);
			n.dataLength=encodedData.GetNumberOfBitsUsed();
			totalCompressedLength+=BITS_TO_BYTES(n.dataLength);
			totalLength+=fileList->fileList[i].fileLength;
			n.data = new char[BITS_TO_BYTES(n.dataLength)];
			memcpy(n.data, encodedData.GetData(), BITS_TO_BYTES(n.dataLength));
			compressedFiles.Push(n);
		}
	}

	// Write the chunk header, which contains the frequency table, the total number of files, and the total number of bytes
	bool anythingToWrite;
	outBitstream.Write((unsigned char)ID_FILE_LIST_TRANSFER_HEADER);
	outBitstream.Write(setID);
	anythingToWrite=fileList->fileList.Size()>0;
	outBitstream.Write(anythingToWrite);
	if (anythingToWrite)
	{
		if (compressData)
		{
			outBitstream.Write(true);
			for (i=0; i < 256; i++)
				outBitstream.WriteCompressed(frequencyTable[i]);
			outBitstream.WriteCompressed(fileList->fileList.Size());
			outBitstream.WriteCompressed(totalLength);
			outBitstream.WriteCompressed(totalCompressedLength);
		}
		else
		{
			outBitstream.Write(false);
			outBitstream.WriteCompressed(fileList->fileList.Size());
			outBitstream.WriteCompressed(totalLength);
		}
		
		rakPeer->Send(&outBitstream, priority, RELIABLE_ORDERED, orderingChannel, recipient, false);

		// Send each possibly compressed file
		for (i=0; i < compressedFiles.Size(); i++)
		{
			outBitstream.Reset();
			outBitstream.Write((unsigned char)ID_FILE_LIST_TRANSFER_FILE);
			outBitstream.Write(fileList->fileList[i].context);
			outBitstream.Write(setID);
			outBitstream.WriteCompressed(i);
			outBitstream.WriteCompressed(fileList->fileList[i].dataLength); // Original length
			if (compressData)
				outBitstream.WriteCompressed(compressedFiles[i].dataLength); // Compressed bitlength			}
			stringCompressor->EncodeString(fileList->fileList[i].filename, 512, &outBitstream);
			if (compressData)
			{
				outBitstream.WriteBits((const unsigned char*)compressedFiles[i].data, compressedFiles[i].dataLength);
				delete [] compressedFiles[i].data;
			}
			else
				outBitstream.WriteBits((const unsigned char*)fileList->fileList[i].data, fileList->fileList[i].dataLength);
			
			rakPeer->Send(&outBitstream, priority, RELIABLE_ORDERED, orderingChannel, recipient, false);
		}
	}
	else
		rakPeer->Send(&outBitstream, priority, RELIABLE_ORDERED, orderingChannel, recipient, false);
}
开发者ID:proton,项目名称:ireon,代码行数:93,代码来源:FileListTransfer.cpp

示例9: AddFilesFromDirectory

void FileList::AddFilesFromDirectory(const char *applicationDirectory, const char *subDirectory, bool writeHash, bool writeData, bool recursive, unsigned char context)
{
#ifndef _COMPATIBILITY_2
	DataStructures::Queue<char*> dirList;
	char root[260];
	char fullPath[520];
	_finddata_t fileInfo;
	intptr_t dir;
	int file;
	FILE *fp;
	CSHA1 sha1;
	char *dirSoFar, *fileData;
	dirSoFar=new char[520];

	if (applicationDirectory)
		strcpy(root, applicationDirectory);
	else
		root[0]=0;

	int rootLen=(int)strlen(root);
	if (rootLen)
	{
		strcpy(dirSoFar, root);
		if (dirSoFar[strlen(dirSoFar)-1]!='/' && dirSoFar[strlen(dirSoFar)-1]!='\\')
		{
			strcat(dirSoFar, "/");
			rootLen++;
		}
	}
	else
		dirSoFar[0]=0;
	
	if (subDirectory)
	{
		strcat(dirSoFar, subDirectory);
		if (dirSoFar[strlen(dirSoFar)-1]!='/' && dirSoFar[strlen(dirSoFar)-1]!='\\')
		{
			strcat(dirSoFar, "/");
		}
	}
	dirList.Push(dirSoFar);
	while (dirList.Size())
	{
		dirSoFar=dirList.Pop();
		strcpy(fullPath, dirSoFar);
		strcat(fullPath, "*.*");
		dir=_findfirst(fullPath, &fileInfo ); // Read .
		if (dir==-1)
		{
			_findclose(dir);
			delete [] dirSoFar;
			unsigned i;
			for (i=0; i < dirList.Size(); i++)
				delete [] dirList[i];
			return;
		}
		file=_findnext(dir, &fileInfo ); // Read ..
		file=_findnext(dir, &fileInfo ); // Skip ..

		while (file!=-1)
		{
			if ((fileInfo.attrib & (_A_HIDDEN | _A_SUBDIR | _A_SYSTEM))==0)
			{
				strcpy(fullPath, dirSoFar);
				strcat(fullPath, fileInfo.name);
				if (writeData && writeHash)
					fileData= new char [fileInfo.size+SHA1_LENGTH];
				else
					fileData= new char [fileInfo.size];
				fp = fopen(fullPath, "rb");
				if (writeData && writeHash)
					fread(fileData+SHA1_LENGTH, fileInfo.size, 1, fp);
				else
					fread(fileData, fileInfo.size, 1, fp);
				fclose(fp);

				if (writeData && writeHash)
				{
					sha1.Reset();
					sha1.Update( ( unsigned char* ) fileData+SHA1_LENGTH, fileInfo.size );
					sha1.Final();
					memcpy(fileData, sha1.GetHash(), SHA1_LENGTH);
					AddFile((const char*)fullPath+rootLen, fileData, fileInfo.size+SHA1_LENGTH, fileInfo.size, context);
				}
				else if (writeHash)
				{
					sha1.Reset();
					sha1.Update( ( unsigned char* ) fileData, fileInfo.size );
					sha1.Final();
					AddFile((const char*)fullPath+rootLen, (const char*)sha1.GetHash(), SHA1_LENGTH, fileInfo.size, context);
				}
				else if (writeData)
				{
					AddFile(fullPath+rootLen, fileData, fileInfo.size, fileInfo.size, context);
				}
				else
					AddFile(fullPath+rootLen, 0, 0, fileInfo.size, context);

				delete [] fileData;
			}
//.........这里部分代码省略.........
开发者ID:Kaperstone,项目名称:open-samp,代码行数:101,代码来源:FileList.cpp


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