| 102 | } |
| 103 | |
| 104 | static void |
| 105 | PrintSortedQueue(Response &r, const Queue &queue, |
| 106 | const QueueSelection &selection) |
| 107 | { |
| 108 | /* collect all matching songs */ |
| 109 | auto v = CollectQueue(queue, selection); |
| 110 | |
| 111 | auto window = selection.window; |
| 112 | if (!window.CheckClip(v.size())) |
| 113 | throw PlaylistError::BadRange(); |
| 114 | |
| 115 | /* sort them */ |
| 116 | const auto sort = selection.sort; |
| 117 | const auto descending = selection.descending; |
| 118 | |
| 119 | if (sort == TagType(SORT_TAG_LAST_MODIFIED)) |
| 120 | std::stable_sort(v.begin(), v.end(), |
| 121 | [&queue, descending](unsigned a_pos, unsigned b_pos){ |
| 122 | if (descending) |
| 123 | std::swap(a_pos, b_pos); |
| 124 | |
| 125 | const auto &a = queue.Get(a_pos); |
| 126 | const auto &b = queue.Get(b_pos); |
| 127 | |
| 128 | return a.GetLastModified() < b.GetLastModified(); |
| 129 | }); |
| 130 | else if (sort == TagType(SORT_TAG_ADDED)) |
| 131 | std::stable_sort(v.begin(), v.end(), |
| 132 | [&queue, descending](unsigned a_pos, unsigned b_pos){ |
| 133 | if (descending) |
| 134 | std::swap(a_pos, b_pos); |
| 135 | |
| 136 | const auto &a = queue.Get(a_pos); |
| 137 | const auto &b = queue.Get(b_pos); |
| 138 | |
| 139 | return a.GetAdded() < b.GetAdded(); |
| 140 | }); |
| 141 | else if (sort == TagType(SORT_TAG_PRIO)) |
| 142 | std::stable_sort(v.begin(), v.end(), |
| 143 | [&queue, descending](unsigned a_pos, unsigned b_pos){ |
| 144 | if (descending) |
| 145 | std::swap(a_pos, b_pos); |
| 146 | |
| 147 | return queue.GetPriorityAtPosition(a_pos) < |
| 148 | queue.GetPriorityAtPosition(b_pos); |
| 149 | }); |
| 150 | else |
| 151 | std::stable_sort(v.begin(), v.end(), |
| 152 | [&queue, sort, descending](unsigned a_pos, |
| 153 | unsigned b_pos){ |
| 154 | const auto &a = queue.Get(a_pos); |
| 155 | const auto &b = queue.Get(b_pos); |
| 156 | |
| 157 | return CompareTags(sort, descending, |
| 158 | a.GetTag(), |
| 159 | b.GetTag()); |
| 160 | }); |
| 161 |
no test coverage detected