本文整理汇总了C++中nsAutoTArray::AppendElements方法的典型用法代码示例。如果您正苦于以下问题:C++ nsAutoTArray::AppendElements方法的具体用法?C++ nsAutoTArray::AppendElements怎么用?C++ nsAutoTArray::AppendElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsAutoTArray
的用法示例。
在下文中一共展示了nsAutoTArray::AppendElements方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NodeToParentOffset
//.........这里部分代码省略.........
else
firstNode = NodeToParentOffset(mFirst, &firstOffset);
lastNode = NodeToParentOffset(mLast, &lastOffset);
++lastOffset;
}
}
// The end positions are always in the range even if it has no parent.
// We need to allow that or 'iter->Init(root)' would assert in Last()
// or First() for example, bug 327694.
if (mFirst != mCurNode && mLast != mCurNode &&
(!firstNode || !lastNode ||
!NodeIsInTraversalRange(mCurNode, mPre, firstNode, firstOffset,
lastNode, lastOffset)))
{
mIsDone = PR_TRUE;
return NS_ERROR_FAILURE;
}
// We can be at ANY node in the sequence.
// Need to regenerate the array of indexes back to the root or common parent!
nsAutoTArray<nsINode*, 8> oldParentStack;
nsAutoTArray<PRInt32, 8> newIndexes;
// Get a list of the parents up to the root, then compare the new node
// with entries in that array until we find a match (lowest common
// ancestor). If no match, use IndexOf, take the parent, and repeat.
// This avoids using IndexOf() N times on possibly large arrays. We
// still end up doing it a fair bit. It's better to use Clone() if
// possible.
// we know the depth we're down (though we may not have started at the
// top).
if (!oldParentStack.SetCapacity(mIndexes.Length()+1))
return NS_ERROR_FAILURE;
// We want to loop mIndexes.Length() + 1 times here, because we want to make
// sure we include mCommonParent in the oldParentStack, for use in the next
// for loop, and mIndexes only has entries for nodes from tempNode up through
// an ancestor of tempNode that's a child of mCommonParent.
for (PRInt32 i = mIndexes.Length()+1; i > 0 && tempNode; i--)
{
// Insert at head since we're walking up
oldParentStack.InsertElementAt(0, tempNode);
nsINode *parent = tempNode->GetNodeParent();
if (!parent) // this node has no parent, and thus no index
break;
if (parent == mCurNode)
{
// The position was moved to a parent of the current position.
// All we need to do is drop some indexes. Shortcut here.
mIndexes.RemoveElementsAt(mIndexes.Length() - oldParentStack.Length(),
oldParentStack.Length());
mIsDone = PR_FALSE;
return NS_OK;
}
tempNode = parent;
}
// Ok. We have the array of old parents. Look for a match.
while (newCurNode)
{
nsINode *parent = newCurNode->GetNodeParent();
if (!parent) // this node has no parent, and thus no index
break;
PRInt32 indx = parent->IndexOf(newCurNode);
// insert at the head!
newIndexes.InsertElementAt(0, indx);
// look to see if the parent is in the stack
indx = oldParentStack.IndexOf(parent);
if (indx >= 0)
{
// ok, the parent IS on the old stack! Rework things.
// we want newIndexes to replace all nodes equal to or below the match
// Note that index oldParentStack.Length()-1 is the last node, which is
// one BELOW the last index in the mIndexes stack. In other words, we
// want to remove elements starting at index (indx+1).
PRInt32 numToDrop = oldParentStack.Length()-(1+indx);
if (numToDrop > 0)
mIndexes.RemoveElementsAt(mIndexes.Length() - numToDrop, numToDrop);
mIndexes.AppendElements(newIndexes);
break;
}
newCurNode = parent;
}
// phew!
mIsDone = PR_FALSE;
return NS_OK;
}