MPD  0.20.6
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:
57  :duration(SignedSongTime::Negative()), has_playlist(false) {}
58 
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);
70 
71  TagBuilder &operator=(Tag &&other);
72 
77  bool IsEmpty() const {
78  return items.empty();
79  }
80 
84  gcc_pure
85  bool IsDefined() const {
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;
128 
133  void Complement(const Tag &other);
134 
143  void AddItem(TagType type, StringView value);
144 
152  void AddItem(TagType type, const char *value);
153 
159  void AddEmptyItem(TagType type);
160 
164  void RemoveAll();
165 
169  void RemoveType(TagType type);
170 
171 private:
173  void AddItemInternal(TagType type, StringView value);
174 };
175 
176 #endif
TagBuilder()
Create an empty tag.
Definition: TagBuilder.hxx:56
void Reserve(unsigned n)
Definition: TagBuilder.hxx:118
void Complement(const Tag &other)
Copy attributes and items from the other object that do not exist in this object. ...
#define gcc_nonnull_all
Definition: Compiler.h:122
The meta information about a song file.
Definition: Tag.hxx:34
constexpr bool IsNegative() const
Definition: Chrono.hxx:202
gcc_pure bool IsDefined() const
Returns true if the object contains any information.
Definition: TagBuilder.hxx:85
gcc_nonnull_all void AddItem(TagType type, StringView value)
Appends a new tag item.
TagBuilder & operator=(const TagBuilder &other)
void AddEmptyItem(TagType type)
Appends a new tag item with an empty value.
bool IsEmpty() const
Returns true if the tag contains no items.
Definition: TagBuilder.hxx:77
A class that constructs Tag objects.
Definition: TagBuilder.hxx:36
gcc_pure bool HasType(TagType type) const
Checks whether the tag contains one or more items with the specified type.
TagType
Codes for the type of a tag item.
Definition: TagType.h:30
One tag value.
Definition: TagItem.hxx:30
void SetHasPlaylist(bool _has_playlist)
Definition: TagBuilder.hxx:114
Tag Commit()
Create a new Tag instance from data in this object.
void RemoveType(TagType type)
Removes all tag items of the specified type.
Tag * CommitNew()
Create a new Tag instance from data in this object.
A variant of SongTime that is based on a signed integer.
Definition: Chrono.hxx:115
void SetDuration(SignedSongTime _duration)
Definition: TagBuilder.hxx:110
#define gcc_pure
Definition: Compiler.h:116
void RemoveAll()
Removes all tag items.
void Clear()