From 173b012d0065e590a75b43f044c3760a71ba988c Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Mon, 16 Feb 2009 20:08:14 +0100 Subject: [PATCH] use vector instead of map --- src/helpers.cpp | 9 +++++++++ src/helpers.h | 1 + src/media_library.cpp | 10 +++++----- src/tag_editor.cpp | 9 +++++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index e62d4542..273f8873 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -180,6 +180,15 @@ bool CaseInsensitiveSorting::operator()(string a, string b) return a < b; } +bool CaseInsensitiveSorting::operator()(const string_pair &a, const string_pair &b) +{ + string aa = a.first; + string bb = b.first; + ToLower(aa); + ToLower(bb); + return aa < bb; +} + bool CaseInsensitiveSorting::operator()(Song *sa, Song *sb) { string a = sa->GetName(); diff --git a/src/helpers.h b/src/helpers.h index f829e5c5..8d5c783a 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -32,6 +32,7 @@ class CaseInsensitiveSorting { public: bool operator()(std::string, std::string); + bool operator()(const string_pair &, const string_pair &); bool operator()(MPD::Song *, MPD::Song *); bool operator()(const MPD::Item &, const MPD::Item &); }; diff --git a/src/media_library.cpp b/src/media_library.cpp index 112327ae..13815899 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -19,7 +19,6 @@ ***************************************************************************/ #include -#include #include "charset.h" #include "display.h" @@ -148,7 +147,7 @@ void MediaLibrary::Update() { Albums->Reset(); TagList list; - std::map maplist; + std::vector maplist; locale_to_utf(Artists->Current()); if (Config.media_lib_primary_tag == MPD_TAG_ITEM_ARTIST) Mpd->GetAlbums(Artists->Current(), list); @@ -184,13 +183,14 @@ void MediaLibrary::Update() { utf_to_locale(*it); l[0]->Localize(); - maplist[l[0]->toString(Config.media_lib_album_format)] = *it; + maplist.push_back(make_pair(l[0]->toString(Config.media_lib_album_format), *it)); } FreeSongList(l); } utf_to_locale(Artists->Current()); - for (std::map::const_iterator it = maplist.begin(); it != maplist.end(); it++) - Albums->AddOption(make_pair(it->first, it->second)); + sort(maplist.begin(), maplist.end(), CaseInsensitiveSorting()); + for (std::vector::const_iterator it = maplist.begin(); it != maplist.end(); it++) + Albums->AddOption(*it); Albums->Window::Clear(); Albums->Refresh(); } diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 167999b8..3e342b37 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -408,7 +408,7 @@ void TagEditor::Update() TagList list; if (Config.albums_in_tag_editor) { - std::map maplist; + std::vector maplist; *Albums << XY(0, 0) << "Fetching albums' list..." << wrefresh; Mpd->GetAlbums("", list); for (TagList::const_iterator it = list.begin(); it != list.end(); it++) @@ -420,12 +420,13 @@ void TagEditor::Update() if (!l.empty()) { l[0]->Localize(); - maplist[l[0]->toString(Config.tag_editor_album_format)] = *it; + maplist.push_back(make_pair(l[0]->toString(Config.tag_editor_album_format), *it)); } FreeSongList(l); } - for (std::map::const_iterator it = maplist.begin(); it != maplist.end(); it++) - Albums->AddOption(make_pair(it->first, it->second)); + sort(maplist.begin(), maplist.end(), CaseInsensitiveSorting()); + for (std::vector::const_iterator it = maplist.begin(); it != maplist.end(); it++) + Albums->AddOption(*it); } else {