本文整理汇总了C++中CBotVar::Eq方法的典型用法代码示例。如果您正苦于以下问题:C++ CBotVar::Eq方法的具体用法?C++ CBotVar::Eq怎么用?C++ CBotVar::Eq使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBotVar
的用法示例。
在下文中一共展示了CBotVar::Eq方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
bool CBotCompExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this);
// if ( pStk1 == EOX ) return TRUE;
if ( pStk1->GetState() == 0 && !m_leftop->Execute(pStk1) ) return FALSE; // interrupted here ?
pStk1->SetState(1); // finished
// requires a little more stack to not touch the result of the left
CBotStack* pStk2 = pStk1->AddStack();
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here ?
int type1 = pStk1->GetType();
int type2 = pStk2->GetType();
CBotVar* result = new CBotVar( NULL, CBotTypBoolean );
switch (GetTokenType())
{
case ID_LO:
result->Lo(pStk1->GetVar(), pStk2->GetVar()); // lower
break;
case ID_HI:
result->Hi(pStk1->GetVar(), pStk2->GetVar()); // higher
break;
case ID_LS:
result->Ls(pStk1->GetVar(), pStk2->GetVar()); // lower or equal
break;
case ID_HS:
result->Hs(pStk1->GetVar(), pStk2->GetVar()); // higher of equal
break;
case ID_EQ:
result->Eq(pStk1->GetVar(), pStk2->GetVar()); // equal
break;
case ID_NE:
result->Ne(pStk1->GetVar(), pStk2->GetVar()); // not equal
break;
}
pStk2->SetVar(result); // puts the result on the stack
pStk1->Return(pStk2); // frees the stack
return pStack->Return(pStk1); // transmit the result
}
示例2: Execute
bool CBotTwoOpExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
// or return in case of recovery
// if ( pStk1 == EOX ) return true;
// according to recovery, it may be in one of two states
if ( pStk1->GetState() == 0 ) // first state, evaluates the left operand
{
if (!m_leftop->Execute(pStk1) ) return false; // interrupted here?
// for OR and AND logic does not evaluate the second expression if not necessary
if ( (GetTokenType() == ID_LOG_AND || GetTokenType() == ID_TXT_AND ) && pStk1->GetVal() == false )
{
CBotVar* res = CBotVar::Create("", CBotTypBoolean);
res->SetValInt(false);
pStk1->SetVar(res);
return pStack->Return(pStk1); // transmits the result
}
if ( (GetTokenType() == ID_LOG_OR||GetTokenType() == ID_TXT_OR) && pStk1->GetVal() == true )
{
CBotVar* res = CBotVar::Create("", CBotTypBoolean);
res->SetValInt(true);
pStk1->SetVar(res);
return pStack->Return(pStk1); // transmits the result
}
// passes to the next step
pStk1->SetState(1); // ready for further
}
// requires a little more stack to avoid touching the result
// of which is left on the stack, precisely
CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack
// or return in case of recovery
// 2e état, évalue l'opérande de droite
if ( pStk2->GetState() == 0 )
{
if ( !m_rightop->Execute(pStk2) ) return false; // interrupted here?
pStk2->IncState();
}
assert(pStk1->GetVar() != nullptr && pStk2->GetVar() != nullptr);
CBotTypResult type1 = pStk1->GetVar()->GetTypResult(); // what kind of results?
CBotTypResult type2 = pStk2->GetVar()->GetTypResult();
CBotStack* pStk3 = pStk2->AddStack(this); // adds an item to the stack
if ( pStk3->IfStep() ) return false; // shows the operation if step by step
// creates a temporary variable to put the result
// what kind of result?
int TypeRes = std::max(type1.GetType(), type2.GetType());
// see "any type convertible chain" in compile method
if ( GetTokenType() == ID_ADD &&
(type1.Eq(CBotTypString) || type2.Eq(CBotTypString)) )
{
TypeRes = CBotTypString;
}
switch ( GetTokenType() )
{
case ID_LOG_OR:
case ID_LOG_AND:
case ID_TXT_OR:
case ID_TXT_AND:
case ID_EQ:
case ID_NE:
case ID_HI:
case ID_LO:
case ID_HS:
case ID_LS:
TypeRes = CBotTypBoolean;
break;
case ID_DIV:
TypeRes = std::max(TypeRes, static_cast<int>(CBotTypFloat));
}
// creates a variable for the result
CBotVar* result = CBotVar::Create("", TypeRes);
// get left and right operands
CBotVar* left = pStk1->GetVar();
CBotVar* right = pStk2->GetVar();
// creates a variable to perform the calculation in the appropriate type
if ( TypeRes != CBotTypString ) // keep string conversion
{
TypeRes = std::max(type1.GetType(), type2.GetType());
}
else
{
left->Update(nullptr);
right->Update(nullptr);
}
//.........这里部分代码省略.........