configure: require c++14 compatible compiler
[ncmpcpp.git] / src / mutable_song.h
blobfa3d2024a30fe76e5c726031af49dc1623672e8a
1 /***************************************************************************
2 * Copyright (C) 2008-2014 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_EDITABLE_SONG_H
22 #define NCMPCPP_EDITABLE_SONG_H
24 #include <map>
25 #include "config.h"
26 #include "song.h"
28 namespace MPD {
30 struct MutableSong : public Song
32 typedef void (MutableSong::*SetFunction)(const std::string &, unsigned);
34 MutableSong() : m_mtime(0), m_duration(0) { }
35 MutableSong(Song s) : Song(s), m_mtime(0), m_duration(0) { }
37 virtual std::string getArtist(unsigned idx = 0) const override;
38 virtual std::string getTitle(unsigned idx = 0) const override;
39 virtual std::string getAlbum(unsigned idx = 0) const override;
40 virtual std::string getAlbumArtist(unsigned idx = 0) const override;
41 virtual std::string getTrack(unsigned idx = 0) const override;
42 virtual std::string getDate(unsigned idx = 0) const override;
43 virtual std::string getGenre(unsigned idx = 0) const override;
44 virtual std::string getComposer(unsigned idx = 0) const override;
45 virtual std::string getPerformer(unsigned idx = 0) const override;
46 virtual std::string getDisc(unsigned idx = 0) const override;
47 virtual std::string getComment(unsigned idx = 0) const override;
49 void setArtist(const std::string &value, unsigned idx = 0);
50 void setTitle(const std::string &value, unsigned idx = 0);
51 void setAlbum(const std::string &value, unsigned idx = 0);
52 void setAlbumArtist(const std::string &value, unsigned idx = 0);
53 void setTrack(const std::string &value, unsigned idx = 0);
54 void setDate(const std::string &value, unsigned idx = 0);
55 void setGenre(const std::string &value, unsigned idx = 0);
56 void setComposer(const std::string &value, unsigned idx = 0);
57 void setPerformer(const std::string &value, unsigned idx = 0);
58 void setDisc(const std::string &value, unsigned idx = 0);
59 void setComment(const std::string &value, unsigned idx = 0);
61 const std::string &getNewName() const;
62 void setNewName(const std::string &value);
64 virtual unsigned getDuration() const override;
65 virtual time_t getMTime() const override;
66 void setDuration(unsigned duration);
67 void setMTime(time_t mtime);
69 void setTags(SetFunction set, const std::string &value);
71 bool isModified() const;
72 void clearModifications();
74 private:
75 struct Tag
77 Tag(mpd_tag_type type_, unsigned idx_) : m_type(type_), m_idx(idx_) { }
79 mpd_tag_type type() const { return m_type; }
80 unsigned idx() const { return m_idx; }
82 bool operator<(const Tag &t) const
84 if (m_type != t.m_type)
85 return m_type < t.m_type;
86 return m_idx < t.m_idx;
89 private:
90 mpd_tag_type m_type;
91 unsigned m_idx;
94 void replaceTag(mpd_tag_type tag_type, std::string orig_value,
95 const std::string &value, unsigned idx);
97 template <typename F>
98 std::string getTag(mpd_tag_type tag_type, F orig_value, unsigned idx) const {
99 auto it = m_tags.find(Tag(tag_type, idx));
100 std::string result;
101 if (it == m_tags.end())
102 result = orig_value();
103 else
104 result = it->second;
105 return result;
108 std::string m_name;
109 time_t m_mtime;
110 unsigned m_duration;
111 std::map<Tag, std::string> m_tags;
116 #endif // NCMPCPP_EDITABLE_SONG_H