Added Sort() functionality.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13494 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -24,6 +24,8 @@
|
|||||||
// Description: A helper class for TRoster. A list of RosterAppInfos.
|
// Description: A helper class for TRoster. A list of RosterAppInfos.
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "AppInfoList.h"
|
#include "AppInfoList.h"
|
||||||
@@ -181,6 +183,21 @@ AppInfoList::It()
|
|||||||
return Iterator(this, 0);
|
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
|
// RemoveInfo
|
||||||
/*! \brief Removes a RosterAppInfo at a given index.
|
/*! \brief Removes a RosterAppInfo at a given index.
|
||||||
\param index The index of the info to be removed
|
\param index The index of the info to be removed
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ public:
|
|||||||
|
|
||||||
Iterator It();
|
Iterator It();
|
||||||
|
|
||||||
|
void Sort(int (*cmpFunc)(const RosterAppInfo *, const RosterAppInfo *));
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RosterAppInfo *RemoveInfo(int32 index);
|
RosterAppInfo *RemoveInfo(int32 index);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user