本文整理汇总了C++中CArrayFixFlat::Sort方法的典型用法代码示例。如果您正苦于以下问题:C++ CArrayFixFlat::Sort方法的具体用法?C++ CArrayFixFlat::Sort怎么用?C++ CArrayFixFlat::Sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CArrayFixFlat
的用法示例。
在下文中一共展示了CArrayFixFlat::Sort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WriteGroupMembersL
/**
Persist the items belonging to curent group into group table
@param aGroup referece to a contact group
*/
void CPplGroupsTable::WriteGroupMembersL(const CContactItem& aGroup)
{
if (aGroup.Type() != KUidContactGroup)
{
return;
}
const TContactItemId KGroupId(aGroup.Id() );
// make sure we clear out any previous, out-of-date data
TBool lowDiskErr(EFalse);
DeleteItemL(KGroupId, lowDiskErr);
if (lowDiskErr)
{
User::Leave(KErrDiskFull);
}
// build the RSqlStatement
RSqlStatement stmnt;
CleanupClosePushL(stmnt);
stmnt.PrepareL(iDatabase, iInsertStmnt->SqlStringL() );
const TInt KGroupIdIndex(KFirstIndex); // first parameter in query...
const TInt KMemberIdIndex(KGroupIdIndex + 1); // ...and the second parameter
// copy and sort the member id array so we can see if there are duplicates
const CContactIdArray* contactIdArray = static_cast<const CContactGroup&>(aGroup).ItemsContained(); //does not take the ownership
const TInt arrayCount = contactIdArray->Count();
CArrayFixFlat<TContactItemId>* sortedList = new(ELeave) CArrayFixFlat<TContactItemId>(KArrayGranularity);
CleanupStack::PushL(sortedList);
for(TInt loop = 0;loop < arrayCount; ++loop)
{
sortedList->AppendL((*contactIdArray)[loop]);
}
TKeyArrayFix key(0,ECmpTInt);
sortedList->Sort(key);
// insert the group-member relationships
const TInt KCountStmntParamIndex(KFirstIndex); // first and only parameter in query
const TInt listLen(sortedList->Count() );
TInt lastId(0);
for (TInt i = 0; i < listLen; ++i)
{
TInt itemId((*sortedList)[i]);
//check if a contact item with itemId id really exists in contact database
RSqlStatement countStmnt;
CleanupClosePushL(countStmnt);
countStmnt.PrepareL(iDatabase, iCountContactsStmnt->SqlStringL() );
User::LeaveIfError(countStmnt.BindInt(KCountStmntParamIndex, itemId) );
TInt count = 0;
TInt err = KErrNone;
if((err = countStmnt.Next() ) == KSqlAtRow)
{
count = countStmnt.ColumnInt(iCountContactsStmnt->ParameterIndex(KSqlCount) );
}
else
{
User::LeaveIfError(err);
}
if(count == 0)
{
User::Leave(KErrNotFound);
}
CleanupStack::PopAndDestroy(&countStmnt);
// only insert this if we haven't already seen it
if (itemId != lastId || i == 0)
{
User::LeaveIfError(stmnt.BindInt(KGroupIdIndex, KGroupId) );
User::LeaveIfError(stmnt.BindInt(KMemberIdIndex, itemId) );
User::LeaveIfError(stmnt.Exec() );
User::LeaveIfError(stmnt.Reset() );
}
lastId = itemId;
}
CleanupStack::PopAndDestroy(2, &stmnt); // and sortedList
}