本文整理汇总了C++中CCLinkedList::Discard方法的典型用法代码示例。如果您正苦于以下问题:C++ CCLinkedList::Discard方法的具体用法?C++ CCLinkedList::Discard怎么用?C++ CCLinkedList::Discard使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCLinkedList
的用法示例。
在下文中一共展示了CCLinkedList::Discard方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
ICCItem *CCodeChain::CreateVectorGivenContent(TArray<int> vShape, CCLinkedList *pContentList)
// CreateVectorGivenContent (new)
//
// Creates a vector with given shape and content
{
int i;
CCVector *pVector;
ICCItem *pItem;
pItem = m_VectorPool.CreateItem(this);
if (pItem->IsError())
return pItem;
pItem->Reset();
pVector = dynamic_cast<CCVector *>(pItem);
pVector->SetContext(this);
pVector->SetShape(this, vShape);
pItem = pContentList->GetFlattened(this, NULL);
if (pItem->IsError())
{
pVector->Discard(this);
return pItem;
};
CCLinkedList *pFlattenedContentList = dynamic_cast<CCLinkedList *>(pItem);
TArray<double> vDataArray;
for (i = 0; i < pFlattenedContentList->GetCount(); i++)
{
vDataArray.Insert(pFlattenedContentList->GetElement(i)->GetDoubleValue());
};
pVector->SetArrayData(this, vDataArray);
// Done
pFlattenedContentList->Discard(this);
return pVector->Reference();
}
示例2: CONSTLIT
ICCItem *fnApply (CEvalContext *pCtx, ICCItem *pArguments, DWORD dwData)
// fnApply
//
// Applies the given parameter list to the lambda expression
//
// (apply exp arg1 arg2 ... argn list)
{
CCodeChain *pCC = pCtx->pCC;
ICCItem *pArgs;
ICCItem *pResult;
ICCItem *pFunction;
ICCItem *pLast;
CCLinkedList *pList;
int i;
// Evaluate the arguments and validate them
pArgs = pCC->EvaluateArgs(pCtx, pArguments, CONSTLIT("v*"));
if (pArgs->IsError())
return pArgs;
// We better have at least two arguments
if (pArgs->GetCount() < 2)
{
pArgs->Discard(pCC);
return pCC->CreateError(CONSTLIT("apply needs a function and a list of arguments."), NULL);
}
// The last argument better be a list
pLast = pArgs->GetElement(pArgs->GetCount() - 1);
if (!pLast->IsList())
{
pArgs->Discard(pCC);
return pCC->CreateError(CONSTLIT("Last argument for apply must be a list."), NULL);
}
// The first argument is the function
pFunction = pArgs->Head(pCC);
// Create a new list to store the arguments in
pResult = pCC->CreateLinkedList();
if (pResult->IsError())
{
pArgs->Discard(pCC);
return pResult;
}
pList = (CCLinkedList *)pResult;
// Add each of the arguments except the last
for (i = 1; i < pArgs->GetCount() - 1; i++)
{
pList->Append(pCC, pArgs->GetElement(i), &pResult);
if (pResult->IsError())
{
pList->Discard(pCC);
pArgs->Discard(pCC);
return pResult;
}
pResult->Discard(pCC);
}
// Add each of the elements of the last list
for (i = 0; i < pLast->GetCount(); i++)
{
pList->Append(pCC, pLast->GetElement(i), &pResult);
if (pResult->IsError())
{
pList->Discard(pCC);
pArgs->Discard(pCC);
return pResult;
}
pResult->Discard(pCC);
}
// Set the literal flag to indicate that the arguments should
// not be evaluated.
pList->SetQuoted();
// Execute the function
if (pFunction->IsFunction())
pResult = pFunction->Execute(pCtx, pList);
else
pResult = pFunction->Reference();
pList->Discard(pCC);
// Done
//.........这里部分代码省略.........
示例3: if
ICCItem *fnLinkedList (CEvalContext *pCtx, ICCItem *pArguments, DWORD dwData)
// fnLinkedList
//
// Handles linked-list specific functions
//
// (lnkAppend linked-list item) -> list
// (lnkRemove linked-list index) -> list
// (lnkRemoveNil linked-list) -> list
// (lnkReplace linked-list index item) -> list
//
// HACK: This function has different behavior depending on the first
// argument. If the first argument is a variable holding a linked list,
// then the variable contents will be changed. If the variable holds Nil,
// then the variable contents are not changed. In all cases, the caller
// should structure the call as: (setq ListVar (lnkAppend ListVar ...))
// in order to handle all cases.
{
CCodeChain *pCC = pCtx->pCC;
ICCItem *pArgs;
ICCItem *pList;
CCLinkedList *pLinkedList;
ICCItem *pResult;
// Evaluate the arguments
if (dwData == FN_LINKEDLIST_APPEND)
pArgs = pCC->EvaluateArgs(pCtx, pArguments, CONSTLIT("lv"));
else if (dwData == FN_LINKEDLIST_REMOVE_NIL)
pArgs = pCC->EvaluateArgs(pCtx, pArguments, CONSTLIT("l"));
else
pArgs = pCC->EvaluateArgs(pCtx, pArguments, CONSTLIT("liv"));
if (pArgs->IsError())
return pArgs;
// Get the linked list
pList = pArgs->GetElement(0);
if (pList->GetClass()->GetObjID() == OBJID_CCLINKEDLIST)
pLinkedList = (CCLinkedList *)pList->Reference();
else if (pList->IsNil())
{
pList = pCC->CreateLinkedList();
if (pList->IsError())
{
pArgs->Discard(pCC);
return pList;
}
pLinkedList = (CCLinkedList *)pList;
}
else
{
pArgs->Discard(pCC);
return pCC->CreateError(CONSTLIT("Linked-list expected:"), NULL);
}
// Do the right thing
switch (dwData)
{
case FN_LINKEDLIST_APPEND:
{
ICCItem *pItem = pArgs->GetElement(1);
ICCItem *pError;
pLinkedList->Append(pCC, pItem, &pError);
if (pError->IsError())
{
pLinkedList->Discard(pCC);
pResult = pError;
}
else
{
pError->Discard(pCC);
pResult = pLinkedList;
}
break;
}
case FN_LINKEDLIST_REMOVE:
{
int iIndex = pArgs->GetElement(1)->GetIntegerValue();
// Make sure we're in range
if (iIndex < 0 || iIndex >= pLinkedList->GetCount())
{
pLinkedList->Discard(pCC);
pResult = pCC->CreateError(CONSTLIT("Index out of range:"), pArgs->GetElement(1));
}
else
{
pLinkedList->RemoveElement(pCC, iIndex);
pResult = pLinkedList;
}
break;
}
//.........这里部分代码省略.........
示例4: if
ICCItem *CCodeChain::EvaluateArgs (CEvalContext *pCtx, ICCItem *pArgs, const CString &sArgValidation)
// EvaluateArgs
//
// Evaluate arguments and validate their types
{
ICCItem *pArg;
ICCItem *pNew;
ICCItem *pError;
CCLinkedList *pEvalList;
char *pValidation;
int i;
BOOL bNoEval;
// If the argument list if quoted, then it means that the arguments
// have already been evaluated. This happens if we've been called by
// (apply).
bNoEval = pArgs->IsQuoted();
// Create a list to hold the results
pNew = CreateLinkedList();
if (pNew->IsError())
return pNew;
pEvalList = dynamic_cast<CCLinkedList *>(pNew);
// Start parsing at the beginning
pValidation = sArgValidation.GetPointer();
// If there is a '*' in the validation, figure out
// how many arguments it represents
int iVarArgs = Max(0, pArgs->GetCount() - (sArgValidation.GetLength() - 1));
// Loop over each argument
for (i = 0; i < pArgs->GetCount(); i++)
{
ICCItem *pResult;
pArg = pArgs->GetElement(i);
// If we're processing variable args, see if we're done
if (*pValidation == '*')
{
if (iVarArgs == 0)
pValidation++;
else
iVarArgs--;
}
// Evaluate the item. If the arg is 'q' or 'u' then we
// don't evaluate it.
if (bNoEval || *pValidation == 'q' || *pValidation == 'u')
pResult = pArg->Reference();
// If the arg is 'c' then we don't evaluate unless it is
// a lambda expression (or an identifier)
else if (*pValidation == 'c' && !pArg->IsLambdaExpression() && !pArg->IsIdentifier())
pResult = pArg->Reference();
// Evaluate
else
{
pResult = Eval(pCtx, pArg);
// We don't want to return on error because some functions
// might want to pass errors around
if (*pValidation != 'v' && *pValidation != '*')
{
if (pResult->IsError())
{
pEvalList->Discard(this);
return pResult;
}
}
}
// Check to see if the item is valid
switch (*pValidation)
{
// We expect a function...
case 'f':
{
if (!pResult->IsFunction())
{
pError = CreateError(LITERAL("Function expected"), pResult);
pResult->Discard(this);
pEvalList->Discard(this);
//.........这里部分代码省略.........
示例5: if
ICCItem *CCodeChain::Link (const CString &sString, int iOffset, int *retiLinked, int *ioiCurLine)
// Link
//
// Parses the given string and converts it into a linked
// chain of items
{
char *pStart;
char *pPos;
ICCItem *pResult = NULL;
int iCurLine = (ioiCurLine ? *ioiCurLine : 1);
pStart = sString.GetPointer() + iOffset;
pPos = pStart;
// Skip any whitespace
pPos = SkipWhiteSpace(pPos, &iCurLine);
// If we've reached the end, then we have
// nothing
if (*pPos == '\0')
pResult = CreateNil();
// If we've got a literal quote, then remember it
else if (*pPos == SYMBOL_QUOTE)
{
int iLinked;
pPos++;
pResult = Link(sString, iOffset + (pPos - pStart), &iLinked, &iCurLine);
if (pResult->IsError())
return pResult;
pPos += iLinked;
// Make it a literal
pResult->SetQuoted();
}
// If we've got an open paren then we start a list
else if (*pPos == SYMBOL_OPENPAREN)
{
ICCItem *pNew = CreateLinkedList();
if (pNew->IsError())
return pNew;
CCLinkedList *pList = dynamic_cast<CCLinkedList *>(pNew);
// Keep reading until we find the end
pPos++;
// If the list is empty, then there's nothing to do
pPos = SkipWhiteSpace(pPos, &iCurLine);
if (*pPos == SYMBOL_CLOSEPAREN)
{
pList->Discard(this);
pResult = CreateNil();
pPos++;
}
// Get all the items in the list
else
{
while (*pPos != SYMBOL_CLOSEPAREN && *pPos != '\0')
{
ICCItem *pItem;
int iLinked;
pItem = Link(sString, iOffset + (pPos - pStart), &iLinked, &iCurLine);
if (pItem->IsError())
return pItem;
// Add the item to the list
pList->Append(this, pItem, NULL);
pItem->Discard(this);
// Move the position
pPos += iLinked;
// Skip whitespace
pPos = SkipWhiteSpace(pPos, &iCurLine);
}
// If we have a close paren then we're done; Otherwise we've
// got an error of some kind
if (*pPos == SYMBOL_CLOSEPAREN)
//.........这里部分代码省略.........