本文整理汇总了C++中ExpReturn::GetArray方法的典型用法代码示例。如果您正苦于以下问题:C++ ExpReturn::GetArray方法的具体用法?C++ ExpReturn::GetArray怎么用?C++ ExpReturn::GetArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpReturn
的用法示例。
在下文中一共展示了ExpReturn::GetArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Evaluate
void ExpAt::Evaluate(ExpReturn *er)
{
ExpReturn param;
// Evaluate both sides
l->Evaluate(er);
r->Evaluate(¶m);
// Left side not an array? Have no effect
if (er->Type() != EXPTYPE_ARRAY) {
#ifdef CONSTRUCT_DEBUGGER
pCExp->pRuntime->LogMsg("Expression 'at': Expression on left is not an array. Operator had no effect.");
#endif
return;
}
// List of array indices to access, eg. 5 then 6 then 3 for at {5,6,3}
int derefs[32];
int derefCount = 0;
// Check right side type and get index
switch(param.Type()) {
case EXPTYPE_INTEGER:
derefs[0] = param.eData.iVal;
derefs[0]--; // Make 0-based
derefCount = 1;
break;
case EXPTYPE_FLOAT:
derefs[0] = param.eData.fVal;
derefs[0]--; // Make 0-based
derefCount = 1;
break;
case EXPTYPE_ARRAY:
const ExpStore* i = param.GetArray();
const ExpStore* const arr_end = i + param.GetArraySize();
for ( ; i != arr_end; i++) {
derefs[derefCount] = i->GetInt() - 1;
derefCount++;
}
}
const ExpReturn* elementPtr = er;
// Dereference the array as needed
for (int i = 0; i < derefCount; i++) {
int index = derefs[i];
// Return 0 for out-of-bounds
if (index < 0 || index >= elementPtr->GetArraySize()) {
er->eType = EXPTYPE_INTEGER;
er->eData.iVal = 0;
#ifdef CONSTRUCT_DEBUGGER
pCExp->pRuntime->LogMsg("Expression 'at': Array access out-of-bounds: returning 0");
#endif
return;
}
elementPtr = (ExpReturn*)&(elementPtr->GetArray()[index]);
}
// Array element is another array? Just pass on the reference
if (elementPtr->Type() == EXPTYPE_ARRAY) {
er->eType = EXPTYPE_ARRAY;
er->eData.arr = elementPtr->eData.arr;
return;
}
// Array element not another array: copy to temp value (arrays are reference semantics)
else {
// operator= copy to ExpStore, then operator= reference to ExpReturn
value = *elementPtr;
*er = (ExpReturn&)value; // force reference copy
return;
}
}