MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- File List
- Globals

DetachedSong.hxx
Go to the documentation of this file.
1 /*
2 * Copyright 2003-2017 The Music Player Daemon Project
3 * http://www.musicpd.org
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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef MPD_DETACHED_SONG_HXX
21 #define MPD_DETACHED_SONG_HXX
22
23 #include "check.h"
24 #include "tag/Tag.hxx"
25 #include "Chrono.hxx"
26 #include "Compiler.h"
27
28 #include <string>
29 #include <utility>
30
31 #include <time.h>
32
33 struct LightSong;
34 class Storage;
35 class Path;
36
37 class DetachedSong {
38 friend DetachedSong DatabaseDetachSong(const Storage &db,
39 const LightSong &song);
40
52 std::string uri;
53
62 std::string real_uri;
63
64 Tag tag;
65
66 time_t mtime = 0;
67
71 SongTime start_time = SongTime::zero();
72
77 SongTime end_time = SongTime::zero();
78
79 explicit DetachedSong(const LightSong &other);
80
81 public:
82 explicit DetachedSong(const DetachedSong &) = default;
83
84 explicit DetachedSong(const char *_uri)
85 :uri(_uri) {}
86
87 explicit DetachedSong(const std::string &_uri)
88 :uri(_uri) {}
89
90 explicit DetachedSong(std::string &&_uri)
91 :uri(std::move(_uri)) {}
92
93 template<typename U>
94 DetachedSong(U &&_uri, Tag &&_tag)
95 :uri(std::forward<U>(_uri)),
96 tag(std::move(_tag)) {}
97
98 DetachedSong(DetachedSong &&) = default;
99
100 ~DetachedSong();
101
102 gcc_pure
103 const char *GetURI() const {
104 return uri.c_str();
105 }
106
107 template<typename T>
108 void SetURI(T &&_uri) {
109 uri = std::forward<T>(_uri);
110 }
111
116 gcc_pure
117 bool HasRealURI() const {
118 return !real_uri.empty();
119 }
120
125 gcc_pure
126 const char *GetRealURI() const {
127 return (HasRealURI() ? real_uri : uri).c_str();
128 }
129
130 template<typename T>
131 void SetRealURI(T &&_uri) {
132 real_uri = std::forward<T>(_uri);
133 }
134
139 gcc_pure
140 bool IsSame(const DetachedSong &other) const {
141 return uri == other.uri &&
142 start_time == other.start_time &&
143 end_time == other.end_time;
144 }
145
146 gcc_pure gcc_nonnull_all
147 bool IsURI(const char *other_uri) const {
148 return uri == other_uri;
149 }
150
151 gcc_pure
152 bool IsRemote() const;
153
154 gcc_pure
155 bool IsFile() const {
156 return !IsRemote();
157 }
158
159 gcc_pure
160 bool IsAbsoluteFile() const;
161
162 gcc_pure
163 bool IsInDatabase() const;
164
165 const Tag &GetTag() const {
166 return tag;
167 }
168
169 Tag &WritableTag() {
170 return tag;
171 }
172
173 void SetTag(const Tag &_tag) {
174 tag = Tag(_tag);
175 }
176
177 void SetTag(Tag &&_tag) {
178 tag = std::move(_tag);
179 }
180
181 void MoveTagFrom(DetachedSong &&other) {
182 tag = std::move(other.tag);
183 }
184
189 void MoveTagItemsFrom(DetachedSong &&other) {
190 tag.MoveItemsFrom(std::move(other.tag));
191 }
192
193 time_t GetLastModified() const {
194 return mtime;
195 }
196
197 void SetLastModified(time_t _value) {
198 mtime = _value;
199 }
200
201 SongTime GetStartTime() const {
202 return start_time;
203 }
204
205 void SetStartTime(SongTime _value) {
206 start_time = _value;
207 }
208
209 SongTime GetEndTime() const {
210 return end_time;
211 }
212
213 void SetEndTime(SongTime _value) {
214 end_time = _value;
215 }
216
217 gcc_pure
218 SignedSongTime GetDuration() const;
219
225 bool Update();
226
230 bool LoadFile(Path path);
231 };
232
233 #endif
check.h
DetachedSong::IsAbsoluteFile
gcc_pure bool IsAbsoluteFile() const
DetachedSong::GetURI
gcc_pure const char * GetURI() const
Definition: DetachedSong.hxx:103
DetachedSong::Update
bool Update()
Update the #tag and #mtime.
DetachedSong::GetTag
const Tag & GetTag() const
Definition: DetachedSong.hxx:165
gcc_nonnull_all
#define gcc_nonnull_all
Definition: Compiler.h:122
DetachedSong::GetRealURI
gcc_pure const char * GetRealURI() const
Returns "real" URI (#real_uri) and falls back to just GetURI().
Definition: DetachedSong.hxx:126
DetachedSong::SetTag
void SetTag(Tag &&_tag)
Definition: DetachedSong.hxx:177
Chrono.hxx
SongTime::zero
static constexpr SongTime zero()
Definition: Chrono.hxx:41
Tag
The meta information about a song file.
Definition: Tag.hxx:34
DetachedSong::IsInDatabase
gcc_pure bool IsInDatabase() const
DetachedSong::IsRemote
gcc_pure bool IsRemote() const
SongTime
A time stamp within a song.
Definition: Chrono.hxx:31
DetachedSong::SetLastModified
void SetLastModified(time_t _value)
Definition: DetachedSong.hxx:197
Tag.hxx
Storage
Definition: StorageInterface.hxx:46
DetachedSong::GetDuration
gcc_pure SignedSongTime GetDuration() const
DetachedSong::GetLastModified
time_t GetLastModified() const
Definition: DetachedSong.hxx:193
DetachedSong::SetEndTime
void SetEndTime(SongTime _value)
Definition: DetachedSong.hxx:213
DetachedSong::DetachedSong
DetachedSong(const std::string &_uri)
Definition: DetachedSong.hxx:87
DetachedSong::LoadFile
bool LoadFile(Path path)
Load #tag and #mtime from a local file.
DetachedSong::SetRealURI
void SetRealURI(T &&_uri)
Definition: DetachedSong.hxx:131
DetachedSong::IsURI
gcc_pure gcc_nonnull_all bool IsURI(const char *other_uri) const
Definition: DetachedSong.hxx:147
DetachedSong::WritableTag
Tag & WritableTag()
Definition: DetachedSong.hxx:169
Path
A path name in the native file system character set.
Definition: Path.hxx:39
Compiler.h
DetachedSong::DetachedSong
DetachedSong(const char *_uri)
Definition: DetachedSong.hxx:84
DetachedSong::MoveTagFrom
void MoveTagFrom(DetachedSong &&other)
Definition: DetachedSong.hxx:181
Tag::MoveItemsFrom
void MoveItemsFrom(Tag &&other)
Similar to the move operator, but move only the TagItem array.
Definition: Tag.hxx:88
DetachedSong::DetachedSong
DetachedSong(std::string &&_uri)
Definition: DetachedSong.hxx:90
DetachedSong::HasRealURI
gcc_pure bool HasRealURI() const
Does this object have a "real" URI different from the displayed URI?
Definition: DetachedSong.hxx:117
DetachedSong::~DetachedSong
~DetachedSong()
DetachedSong::IsFile
gcc_pure bool IsFile() const
Definition: DetachedSong.hxx:155
DetachedSong::DatabaseDetachSong
friend DetachedSong DatabaseDetachSong(const Storage &db, const LightSong &song)
"Detach" the Song object, i.e.
LightSong::tag
const Tag * tag
Must not be nullptr.
Definition: LightSong.hxx:63
SignedSongTime
A variant of SongTime that is based on a signed integer.
Definition: Chrono.hxx:115
DetachedSong::SetTag
void SetTag(const Tag &_tag)
Definition: DetachedSong.hxx:173
DetachedSong::SetStartTime
void SetStartTime(SongTime _value)
Definition: DetachedSong.hxx:205
DetachedSong::GetStartTime
SongTime GetStartTime() const
Definition: DetachedSong.hxx:201
DetachedSong::GetEndTime
SongTime GetEndTime() const
Definition: DetachedSong.hxx:209
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
DetachedSong
Definition: DetachedSong.hxx:37
DetachedSong::DetachedSong
DetachedSong(U &&_uri, Tag &&_tag)
Definition: DetachedSong.hxx:94
DetachedSong::SetURI
void SetURI(T &&_uri)
Definition: DetachedSong.hxx:108
DetachedSong::MoveTagItemsFrom
void MoveTagItemsFrom(DetachedSong &&other)
Similar to the MoveTagFrom(), but move only the TagItem array.
Definition: DetachedSong.hxx:189
DetachedSong::IsSame
gcc_pure bool IsSame(const DetachedSong &other) const
Returns true if both objects refer to the same physical song.
Definition: DetachedSong.hxx:140
LightSong
A reference to a song file.
Definition: LightSong.hxx:40