Tag Parser 12.4.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
|
The GenericFileElement class helps to parse binary files which consist of an arboreal element structure. More...
#include <genericfileelement.h>
Public Types | |
using | ContainerType = typename FileElementTraits<ImplementationType>::ContainerType |
Specifies the type of the corresponding container. | |
using | IdentifierType = typename FileElementTraits<ImplementationType>::IdentifierType |
Specifies the type used to store identifiers. | |
using | DataSizeType = typename FileElementTraits<ImplementationType>::DataSizeType |
Specifies the type used to store data sizes. | |
Public Member Functions | |
GenericFileElement (ContainerType &container, std::uint64_t startOffset) | |
GenericFileElement (ImplementationType &parent, std::uint64_t startOffset) | |
Constructs a new sub level file element with the specified parent at the specified startOffset. | |
GenericFileElement (ContainerType &container, std::uint64_t startOffset, std::uint64_t maxSize) | |
GenericFileElement (const GenericFileElement &other)=delete | |
GenericFileElement (GenericFileElement &other)=delete | |
GenericFileElement & | operator= (const GenericFileElement &other)=delete |
ContainerType & | container () |
Returns the related container. | |
const ContainerType & | container () const |
Returns the related container. | |
std::iostream & | stream () |
Returns the related stream. | |
CppUtilities::BinaryReader & | reader () |
Returns the related BinaryReader. | |
CppUtilities::BinaryWriter & | writer () |
Returns the related BinaryWriter. | |
std::uint64_t | startOffset () const |
Returns the start offset in the related stream. | |
std::uint64_t | relativeStartOffset () const |
Returns the offset of the element in its parent or - if it is a top-level element - in the related stream. | |
const IdentifierType & | id () const |
Returns the element ID. | |
std::string | idToString () const |
Returns a printable string representation of the element ID. | |
std::uint32_t | idLength () const |
Returns the length of the id denotation in byte. | |
std::uint32_t | headerSize () const |
Returns the header size of the element in byte. | |
DataSizeType | dataSize () const |
Returns the data size of the element in byte. | |
std::uint32_t | sizeLength () const |
Returns the length of the size denotation of the element in byte. | |
std::uint64_t | dataOffset () const |
Returns the data offset of the element in the related stream. | |
std::uint64_t | totalSize () const |
Returns the total size of the element. | |
std::uint64_t | endOffset () const |
Returns the offset of the first byte which doesn't belong to this element anymore. | |
std::uint64_t | maxTotalSize () const |
Returns maximum total size. | |
std::uint8_t | level () const |
Returns how deep the element is nested (0 for top-level elements, 1 for children of top-level elements, ...). | |
ImplementationType * | parent () |
Returns the parent of the element. | |
const ImplementationType * | parent () const |
Returns the parent of the element. | |
ImplementationType * | parent (std::uint8_t n) |
Returns the n-th parent of the element. | |
const ImplementationType * | parent (std::uint8_t n) const |
Returns the n-th parent of the element. | |
ImplementationType * | nextSibling () |
Returns the next sibling of the element. | |
const ImplementationType * | nextSibling () const |
Returns the next sibling of the element. | |
ImplementationType * | firstChild () |
Returns the first child of the element. | |
const ImplementationType * | firstChild () const |
Returns the first child of the element. | |
ImplementationType * | lastChild () |
Returns the last child of the element. | |
const ImplementationType * | lastChild () const |
Returns the last child of the element. | |
template<class IdType > | |
ImplementationType * | subelementByPath (Diagnostics &diag, IdType item) |
Returns the sub element for the specified path. | |
template<class IdType , class... IdTypes> | |
ImplementationType * | subelementByPath (Diagnostics &diag, IdType item, IdTypes... remainingPath) |
Returns the sub element for the specified path. | |
template<class IdType > | |
const ImplementationType * | subelementByPath (Diagnostics &diag, IdType item) const |
Returns the sub element for the specified path. | |
template<class IdType , class... IdTypes> | |
const ImplementationType * | subelementByPath (Diagnostics &diag, IdType item, IdTypes... remainingPath) const |
Returns the sub element for the specified path. | |
ImplementationType * | childById (const IdentifierType &id, Diagnostics &diag) |
Returns the first child with the specified id. | |
const ImplementationType * | childById (const IdentifierType &id, Diagnostics &diag) const |
Returns the first child with the specified id. | |
ImplementationType * | siblingById (const IdentifierType &id, Diagnostics &diag) |
Returns the first sibling with the specified id. | |
const ImplementationType * | siblingById (const IdentifierType &id, Diagnostics &diag) const |
Returns the first sibling with the specified id. | |
ImplementationType * | siblingByIdIncludingThis (const IdentifierType &id, Diagnostics &diag) |
Returns the first sibling with the specified id or the current instance if its ID equals id. | |
const ImplementationType * | siblingByIdIncludingThis (const IdentifierType &id, Diagnostics &diag) const |
Returns the first sibling with the specified id or the current instance if its ID equals id. | |
bool | isParent () const |
Returns an indication whether this instance is a parent element. | |
bool | isPadding () const |
Returns an indication whether this instance is a padding element. | |
std::uint64_t | firstChildOffset () const |
Returns the offset of the first child (relative to the start offset of this element). | |
bool | isParsed () const |
Returns an indication whether this instance has been parsed yet. | |
void | clear () |
Clears the status of the element. | |
void | parse (Diagnostics &diag) |
Parses the header information of the element which is read from the related stream at the start offset. | |
void | reparse (Diagnostics &diag) |
Parses the header information of the element which is read from the related stream at the start offset. | |
void | validateSubsequentElementStructure (Diagnostics &diag, std::uint64_t *paddingSize=nullptr, AbortableProgressFeedback *progress=nullptr) |
Parses (see parse()) this and all subsequent elements. | |
template<typename TargetStream = std::ostream> | |
void | copyHeader (TargetStream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress) |
Writes the header information of the element to the specified targetStream. | |
template<typename TargetStream = std::ostream> | |
void | copyWithoutChilds (TargetStream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress) |
Writes the element without its children to the specified targetStream. | |
template<typename TargetStream = std::ostream> | |
void | copyEntirely (TargetStream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress) |
Writes the entire element including all children to the specified targetStream. | |
void | makeBuffer () |
Buffers the element (header and data). | |
void | discardBuffer () |
Discards buffered data. | |
template<typename TargetStream = std::ostream> | |
void | copyBuffer (TargetStream &targetStream) |
Copies buffered data to targetStream. | |
template<typename TargetStream = std::ostream> | |
void | copyPreferablyFromBuffer (TargetStream &targetStream, Diagnostics &diag, AbortableProgressFeedback *progress) |
Copies buffered data to targetStream if data has been buffered; copies from input stream otherwise. | |
const std::unique_ptr< char[]> & | buffer () |
Returns buffered data. | |
ImplementationType * | denoteFirstChild (std::uint32_t offset) |
Denotes the first child to start at the specified offset (relative to the start offset of this descriptor). | |
Static Public Member Functions | |
static constexpr std::uint32_t | maximumIdLengthSupported () |
Returns the maximum id length supported by the class in byte. | |
static constexpr std::uint32_t | maximumSizeLengthSupported () |
Returns the maximum size length supported by the class in byte. | |
static constexpr std::uint8_t | minimumElementSize () |
Returns the minimum element size. | |
Protected Attributes | |
IdentifierType | m_id |
std::uint64_t | m_startOffset |
std::uint64_t | m_maxSize |
DataSizeType | m_dataSize |
std::uint32_t | m_idLength |
std::uint32_t | m_sizeLength |
ImplementationType * | m_parent |
std::unique_ptr< ImplementationType > | m_nextSibling |
std::unique_ptr< ImplementationType > | m_firstChild |
std::unique_ptr< char[]> | m_buffer |
bool | m_sizeUnknown |
Friends | |
class | FileElementTraits< ImplementationType > |
The GenericFileElement class helps to parse binary files which consist of an arboreal element structure.
ImplementationType | Specifies the type of the actual implementation. |
using TagParser::GenericFileElement< ImplementationType >::ContainerType = typename FileElementTraits<ImplementationType>::ContainerType |
Specifies the type of the corresponding container.
Definition at line 51 of file genericfileelement.h.
using TagParser::GenericFileElement< ImplementationType >::DataSizeType = typename FileElementTraits<ImplementationType>::DataSizeType |
Specifies the type used to store data sizes.
Definition at line 61 of file genericfileelement.h.
using TagParser::GenericFileElement< ImplementationType >::IdentifierType = typename FileElementTraits<ImplementationType>::IdentifierType |
Specifies the type used to store identifiers.
Definition at line 56 of file genericfileelement.h.
TagParser::GenericFileElement< ImplementationType >::GenericFileElement | ( | ContainerType & | container, |
std::uint64_t | startOffset ) |
TagParser::GenericFileElement< ImplementationType >::GenericFileElement | ( | ImplementationType & | parent, |
std::uint64_t | startOffset ) |
Constructs a new sub level file element with the specified parent at the specified startOffset.
Definition at line 188 of file genericfileelement.h.
TagParser::GenericFileElement< ImplementationType >::GenericFileElement | ( | ContainerType & | container, |
std::uint64_t | startOffset, | ||
std::uint64_t | maxSize ) |
|
delete |
|
delete |
|
inline |
Returns buffered data.
The returned array is totalSize() bytes long.
Definition at line 928 of file genericfileelement.h.
ImplementationType * TagParser::GenericFileElement< ImplementationType >::childById | ( | const IdentifierType & | id, |
Diagnostics & | diag ) |
Returns the first child with the specified id.
The current element keeps ownership over the returned element. If no element could be found nullptr is returned.
Throws | a parsing exception when a parsing error occurs. |
Throws | std::ios_base::failure when an IO error occurs. |
Definition at line 610 of file genericfileelement.h.
const ImplementationType * TagParser::GenericFileElement< ImplementationType >::childById | ( | const IdentifierType & | id, |
Diagnostics & | diag ) const |
Returns the first child with the specified id.
The current element keeps ownership over the returned element. If no element could be found nullptr is returned.
Throws | a parsing exception when a parsing error occurs. |
Throws | std::ios_base::failure when an IO error occurs. |
Definition at line 632 of file genericfileelement.h.
void TagParser::GenericFileElement< ImplementationType >::clear | ( | ) |
Clears the status of the element.
Resets id length, data size, size length to zero. Subsequent elements will be deleted.
Definition at line 753 of file genericfileelement.h.
|
inline |
Returns the related container.
Definition at line 225 of file genericfileelement.h.
|
inline |
Returns the related container.
Definition at line 234 of file genericfileelement.h.
|
inline |
Copies buffered data to targetStream.
Definition at line 907 of file genericfileelement.h.
void TagParser::GenericFileElement< ImplementationType >::copyEntirely | ( | TargetStream & | targetStream, |
Diagnostics & | diag, | ||
AbortableProgressFeedback * | progress ) |
Writes the entire element including all children to the specified targetStream.
Definition at line 877 of file genericfileelement.h.
void TagParser::GenericFileElement< ImplementationType >::copyHeader | ( | TargetStream & | targetStream, |
Diagnostics & | diag, | ||
AbortableProgressFeedback * | progress ) |
Writes the header information of the element to the specified targetStream.
Definition at line 853 of file genericfileelement.h.
|
inline |
Copies buffered data to targetStream if data has been buffered; copies from input stream otherwise.
Definition at line 918 of file genericfileelement.h.
void TagParser::GenericFileElement< ImplementationType >::copyWithoutChilds | ( | TargetStream & | targetStream, |
Diagnostics & | diag, | ||
AbortableProgressFeedback * | progress ) |
Writes the element without its children to the specified targetStream.
Definition at line 863 of file genericfileelement.h.
|
inline |
Returns the data offset of the element in the related stream.
This is the sum of start offset and header size.
Definition at line 338 of file genericfileelement.h.
|
inline |
Returns the data size of the element in byte.
This is the size of the element excluding the header.
Definition at line 320 of file genericfileelement.h.
ImplementationType * TagParser::GenericFileElement< ImplementationType >::denoteFirstChild | ( | std::uint32_t | relativeFirstChildOffset | ) |
Denotes the first child to start at the specified offset (relative to the start offset of this descriptor).
Definition at line 967 of file genericfileelement.h.
|
inline |
Discards buffered data.
Definition at line 896 of file genericfileelement.h.
|
inline |
Returns the offset of the first byte which doesn't belong to this element anymore.
Definition at line 356 of file genericfileelement.h.
|
inline |
Returns the first child of the element.
The current element keeps ownership over the returned element. If no children are present nullptr is returned.
Definition at line 465 of file genericfileelement.h.
|
inline |
Returns the first child of the element.
The current element keeps ownership over the returned element. If no children are present nullptr is returned.
Definition at line 478 of file genericfileelement.h.
|
inline |
Returns the offset of the first child (relative to the start offset of this element).
Definition at line 734 of file genericfileelement.h.
|
inline |
Returns the header size of the element in byte.
This is the sum of the id length and the size length.
Definition at line 309 of file genericfileelement.h.
|
inline |
Returns the element ID.
Definition at line 283 of file genericfileelement.h.
|
inline |
Returns the length of the id denotation in byte.
Definition at line 299 of file genericfileelement.h.
|
inline |
Returns a printable string representation of the element ID.
Definition at line 291 of file genericfileelement.h.
|
inline |
Returns an indication whether this instance is a padding element.
Definition at line 726 of file genericfileelement.h.
|
inline |
Returns an indication whether this instance is a parent element.
Definition at line 718 of file genericfileelement.h.
|
inline |
Returns an indication whether this instance has been parsed yet.
Definition at line 742 of file genericfileelement.h.
|
inline |
Returns the last child of the element.
The current element keeps ownership over the returned element. If no children are present nullptr is returned.
Definition at line 491 of file genericfileelement.h.
|
inline |
Returns the last child of the element.
The current element keeps ownership over the returned element. If no children are present nullptr is returned.
Definition at line 509 of file genericfileelement.h.
std::uint8_t TagParser::GenericFileElement< ImplementationType >::level | ( | ) | const |
Returns how deep the element is nested (0 for top-level elements, 1 for children of top-level elements, ...).
Definition at line 376 of file genericfileelement.h.
void TagParser::GenericFileElement< ImplementationType >::makeBuffer | ( | ) |
Buffers the element (header and data).
Definition at line 886 of file genericfileelement.h.
|
staticconstexpr |
Returns the maximum id length supported by the class in byte.
Definition at line 980 of file genericfileelement.h.
|
staticconstexpr |
Returns the maximum size length supported by the class in byte.
Definition at line 988 of file genericfileelement.h.
|
inline |
Returns maximum total size.
This is usually the size of the file for top-level elements and the remaining size of the parent for non-top-level elements.
Definition at line 367 of file genericfileelement.h.
|
staticconstexpr |
Returns the minimum element size.
Definition at line 996 of file genericfileelement.h.
|
inline |
Returns the next sibling of the element.
The current element keeps ownership over the returned element. If no next sibling is present nullptr is returned.
Definition at line 439 of file genericfileelement.h.
|
inline |
Returns the next sibling of the element.
The current element keeps ownership over the returned element. If no next sibling is present nullptr is returned.
Definition at line 452 of file genericfileelement.h.
|
delete |
|
inline |
Returns the parent of the element.
The returned element has ownership over the current instance. If the current element is a top level element nullptr is returned.
Definition at line 390 of file genericfileelement.h.
|
inline |
Returns the parent of the element.
The returned element has ownership over the current instance. If the current element is a top level element nullptr is returned.
Definition at line 401 of file genericfileelement.h.
ImplementationType * TagParser::GenericFileElement< ImplementationType >::parent | ( | std::uint8_t | n | ) |
Returns the n-th parent of the element.
Definition at line 412 of file genericfileelement.h.
|
inline |
Returns the n-th parent of the element.
Definition at line 426 of file genericfileelement.h.
void TagParser::GenericFileElement< ImplementationType >::parse | ( | Diagnostics & | diag | ) |
Parses the header information of the element which is read from the related stream at the start offset.
The parsed information can accessed using the corresponding methods such as id() for the element id and totalSize() for the element size.
If the element has already been parsed (isParsed() returns true) this method does nothing. To force reparsing call reparse().
Throws | std::ios_base::failure when an IO error occurs. |
Throws | TagParser::Failure or a derived exception when a parsing error occurs. |
Definition at line 779 of file genericfileelement.h.
|
inline |
Returns the related BinaryReader.
Definition at line 250 of file genericfileelement.h.
|
inline |
Returns the offset of the element in its parent or - if it is a top-level element - in the related stream.
Definition at line 274 of file genericfileelement.h.
void TagParser::GenericFileElement< ImplementationType >::reparse | ( | Diagnostics & | diag | ) |
Parses the header information of the element which is read from the related stream at the start offset.
The parsed information can accessed using the corresponding methods such as id() for the element id and totalSize() for the element size.
If the element has already been parsed (isParsed() returns true) this method clears the parsed information and reparses the header.
Throws | std::ios_base::failure when an IO error occurs. |
Throws | TagParser::Failure or a derived exception when a parsing error occurs. |
Definition at line 803 of file genericfileelement.h.
ImplementationType * TagParser::GenericFileElement< ImplementationType >::siblingById | ( | const IdentifierType & | id, |
Diagnostics & | diag ) |
Returns the first sibling with the specified id.
The current element keeps ownership over the returned element. If no element could be found nullptr is returned. Possibly returns a pointer to the current instance (see includeThis).
Throws | a parsing exception when a parsing error occurs. |
Throws | std::ios_base::failure when an IO error occurs. |
Definition at line 648 of file genericfileelement.h.
const ImplementationType * TagParser::GenericFileElement< ImplementationType >::siblingById | ( | const IdentifierType & | id, |
Diagnostics & | diag ) const |
Returns the first sibling with the specified id.
The current element keeps ownership over the returned element. If no element could be found nullptr is returned. Possibly returns a pointer to the current instance (see includeThis).
Throws | a parsing exception when a parsing error occurs. |
Throws | std::ios_base::failure when an IO error occurs. |
Definition at line 671 of file genericfileelement.h.
ImplementationType * TagParser::GenericFileElement< ImplementationType >::siblingByIdIncludingThis | ( | const IdentifierType & | id, |
Diagnostics & | diag ) |
Returns the first sibling with the specified id or the current instance if its ID equals id.
The current element keeps ownership over the returned element. If no element could be found nullptr is returned. Possibly returns a pointer to the current instance (see includeThis).
Throws | a parsing exception when a parsing error occurs. |
Throws | std::ios_base::failure when an IO error occurs. |
Definition at line 687 of file genericfileelement.h.
const ImplementationType * TagParser::GenericFileElement< ImplementationType >::siblingByIdIncludingThis | ( | const IdentifierType & | id, |
Diagnostics & | diag ) const |
Returns the first sibling with the specified id or the current instance if its ID equals id.
The current element keeps ownership over the returned element. If no element could be found nullptr is returned. Possibly returns a pointer to the current instance (see includeThis).
Throws | a parsing exception when a parsing error occurs. |
Throws | std::ios_base::failure when an IO error occurs. |
Definition at line 710 of file genericfileelement.h.
|
inline |
Returns the length of the size denotation of the element in byte.
Definition at line 328 of file genericfileelement.h.
|
inline |
Returns the start offset in the related stream.
Definition at line 266 of file genericfileelement.h.
|
inline |
Returns the related stream.
Definition at line 242 of file genericfileelement.h.
ImplementationType * TagParser::GenericFileElement< ImplementationType >::subelementByPath | ( | Diagnostics & | diag, |
IdType | item ) |
Returns the sub element for the specified path.
The current element keeps ownership over the returned element. If no element could be found nullptr is returned.
Throws | a parsing exception when a parsing error occurs. |
Throws | std::ios_base::failure when an IO error occurs. |
Definition at line 525 of file genericfileelement.h.
const ImplementationType * TagParser::GenericFileElement< ImplementationType >::subelementByPath | ( | Diagnostics & | diag, |
IdType | item ) const |
Returns the sub element for the specified path.
The current element keeps ownership over the returned element. If no element could be found nullptr is returned.
Throws | a parsing exception when a parsing error occurs. |
Throws | std::ios_base::failure when an IO error occurs. |
Definition at line 580 of file genericfileelement.h.
ImplementationType * TagParser::GenericFileElement< ImplementationType >::subelementByPath | ( | Diagnostics & | diag, |
IdType | item, | ||
IdTypes... | remainingPath ) |
Returns the sub element for the specified path.
The current element keeps ownership over the returned element. If no element could be found nullptr is returned.
Throws | a parsing exception when a parsing error occurs. |
Throws | std::ios_base::failure when an IO error occurs. |
Definition at line 551 of file genericfileelement.h.
const ImplementationType * TagParser::GenericFileElement< ImplementationType >::subelementByPath | ( | Diagnostics & | diag, |
IdType | item, | ||
IdTypes... | remainingPath ) const |
Returns the sub element for the specified path.
The current element keeps ownership over the returned element. If no element could be found nullptr is returned.
Throws | a parsing exception when a parsing error occurs. |
Throws | std::ios_base::failure when an IO error occurs. |
Definition at line 596 of file genericfileelement.h.
|
inline |
Returns the total size of the element.
This is the sum of the header size and the data size.
Definition at line 348 of file genericfileelement.h.
void TagParser::GenericFileElement< ImplementationType >::validateSubsequentElementStructure | ( | Diagnostics & | diag, |
std::uint64_t * | paddingSize = nullptr, | ||
AbortableProgressFeedback * | progress = nullptr ) |
Parses (see parse()) this and all subsequent elements.
All diagnostic message will be stored in diag. If padding is found its size will be set to paddingSize if not nullptr.
Throws | std::ios_base::failure when an IO error occurs. |
Throws | TagParser::Failure or a derived exception when a parsing error occurs. |
Definition at line 823 of file genericfileelement.h.
|
inline |
Returns the related BinaryWriter.
Definition at line 258 of file genericfileelement.h.
|
friend |
Definition at line 996 of file genericfileelement.h.
|
protected |
Definition at line 144 of file genericfileelement.h.
|
protected |
Definition at line 138 of file genericfileelement.h.
|
protected |
Definition at line 143 of file genericfileelement.h.
|
protected |
Definition at line 135 of file genericfileelement.h.
|
protected |
Definition at line 139 of file genericfileelement.h.
|
protected |
Definition at line 137 of file genericfileelement.h.
|
protected |
Definition at line 142 of file genericfileelement.h.
|
protected |
Definition at line 141 of file genericfileelement.h.
|
protected |
Definition at line 140 of file genericfileelement.h.
|
protected |
Definition at line 155 of file genericfileelement.h.
|
protected |
Definition at line 136 of file genericfileelement.h.