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


C++ SimpleString::AsBool方法代码示例

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


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

示例1: 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


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