本文整理汇总了C++中CBotVar::Sub方法的典型用法代码示例。如果您正苦于以下问题:C++ CBotVar::Sub方法的具体用法?C++ CBotVar::Sub怎么用?C++ CBotVar::Sub使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBotVar
的用法示例。
在下文中一共展示了CBotVar::Sub方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
BOOL CBotAddExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
// if ( pSk1 == EOX ) return TRUE;
// selon la reprise, on peut être dans l'un des 2 états
if ( pStk1->GetState() == 0 && // 1er état, évalue l'opérande de gauche
!m_leftop->Execute(pStk1) ) return FALSE; // interrompu ici ?
// passe à l'étape suivante
pStk1->SetState(1); // prêt pour la suite
// demande un peu plus de stack pour ne pas toucher le résultat de gauche
// qui se trouve sur la pile, justement.
CBotStack* pStk2 = pStk1->AddStack(); // ajoute un élément à la pile
// ou le retrouve en cas de reprise
// 2e état, évalue l'opérande de droite
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrompu ici ?
int type1 = pStk1->GetType(); // de quels types les résultats ?
int type2 = pStk2->GetType();
// crée une variable temporaire pour y mettre le résultat
CBotVar* result = new CBotVar( NULL, MAX(type1, type2));
// fait l'opération selon la demande
switch (GetTokenType())
{
case ID_ADD:
result->Add(pStk1->GetVar(), pStk2->GetVar()); // additionne
break;
case ID_SUB:
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // soustrait
break;
}
pStk2->SetVar(result); // met le résultat sur la pile
pStk1->Return(pStk2); // libère la pile
return pStack->Return(pStk1); // transmet le résultat
}
示例2: Execute
bool CBotAddExpr::Execute(CBotStack* &pStack)
{
CBotStack* pStk1 = pStack->AddStack(this); // adds an item to the stack
// or is found in case of recovery
// if ( pSk1 == EOX ) return TRUE;
// according to recovery, it may be in one of two states
if ( pStk1->GetState() == 0 && // first state, evaluates the left operand
!m_leftop->Execute(pStk1) ) return FALSE; // interrupted here?
// passes to the next step
pStk1->SetState(1); // ready for further
// requires a little more stack to not touch the result of the left
// which is on the stack, precisely.
CBotStack* pStk2 = pStk1->AddStack(); // adds an item to the stack
// or is found in case of recovery
// Second state, evaluates the right operand
if ( !m_rightop->Execute(pStk2) ) return FALSE; // interrupted here?
int type1 = pStk1->GetType(); // what kind of results?
int type2 = pStk2->GetType();
// creates a temporary variable to put the result
CBotVar* result = new CBotVar( nullptr, MAX(type1, type2));
// is the operation as requested
switch (GetTokenType())
{
case ID_ADD:
result->Add(pStk1->GetVar(), pStk2->GetVar()); // addition
break;
case ID_SUB:
result->Sub(pStk1->GetVar(), pStk2->GetVar()); // subtraction
break;
}
pStk2->SetVar(result); // puts the result on the stack
pStk1->Return(pStk2); // frees the stack
return pStack->Return(pStk1); // transmits the result
}
示例3: Execute
//.........这里部分代码省略.........
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);
}
if ( GetTokenType() == ID_ADD && type1.Eq(CBotTypString) )
{
TypeRes = CBotTypString;
}
CBotVar* temp;
if ( TypeRes == CBotTypPointer ) TypeRes = CBotTypNullPointer;
if ( TypeRes == CBotTypClass ) temp = CBotVar::Create("", CBotTypResult(CBotTypIntrinsic, type1.GetClass() ) );
else temp = CBotVar::Create("", TypeRes );
CBotError err = CBotNoErr;
// is a operation according to request
switch (GetTokenType())
{
case ID_ADD:
if ( !IsNan(left, right, &err) ) result->Add(left , right); // addition
break;
case ID_SUB:
if ( !IsNan(left, right, &err) ) result->Sub(left , right); // substraction
break;
case ID_MUL:
if ( !IsNan(left, right, &err) ) result->Mul(left , right); // multiplies
break;
case ID_POWER:
if ( !IsNan(left, right, &err) ) result->Power(left , right); // power
break;
case ID_DIV:
if ( !IsNan(left, right, &err) ) err = result->Div(left , right);// division
break;
case ID_MODULO:
if ( !IsNan(left, right, &err) ) err = result->Modulo(left , right);// remainder of division
break;
case ID_LO:
if ( !IsNan(left, right, &err) )
result->SetValInt(temp->Lo(left , right)); // lower
break;
case ID_HI:
if ( !IsNan(left, right, &err) )
result->SetValInt(temp->Hi(left , right)); // top
break;
case ID_LS:
if ( !IsNan(left, right, &err) )
result->SetValInt(temp->Ls(left , right)); // less than or equal
break;
case ID_HS:
if ( !IsNan(left, right, &err) )
result->SetValInt(temp->Hs(left , right)); // greater than or equal
break;
case ID_EQ:
if ( IsNan(left, right) )
result->SetValInt(left->GetInit() == right->GetInit()) ;