本文整理汇总了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;
}