本文整理汇总了C++中BaseArray::Insert方法的典型用法代码示例。如果您正苦于以下问题:C++ BaseArray::Insert方法的具体用法?C++ BaseArray::Insert怎么用?C++ BaseArray::Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseArray
的用法示例。
在下文中一共展示了BaseArray::Insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// This function demonstrates the basic methods of our arrays and lists.
// To keep it simple it does not check for errors. For real-life code
// you have to check the return value of Append() or Insert() before you
// access the memory.
static void BaseArrayDemo()
{
BaseArray<VLONG> test; // this could be BlockArray, PointerArray, SortedArray or BaseList
VLONG copyMe = 42;
VLONG i;
test.Append(); // append an element with default value
test.Append(copyMe); // append a copy of copyMe
test.Insert(1); // insert an element with default value at index 1
test.Insert(2, copyMe); // insert a copy of copyMe at index 2
test.Erase(0); // erase element at index 0
test[2] = 12345; // assign a value to the element at index 2
// iterate over all elements, assign value
for (i = 0; i < test.GetCount(); i++)
test[i] = i;
test.Resize(27); // the array has now 27 elements
test.Erase(10, 15); // erase 15 elements from index 10 on
test.Append(9876);
test.Append(54321);
// iterate over all elements, check for some value
for (AutoIterator<BaseArray<VLONG> > it(test); it; ++it)
{
if (*it == 9876)
break; // BTW: the index of this element is it - test.Begin();
}
}
示例2: Insert
//-----------------------------------------------------------------------------
EStatus BaseArray::Insert (INT iStartIndex,
INT iNumToInsert,
BOOL bDebug)
{
// This routine inserts new entries before the iStartIndex.
INT iStartIndexActual = iStartIndex;
// perform the insertion on the actual sequential data
INT iOldLength = iLength;
if (iStartIndexActual > iLength) return (EStatus::kFailure);
if (SetLength (iOldLength + iNumToInsert) == EStatus::kFailure) {return EStatus::kFailure;};
if (Length () < (iOldLength + iNumToInsert) ) {return EStatus::kFailure;};
if (bDebug)
{
DBG_INFO ("BA:Ins %d old:%d cur:%d\n", iStartIndexActual, iOldLength, Length ());
};
//printf ("start index %d old length %d\n", iStartIndexActual,iOldLength);
if ((iStartIndexActual != iLength) && (iOldLength - iStartIndexActual > 0))
{
//DBG_INFO ("Copy values rev %d %d %d\n", iStartIndexActual, iStartIndexActual + iNumToInsert, iOldLength - iStartIndexActual);
CopyValuesRev (pArray, iStartIndexActual, iStartIndexActual + iNumToInsert, iOldLength - iStartIndexActual);
};
// update siblings
BaseArray * pCurr = pNext;
while (pCurr != this)
{
pCurr->Insert (iStartIndex, iNumToInsert);
pCurr = pCurr->pNext;
};
return (EStatus::kSuccess);
};