⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 outstream.cpp

📁 vncviewer_source_1.0
💻 CPP
字号:
/* Copyright (C) 2006 Lucas Gomez  All Rights Reserved.
 * 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */

// INCLUDE FILES
#include "OutStream.h"

//LITERALS

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// OutStream::OutStream()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
OutStream::OutStream()
{

}

// ---------------------------------------------------------------------------
// OutStream::~OutStream()
// Destructor.
// ---------------------------------------------------------------------------
//
OutStream::~OutStream()
{
	iBuf.Close();
}

TInt OutStream::Check(TInt aItemSize,TInt aNItems)
{
	if((iPtr+(aItemSize*aNItems))>iEnd)
	{
		if((iPtr+aItemSize)>iEnd)
			return Overrun(aItemSize,aNItems);
		
		aNItems=(iEnd-iPtr)/aItemSize;
	}
	return aNItems;
}
	
void OutStream::Check(TInt aItemSize)
{
	if(iPtr+aItemSize>iEnd)
		Overrun(aItemSize,1);
}

void OutStream::WriteU8(TInt aU)
{
	Check(1);
	iBuf[iPtr++]=static_cast<TUint8>(aU);
}

void OutStream::WriteU16(TInt aU)
{
	Check(2);
	iBuf[iPtr++]=static_cast<TUint8>(aU>>8);
	iBuf[iPtr++]=static_cast<TUint8>(aU);
}

void OutStream::WriteU32(TInt aU)
{
	Check(4);
	iBuf[iPtr++]=static_cast<TUint8>(aU>>24);
	iBuf[iPtr++]=static_cast<TUint8>(aU>>16);
	iBuf[iPtr++]=static_cast<TUint8>(aU>>8);
	iBuf[iPtr++]=static_cast<TUint8>(aU);
}

void OutStream::WriteS8(TInt aS)
{
	WriteU8(aS);
}

void OutStream::WriteS16(TInt aS)
{
	WriteU16(aS);
}

void OutStream::WriteS32(TInt aS)
{
	WriteU32(aS);
}

void OutStream::WriteString(TDesC8& aStr)
{
	TInt len=aStr.Length();
	WriteU32(len);
	for(TInt i=0;i<len;)
	{
		TInt j=i+Check(1,len-1);
		while(i<j)
		{
			iBuf[iPtr++]=static_cast<TUint8>(aStr[i++]);
		}
	}
}

void OutStream::Pad(TInt aBytes)
{
	while((aBytes--)>0) WriteU8(0);
}

void OutStream::Skip(TInt aBytes)
{
	while(aBytes>0)
	{
		TInt n=Check(1,aBytes);
		iPtr+=n;
		aBytes-=n;
	}
}

void OutStream::WriteBytes(RBuf8& aData,TInt aOffset,TInt aLength)
{
	TInt offsetEnd=aOffset+aLength;
	while(aOffset<offsetEnd)
	{
		TInt n=Check(1,offsetEnd-aOffset);
		for(TInt i=0;i<n;i++)
		{
			iBuf[iPtr++]=aData[aOffset++];
		}
	}
}

void OutStream::WriteOpaque8(TInt aU)
{
	WriteU8(aU);
}

void OutStream::WriteOpaque16(TInt aU)
{
	WriteU16(aU);
}

void OutStream::WriteOpaque32(TInt aU)
{
	WriteU32(aU);
}

void OutStream::WriteOpaque24A(TInt aU)
{
	Check(3);
	iBuf[iPtr++]=static_cast<TUint8>(aU>>24);
	iBuf[iPtr++]=static_cast<TUint8>(aU>>16);
	iBuf[iPtr++]=static_cast<TUint8>(aU>>8);
}

void OutStream::WriteOpaque24B(TInt aU)
{
	Check(3);
	iBuf[iPtr++]=static_cast<TUint8>(aU>>16);
	iBuf[iPtr++]=static_cast<TUint8>(aU>>8);
	iBuf[iPtr++]=static_cast<TUint8>(aU);
}

/*void OutStream::Flush()
{
	// Do nothing
}*/

⌨️ 快捷键说明

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