MPD: tag/TagBuilder.hxx Source File

MPD 0.20.15

TagBuilder.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_TAG_BUILDER_HXX
21 #define MPD_TAG_BUILDER_HXX
22
23 #include "TagType.h"
24 #include "Chrono.hxx"
25 #include "Compiler.h"
26
27 #include <vector>
28
29 struct StringView;
30 struct TagItem;
31 struct Tag;
32
36 class TagBuilder {
41 SignedSongTime duration;
42
47 bool has_playlist;
48
50 std::vector<TagItem *> items;
51
52 public:
56 TagBuilder()
57 :duration(SignedSongTime::Negative()), has_playlist(false) {}
58
59 ~TagBuilder() {
60 Clear();
61 }
62
63 TagBuilder(const TagBuilder &other) = delete;
64
65 explicit TagBuilder(const Tag &other);
66 explicit TagBuilder(Tag &&other);
67
68 TagBuilder &operator=(const TagBuilder &other);
69 TagBuilder &operator=(TagBuilder &&other);
70
71 TagBuilder &operator=(Tag &&other);
72
77 bool IsEmpty() const {
78 return items.empty();
79 }
80
84 gcc_pure
85 bool IsDefined() const noexcept {
86 return !duration.IsNegative() || has_playlist || !IsEmpty();
87 }
88
89 void Clear();
90
95 void Commit(Tag &tag);
96
101 Tag Commit();
102
108 Tag *CommitNew();
109
110 void SetDuration(SignedSongTime _duration) {
111 duration = _duration;
112 }
113
114 void SetHasPlaylist(bool _has_playlist) {
115 has_playlist = _has_playlist;
116 }
117
118 void Reserve(unsigned n) {
119 items.reserve(n);
120 }
121
126 gcc_pure
127 bool HasType(TagType type) const noexcept;
128
133 void Complement(const Tag &other);
134
142 gcc_nonnull_all
143 void AddItem(TagType type, StringView value);
144
151 gcc_nonnull_all
152 void AddItem(TagType type, const char *value);
153
159 void AddEmptyItem(TagType type);
160
164 void RemoveAll() noexcept;
165
169 void RemoveType(TagType type) noexcept;
170
171 private:
172 gcc_nonnull_all
173 void AddItemInternal(TagType type, StringView value);
174 };
175
176 #endif
TagBuilder::TagBuilder
TagBuilder()
Create an empty tag.
Definition: TagBuilder.hxx:56
TagBuilder::Reserve
void Reserve(unsigned n)
Definition: TagBuilder.hxx:118
TagBuilder::Complement
void Complement(const Tag &other)
Copy attributes and items from the other object that do not exist in this object. ...
gcc_nonnull_all
#define gcc_nonnull_all
Definition: Compiler.h:122
Chrono.hxx
Tag
The meta information about a song file.
Definition: Tag.hxx:34
TagBuilder::AddItem
gcc_nonnull_all void AddItem(TagType type, StringView value)
Appends a new tag item.
TagBuilder::operator=
TagBuilder & operator=(const TagBuilder &other)
TagBuilder::AddEmptyItem
void AddEmptyItem(TagType type)
Appends a new tag item with an empty value.
SignedSongTime::IsNegative
constexpr bool IsNegative() const
Definition: Chrono.hxx:202
TagBuilder
A class that constructs Tag objects.
Definition: TagBuilder.hxx:36
TagBuilder::HasType
gcc_pure bool HasType(TagType type) const noexcept
Checks whether the tag contains one or more items with the specified type.
TagBuilder::IsEmpty
bool IsEmpty() const
Returns true if the tag contains no items.
Definition: TagBuilder.hxx:77
Compiler.h
TagType
TagType
Codes for the type of a tag item.
Definition: TagType.h:30
StringView
Definition: StringView.hxx:37
TagItem
One tag value.
Definition: TagItem.hxx:30
TagBuilder::SetHasPlaylist
void SetHasPlaylist(bool _has_playlist)
Definition: TagBuilder.hxx:114
TagBuilder::Commit
Tag Commit()
Create a new Tag instance from data in this object.
TagBuilder::IsDefined
gcc_pure bool IsDefined() const noexcept
Returns true if the object contains any information.
Definition: TagBuilder.hxx:85
TagType.h
TagBuilder::CommitNew
Tag * CommitNew()
Create a new Tag instance from data in this object.
SignedSongTime
A variant of SongTime that is based on a signed integer.
Definition: Chrono.hxx:115
TagBuilder::SetDuration
void SetDuration(SignedSongTime _duration)
Definition: TagBuilder.hxx:110
TagBuilder::~TagBuilder
~TagBuilder()
Definition: TagBuilder.hxx:59
gcc_pure
#define gcc_pure
Definition: Compiler.h:116
TagBuilder::RemoveType
void RemoveType(TagType type) noexcept
Removes all tag items of the specified type.
TagBuilder::RemoveAll
void RemoveAll() noexcept
Removes all tag items.
TagBuilder::Clear
void Clear()