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);