本文整理汇总了C++中CCodeChain::CreateLinkedList方法的典型用法代码示例。如果您正苦于以下问题:C++ CCodeChain::CreateLinkedList方法的具体用法?C++ CCodeChain::CreateLinkedList怎么用?C++ CCodeChain::CreateLinkedList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCodeChain
的用法示例。
在下文中一共展示了CCodeChain::CreateLinkedList方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
ICCItem *fnAppend (CEvalContext *pCtx, ICCItem *pArgs, DWORD dwData)
// fnAppend
//
// Appends two or more elements together
{
int i, j;
CCodeChain *pCC = pCtx->pCC;
// Create a new list to store the result in
ICCItem *pResult = pCC->CreateLinkedList();
if (pResult->IsError())
return pResult;
CCLinkedList *pList = (CCLinkedList *)pResult;
// Loop over all arguments and add to result list
for (i = 0; i < pArgs->GetCount(); i++)
{
ICCItem *pItem = pArgs->GetElement(i);
for (j = 0; j < pItem->GetCount(); j++)
pList->Append(pCC, pItem->GetElement(j), NULL);
}
// Done
return pResult;
}
示例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: strEquals
ICCItem *fnPageMap (CEvalContext *pEvalCtx, ICCItem *pArgs, DWORD dwData)
// fnPageMap
//
// (pageMap address|pageID enumMethod ['excludeNil] var exp) -> filtered list
{
CCodeChain *pCC = pEvalCtx->pCC;
// Args
ICCItem *pAddress = pArgs->GetElement(0);
ICCItem *pMethod = pArgs->GetElement(1);
bool bExcludeNil;
int iOptionalArg = 2;
if (pArgs->GetCount() > 4)
bExcludeNil = strEquals(pArgs->GetElement(iOptionalArg++)->GetStringValue(), CONSTLIT("excludeNil"));
else
bExcludeNil = false;
ICCItem *pVar = pArgs->GetElement(iOptionalArg++);
ICCItem *pBody = pArgs->GetElement(iOptionalArg++);
// Open the page
IPage *pPage;
CString sError;
if (g_PM.OpenPage(pAddress->GetStringValue(), &pPage, &sError) != NOERROR)
return pCC->CreateError(sError, NULL);
// Prepare the method
SPageEnumCtx EnumCtx;
if (pPage->EnumReset(*pCC, pMethod, EnumCtx, &sError))
{
g_PM.ClosePage(pPage);
return pCC->CreateError(sError, NULL);
}
// Create a destination list
ICCItem *pResult = pCC->CreateLinkedList();
if (pResult->IsError())
{
g_PM.ClosePage(pPage);
return pResult;
}
CCLinkedList *pList = (CCLinkedList *)pResult;
// Setup the locals. We start by creating a local symbol table
ICCItem *pLocalSymbols = pCC->CreateSymbolTable();
if (pLocalSymbols->IsError())
{
pResult->Discard(pCC);
g_PM.ClosePage(pPage);
return pLocalSymbols;
}
// Associate the enumaration variable
ICCItem *pError = pLocalSymbols->AddEntry(pCC, pVar, pCC->CreateNil());
if (pError->IsError())
{
pLocalSymbols->Discard(pCC);
pResult->Discard(pCC);
g_PM.ClosePage(pPage);
return pError;
}
pError->Discard(pCC);
// Setup the context
if (pEvalCtx->pLocalSymbols)
pLocalSymbols->SetParent(pEvalCtx->pLocalSymbols);
else
pLocalSymbols->SetParent(pEvalCtx->pLexicalSymbols);
ICCItem *pOldSymbols = pEvalCtx->pLocalSymbols;
pEvalCtx->pLocalSymbols = pLocalSymbols;
// Get the offset of the variable so we don't have to
// search for it all the time
int iVarOffset = pLocalSymbols->FindOffset(pCC, pVar);
// Enumerate the page
while (pPage->EnumHasMore(EnumCtx))
{
ICCItem *pItem = pPage->EnumGetNext(*pCC, EnumCtx);
if (pItem->IsError())
{
pResult->Discard(pCC);
pResult = pItem;
break;
}
//.........这里部分代码省略.........
示例5:
ICCItem *fnPageGet (CEvalContext *pEvalCtx, ICCItem *pArgs, DWORD dwData)
// fnPageGet
//
// (pageGet address|pageID enumMethod [startIndex] [count]) -> list
{
CCodeChain *pCC = pEvalCtx->pCC;
// Args
ICCItem *pAddress = pArgs->GetElement(0);
ICCItem *pMethod = pArgs->GetElement(1);
int iStart = (pArgs->GetCount() > 2 ? pArgs->GetElement(2)->GetIntegerValue() : 0);
int iCount = (pArgs->GetCount() > 3 ? pArgs->GetElement(3)->GetIntegerValue() : -1);
// Open the page
IPage *pPage;
CString sError;
if (g_PM.OpenPage(pAddress->GetStringValue(), &pPage, &sError) != NOERROR)
return pCC->CreateError(sError, NULL);
// Prepare the method
SPageEnumCtx EnumCtx;
if (pPage->EnumReset(*pCC, pMethod, EnumCtx, &sError))
{
g_PM.ClosePage(pPage);
return pCC->CreateError(sError, NULL);
}
// Create a destination list
ICCItem *pResult = pCC->CreateLinkedList();
if (pResult->IsError())
{
g_PM.ClosePage(pPage);
return pResult;
}
CCLinkedList *pList = (CCLinkedList *)pResult;
// Enumerate the page
while ((iCount == -1 || iCount > 0) && pPage->EnumHasMore(EnumCtx))
{
ICCItem *pItem = pPage->EnumGetNext(*pCC, EnumCtx);
if (pItem->IsError())
{
pResult->Discard(pCC);
pResult = pItem;
break;
}
// Add to list
if (iStart == 0)
{
pList->Append(*pCC, pItem);
iCount--;
}
else
iStart--;
pItem->Discard(pCC);
}
// Clean up
g_PM.ClosePage(pPage);
// Done
if (pResult->GetCount() > 0)
return pResult;
else
{
pResult->Discard(pCC);
return pCC->CreateNil();
}
}
示例6: if
ICCItem *CCLambda::Execute (CEvalContext *pCtx, ICCItem *pArgs)
// Execute
//
// Executes the function and returns a result
{
CCodeChain *pCC = pCtx->pCC;
ICCItem *pItem;
ICCItem *pOldSymbols;
ICCItem *pLocalSymbols;
ICCItem *pVar;
ICCItem *pArg;
ICCItem *pResult;
int i;
BOOL bNoEval;
// We must have been initialized
if (m_pArgList == NULL || m_pCode == NULL)
return pCC->CreateNil();
// 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();
// Set up the symbol table
pLocalSymbols = pCC->CreateSymbolTable();
if (pLocalSymbols->IsError())
return pLocalSymbols;
// Loop over each item and associate it
for (i = 0; i < m_pArgList->GetCount(); i++)
{
pVar = m_pArgList->GetElement(i);
pArg = pArgs->GetElement(i);
// If the name of this variable is %args, then the rest of the arguments
// should go into a list
if (strCompareAbsolute(pVar->GetStringValue(), CONSTLIT("%args")) == 0)
{
ICCItem *pVarArgs;
// If there are arguments left, add them to a list
if (pArg)
{
int j;
ICCItem *pError;
CCLinkedList *pList;
// Create a list
pVarArgs = pCC->CreateLinkedList();
if (pVarArgs->IsError())
{
pLocalSymbols->Discard(pCC);
return pVarArgs;
}
pList = (CCLinkedList *)pVarArgs;
// Add each argument to the list
for (j = i; j < pArgs->GetCount(); j++)
{
pArg = pArgs->GetElement(j);
if (bNoEval)
pResult = pArg->Reference();
else
pResult = pCC->Eval(pCtx, pArg);
pList->Append(pCC, pResult, &pError);
pResult->Discard(pCC);
if (pError->IsError())
{
pVarArgs->Discard(pCC);
pLocalSymbols->Discard(pCC);
return pError;
}
pError->Discard(pCC);
}
}
else
pVarArgs = pCC->CreateNil();
// Add to the local symbol table
pItem = pLocalSymbols->AddEntry(pCC, pVar, pVarArgs);
pVarArgs->Discard(pCC);
}
// Bind the variable to the argument
//.........这里部分代码省略.........