1#ifndef TAG_PARSER_GENERICCONTAINER_H
2#define TAG_PARSER_GENERICCONTAINER_H
22template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
class TAG_PARSER_EXPORT GenericContainer :
public AbstractContainer {
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;
70template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
73 , m_fileInfo(&fileInfo)
83template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
98template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
102 parseHeader(diag, progress);
103 if (m_firstElement) {
104 m_firstElement->validateSubsequentElementStructure(diag, paddingSize, &progress);
113template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
131template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
134 return m_firstElement.get();
144template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
147 return m_additionalElements;
157template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
160 return m_additionalElements;
163template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
166 return m_tags[index].get();
169template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
172 return m_tags.size();
175template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
178 return m_tracks[index].get();
181template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
184 for (
auto &track : m_tracks) {
185 if (track->id() ==
id) {
192template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
195 return m_tracks.size();
207template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
222template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
237template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
252template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
258template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
262 if (!m_tags.empty()) {
263 if (!target.
isEmpty() && m_tags.front()->supportsTarget()) {
264 for (
auto &tag : m_tags) {
265 if (tag->target() == target) {
270 return m_tags.front().get();
275 const auto &tag = m_tags.emplace_back(std::make_unique<TagType>());
276 tag->setTarget(target);
280template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
283 if (
const 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();
292template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
314template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
317 if (!areTracksParsed() || !supportsTrackModifications()) {
321 auto id = track->id();
323 for (
const auto &existingTrack : m_tracks) {
324 if (existingTrack->id() ==
id) {
326 goto ensureIdIsUnique;
331 m_tracks.emplace_back(track);
332 return m_tracksAltered =
true;
335template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
338 if (!areTracksParsed() || !supportsTrackModifications() || m_tracks.empty()) {
341 auto removed =
false;
342 for (
auto i = m_tracks.end() - 1, begin = m_tracks.begin();; --i) {
353 m_tracksAltered =
true;
358template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
361 if (areTracksParsed() && supportsTrackModifications() && m_tracks.size()) {
363 m_tracksAltered =
true;
367template <
class FileInfoType,
class TagType,
class TrackType,
class ElementType>
371 m_firstElement.reset();
372 m_additionalElements.clear();
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks.
The AbstractContainer class provides an interface and common functionality to parse and make a certai...
virtual void reset()
Discards all parsing results.
The AbstractTrack class parses and stores technical information about video, audio and other kinds of...
The Diagnostics class is a container for DiagMessage.
const std::vector< std::unique_ptr< TrackType > > & tracks() const
Returns the tracks of the file.
bool removeTrack(AbstractTrack *track) override
Removes the specified track to the container.
TagType * tag(std::size_t index) override
Returns the tag with the specified index.
void validateElementStructure(Diagnostics &diag, AbortableProgressFeedback &progress, std::uint64_t *paddingSize=nullptr)
Parses all elements the file consists of.
bool removeTag(Tag *tag) override
Removes the specified tag from the container.
TrackType * track(std::size_t index) override
Returns the track with the specified index.
void removeAllTags() override
Removes all tags attached to the container.
std::vector< std::unique_ptr< TrackType > > m_tracks
TagType * createTag(const TagTarget &target=TagTarget()) override
Creates and returns a tag for the specified target.
const std::vector< std::unique_ptr< TagType > > & tags() const
Returns the tags of the file.
GenericContainer(FileInfoType &fileInfo, std::uint64_t startOffset)
Constructs a new container for the specified fileInfo at the specified startOffset.
TrackType * trackById(std::uint64_t id)
bool addTrack(TrackType *track)
Adds the specified track to the container.
std::unique_ptr< ElementType > m_firstElement
ElementType ContainerElementType
FileInfoType & fileInfo() const
Returns the related file info.
~GenericContainer() override
Destroys the container.
std::vector< std::unique_ptr< ElementType > > m_additionalElements
void removeAllTracks() override
Removes all tracks from the container.
std::vector< std::unique_ptr< TrackType > > & tracks()
Returns the tracks of the file.
ElementType * firstElement() const
Returns the first element of the file if available; otherwiese returns nullptr.
std::vector< std::unique_ptr< TagType > > m_tags
std::size_t trackCount() const override
Returns the number of tracks the container holds.
std::vector< std::unique_ptr< TagType > > & tags()
Returns the tags of the file.
const std::vector< std::unique_ptr< ElementType > > & additionalElements() const
Returns all available additional elements.
void reset() override
Discards all parsing results.
std::size_t tagCount() const override
Returns the number of tags attached to the container.
FileInfoType ContainerFileInfoType
std::vector< std::unique_ptr< ElementType > > & additionalElements()
Returns all available additional elements.
The TagTarget class specifies the target of a tag.
bool isEmpty() const
Returns an indication whether the target is empty.
The Tag class is used to store, read and write tag information.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Contains all classes and functions of the TagInfo library.
TagType
Specifies the tag type.
TrackType
The TrackType enum specifies the underlying file type of a track and the concrete class of the track ...