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


C++ IDataStream::ReadInt8方法代码示例

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


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

示例1: Load

void TGA::Load( const IDataStream& Stream, TGA::SHeader& InOutHeader )
{
	InOutHeader.m_IDLength = Stream.ReadInt8();
	InOutHeader.m_ColorMapType = Stream.ReadInt8();
	InOutHeader.m_ImageType = Stream.ReadInt8();
	InOutHeader.m_ColorMapIndex = Stream.ReadInt16();
	InOutHeader.m_ColorMapNum = Stream.ReadInt16();
	InOutHeader.m_ColorMapDepth = Stream.ReadInt8();
	InOutHeader.m_OriginX = Stream.ReadInt16();
	InOutHeader.m_OriginY = Stream.ReadInt16();
	InOutHeader.m_Width = Stream.ReadInt16();
	InOutHeader.m_Height = Stream.ReadInt16();
	InOutHeader.m_BPP = Stream.ReadInt8();
	InOutHeader.m_Flags = Stream.ReadInt8();
}
开发者ID:Johnicholas,项目名称:EldritchCopy,代码行数:15,代码来源:tga.cpp

示例2: LoadTGA

int Surface::LoadTGA( const IDataStream& Stream )
{
    TGA::SHeader Header;
    TGA::Load( Stream, Header );

    ASSERTDESC( Header.m_ImageType == TGA::EIT_RLE_RBG, "Loading this type of TGA has not been implemented." );

    // Bunch of other checks that may not matter; if ID length and color map are present, I can skip them
    ASSERT( Header.m_IDLength == 0 );
    ASSERT( Header.m_ColorMapType == 0 );
    ASSERT( Header.m_ColorMapIndex == 0 );
    ASSERT( Header.m_ColorMapNum == 0 );
    ASSERT( Header.m_ColorMapDepth == 0 );
    ASSERT( Header.m_OriginX == 0 );
    ASSERT( Header.m_OriginY == 0 );
    ASSERT( Header.m_BPP == 24 );
    ASSERT( Header.m_Flags == 0 );

    int Width = Header.m_Width;
    int Height = Header.m_Height;
    int Stride = ( ( Width + 1 ) * 3 ) & 0xffffffc;	// TODO: Generalize to more than 24-bit images

    Reset( Width, Height, 24 );

    // Read RLE data
    int StridePos = 0;
    int HeightPos = 0;
    byte* pImageData = m_pPixels;
    while( HeightPos < Height )
    {
        byte PacketHeader = Stream.ReadInt8();
        byte PacketSize = 1 + ( PacketHeader & 0x7f );
        if( 0 == ( PacketHeader & 0x80 ) )
        {
            // This is a raw packet
            for( int i = 0; i < PacketSize; ++i )
            {
                *pImageData++ = Stream.ReadInt8();
                *pImageData++ = Stream.ReadInt8();
                *pImageData++ = Stream.ReadInt8();

                StridePos += 3;
                int StrideRemaining = Stride - StridePos;
                if( StrideRemaining < 3 )
                {
                    pImageData += StrideRemaining;
                    StridePos = 0;
                    HeightPos++;
                }
            }
        }
        else
        {
            // This is a run packet
            byte B = Stream.ReadInt8();
            byte G = Stream.ReadInt8();
            byte R = Stream.ReadInt8();

            for( int i = 0; i < PacketSize; ++i )
            {
                *pImageData++ = B;
                *pImageData++ = G;
                *pImageData++ = R;

                StridePos += 3;
                int StrideRemaining = Stride - StridePos;
                if( StrideRemaining < 3 )
                {
                    pImageData += StrideRemaining;
                    StridePos = 0;
                    HeightPos++;
                }
            }
        }
    }

    return 0;
}
开发者ID:Johnicholas,项目名称:EldritchCopy,代码行数:78,代码来源:surface.cpp

示例3: ParseTiny

// NOTE: This is a lot of duplicated code from the value parsing parts
// of Parse(). Could do to clean this up and use common functions.
void ConfigParser::ParseTiny( const IDataStream& Stream )
{
	Array< char >		FirstPart;	// Could be name or context
	Array< char >		SecondPart;	// Name if first part is context
	Array< char >		ValuePart;
	SToken::ETokenType	Type = SToken::ET_None;
	char				QuoteType = '\"';
	bool				StringClosed = false;

	enum EParseState
	{
		EPS_FirstPart,
		EPS_SecondPart,
		EPS_ValuePart,
	} ParseState = EPS_FirstPart;

	while( !Stream.EOS() )
	{
		char c = Stream.ReadInt8();

		if( ParseState == EPS_FirstPart )
		{
			if( c == ' ' || c == '\t' || c == '\n' || c == '\0' )
			{
				// Ignore whitespace
				continue;
			}
			else if( c == ':' )
			{
				FirstPart.PushBack( '\0' );
				ParseState = EPS_SecondPart;
				continue;
			}
			else if( c == '=' )
			{
				FirstPart.PushBack( '\0' );
				ParseState = EPS_ValuePart;
				continue;
			}
			else
			{
				FirstPart.PushBack( c );
			}
		}
		else if( ParseState == EPS_SecondPart )
		{
			if( c == ' ' || c == '\t' || c == '\n' || c == '\0' )
			{
				// Ignore whitespace
				continue;
			}
			else if( c == '=' )
			{
				SecondPart.PushBack( '\0' );
				ParseState = EPS_ValuePart;
				continue;
			}
			else
			{
				SecondPart.PushBack( c );
			}
		}
		else if( ParseState == EPS_ValuePart )
		{
			if( ( ( Type != SToken::ET_String || StringClosed ) && ( c == ' ' || c == '\t' ) ) || c == '\n' || c == '\0' )
			{
				// Parse the value and set the config var
				ValuePart.PushBack( '\0' );

				SimpleString Name = ( SecondPart.Size() > 1 ) ? SecondPart.GetData() : FirstPart.GetData();
				SimpleString Context = ( SecondPart.Size() > 1 ) ? FirstPart.GetData() : "";

				switch( Type )
				{
				case SToken::ET_Bool:
					{
						// Just use the first character to determine truth
						bool Value = false;
						char first = ValuePart[0];
						if( first == 't' || first == 'T' )
						{
							Value = true;
						}
						ConfigManager::SetBool( Name, Value, Context );
					}
					break;
				case SToken::ET_Int:
					{
						int Value = atoi( ValuePart.GetData() );
						ConfigManager::SetInt( Name, Value, Context );
					}
					break;
				case SToken::ET_Float:
					{
						float Value = (float)atof( ValuePart.GetData() );
						ConfigManager::SetFloat( Name, Value, Context );
					}
					break;
//.........这里部分代码省略.........
开发者ID:Johnicholas,项目名称:EldritchCopy,代码行数:101,代码来源:configparser.cpp

示例4: EvaluateConditional

// It might be useful to have some arithmetic parsing for more complex expressions,
// but eventually that would just become writing a whole little language...
// NOTE: This is very error-prone if the format isn't exactly "A OP B", so
// don't use this for anything that the user can touch.
bool ConfigParser::EvaluateConditional( const IDataStream& Stream )
{
	// Parse three tokens: a left side, an operator, and a right side
	// Valid expressions:
	// bool b-op bool
	// int n-op int
	// int n-op float
	// float n-op float
	// float n-op int
	// string s-op string
	// b-op: == !=
	// n-op: < <= > >= == !=
	// s-op: == != ~= ~!= (case-insensitive)

	// Use same rules as above to determine the type of each value
	// This would be a good place to refactor to reuse some code

	SToken::ETokenType LeftSideType = SToken::ET_None;
	SToken::ETokenType RightSideType = SToken::ET_None;

	Array< char > LeftSideString;
	Array< char > OperatorString;
	Array< char > RightSideString;

	char StrMark = '\"';

	// Parse left side
	for(;;)
	{
		char c = Stream.ReadInt8();
		if( c == ' ' || Stream.EOS() )
		{
			LeftSideString.PushBack( '\0' );
			break;
		}
		else
		{
			InnerParse( c, StrMark, LeftSideString, 0, LeftSideType );
		}
	}

	// Parse operator
	for(;;)
	{
		char c = Stream.ReadInt8();
		if( c == ' ' || Stream.EOS() )
		{
			OperatorString.PushBack( '\0' );
			break;
		}
		OperatorString.PushBack( c );
	}

	// Parse right side
	for(;;)
	{
		char c = Stream.ReadInt8();
		if( c == '\0' || c == ' ' || Stream.EOS() )
		{
			RightSideString.PushBack( '\0' );
			break;
		}
		else
		{
			InnerParse( c, StrMark, RightSideString, 0, RightSideType );
		}
	}

	// Evaluate
	if( LeftSideType == RightSideType ||
		( LeftSideType == SToken::ET_Int && RightSideType == SToken::ET_Float ) ||
		( LeftSideType == SToken::ET_Float && RightSideType == SToken::ET_Int ) )
	{
		SimpleString LeftSide = LeftSideString.GetData();
		SimpleString RightSide = RightSideString.GetData();
		SimpleString Operator = OperatorString.GetData();

		if( LeftSideType == SToken::ET_Bool )
		{
			bool LeftSideBool = LeftSide.AsBool();
			bool RightSideBool = RightSide.AsBool();

			if( Operator == "==" )
			{
				return ( LeftSideBool == RightSideBool );
			}
			else if( Operator == "!=" )
			{
				return ( LeftSideBool != RightSideBool );
			}
			else
			{
				DEBUGWARNDESC( "Unknown operator in conditional expression" );
				return false;
			}
		}
//.........这里部分代码省略.........
开发者ID:Johnicholas,项目名称:EldritchCopy,代码行数:101,代码来源:configparser.cpp

示例5: Parse

void ConfigParser::Parse( const IDataStream& Stream )
{
	Array< SToken >	Tokens;
	SToken			Token;
	Token.m_TokenType						= SToken::ET_Name;
	char			StrMark					= 0;	// Stores the character (either ' or ") that opened a string
	SToken			MacroToken;
	List<int>		ArrayCounters;
	Array<char>		CounterCharArray;
	int				LineCount				= 1;

	for(;;)
	{
		char c = Stream.ReadInt8();

		// Skip the UTF-8 byte order mark if present.
		if( UTF8_BOM_0 == static_cast<byte>( c ) )
		{
			CHECK( UTF8_BOM_1 == static_cast<byte>( Stream.ReadInt8() ) );
			CHECK( UTF8_BOM_2 == static_cast<byte>( Stream.ReadInt8() ) );
			c = Stream.ReadInt8();
		}

		if( Stream.EOS() )
		{
			if( Token.m_TokenString.Empty() )
			{
				Token.m_TokenType = SToken::ET_None;
				Tokens.PushBack( Token );
				DEBUGCATPRINTF( "Core", 2, "%s\n", SToken::m_TokenNames[ Token.m_TokenType ] );
			}
			else
			{
				Token.m_TokenString.PushBack( '\0' );
				Tokens.PushBack( Token );
				DEBUGCATPRINTF( "Core", 2, "%s: %s\n", SToken::m_TokenNames[ Token.m_TokenType ], Token.m_TokenString.GetData() );
				Token.m_TokenString.Clear();
			}

			break;
		}

		if( c == '&' )
		{
			if( Token.m_TokenType == SToken::ET_Name )
			{
				// Increment the current counter and add it to the current name.
				ASSERT( ArrayCounters.Size() > 0 );
				List<int>::Iterator CounterIter = ArrayCounters.Back();
				( *CounterIter )++;
				SimpleString CounterString = SimpleString::PrintF( "%d", *CounterIter );
				CounterCharArray.Clear();
				CounterString.FillArray( CounterCharArray );
				Token.m_TokenString.Append( CounterCharArray );
			}
			else if( Token.m_TokenType == SToken::ET_None )
			{
				// Add a new counter
				// Push a counter token that will be replaced with the count int later.
				ArrayCounters.PushBack( -1 );
				Token.m_TokenType = SToken::ET_Counter;
			}
			else if( Token.m_TokenType == SToken::ET_String )
			{
				Token.m_TokenString.PushBack( c );
			}
			else
			{
				WARNDESC( "Unexpected character '&' in token." );
			}
		}
		else if( c == '^' )
		{
			if( Token.m_TokenType == SToken::ET_Name )
			{
				// Add the current counter to the current name.
				ASSERT( ArrayCounters.Size() > 0 );
				List<int>::Iterator CounterIter = ArrayCounters.Back();
				ASSERT( ( *CounterIter ) >= 0 );
				SimpleString CounterString = SimpleString::PrintF( "%d", *CounterIter );
				CounterCharArray.Clear();
				CounterString.FillArray( CounterCharArray );
				Token.m_TokenString.Append( CounterCharArray );
			}
			else if( Token.m_TokenType == SToken::ET_String )
			{
				Token.m_TokenString.PushBack( c );
			}
			else
			{
				WARNDESC( "Unexpected character '^' in token." );
			}
		}
		else if( c == ' ' || c == '\t' )
		{
			switch( Token.m_TokenType )
			{
			case SToken::ET_None:
			case SToken::ET_Equals:
				// Ignore whitespace
//.........这里部分代码省略.........
开发者ID:Johnicholas,项目名称:EldritchCopy,代码行数:101,代码来源:configparser.cpp


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