From 4852c3cd502e9a5e11f9164fcc1e01e9d5280046 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Wed, 6 Jul 2005 14:25:05 +0000 Subject: [PATCH] Added Sort() functionality. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13494 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/registrar/AppInfoList.cpp | 17 +++++++++++++++++ src/servers/registrar/AppInfoList.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/servers/registrar/AppInfoList.cpp b/src/servers/registrar/AppInfoList.cpp index ef0e5d18f7..9e6a56550e 100644 --- a/src/servers/registrar/AppInfoList.cpp +++ b/src/servers/registrar/AppInfoList.cpp @@ -24,6 +24,8 @@ // Description: A helper class for TRoster. A list of RosterAppInfos. //------------------------------------------------------------------------------ +#include + #include #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 diff --git a/src/servers/registrar/AppInfoList.h b/src/servers/registrar/AppInfoList.h index 95801bc167..bf9c4ffb03 100644 --- a/src/servers/registrar/AppInfoList.h +++ b/src/servers/registrar/AppInfoList.h @@ -57,6 +57,8 @@ public: Iterator It(); + void Sort(int (*cmpFunc)(const RosterAppInfo *, const RosterAppInfo *)); + private: RosterAppInfo *RemoveInfo(int32 index);