queue.cpp

来自「VC—网络与通信」· C++ 代码 · 共 72 行

CPP
72
字号
// Queue.cpp: implementation of the Queue class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MirrorGuide.h"
#include "Queue.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Queue::Queue()
{
	pQueue = NULL;
	putIndex = getIndex = 0;

}

Queue::~Queue()
{
	if ( pQueue != NULL )
		_rmtmp ();
}


BOOL Queue::IsEmpty()
{
	if ( pQueue == NULL || getIndex == putIndex )
		return TRUE;
	return FALSE;
}

BOOL Queue::InQueue ( CString string )
{
	if ( pQueue == NULL )
		if ( (pQueue = tmpfile()) == NULL )
		{
			AfxMessageBox ( "Please Email to default@etang.com, error occurs!", NULL, MB_OK );
			exit ( 0 );
		}

	fseek ( pQueue, 0, 2 );
	fputs ( string, pQueue );
	fputs ( "\r\n", pQueue );
	fflush ( pQueue );
	putIndex ++;
	return TRUE;
}

BOOL Queue::GetHead ( CString &string )
{
	if ( pQueue != NULL && !IsEmpty() )
	{
		rewind ( pQueue );
		char buf[1024];
		for ( int i = 0; i <= getIndex; i ++ )
			fgets ( buf, 1024, pQueue );
		getIndex ++;
		string.Format ( "%s", buf );
		string.Delete ( string.GetLength() - 2, 2 );
		return TRUE;
	}
	return FALSE;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?