song list: get rid of boost::zip_iterator and improve {Const,}SongIterator
[ncmpcpp.git] / src / utility / type_conversions.cpp
blob3e51f83e841152e4344ec2c35f3f77890196e246
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 #include <cassert>
22 #include "utility/type_conversions.h"
24 NC::Color charToColor(char c)
26 switch (c)
28 case '0':
29 return NC::Color::Default;
30 case '1':
31 return NC::Color::Black;
32 case '2':
33 return NC::Color::Red;
34 case '3':
35 return NC::Color::Green;
36 case '4':
37 return NC::Color::Yellow;
38 case '5':
39 return NC::Color::Blue;
40 case '6':
41 return NC::Color::Magenta;
42 case '7':
43 return NC::Color::Cyan;
44 case '8':
45 return NC::Color::White;
46 case '9':
47 return NC::Color::End;
48 default:
49 throw std::runtime_error("invalid character");
53 std::string tagTypeToString(mpd_tag_type tag)
55 switch (tag)
57 case MPD_TAG_ARTIST:
58 return "Artist";
59 case MPD_TAG_ALBUM:
60 return "Album";
61 case MPD_TAG_ALBUM_ARTIST:
62 return "Album Artist";
63 case MPD_TAG_TITLE:
64 return "Title";
65 case MPD_TAG_TRACK:
66 return "Track";
67 case MPD_TAG_GENRE:
68 return "Genre";
69 case MPD_TAG_DATE:
70 return "Date";
71 case MPD_TAG_COMPOSER:
72 return "Composer";
73 case MPD_TAG_PERFORMER:
74 return "Performer";
75 case MPD_TAG_COMMENT:
76 return "Comment";
77 case MPD_TAG_DISC:
78 return "Disc";
79 default:
80 return "";
84 MPD::MutableSong::SetFunction tagTypeToSetFunction(mpd_tag_type tag)
86 switch (tag)
88 case MPD_TAG_ARTIST:
89 return &MPD::MutableSong::setArtist;
90 case MPD_TAG_ALBUM:
91 return &MPD::MutableSong::setAlbum;
92 case MPD_TAG_ALBUM_ARTIST:
93 return &MPD::MutableSong::setAlbumArtist;
94 case MPD_TAG_TITLE:
95 return &MPD::MutableSong::setTitle;
96 case MPD_TAG_TRACK:
97 return &MPD::MutableSong::setTrack;
98 case MPD_TAG_GENRE:
99 return &MPD::MutableSong::setGenre;
100 case MPD_TAG_DATE:
101 return &MPD::MutableSong::setDate;
102 case MPD_TAG_COMPOSER:
103 return &MPD::MutableSong::setComposer;
104 case MPD_TAG_PERFORMER:
105 return &MPD::MutableSong::setPerformer;
106 case MPD_TAG_COMMENT:
107 return &MPD::MutableSong::setComment;
108 case MPD_TAG_DISC:
109 return &MPD::MutableSong::setDisc;
110 default:
111 return nullptr;
115 mpd_tag_type charToTagType(char c)
117 switch (c)
119 case 'a':
120 return MPD_TAG_ARTIST;
121 case 'A':
122 return MPD_TAG_ALBUM_ARTIST;
123 case 't':
124 return MPD_TAG_TITLE;
125 case 'b':
126 return MPD_TAG_ALBUM;
127 case 'y':
128 return MPD_TAG_DATE;
129 case 'n':
130 return MPD_TAG_TRACK;
131 case 'g':
132 return MPD_TAG_GENRE;
133 case 'c':
134 return MPD_TAG_COMPOSER;
135 case 'p':
136 return MPD_TAG_PERFORMER;
137 case 'd':
138 return MPD_TAG_DISC;
139 case 'C':
140 return MPD_TAG_COMMENT;
141 default:
142 assert(false);
143 return MPD_TAG_ARTIST;
147 MPD::Song::GetFunction charToGetFunction(char c)
149 switch (c)
151 case 'l':
152 return &MPD::Song::getLength;
153 case 'D':
154 return &MPD::Song::getDirectory;
155 case 'f':
156 return &MPD::Song::getName;
157 case 'a':
158 return &MPD::Song::getArtist;
159 case 'A':
160 return &MPD::Song::getAlbumArtist;
161 case 't':
162 return &MPD::Song::getTitle;
163 case 'b':
164 return &MPD::Song::getAlbum;
165 case 'y':
166 return &MPD::Song::getDate;
167 case 'n':
168 return &MPD::Song::getTrackNumber;
169 case 'N':
170 return &MPD::Song::getTrack;
171 case 'g':
172 return &MPD::Song::getGenre;
173 case 'c':
174 return &MPD::Song::getComposer;
175 case 'p':
176 return &MPD::Song::getPerformer;
177 case 'd':
178 return &MPD::Song::getDisc;
179 case 'C':
180 return &MPD::Song::getComment;
181 case 'P':
182 return &MPD::Song::getPriority;
183 default:
184 return nullptr;
188 std::string itemTypeToString(MPD::Item::Type type)
190 std::string result;
191 switch (type)
193 case MPD::Item::Type::Directory:
194 result = "directory";
195 break;
196 case MPD::Item::Type::Song:
197 result = "song";
198 break;
199 case MPD::Item::Type::Playlist:
200 result = "playlist";
201 break;
203 return result;