db/DatabasePrint: support descending sort
This commit is contained in:
@@ -149,11 +149,16 @@ CompareNumeric(const char *a, const char *b)
|
||||
}
|
||||
|
||||
static bool
|
||||
CompareTags(TagType type, const Tag &a, const Tag &b)
|
||||
CompareTags(TagType type, bool descending, const Tag &a, const Tag &b)
|
||||
{
|
||||
const char *a_value = a.GetSortValue(type);
|
||||
const char *b_value = b.GetSortValue(type);
|
||||
|
||||
if (descending) {
|
||||
using std::swap;
|
||||
swap(a_value, b_value);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case TAG_DISC:
|
||||
case TAG_TRACK:
|
||||
@@ -168,7 +173,7 @@ void
|
||||
db_selection_print(Response &r, Partition &partition,
|
||||
const DatabaseSelection &selection,
|
||||
bool full, bool base,
|
||||
TagType sort,
|
||||
TagType sort, bool descending,
|
||||
unsigned window_start, unsigned window_end)
|
||||
{
|
||||
const Database &db = partition.GetDatabaseOrThrow();
|
||||
@@ -216,8 +221,10 @@ db_selection_print(Response &r, Partition &partition,
|
||||
}
|
||||
|
||||
std::stable_sort(songs.begin(), songs.end(),
|
||||
[sort](const DetachedSong &a, const DetachedSong &b){
|
||||
return CompareTags(sort, a.GetTag(),
|
||||
[sort, descending](const DetachedSong &a,
|
||||
const DetachedSong &b){
|
||||
return CompareTags(sort, descending,
|
||||
a.GetTag(),
|
||||
b.GetTag());
|
||||
});
|
||||
|
||||
@@ -242,7 +249,7 @@ db_selection_print(Response &r, Partition &partition,
|
||||
bool full, bool base)
|
||||
{
|
||||
db_selection_print(r, partition, selection, full, base,
|
||||
TAG_NUM_OF_ITEM_TYPES,
|
||||
TAG_NUM_OF_ITEM_TYPES, false,
|
||||
0, std::numeric_limits<int>::max());
|
||||
}
|
||||
|
||||
|
@@ -42,7 +42,7 @@ void
|
||||
db_selection_print(Response &r, Partition &partition,
|
||||
const DatabaseSelection &selection,
|
||||
bool full, bool base,
|
||||
TagType sort,
|
||||
TagType sort, bool descending,
|
||||
unsigned window_start, unsigned window_end);
|
||||
|
||||
void
|
||||
|
Reference in New Issue
Block a user