Tag Parser
9.4.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
|
Go to the documentation of this file. 1 #ifndef TAG_PARSER_GENERICCONTAINER_H
2 #define TAG_PARSER_GENERICCONTAINER_H
39 const std::vector<std::unique_ptr<TagType>> &
tags()
const;
40 std::vector<std::unique_ptr<TagType>> &
tags();
41 const std::vector<std::unique_ptr<TrackType>> &
tracks()
const;
42 std::vector<std::unique_ptr<TrackType>> &
tracks();
60 std::vector<std::unique_ptr<TagType>>
m_tags;
61 std::vector<std::unique_ptr<TrackType>>
m_tracks;
64 FileInfoType *m_fileInfo;
70 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
73 , m_fileInfo(&fileInfo)
83 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
98 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
102 if (m_firstElement) {
103 m_firstElement->validateSubsequentElementStructure(diag, paddingSize);
112 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
130 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
133 return m_firstElement.get();
143 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
146 return m_additionalElements;
156 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
159 return m_additionalElements;
162 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
165 return m_tags[index].get();
168 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
171 return m_tags.size();
174 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
177 return m_tracks[index].get();
180 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
183 for (
auto &track : m_tracks) {
184 if (track->id() ==
id) {
191 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
194 return m_tracks.size();
206 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
221 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
236 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
251 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
257 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
261 if (!m_tags.empty()) {
262 if (!target.
isEmpty() && m_tags.front()->supportsTarget()) {
263 for (
auto &tag : m_tags) {
264 if (tag->target() == target) {
269 return m_tags.front().get();
274 m_tags.emplace_back(std::make_unique<TagType>());
275 auto &tag = m_tags.back();
276 tag->setTarget(target);
280 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
283 if (
auto size = m_tags.size()) {
284 m_tags.erase(std::remove_if(m_tags.begin(), m_tags.end(),
285 [tag](
const std::unique_ptr<TagType> &existingTag) ->
bool { return static_cast<Tag *>(existingTag.get()) == tag; }),
287 return size != m_tags.size();
292 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
314 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
317 if (areTracksParsed() && supportsTrackModifications()) {
319 auto id = track->id();
321 for (
const auto &track : m_tracks) {
322 if (track->id() ==
id) {
324 goto ensureIdIsUnique;
329 m_tracks.emplace_back(track);
330 return m_tracksAltered =
true;
335 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
338 bool removed =
false;
339 if (areTracksParsed() && supportsTrackModifications() && !m_tracks.empty()) {
340 for (
auto i = m_tracks.end() - 1, begin = m_tracks.begin();; --i) {
351 m_tracksAltered =
true;
357 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
360 if (areTracksParsed() && supportsTrackModifications() && m_tracks.size()) {
362 m_tracksAltered =
true;
366 template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
370 m_firstElement.reset();
371 m_additionalElements.clear();
378 #endif // TAG_PARSER_GENERICCONTAINER_H
std::unique_ptr< ElementType > m_firstElement
const std::vector< std::unique_ptr< TrackType > > & tracks() const
Returns the tracks of the file.
std::vector< std::unique_ptr< TagType > > m_tags
TagType * tag(std::size_t index) override
Returns the tag with the specified index.
bool addTrack(TrackType *track)
Adds the specified track to the container.
ElementType * firstElement() const
Returns the first element of the file if available; otherwiese returns nullptr.
TrackType * trackById(std::uint64_t id)
bool removeTag(Tag *tag) override
Removes the specified tag from the container.
The Tag class is used to store, read and write tag information.
~GenericContainer() override
Destroys the container.
The Diagnostics class is a container for DiagMessage.
Contains all classes and functions of the TagInfo library.
std::vector< std::unique_ptr< ElementType > > & additionalElements()
Returns all available additional elements.
std::vector< std::unique_ptr< ElementType > > m_additionalElements
std::vector< std::unique_ptr< TrackType > > & tracks()
Returns the tracks of the file.
TrackType * track(std::size_t index) override
Returns the track with the specified index.
TrackType
Specifies the track type.
The GenericContainer class helps parsing header, track, tag and chapter information of a file.
The AbstractContainer class provides an interface and common functionality to parse and make a certai...
std::vector< std::unique_ptr< TrackType > > m_tracks
void validateElementStructure(Diagnostics &diag, std::uint64_t *paddingSize=nullptr)
Parses all elements the file consists of.
TagType * createTag(const TagTarget &target=TagTarget()) override
Creates and returns a tag for the specified target.
std::size_t tagCount() const override
Returns the number of tags attached to the container.
Implementation of TagParser::AbstractTrack for the MP4 container.
The AbstractTrack class parses and stores technical information about video, audio and other kinds of...
const std::vector< std::unique_ptr< TagType > > & tags() const
Returns the tags of the file.
void removeAllTracks() override
Removes all tracks from the container.
void removeAllTags() override
Removes all tags attached to the container.
GenericContainer(FileInfoType &fileInfo, std::uint64_t startOffset)
Constructs a new container for the specified fileInfo at the specified startOffset.
The TagTarget class specifies the target of a tag.
Implementation of TagParser::Tag for the MP4 container.
void reset() override
Discards all parsing results.
const std::vector< std::unique_ptr< ElementType > > & additionalElements() const
Returns all available additional elements.
std::size_t trackCount() const override
Returns the number of tracks the container holds.
bool removeTrack(AbstractTrack *track) override
Removes the specified track to the container.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
FileInfoType & fileInfo() const
Returns the related file info.
The Mp4Atom class helps to parse MP4 files.
virtual void reset()
Discards all parsing results.
bool isEmpty() const
Returns an indication whether the target is empty.
std::vector< std::unique_ptr< TagType > > & tags()
Returns the tags of the file.
TagType
Specifies the tag type.