2013-07-30 20:11:57 +02:00
|
|
|
/*
|
2022-07-14 17:58:12 +02:00
|
|
|
* Copyright 2003-2022 The Music Player Daemon Project
|
2013-07-30 20:11:57 +02:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MPD_TAG_HXX
|
|
|
|
#define MPD_TAG_HXX
|
|
|
|
|
2017-02-08 08:26:58 +01:00
|
|
|
#include "Type.h" // IWYU pragma: export
|
|
|
|
#include "Item.hxx" // IWYU pragma: export
|
2014-08-29 12:14:27 +02:00
|
|
|
#include "Chrono.hxx"
|
2020-04-24 16:00:05 +02:00
|
|
|
#include "util/DereferenceIterator.hxx"
|
2013-07-30 20:11:57 +02:00
|
|
|
|
2017-12-20 14:59:51 +01:00
|
|
|
#include <memory>
|
2019-07-05 09:59:00 +02:00
|
|
|
#include <utility>
|
2013-07-30 20:11:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The meta information about a song file. It is a MPD specific
|
|
|
|
* subset of tags (e.g. from ID3, vorbis comments, ...).
|
|
|
|
*/
|
|
|
|
struct Tag {
|
|
|
|
/**
|
2014-08-29 12:14:27 +02:00
|
|
|
* The duration of the song. A negative value means that the
|
|
|
|
* length is unknown.
|
2013-07-30 20:11:57 +02:00
|
|
|
*/
|
2018-01-20 19:39:06 +01:00
|
|
|
SignedSongTime duration = SignedSongTime::Negative();
|
2013-07-30 20:11:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Does this file have an embedded playlist (e.g. embedded CUE
|
|
|
|
* sheet)?
|
|
|
|
*/
|
2018-01-20 19:39:06 +01:00
|
|
|
bool has_playlist = false;
|
2013-07-30 20:11:57 +02:00
|
|
|
|
2014-01-19 03:11:01 +01:00
|
|
|
/** the total number of tag items in the #items array */
|
2018-01-20 19:39:06 +01:00
|
|
|
unsigned short num_items = 0;
|
2014-01-19 03:11:01 +01:00
|
|
|
|
2013-07-30 20:11:57 +02:00
|
|
|
/** an array of tag items */
|
2018-01-20 19:39:06 +01:00
|
|
|
TagItem **items = nullptr;
|
2013-07-30 20:11:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an empty tag.
|
|
|
|
*/
|
2018-01-20 19:39:06 +01:00
|
|
|
Tag() = default;
|
2013-07-30 20:11:57 +02:00
|
|
|
|
2018-01-20 19:38:52 +01:00
|
|
|
Tag(const Tag &other) noexcept;
|
2013-07-30 20:11:57 +02:00
|
|
|
|
2018-01-20 19:38:52 +01:00
|
|
|
Tag(Tag &&other) noexcept
|
2014-08-29 12:14:27 +02:00
|
|
|
:duration(other.duration), has_playlist(other.has_playlist),
|
2014-01-19 03:11:01 +01:00
|
|
|
num_items(other.num_items), items(other.items) {
|
2013-07-30 20:11:57 +02:00
|
|
|
other.items = nullptr;
|
|
|
|
other.num_items = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free the tag object and all its items.
|
|
|
|
*/
|
2018-01-20 19:38:52 +01:00
|
|
|
~Tag() noexcept {
|
2013-12-03 13:18:53 +01:00
|
|
|
Clear();
|
|
|
|
}
|
2013-07-30 20:11:57 +02:00
|
|
|
|
|
|
|
Tag &operator=(const Tag &other) = delete;
|
|
|
|
|
2018-01-20 19:38:52 +01:00
|
|
|
Tag &operator=(Tag &&other) noexcept {
|
2014-08-29 12:14:27 +02:00
|
|
|
duration = other.duration;
|
2013-07-30 20:11:57 +02:00
|
|
|
has_playlist = other.has_playlist;
|
2016-02-23 20:57:56 +01:00
|
|
|
MoveItemsFrom(std::move(other));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Similar to the move operator, but move only the #TagItem
|
|
|
|
* array.
|
|
|
|
*/
|
2017-06-04 13:09:11 +02:00
|
|
|
void MoveItemsFrom(Tag &&other) noexcept {
|
2013-07-30 20:11:57 +02:00
|
|
|
std::swap(items, other.items);
|
|
|
|
std::swap(num_items, other.num_items);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-08-29 12:14:27 +02:00
|
|
|
* Returns true if the tag contains no items. This ignores
|
|
|
|
* the "duration" attribute.
|
2013-07-30 20:11:57 +02:00
|
|
|
*/
|
2017-06-04 13:09:11 +02:00
|
|
|
bool IsEmpty() const noexcept {
|
2013-07-30 20:11:57 +02:00
|
|
|
return num_items == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the tag contains any information.
|
|
|
|
*/
|
2017-06-04 13:09:11 +02:00
|
|
|
bool IsDefined() const noexcept {
|
2014-08-29 12:14:27 +02:00
|
|
|
return !IsEmpty() || !duration.IsNegative();
|
2013-07-30 20:11:57 +02:00
|
|
|
}
|
|
|
|
|
2013-07-31 00:26:55 +02:00
|
|
|
/**
|
|
|
|
* Clear everything, as if this was a new Tag object.
|
|
|
|
*/
|
2017-06-04 13:09:11 +02:00
|
|
|
void Clear() noexcept;
|
2013-07-31 00:26:55 +02:00
|
|
|
|
2013-07-30 20:11:57 +02:00
|
|
|
/**
|
|
|
|
* Merges the data from two tags. If both tags share data for the
|
2013-10-20 13:32:59 +02:00
|
|
|
* same TagType, only data from "add" is used.
|
2013-07-30 20:11:57 +02:00
|
|
|
*
|
|
|
|
* @return a newly allocated tag
|
|
|
|
*/
|
2021-08-05 17:31:31 +02:00
|
|
|
static Tag Merge(const Tag &base,
|
|
|
|
const Tag &add) noexcept;
|
|
|
|
|
|
|
|
static std::unique_ptr<Tag> MergePtr(const Tag &base,
|
|
|
|
const Tag &add) noexcept;
|
2013-07-30 20:11:57 +02:00
|
|
|
|
|
|
|
/**
|
2013-10-28 23:58:17 +01:00
|
|
|
* Merges the data from two tags. Any of the two may be nullptr. Both
|
2013-07-30 20:11:57 +02:00
|
|
|
* are freed by this function.
|
|
|
|
*
|
|
|
|
* @return a newly allocated tag
|
|
|
|
*/
|
2017-12-20 14:43:29 +01:00
|
|
|
static std::unique_ptr<Tag> Merge(std::unique_ptr<Tag> base,
|
2018-01-20 19:38:52 +01:00
|
|
|
std::unique_ptr<Tag> add) noexcept;
|
2013-07-30 20:11:57 +02:00
|
|
|
|
2021-08-05 17:34:05 +02:00
|
|
|
/**
|
|
|
|
* Merges the data from two tags. Any of the two may be nullptr.
|
|
|
|
*
|
|
|
|
* @return a newly allocated tag (or nullptr if both
|
|
|
|
* parameters are nullptr)
|
|
|
|
*/
|
|
|
|
static std::unique_ptr<Tag> Merge(const Tag *base,
|
|
|
|
const Tag *add) noexcept;
|
|
|
|
|
2013-07-30 20:11:57 +02:00
|
|
|
/**
|
2013-10-28 23:58:17 +01:00
|
|
|
* Returns the first value of the specified tag type, or
|
|
|
|
* nullptr if none is present in this tag object.
|
2013-07-30 20:11:57 +02:00
|
|
|
*/
|
2021-10-13 10:30:43 +02:00
|
|
|
[[gnu::pure]]
|
2017-05-08 14:44:49 +02:00
|
|
|
const char *GetValue(TagType type) const noexcept;
|
2013-07-30 20:11:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the tag contains one or more items with
|
|
|
|
* the specified type.
|
|
|
|
*/
|
2021-10-13 10:30:43 +02:00
|
|
|
[[gnu::pure]]
|
2017-05-08 14:44:49 +02:00
|
|
|
bool HasType(TagType type) const noexcept;
|
2017-02-08 09:22:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a value for sorting on the specified type, with
|
|
|
|
* automatic fallbacks to the next best tag type
|
|
|
|
* (e.g. #TAG_ALBUM_ARTIST falls back to #TAG_ARTIST). If
|
|
|
|
* there is no such value, returns an empty string.
|
|
|
|
*/
|
2021-10-13 10:30:43 +02:00
|
|
|
[[gnu::pure]] [[gnu::returns_nonnull]]
|
2017-06-04 13:09:11 +02:00
|
|
|
const char *GetSortValue(TagType type) const noexcept;
|
2014-07-12 17:22:39 +02:00
|
|
|
|
2020-04-24 16:00:05 +02:00
|
|
|
using const_iterator = DereferenceIterator<TagItem *const*,
|
|
|
|
const TagItem>;
|
2014-07-12 17:22:39 +02:00
|
|
|
|
2018-01-20 19:38:52 +01:00
|
|
|
const_iterator begin() const noexcept {
|
2014-07-12 17:22:39 +02:00
|
|
|
return const_iterator{items};
|
|
|
|
}
|
|
|
|
|
2018-01-20 19:38:52 +01:00
|
|
|
const_iterator end() const noexcept {
|
2014-07-12 17:22:39 +02:00
|
|
|
return const_iterator{items + num_items};
|
|
|
|
}
|
2013-07-30 20:11:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|