tagparser/tagtarget.h

225 lines
5.7 KiB
C
Raw Normal View History

#ifndef TAG_PARSER_TAGTARGET_H
#define TAG_PARSER_TAGTARGET_H
2015-04-22 19:22:01 +02:00
2016-08-29 15:43:05 +02:00
#include "./global.h"
2019-03-13 19:06:42 +01:00
#include <cstdint>
2018-03-07 01:17:50 +01:00
#include <functional>
2015-04-22 19:22:01 +02:00
#include <string>
#include <vector>
namespace TagParser {
2015-04-22 19:22:01 +02:00
2016-05-26 01:59:22 +02:00
/*!
* \brief The TagTargetLevel enum specifies tag target levels.
*/
2018-03-07 01:17:50 +01:00
enum class TagTargetLevel : unsigned char { Unspecified, Shot, Subtrack, Track, Part, Album, Edition, Collection };
2016-05-26 01:59:22 +02:00
TAG_PARSER_EXPORT std::string_view tagTargetLevelName(TagTargetLevel tagTargetLevel);
2016-05-26 01:59:22 +02:00
2018-03-07 01:17:50 +01:00
class TAG_PARSER_EXPORT TagTarget {
2015-04-22 19:22:01 +02:00
public:
2019-03-13 19:06:42 +01:00
using IdType = std::uint64_t;
2018-07-11 13:19:43 +02:00
using IdContainerType = std::vector<IdType>;
2015-04-22 19:22:01 +02:00
explicit TagTarget(std::uint64_t level = 0, IdContainerType tracks = IdContainerType(), IdContainerType chapters = IdContainerType(),
2018-03-07 01:17:50 +01:00
IdContainerType editions = IdContainerType(), IdContainerType attachments = IdContainerType());
2015-04-22 19:22:01 +02:00
2019-03-13 19:06:42 +01:00
std::uint64_t level() const;
void setLevel(std::uint64_t level);
2015-04-22 19:22:01 +02:00
const std::string &levelName() const;
void setLevelName(const std::string &levelName);
const IdContainerType &tracks() const;
IdContainerType &tracks();
const IdContainerType &chapters() const;
IdContainerType &chapters();
const IdContainerType &editions() const;
IdContainerType &editions();
const IdContainerType &attachments() const;
IdContainerType &attachments();
bool isEmpty() const;
void clear();
2019-03-13 19:06:42 +01:00
std::string toString(const std::function<TagTargetLevel(std::uint64_t)> &tagTargetMapping) const;
2016-05-26 01:59:22 +02:00
std::string toString(TagTargetLevel tagTargetLevel) const;
2018-03-07 01:17:50 +01:00
bool operator==(const TagTarget &other) const;
2021-12-31 00:31:32 +01:00
bool matches(const TagTarget &other) const;
2015-04-22 19:22:01 +02:00
private:
2019-03-13 19:06:42 +01:00
std::uint64_t m_level;
2015-04-22 19:22:01 +02:00
std::string m_levelName;
IdContainerType m_tracks;
IdContainerType m_chapters;
IdContainerType m_editions;
IdContainerType m_attachments;
};
/*!
* \brief Constructs a new TagTarget with the specified \a level, \a track, \a chapter,
* \a edition and \a attachment.
*/
2019-03-13 19:06:42 +01:00
inline TagTarget::TagTarget(
std::uint64_t level, IdContainerType tracks, IdContainerType chapters, IdContainerType editions, IdContainerType attachments)
2018-03-07 01:17:50 +01:00
: m_level(level)
, m_tracks(tracks)
, m_chapters(chapters)
, m_editions(editions)
, m_attachments(attachments)
{
}
2015-04-22 19:22:01 +02:00
/*!
* \brief Returns the level.
*/
2019-03-13 19:06:42 +01:00
inline std::uint64_t TagTarget::level() const
2015-04-22 19:22:01 +02:00
{
return m_level ? m_level : 50;
2015-04-22 19:22:01 +02:00
}
/*!
* \brief Sets the level.
*/
2019-03-13 19:06:42 +01:00
inline void TagTarget::setLevel(std::uint64_t level)
2015-04-22 19:22:01 +02:00
{
m_level = level;
}
/*!
* \brief Returns the level name.
*/
inline const std::string &TagTarget::levelName() const
{
return m_levelName;
}
/*!
* \brief Sets the level name.
*/
inline void TagTarget::setLevelName(const std::string &levelName)
{
m_levelName = levelName;
}
/*!
* \brief Returns the tracks.
*/
inline const TagTarget::IdContainerType &TagTarget::tracks() const
{
return m_tracks;
}
/*!
* \brief Returns the tracks.
*/
inline TagTarget::IdContainerType &TagTarget::tracks()
{
return m_tracks;
}
/*!
* \brief Returns the chapters.
*/
inline const TagTarget::IdContainerType &TagTarget::chapters() const
{
return m_chapters;
}
/*!
* \brief Returns the chapters.
*/
inline TagTarget::IdContainerType &TagTarget::chapters()
{
return m_chapters;
}
/*!
* \brief Returns the editions.
*/
inline const TagTarget::IdContainerType &TagTarget::editions() const
{
return m_editions;
}
/*!
* \brief Returns the editions.
*/
inline TagTarget::IdContainerType &TagTarget::editions()
{
return m_editions;
}
/*!
* \brief Returns the attachments.
*/
inline const TagTarget::IdContainerType &TagTarget::attachments() const
{
return m_attachments;
}
/*!
* \brief Returns the attachments.
*/
inline TagTarget::IdContainerType &TagTarget::attachments()
{
return m_attachments;
}
/*!
* \brief Returns an indication whether the target is empty.
*/
inline bool TagTarget::isEmpty() const
{
2018-03-07 01:17:50 +01:00
return m_level == 0 && m_levelName.empty() && m_tracks.empty() && m_chapters.empty() && m_editions.empty() && m_attachments.empty();
2015-04-22 19:22:01 +02:00
}
/*!
* \brief Clears the TagTarget.
*/
inline void TagTarget::clear()
{
m_level = 0;
m_levelName.clear();
m_tracks.clear();
m_chapters.clear();
m_editions.clear();
m_attachments.clear();
}
/*!
* \brief Returns whether the tag targets are equal.
2021-12-31 00:31:32 +01:00
* \returns
* Returns whether all specifications of the current instance (besides the level name) are equal
* to the corresponding specification in \a other.
2015-04-22 19:22:01 +02:00
*/
2018-03-07 01:17:50 +01:00
inline bool TagTarget::operator==(const TagTarget &other) const
2015-04-22 19:22:01 +02:00
{
2018-03-07 01:17:50 +01:00
return level() == other.level() && m_tracks == other.m_tracks && m_chapters == other.m_chapters && m_editions == other.m_editions
&& m_attachments == other.m_attachments;
2015-04-22 19:22:01 +02:00
}
2021-12-31 00:31:32 +01:00
/*!
* \brief Returns whether the current instance matches \a other.
* \returns
* Returns whether all non-empty/non-null specifications of the current instance (besides the level
* name) are equal to the corresponding specification in \a other.
*/
inline bool TagTarget::matches(const TagTarget &other) const
{
return (!m_level || level() == other.level()) && (m_tracks.empty() || m_tracks == other.m_tracks)
&& (m_chapters.empty() || m_chapters == other.m_chapters) && (m_editions.empty() || m_editions == other.m_editions)
&& (m_attachments.empty() || m_attachments == other.m_attachments);
}
2016-05-26 01:59:22 +02:00
/*!
* \brief Returns the string representation of the current instance.
* \remarks Uses the specified \a tagTargetMapping function to map the assigned level()
* to a TagTargetLevel if no levelName() is assigned.
*/
2019-03-13 19:06:42 +01:00
inline std::string TagTarget::toString(const std::function<TagTargetLevel(std::uint64_t)> &tagTargetMapping) const
2016-05-26 01:59:22 +02:00
{
return toString(tagTargetMapping ? tagTargetMapping(this->level()) : TagTargetLevel::Unspecified);
}
2018-03-07 01:17:50 +01:00
} // namespace TagParser
2015-04-22 19:22:01 +02:00
#endif // TAG_PARSER_TAGTARGET_H