本文整理汇总了C++中CBotVar::ConstructorSet方法的典型用法代码示例。如果您正苦于以下问题:C++ CBotVar::ConstructorSet方法的具体用法?C++ CBotVar::ConstructorSet怎么用?C++ CBotVar::ConstructorSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBotVar
的用法示例。
在下文中一共展示了CBotVar::ConstructorSet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
bool CBotNew::Execute(CBotStack* &pj)
{
CBotStack* pile = pj->AddStack(this); //main stack
if (m_exprRetVar != nullptr) // new Class().method()
{
if (pile->GetState() == 2)
{
CBotStack* pile3 = pile->AddStack();
if (!m_exprRetVar->Execute(pile3)) return false;
return pj->Return(pile3);
}
}
if (pile->IfStep()) return false;
CBotStack* pile1 = pj->AddStack2(); //secondary stack
CBotVar* pThis = nullptr;
CBotToken* pt = &m_vartoken;
CBotClass* pClass = CBotClass::Find(pt);
// create the variable "this" pointer type to the stack
if ( pile->GetState()==0)
{
// create an instance of the requested class
// and initialize the pointer to that object
pThis = CBotVar::Create("this", pClass);
pThis->SetUniqNum(-2) ;
pile1->SetVar(pThis); // place on stack1
pile->IncState();
}
// fetch the this pointer if it was interrupted
if ( pThis == nullptr)
{
pThis = pile1->GetVar(); // find the pointer
}
// is there an assignment or parameters (constructor)
if ( pile->GetState()==1)
{
// evaluates the constructor of the instance
CBotVar* ppVars[1000];
CBotStack* pile2 = pile;
int i = 0;
CBotInstr* p = m_parameters;
// evaluate the parameters
// and places the values on the stack
// to be interrupted at any time
if (p != nullptr) while ( true)
{
pile2 = pile2->AddStack(); // space on the stack for the result
if (pile2->GetState() == 0)
{
if (!p->Execute(pile2)) return false; // interrupted here?
pile2->SetState(1);
}
ppVars[i++] = pile2->GetVar();
p = p->GetNext();
if ( p == nullptr) break;
}
ppVars[i] = nullptr;
// create a variable for the result
CBotVar* pResult = nullptr; // constructos still void
if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GetName(),
pThis, ppVars,
pResult, pile2, GetToken())) return false; // interrupt
pThis->ConstructorSet(); // indicates that the constructor has been called
}
if (m_exprRetVar != nullptr) // new Class().method()
{
pile->AddStack()->Delete(); // release pile2 stack
CBotStack* pile3 = pile->AddStack(); // add new stack
pile3->SetCopyVar(pThis); // copy the pointer (from pile1)
pile1->Delete(); // release secondary stack(pile1)
pile->SetState(2);
return false; // go back to the top ^^^
}
return pj->Return(pile1); // passes below
}
示例2: Execute
//.........这里部分代码省略.........
if ( pile->GetState()<3)
{
// ss there an assignment or parameters (contructor)
// CBotVarClass* pInstance = NULL;
if ( m_expr != NULL )
{
// evaluates the expression for the assignment
if (!m_expr->Execute(pile)) return false;
if ( bIntrincic )
{
CBotVar* pv = pile->GetVar();
if ( pv == NULL || pv->GetPointer() == NULL )
{
pile->SetError(TX_NULLPT, &m_token);
return pj->Return(pile);
}
pThis->Copy(pile->GetVar(), false);
}
else
{
CBotVarClass* pInstance;
pInstance = (static_cast<CBotVarPointer*>(pile->GetVar()))->GetPointer(); // value for the assignment
pThis->SetPointer(pInstance);
}
pThis->SetInit(true);
}
else if ( m_hasParams )
{
// evaluates the constructor of an instance
if ( !bIntrincic && pile->GetState() == 1)
{
CBotToken* pt = &m_token;
CBotClass* pClass = CBotClass::Find(pt);
// creates an instance of the requested class
CBotVarClass* pInstance;
pInstance = static_cast<CBotVarClass*>(CBotVar::Create("", pClass));
pThis->SetPointer(pInstance);
delete pInstance;
pile->IncState();
}
CBotVar* ppVars[1000];
CBotStack* pile2 = pile;
int i = 0;
CBotInstr* p = m_Parameters;
// evaluates the parameters
// and places the values on the stack
// to (can) be interrupted (broken) at any time
if ( p != NULL) while ( true )
{
pile2 = pile2->AddStack(); // place on the stack for the results
if ( pile2->GetState() == 0 )
{
if (!p->Execute(pile2)) return false; // interrupted here?
pile2->SetState(1);
}
ppVars[i++] = pile2->GetVar();
p = p->GetNext();
if ( p == NULL) break;
}
ppVars[i] = NULL;
// creates a variable for the result
CBotVar* pResult = NULL; // constructor still void
if ( !pClass->ExecuteMethode(m_nMethodeIdent, pClass->GetName(),
pThis, ppVars,
pResult, pile2, GetToken())) return false; // interrupt
pThis->SetInit(true);
pThis->ConstructorSet(); // indicates that the constructor has been called
pile->Return(pile2); // releases a piece of stack
// pInstance = pThis->GetPointer();
}
// if ( !bIntrincic ) pThis->SetPointer(pInstance); // a pointer to the instance
pile->SetState(3); // finished this part
}
if ( pile->IfStep() ) return false;
if ( m_next2b != NULL &&
!m_next2b->Execute(pile)) return false; // other (s) definition (s)
return pj->Return( pile ); // transmits below (further)
}