本文整理汇总了C++中CExpression::Calculate方法的典型用法代码示例。如果您正苦于以下问题:C++ CExpression::Calculate方法的具体用法?C++ CExpression::Calculate怎么用?C++ CExpression::Calculate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CExpression
的用法示例。
在下文中一共展示了CExpression::Calculate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetValue
CValue* CParser::GetValue(STR_String& txt, bool bFallbackToText)
{
// returns parsed text into a value,
// empty string returns NULL value !
// if bFallbackToText then unparsed stuff is put into text
CValue* result=NULL;
CExpression* expr = ProcessText(txt);
if (expr) {
result = expr->Calculate();
expr->Release();
}
if (result)
{
// if the parsed stuff lead to an errorvalue, don't return errors, just NULL
if (result->IsError()) {
result->Release();
result=NULL;
if (bFallbackToText) {
if (txt.Length()>0)
{
result = new CStringValue(txt,"");
}
}
}
}
return result;
}
示例2: EXP_ParseInput
/* calculate expression from inputtext */
EXP_ValueHandle EXP_ParseInput(const char* inputtext)
{
CValue* resultval=NULL;
CParser parser;
CExpression* expr = parser.ProcessText(inputtext);
if (expr)
{
resultval = expr->Calculate();
expr->Release();
}
else
{
resultval = new CErrorValue("couldn't parsetext");
}
return (EXP_ValueHandle) resultval;
}
示例3: GetFloat
float CParser::GetFloat(STR_String& txt)
{
// returns parsed text into a float
// empty string returns -1
// AfxMessageBox("parsed string="+txt);
CValue* val=NULL;
float result=-1;
// String tmpstr;
CExpression* expr = ProcessText(txt);
if (expr) {
val = expr->Calculate();
result=(float)val->GetNumber();
val->Release();
expr->Release();
}
// tmpstr.Format("parseresult=%g",result);
// AfxMessageBox(tmpstr);
return result;
}
示例4: Update
bool SCA_PropertyActuator::Update()
{
bool result = false;
bool bNegativeEvent = IsNegativeEvent();
RemoveAllEvents();
if (bNegativeEvent)
return false; // do nothing on negative events
CValue* propowner = GetParent();
CParser parser;
parser.SetContext( propowner->AddRef());
CExpression* userexpr= NULL;
if (m_type==KX_ACT_PROP_TOGGLE)
{
/* dont use */
CValue* newval;
CValue* oldprop = propowner->GetProperty(m_propname);
if (oldprop)
{
newval = new CBoolValue((oldprop->GetNumber()==0.0) ? true:false);
oldprop->SetValue(newval);
} else
{ /* as not been assigned, evaluate as false, so assign true */
newval = new CBoolValue(true);
propowner->SetProperty(m_propname,newval);
}
newval->Release();
}
else if ((userexpr = parser.ProcessText(m_exprtxt))) {
switch (m_type)
{
case KX_ACT_PROP_ASSIGN:
{
CValue* newval = userexpr->Calculate();
CValue* oldprop = propowner->GetProperty(m_propname);
if (oldprop)
{
oldprop->SetValue(newval);
} else
{
propowner->SetProperty(m_propname,newval);
}
newval->Release();
break;
}
case KX_ACT_PROP_ADD:
{
CValue* oldprop = propowner->GetProperty(m_propname);
if (oldprop)
{
// int waarde = (int)oldprop->GetNumber(); /*unused*/
CExpression* expr = new COperator2Expr(VALUE_ADD_OPERATOR,new CConstExpr(oldprop->AddRef()),
userexpr->AddRef());
CValue* newprop = expr->Calculate();
oldprop->SetValue(newprop);
newprop->Release();
expr->Release();
}
break;
}
case KX_ACT_PROP_COPY:
{
if (m_sourceObj)
{
CValue* copyprop = m_sourceObj->GetProperty(m_exprtxt);
if (copyprop)
{
CValue *val = copyprop->GetReplica();
GetParent()->SetProperty(
m_propname,
val);
val->Release();
}
}
break;
}
/* case KX_ACT_PROP_TOGGLE: */ /* accounted for above, no need for userexpr */
default:
{
}
}
userexpr->Release();
}
return result;
}