Added Sort() functionality.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13494 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2005-07-06 14:25:05 +00:00
parent 7560d40290
commit 4852c3cd50
2 changed files with 19 additions and 0 deletions

View File

@ -24,6 +24,8 @@
// Description: A helper class for TRoster. A list of RosterAppInfos.
//------------------------------------------------------------------------------
#include <algorithm>
#include <string.h>
#include "AppInfoList.h"
@ -181,6 +183,21 @@ AppInfoList::It()
return Iterator(this, 0);
}
// Sort
/*! \brief Sorts the infos in ascending order according to the given compare
function.
\param cmpFunc The compare function to be used.
*/
void
AppInfoList::Sort(int (*cmpFunc)(const RosterAppInfo *, const RosterAppInfo *))
{
int32 count = CountInfos();
if (count > 1) {
RosterAppInfo **infos = (RosterAppInfo **)fInfos.Items();
sort(infos, infos + count, cmpFunc);
}
}
// RemoveInfo
/*! \brief Removes a RosterAppInfo at a given index.
\param index The index of the info to be removed

View File

@ -57,6 +57,8 @@ public:
Iterator It();
void Sort(int (*cmpFunc)(const RosterAppInfo *, const RosterAppInfo *));
private:
RosterAppInfo *RemoveInfo(int32 index);