Make 'update_environment' action also update local mpd status
[ncmpcpp.git] / src / utility / comparators.h
blobe26213da836a075920c07fe2879245db04ac2762
1 /***************************************************************************
2 * Copyright (C) 2008-2016 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef NCMPCPP_UTILITY_COMPARATORS_H
22 #define NCMPCPP_UTILITY_COMPARATORS_H
24 #include <string>
25 #include "runnable_item.h"
26 #include "mpdpp.h"
27 #include "settings.h"
28 #include "menu.h"
30 class LocaleStringComparison
32 std::locale m_locale;
33 bool m_ignore_the;
35 public:
36 LocaleStringComparison(const std::locale &loc, bool ignore_the)
37 : m_locale(loc), m_ignore_the(ignore_the) { }
39 int operator()(const char *a, const char *b) const {
40 return compare(a, strlen(a), b, strlen(b));
42 int operator()(const std::string &a, const std::string &b) const {
43 return compare(a.c_str(), a.length(), b.c_str(), b.length());
46 int compare(const char *a, size_t a_len, const char *b, size_t b_len) const;
49 class LocaleBasedSorting
51 LocaleStringComparison m_cmp;
53 public:
54 LocaleBasedSorting(const std::locale &loc, bool ignore_the) : m_cmp(loc, ignore_the) { }
56 bool operator()(const std::string &a, const std::string &b) const {
57 return m_cmp(a, b) < 0;
60 bool operator()(const MPD::Playlist &a, const MPD::Playlist &b) const {
61 return m_cmp(a.path(), b.path()) < 0;
64 bool operator()(const MPD::Song &a, const MPD::Song &b) const {
65 return m_cmp(a.getName(), b.getName()) < 0;
68 template <typename A, typename B>
69 bool operator()(const std::pair<A, B> &a, const std::pair<A, B> &b) const {
70 return m_cmp(a.first, b.first) < 0;
73 template <typename ItemT, typename FunT>
74 bool operator()(const RunnableItem<ItemT, FunT> &a, const RunnableItem<ItemT, FunT> &b) const {
75 return m_cmp(a.item(), b.item()) < 0;
79 class LocaleBasedItemSorting
81 LocaleBasedSorting m_cmp;
82 SortMode m_sort_mode;
84 public:
85 LocaleBasedItemSorting(const std::locale &loc, bool ignore_the, SortMode mode)
86 : m_cmp(loc, ignore_the), m_sort_mode(mode) { }
88 bool operator()(const MPD::Item &a, const MPD::Item &b) const;
90 bool operator()(const NC::Menu<MPD::Item>::Item &a, const NC::Menu<MPD::Item>::Item &b) const {
91 return (*this)(a.value(), b.value());
95 #endif // NCMPCPP_UTILITY_COMPARATORS_H