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


C++ ExpReturn::GetDouble方法代码示例

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


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

示例1: runtime_error

///////////
// Collapse a constant tree
// If an ExpPart* returns true for Constant(), evaluate it, and reallocate a new
// literal to represent the constant part of that expression.
// Ctor
CollapseConstantTreeObj::CollapseConstantTreeObj(ExpPart*& p)
{
	// Store existing details
	CExpression* pExpression = p->pCExp;
	int tnum = p->tokennum;

	// Create an ExpReturn, evaluate in to it, then delete the old ExpPart.
	ExpReturn e;
	p->Evaluate(&e);

	// For deleting later (the string might be used)
	ExpPart* oldPart = p;

	// Reallocate a literal to represent that part of the tree.
	switch(e.Type()) {
	case EXPTYPE_INTEGER:
		p = new ExpInteger;
		p->t = T_INTEGER;
		static_cast<ExpInteger*>(p)->value = e.GetInt64();
		break;
	case EXPTYPE_FLOAT:
		p = new ExpFloat;
		p->t = T_FLOAT;
		static_cast<ExpFloat*>(p)->value = e.GetDouble();
		break;
	case EXPTYPE_STRING:
		p = new ExpString;
		p->t = T_STRINGLITERAL;
		static_cast<ExpString*>(p)->value = *(e.GetStringPtr());
		break;
	case EXPTYPE_ARRAY:
		// Arrays cannot be folded; they collapse their elements but nothing can be
		// done with a const array
		p = oldPart;
		return;
	case EXPTYPE_VARIABLENAME:
		p = new ExpVariableName;
		static_cast<ExpVariableName*>(p)->index = e.eData.vni.varIndex;
		static_cast<ExpVariableName*>(p)->pOwnerType = e.eData.vni.pOwnerType;
		break;
	default:
		throw runtime_error("Unexpected type in a constant expression");
	}

	// Set the pCExp and tokennum back.
	p->pCExp = pExpression;
	p->tokennum = tnum;

	// Delete the old tree part now
	delete oldPart;
}
开发者ID:aolko,项目名称:construct,代码行数:56,代码来源:ExpTree.cpp


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