本文整理汇总了C++中IDataStream::EOS方法的典型用法代码示例。如果您正苦于以下问题:C++ IDataStream::EOS方法的具体用法?C++ IDataStream::EOS怎么用?C++ IDataStream::EOS使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataStream
的用法示例。
在下文中一共展示了IDataStream::EOS方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
uint32 Checksum::Adler32( const IDataStream& Stream )
{
uint32 A = 1;
uint32 B = 0;
int Length = Stream.Size();
for( int Index = 0; Index < Length && !Stream.EOS(); ++Index )
{
A = ( A + Stream.ReadUInt8() ) % Adler32Mod;
B = ( B + A ) % Adler32Mod;
}
return ( B << 16 ) | A;
}
示例2: 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;
//.........这里部分代码省略.........
示例3: 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;
}
}
//.........这里部分代码省略.........
示例4: 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
//.........这里部分代码省略.........