Uniform/simplify typedefs in templates

* Begin type names with capital letter
* Remove typedefs for implementation type
* Remove useless/obsolete comments
* Simplify relevant code
This commit is contained in:
Martchus 2017-03-07 17:16:17 +01:00
parent 0daabba17a
commit 7a02e8a325
29 changed files with 235 additions and 339 deletions

View File

@ -35,49 +35,48 @@ class FieldMapBasedTag : public Tag
friend class FieldMapBasedTagTraits<ImplementationType>; friend class FieldMapBasedTagTraits<ImplementationType>;
public: public:
typedef typename FieldMapBasedTagTraits<ImplementationType>::implementationType implementationType; typedef typename FieldMapBasedTagTraits<ImplementationType>::FieldType FieldType;
typedef typename FieldMapBasedTagTraits<ImplementationType>::fieldType fieldType; typedef typename FieldMapBasedTagTraits<ImplementationType>::FieldType::IdentifierType IdentifierType;
typedef typename FieldMapBasedTagTraits<ImplementationType>::fieldType::identifierType identifierType; typedef typename FieldMapBasedTagTraits<ImplementationType>::Compare Compare;
typedef typename FieldMapBasedTagTraits<ImplementationType>::compare compare;
FieldMapBasedTag(); FieldMapBasedTag();
TagType type() const; TagType type() const;
const char *typeName() const; const char *typeName() const;
TagTextEncoding proposedTextEncoding() const; TagTextEncoding proposedTextEncoding() const;
const TagValue &value(const identifierType &id) const; const TagValue &value(const IdentifierType &id) const;
const TagValue &value(KnownField field) const; const TagValue &value(KnownField field) const;
std::vector<const TagValue *> values(const identifierType &id) const; std::vector<const TagValue *> values(const IdentifierType &id) const;
std::vector<const TagValue *> values(KnownField field) const; std::vector<const TagValue *> values(KnownField field) const;
bool setValue(const identifierType &id, const TagValue &value); bool setValue(const IdentifierType &id, const TagValue &value);
bool setValue(KnownField field, const TagValue &value); bool setValue(KnownField field, const TagValue &value);
bool setValues(const identifierType &id, const std::vector<TagValue> &values); bool setValues(const IdentifierType &id, const std::vector<TagValue> &values);
bool setValues(KnownField field, const std::vector<TagValue> &values); bool setValues(KnownField field, const std::vector<TagValue> &values);
bool hasField(KnownField field) const; bool hasField(KnownField field) const;
bool hasField(const identifierType &id) const; bool hasField(const IdentifierType &id) const;
void removeAllFields(); void removeAllFields();
const std::multimap<identifierType, fieldType, compare> &fields() const; const std::multimap<IdentifierType, FieldType, Compare> &fields() const;
std::multimap<identifierType, fieldType, compare> &fields(); std::multimap<IdentifierType, FieldType, Compare> &fields();
unsigned int fieldCount() const; unsigned int fieldCount() const;
identifierType fieldId(KnownField value) const; IdentifierType fieldId(KnownField value) const;
KnownField knownField(const identifierType &id) const; KnownField knownField(const IdentifierType &id) const;
bool supportsField(KnownField field) const; bool supportsField(KnownField field) const;
using Tag::proposedDataType; using Tag::proposedDataType;
TagDataType proposedDataType(const identifierType &id) const; TagDataType proposedDataType(const IdentifierType &id) const;
int insertFields(const FieldMapBasedTag<ImplementationType> &from, bool overwrite); int insertFields(const FieldMapBasedTag<ImplementationType> &from, bool overwrite);
unsigned int insertValues(const Tag &from, bool overwrite); unsigned int insertValues(const Tag &from, bool overwrite);
void ensureTextValuesAreProperlyEncoded(); void ensureTextValuesAreProperlyEncoded();
protected: protected:
const TagValue &internallyGetValue(const identifierType &id) const; const TagValue &internallyGetValue(const IdentifierType &id) const;
bool internallySetValue(const identifierType &id, const TagValue &value); bool internallySetValue(const IdentifierType &id, const TagValue &value);
bool internallyHasField(const identifierType &id) const; bool internallyHasField(const IdentifierType &id) const;
// no default implementation: identifierType internallyGetFieldId(KnownField field) const; // no default implementation: IdentifierType internallyGetFieldId(KnownField field) const;
// no default implementation: KnownField internallyGetKnownField(const identifierType &id) const; // no default implementation: KnownField internallyGetKnownField(const IdentifierType &id) const;
TagDataType internallyGetProposedDataType(const identifierType &id) const; TagDataType internallyGetProposedDataType(const IdentifierType &id) const;
private: private:
std::multimap<identifierType, fieldType, compare> m_fields; std::multimap<IdentifierType, FieldType, Compare> m_fields;
}; };
/*! /*!
@ -124,7 +123,7 @@ TagTextEncoding FieldMapBasedTag<ImplementationType>::proposedTextEncoding() con
* \remarks Shadow in subclass to provide custom implementation. * \remarks Shadow in subclass to provide custom implementation.
*/ */
template<class ImplementationType> template<class ImplementationType>
const TagValue &FieldMapBasedTag<ImplementationType>::internallyGetValue(const identifierType &id) const const TagValue &FieldMapBasedTag<ImplementationType>::internallyGetValue(const IdentifierType &id) const
{ {
auto i = m_fields.find(id); auto i = m_fields.find(id);
return i != m_fields.end() ? i->second.value() : TagValue::empty(); return i != m_fields.end() ? i->second.value() : TagValue::empty();
@ -135,7 +134,7 @@ const TagValue &FieldMapBasedTag<ImplementationType>::internallyGetValue(const i
* \sa Tag::value() * \sa Tag::value()
*/ */
template <class ImplementationType> template <class ImplementationType>
inline const TagValue &FieldMapBasedTag<ImplementationType>::value(const identifierType &id) const inline const TagValue &FieldMapBasedTag<ImplementationType>::value(const IdentifierType &id) const
{ {
return static_cast<const ImplementationType *>(this)->internallyGetValue(id); return static_cast<const ImplementationType *>(this)->internallyGetValue(id);
} }
@ -151,7 +150,7 @@ inline const TagValue &FieldMapBasedTag<ImplementationType>::value(KnownField fi
* \sa Tag::values() * \sa Tag::values()
*/ */
template <class ImplementationType> template <class ImplementationType>
inline std::vector<const TagValue *> FieldMapBasedTag<ImplementationType>::values(const identifierType &id) const inline std::vector<const TagValue *> FieldMapBasedTag<ImplementationType>::values(const IdentifierType &id) const
{ {
auto range = m_fields.equal_range(id); auto range = m_fields.equal_range(id);
std::vector<const TagValue *> values; std::vector<const TagValue *> values;
@ -180,13 +179,13 @@ inline bool FieldMapBasedTag<ImplementationType>::setValue(KnownField field, con
* \remarks Shadow in subclass to provide custom implementation. * \remarks Shadow in subclass to provide custom implementation.
*/ */
template<class ImplementationType> template<class ImplementationType>
bool FieldMapBasedTag<ImplementationType>::internallySetValue(const identifierType &id, const TagValue &value) bool FieldMapBasedTag<ImplementationType>::internallySetValue(const IdentifierType &id, const TagValue &value)
{ {
auto i = m_fields.find(id); auto i = m_fields.find(id);
if(i != m_fields.end()) { // field already exists -> set its value if(i != m_fields.end()) { // field already exists -> set its value
i->second.setValue(value); i->second.setValue(value);
} else if(!value.isEmpty()) { // field doesn't exist -> create new one if value is not null } else if(!value.isEmpty()) { // field doesn't exist -> create new one if value is not null
m_fields.insert(std::make_pair(id, fieldType(id, value))); m_fields.insert(std::make_pair(id, FieldType(id, value)));
} else { // otherwise return false } else { // otherwise return false
return false; return false;
} }
@ -198,7 +197,7 @@ bool FieldMapBasedTag<ImplementationType>::internallySetValue(const identifierTy
* \sa Tag::setValue() * \sa Tag::setValue()
*/ */
template <class ImplementationType> template <class ImplementationType>
bool FieldMapBasedTag<ImplementationType>::setValue(const identifierType &id, const Media::TagValue &value) bool FieldMapBasedTag<ImplementationType>::setValue(const IdentifierType &id, const Media::TagValue &value)
{ {
return static_cast<ImplementationType *>(this)->internallySetValue(id, value); return static_cast<ImplementationType *>(this)->internallySetValue(id, value);
} }
@ -210,7 +209,7 @@ bool FieldMapBasedTag<ImplementationType>::setValue(const identifierType &id, co
* \sa Tag::setValues() * \sa Tag::setValues()
*/ */
template <class ImplementationType> template <class ImplementationType>
bool FieldMapBasedTag<ImplementationType>::setValues(const identifierType &id, const std::vector<TagValue> &values) bool FieldMapBasedTag<ImplementationType>::setValues(const IdentifierType &id, const std::vector<TagValue> &values)
{ {
auto valuesIterator = values.cbegin(); auto valuesIterator = values.cbegin();
auto range = m_fields.equal_range(id); auto range = m_fields.equal_range(id);
@ -224,7 +223,7 @@ bool FieldMapBasedTag<ImplementationType>::setValues(const identifierType &id, c
} }
// add remaining specified values (there are more specified values than existing ones) // add remaining specified values (there are more specified values than existing ones)
for(; valuesIterator != values.cend(); ++valuesIterator) { for(; valuesIterator != values.cend(); ++valuesIterator) {
m_fields.insert(std::make_pair(id, fieldType(id, *valuesIterator))); m_fields.insert(std::make_pair(id, FieldType(id, *valuesIterator)));
} }
// remove remaining existing values (there are more existing values than specified ones) // remove remaining existing values (there are more existing values than specified ones)
for(; range.first != range.second; ++range.first) { for(; range.first != range.second; ++range.first) {
@ -256,7 +255,7 @@ inline bool FieldMapBasedTag<ImplementationType>::hasField(KnownField field) con
* \remarks Shadow in subclass to provide custom implementation. * \remarks Shadow in subclass to provide custom implementation.
*/ */
template<class ImplementationType> template<class ImplementationType>
bool FieldMapBasedTag<ImplementationType>::internallyHasField(const identifierType &id) const bool FieldMapBasedTag<ImplementationType>::internallyHasField(const IdentifierType &id) const
{ {
for (auto range = m_fields.equal_range(id); range.first != range.second; ++range.first) { for (auto range = m_fields.equal_range(id); range.first != range.second; ++range.first) {
if(!range.first->second.value().isEmpty()) { if(!range.first->second.value().isEmpty()) {
@ -270,7 +269,7 @@ bool FieldMapBasedTag<ImplementationType>::internallyHasField(const identifierTy
* \brief Returns an indication whether the field with the specified \a id is present. * \brief Returns an indication whether the field with the specified \a id is present.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline bool FieldMapBasedTag<ImplementationType>::hasField(const identifierType &id) const inline bool FieldMapBasedTag<ImplementationType>::hasField(const IdentifierType &id) const
{ {
return static_cast<const ImplementationType *>(this)->internallyHasField(id); return static_cast<const ImplementationType *>(this)->internallyHasField(id);
} }
@ -285,7 +284,7 @@ inline void FieldMapBasedTag<ImplementationType>::removeAllFields()
* \brief Returns the fields of the tag by providing direct access to the field map of the tag. * \brief Returns the fields of the tag by providing direct access to the field map of the tag.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline auto FieldMapBasedTag<ImplementationType>::fields() const -> const std::multimap<identifierType, fieldType, compare> & inline auto FieldMapBasedTag<ImplementationType>::fields() const -> const std::multimap<IdentifierType, FieldType, Compare> &
{ {
return m_fields; return m_fields;
} }
@ -294,7 +293,7 @@ inline auto FieldMapBasedTag<ImplementationType>::fields() const -> const std::m
* \brief Returns the fields of the tag by providing direct access to the field map of the tag. * \brief Returns the fields of the tag by providing direct access to the field map of the tag.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline auto FieldMapBasedTag<ImplementationType>::fields() -> std::multimap<identifierType, fieldType, compare> & inline auto FieldMapBasedTag<ImplementationType>::fields() -> std::multimap<IdentifierType, FieldType, Compare> &
{ {
return m_fields; return m_fields;
} }
@ -316,7 +315,7 @@ unsigned int FieldMapBasedTag<ImplementationType>::fieldCount() const
* \remarks Must be implemented in internallyGetFieldId() when creating subclass. * \remarks Must be implemented in internallyGetFieldId() when creating subclass.
*/ */
template<class ImplementationType> template<class ImplementationType>
inline typename FieldMapBasedTag<ImplementationType>::identifierType FieldMapBasedTag<ImplementationType>::fieldId(KnownField value) const inline typename FieldMapBasedTag<ImplementationType>::IdentifierType FieldMapBasedTag<ImplementationType>::fieldId(KnownField value) const
{ {
return static_cast<const ImplementationType *>(this)->internallyGetFieldId(value); return static_cast<const ImplementationType *>(this)->internallyGetFieldId(value);
} }
@ -326,7 +325,7 @@ inline typename FieldMapBasedTag<ImplementationType>::identifierType FieldMapBas
* \remarks Must be implemented in internallyGetKnownField() when creating subclass. * \remarks Must be implemented in internallyGetKnownField() when creating subclass.
*/ */
template<class ImplementationType> template<class ImplementationType>
inline KnownField FieldMapBasedTag<ImplementationType>::knownField(const identifierType &id) const inline KnownField FieldMapBasedTag<ImplementationType>::knownField(const IdentifierType &id) const
{ {
return static_cast<FieldMapBasedTag<ImplementationType> *>(this)->internallyGetKnownField(id); return static_cast<FieldMapBasedTag<ImplementationType> *>(this)->internallyGetKnownField(id);
} }
@ -334,7 +333,7 @@ inline KnownField FieldMapBasedTag<ImplementationType>::knownField(const identif
template <class ImplementationType> template <class ImplementationType>
inline bool FieldMapBasedTag<ImplementationType>::supportsField(KnownField field) const inline bool FieldMapBasedTag<ImplementationType>::supportsField(KnownField field) const
{ {
static identifierType def; static IdentifierType def;
return fieldId(field) != def; return fieldId(field) != def;
} }
@ -343,7 +342,7 @@ inline bool FieldMapBasedTag<ImplementationType>::supportsField(KnownField field
* \remarks Shadow in subclass to provide custom implementation. * \remarks Shadow in subclass to provide custom implementation.
*/ */
template<class ImplementationType> template<class ImplementationType>
inline TagDataType FieldMapBasedTag<ImplementationType>::internallyGetProposedDataType(const identifierType &id) const inline TagDataType FieldMapBasedTag<ImplementationType>::internallyGetProposedDataType(const IdentifierType &id) const
{ {
return Tag::proposedDataType(knownField(id)); return Tag::proposedDataType(knownField(id));
} }
@ -352,7 +351,7 @@ inline TagDataType FieldMapBasedTag<ImplementationType>::internallyGetProposedDa
* \brief Returns the proposed data type for the field with the specified \a id. * \brief Returns the proposed data type for the field with the specified \a id.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline TagDataType FieldMapBasedTag<ImplementationType>::proposedDataType(const identifierType &id) const inline TagDataType FieldMapBasedTag<ImplementationType>::proposedDataType(const IdentifierType &id) const
{ {
return static_cast<ImplementationType *>(this)->determineProposedDataType(id); return static_cast<ImplementationType *>(this)->determineProposedDataType(id);
} }
@ -368,13 +367,13 @@ int FieldMapBasedTag<ImplementationType>::insertFields(const FieldMapBasedTag<Im
{ {
int fieldsInserted = 0; int fieldsInserted = 0;
for(const auto &pair : from.fields()) { for(const auto &pair : from.fields()) {
const fieldType &fromField = pair.second; const FieldType &fromField = pair.second;
if(fromField.value().isEmpty()) if(fromField.value().isEmpty())
continue; continue;
bool fieldInserted = false; bool fieldInserted = false;
auto range = fields().equal_range(fromField.id()); auto range = fields().equal_range(fromField.id());
for(auto i = range.first; i != range.second; ++i) { for(auto i = range.first; i != range.second; ++i) {
fieldType &ownField = i->second; FieldType &ownField = i->second;
if((fromField.isTypeInfoAssigned() && ownField.isTypeInfoAssigned() if((fromField.isTypeInfoAssigned() && ownField.isTypeInfoAssigned()
&& fromField.typeInfo() == ownField.typeInfo()) && fromField.typeInfo() == ownField.typeInfo())
|| (!fromField.isTypeInfoAssigned() && ! ownField.isTypeInfoAssigned())) { || (!fromField.isTypeInfoAssigned() && ! ownField.isTypeInfoAssigned())) {

View File

@ -52,10 +52,10 @@ public:
void removeAllTracks(); void removeAllTracks();
void reset(); void reset();
typedef FileInfoType fileInfoType; typedef FileInfoType ContainerFileInfoType;
typedef TagType tagType; typedef TagType ContainerTagType;
typedef TrackType trackType; typedef TrackType ContainerTrackType;
typedef ElementType elementType; typedef ElementType ContainerElementType;
protected: protected:
std::unique_ptr<ElementType> m_firstElement; std::unique_ptr<ElementType> m_firstElement;

View File

@ -121,61 +121,56 @@ public:
/*! /*!
* \brief Specifies the type of the corresponding container. * \brief Specifies the type of the corresponding container.
*/ */
typedef typename FileElementTraits<ImplementationType>::containerType containerType; typedef typename FileElementTraits<ImplementationType>::ContainerType ContainerType;
/*! /*!
* \brief Specifies the type used to store identifiers. * \brief Specifies the type used to store identifiers.
*/ */
typedef typename FileElementTraits<ImplementationType>::identifierType identifierType; typedef typename FileElementTraits<ImplementationType>::IdentifierType IdentifierType;
/*! /*!
* \brief Specifies the type used to store data sizes. * \brief Specifies the type used to store data sizes.
*/ */
typedef typename FileElementTraits<ImplementationType>::dataSizeType dataSizeType; typedef typename FileElementTraits<ImplementationType>::DataSizeType DataSizeType;
/*! GenericFileElement(ContainerType &container, uint64 startOffset);
* \brief Specifies the type of the actual implementation. GenericFileElement(ImplementationType &parent, uint64 startOffset);
*/ GenericFileElement(ContainerType &container, uint64 startOffset, uint64 maxSize);
typedef typename FileElementTraits<ImplementationType>::implementationType implementationType;
GenericFileElement(containerType &container, uint64 startOffset);
GenericFileElement(implementationType &parent, uint64 startOffset);
GenericFileElement(containerType &container, uint64 startOffset, uint64 maxSize);
GenericFileElement(const GenericFileElement& other) = delete; GenericFileElement(const GenericFileElement& other) = delete;
GenericFileElement(GenericFileElement& other) = delete; GenericFileElement(GenericFileElement& other) = delete;
GenericFileElement& operator =(const GenericFileElement& other) = delete; GenericFileElement& operator =(const GenericFileElement& other) = delete;
containerType& container(); ContainerType& container();
const containerType& container() const; const ContainerType& container() const;
std::iostream &stream(); std::iostream &stream();
IoUtilities::BinaryReader &reader(); IoUtilities::BinaryReader &reader();
IoUtilities::BinaryWriter &writer(); IoUtilities::BinaryWriter &writer();
uint64 startOffset() const; uint64 startOffset() const;
uint64 relativeStartOffset() const; uint64 relativeStartOffset() const;
const identifierType &id() const; const IdentifierType &id() const;
std::string idToString() const; std::string idToString() const;
uint32 idLength() const; uint32 idLength() const;
uint32 headerSize() const; uint32 headerSize() const;
dataSizeType dataSize() const; DataSizeType dataSize() const;
uint32 sizeLength() const; uint32 sizeLength() const;
uint64 dataOffset() const; uint64 dataOffset() const;
uint64 totalSize() const; uint64 totalSize() const;
uint64 endOffset() const; uint64 endOffset() const;
uint64 maxTotalSize() const; uint64 maxTotalSize() const;
implementationType* parent(); ImplementationType* parent();
const implementationType* parent() const; const ImplementationType* parent() const;
implementationType* nextSibling(); ImplementationType* nextSibling();
const implementationType* nextSibling() const; const ImplementationType* nextSibling() const;
implementationType* firstChild(); ImplementationType* firstChild();
const implementationType* firstChild() const; const ImplementationType* firstChild() const;
implementationType* subelementByPath(const std::initializer_list<identifierType> &path); ImplementationType* subelementByPath(const std::initializer_list<IdentifierType> &path);
implementationType* subelementByPath(std::list<identifierType> &path); ImplementationType* subelementByPath(std::list<IdentifierType> &path);
implementationType* childById(const identifierType &id); ImplementationType* childById(const IdentifierType &id);
implementationType* siblingById(const identifierType &id, bool includeThis = false); ImplementationType* siblingById(const IdentifierType &id, bool includeThis = false);
FileElementIterator<implementationType> begin(); FileElementIterator<ImplementationType> begin();
FileElementIterator<implementationType> end(); FileElementIterator<ImplementationType> end();
const FileElementIterator<implementationType> begin() const; const FileElementIterator<ImplementationType> begin() const;
const FileElementIterator<implementationType> end() const; const FileElementIterator<ImplementationType> end() const;
bool isParent() const; bool isParent() const;
bool isPadding() const; bool isPadding() const;
uint64 firstChildOffset() const; uint64 firstChildOffset() const;
@ -195,24 +190,24 @@ public:
void copyBuffer(std::ostream &targetStream); void copyBuffer(std::ostream &targetStream);
void copyPreferablyFromBuffer(std::ostream &targetStream); void copyPreferablyFromBuffer(std::ostream &targetStream);
const std::unique_ptr<char[]> &buffer(); const std::unique_ptr<char[]> &buffer();
implementationType *denoteFirstChild(uint32 offset); ImplementationType *denoteFirstChild(uint32 offset);
protected: protected:
identifierType m_id; IdentifierType m_id;
uint64 m_startOffset; uint64 m_startOffset;
uint64 m_maxSize; uint64 m_maxSize;
uint32 m_idLength; uint32 m_idLength;
dataSizeType m_dataSize; DataSizeType m_dataSize;
uint32 m_sizeLength; uint32 m_sizeLength;
implementationType* m_parent; ImplementationType* m_parent;
std::unique_ptr<implementationType> m_nextSibling; std::unique_ptr<ImplementationType> m_nextSibling;
std::unique_ptr<implementationType> m_firstChild; std::unique_ptr<ImplementationType> m_firstChild;
std::unique_ptr<char[]> m_buffer; std::unique_ptr<char[]> m_buffer;
private: private:
void copyInternal(std::ostream &targetStream, uint64 startOffset, uint64 bytesToCopy); void copyInternal(std::ostream &targetStream, uint64 startOffset, uint64 bytesToCopy);
containerType* m_container; ContainerType* m_container;
bool m_parsed; bool m_parsed;
}; };
@ -221,8 +216,8 @@ private:
* \remarks The available size is obtained using the stream of the \a container. * \remarks The available size is obtained using the stream of the \a container.
*/ */
template <class ImplementationType> template <class ImplementationType>
GenericFileElement<ImplementationType>::GenericFileElement(GenericFileElement<ImplementationType>::containerType &container, uint64 startOffset) : GenericFileElement<ImplementationType>::GenericFileElement(GenericFileElement<ImplementationType>::ContainerType &container, uint64 startOffset) :
m_id(identifierType()), m_id(IdentifierType()),
m_startOffset(startOffset), m_startOffset(startOffset),
m_idLength(0), m_idLength(0),
m_dataSize(0), m_dataSize(0),
@ -244,8 +239,8 @@ GenericFileElement<ImplementationType>::GenericFileElement(GenericFileElement<Im
* \brief Constructs a new sub level file element with the specified \a parent at the specified \a startOffset. * \brief Constructs a new sub level file element with the specified \a parent at the specified \a startOffset.
*/ */
template <class ImplementationType> template <class ImplementationType>
GenericFileElement<ImplementationType>::GenericFileElement(GenericFileElement<ImplementationType>::implementationType &parent, uint64 startOffset) : GenericFileElement<ImplementationType>::GenericFileElement(ImplementationType &parent, uint64 startOffset) :
m_id(identifierType()), m_id(IdentifierType()),
m_startOffset(startOffset), m_startOffset(startOffset),
m_maxSize(parent.startOffset() + parent.totalSize() - startOffset), m_maxSize(parent.startOffset() + parent.totalSize() - startOffset),
m_idLength(0), m_idLength(0),
@ -260,8 +255,8 @@ GenericFileElement<ImplementationType>::GenericFileElement(GenericFileElement<Im
* \brief Constructs a new sub level file element with the specified \a container, \a startOffset and \a maxSize. * \brief Constructs a new sub level file element with the specified \a container, \a startOffset and \a maxSize.
*/ */
template <class ImplementationType> template <class ImplementationType>
GenericFileElement<ImplementationType>::GenericFileElement(GenericFileElement<ImplementationType>::containerType &container, uint64 startOffset, uint64 maxSize) : GenericFileElement<ImplementationType>::GenericFileElement(GenericFileElement<ImplementationType>::ContainerType &container, uint64 startOffset, uint64 maxSize) :
m_id(identifierType()), m_id(IdentifierType()),
m_startOffset(startOffset), m_startOffset(startOffset),
m_maxSize(maxSize), m_maxSize(maxSize),
m_idLength(0), m_idLength(0),
@ -276,7 +271,7 @@ GenericFileElement<ImplementationType>::GenericFileElement(GenericFileElement<Im
* \brief Returns the related container. * \brief Returns the related container.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline typename GenericFileElement<ImplementationType>::containerType& GenericFileElement<ImplementationType>::container() inline typename GenericFileElement<ImplementationType>::ContainerType& GenericFileElement<ImplementationType>::container()
{ {
return *m_container; return *m_container;
} }
@ -285,7 +280,7 @@ inline typename GenericFileElement<ImplementationType>::containerType& GenericFi
* \brief Returns the related container. * \brief Returns the related container.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline const typename GenericFileElement<ImplementationType>::containerType &GenericFileElement<ImplementationType>::container() const inline const typename GenericFileElement<ImplementationType>::ContainerType &GenericFileElement<ImplementationType>::container() const
{ {
return *m_container; return *m_container;
} }
@ -339,7 +334,7 @@ inline uint64 GenericFileElement<ImplementationType>::relativeStartOffset() cons
* \brief Returns the element ID. * \brief Returns the element ID.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline const typename GenericFileElement<ImplementationType>::identifierType &GenericFileElement<ImplementationType>::id() const inline const typename GenericFileElement<ImplementationType>::IdentifierType &GenericFileElement<ImplementationType>::id() const
{ {
return m_id; return m_id;
} }
@ -379,7 +374,7 @@ inline uint32 GenericFileElement<ImplementationType>::headerSize() const
* This is the size of the element excluding the header. * This is the size of the element excluding the header.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline typename GenericFileElement<ImplementationType>::dataSizeType GenericFileElement<ImplementationType>::dataSize() const inline typename GenericFileElement<ImplementationType>::DataSizeType GenericFileElement<ImplementationType>::dataSize() const
{ {
return m_dataSize; return m_dataSize;
} }
@ -443,7 +438,7 @@ inline uint64 GenericFileElement<ImplementationType>::maxTotalSize() const
* If the current element is a top level element nullptr is returned. * If the current element is a top level element nullptr is returned.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline typename GenericFileElement<ImplementationType>::implementationType *GenericFileElement<ImplementationType>::parent() inline ImplementationType *GenericFileElement<ImplementationType>::parent()
{ {
return m_parent; return m_parent;
} }
@ -455,7 +450,7 @@ inline typename GenericFileElement<ImplementationType>::implementationType *Gene
* If the current element is a top level element nullptr is returned. * If the current element is a top level element nullptr is returned.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline const typename GenericFileElement<ImplementationType>::implementationType *GenericFileElement<ImplementationType>::parent() const inline const ImplementationType *GenericFileElement<ImplementationType>::parent() const
{ {
return m_parent; return m_parent;
} }
@ -469,7 +464,7 @@ inline const typename GenericFileElement<ImplementationType>::implementationType
* \remarks parse() needs to be called before. * \remarks parse() needs to be called before.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline typename GenericFileElement<ImplementationType>::implementationType *GenericFileElement<ImplementationType>::nextSibling() inline ImplementationType *GenericFileElement<ImplementationType>::nextSibling()
{ {
return m_nextSibling.get(); return m_nextSibling.get();
} }
@ -483,7 +478,7 @@ inline typename GenericFileElement<ImplementationType>::implementationType *Gene
* \remarks parse() needs to be called before. * \remarks parse() needs to be called before.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline const typename GenericFileElement<ImplementationType>::implementationType *GenericFileElement<ImplementationType>::nextSibling() const inline const ImplementationType *GenericFileElement<ImplementationType>::nextSibling() const
{ {
return m_nextSibling.get(); return m_nextSibling.get();
} }
@ -497,7 +492,7 @@ inline const typename GenericFileElement<ImplementationType>::implementationType
* \remarks parse() needs to be called before. * \remarks parse() needs to be called before.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline typename GenericFileElement<ImplementationType>::implementationType *GenericFileElement<ImplementationType>::firstChild() inline ImplementationType *GenericFileElement<ImplementationType>::firstChild()
{ {
return m_firstChild.get(); return m_firstChild.get();
} }
@ -511,7 +506,7 @@ inline typename GenericFileElement<ImplementationType>::implementationType *Gene
* \remarks parse() needs to be called before. * \remarks parse() needs to be called before.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline const typename GenericFileElement<ImplementationType>::implementationType *GenericFileElement<ImplementationType>::firstChild() const inline const ImplementationType *GenericFileElement<ImplementationType>::firstChild() const
{ {
return m_firstChild.get(); return m_firstChild.get();
} }
@ -526,9 +521,9 @@ inline const typename GenericFileElement<ImplementationType>::implementationType
* \throws Throws std::ios_base::failure when an IO error occurs. * \throws Throws std::ios_base::failure when an IO error occurs.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline typename GenericFileElement<ImplementationType>::implementationType *GenericFileElement<ImplementationType>::subelementByPath(const std::initializer_list<identifierType> &path) inline ImplementationType *GenericFileElement<ImplementationType>::subelementByPath(const std::initializer_list<IdentifierType> &path)
{ {
std::list<GenericFileElement<ImplementationType>::identifierType> list(path); std::list<GenericFileElement<ImplementationType>::IdentifierType> list(path);
return subelementByPath(list); return subelementByPath(list);
} }
@ -543,13 +538,13 @@ inline typename GenericFileElement<ImplementationType>::implementationType *Gene
* \throws Throws std::ios_base::failure when an IO error occurs. * \throws Throws std::ios_base::failure when an IO error occurs.
*/ */
template <class ImplementationType> template <class ImplementationType>
typename GenericFileElement<ImplementationType>::implementationType *GenericFileElement<ImplementationType>::subelementByPath(std::list<GenericFileElement<ImplementationType>::identifierType> &path) ImplementationType *GenericFileElement<ImplementationType>::subelementByPath(std::list<IdentifierType> &path)
{ {
parse(); // ensure element is parsed parse(); // ensure element is parsed
if(path.size()) { if(path.size()) {
if(path.front() == id()) { if(path.front() == id()) {
if(path.size() == 1) { if(path.size() == 1) {
return static_cast<implementationType*>(this); return static_cast<ImplementationType *>(this);
} else { } else {
if(firstChild()) { if(firstChild()) {
path.pop_front(); path.pop_front();
@ -575,10 +570,10 @@ typename GenericFileElement<ImplementationType>::implementationType *GenericFile
* \throws Throws std::ios_base::failure when an IO error occurs. * \throws Throws std::ios_base::failure when an IO error occurs.
*/ */
template <class ImplementationType> template <class ImplementationType>
typename GenericFileElement<ImplementationType>::implementationType *GenericFileElement<ImplementationType>::childById(const GenericFileElement<ImplementationType>::identifierType &id) ImplementationType *GenericFileElement<ImplementationType>::childById(const IdentifierType &id)
{ {
parse(); // ensure element is parsed parse(); // ensure element is parsed
for(implementationType *child = firstChild(); child; child = child->nextSibling()) { for(ImplementationType *child = firstChild(); child; child = child->nextSibling()) {
child->parse(); child->parse();
if(child->id() == id) { if(child->id() == id) {
return child; return child;
@ -602,10 +597,10 @@ typename GenericFileElement<ImplementationType>::implementationType *GenericFile
* \throws Throws std::ios_base::failure when an IO error occurs. * \throws Throws std::ios_base::failure when an IO error occurs.
*/ */
template <class ImplementationType> template <class ImplementationType>
typename GenericFileElement<ImplementationType>::implementationType *GenericFileElement<ImplementationType>::siblingById(const GenericFileElement<ImplementationType>::identifierType &id, bool includeThis) ImplementationType *GenericFileElement<ImplementationType>::siblingById(const IdentifierType &id, bool includeThis)
{ {
parse(); // ensure element is parsed parse(); // ensure element is parsed
for(implementationType *sibling = includeThis ? static_cast<implementationType*>(this) : nextSibling(); sibling; sibling = sibling->nextSibling()) { for(ImplementationType *sibling = includeThis ? static_cast<ImplementationType *>(this) : nextSibling(); sibling; sibling = sibling->nextSibling()) {
sibling->parse(); sibling->parse();
if(sibling->id() == id) { if(sibling->id() == id) {
return sibling; return sibling;
@ -618,25 +613,25 @@ typename GenericFileElement<ImplementationType>::implementationType *GenericFile
* \brief Returns an iterator for iterating over the element's childs. * \brief Returns an iterator for iterating over the element's childs.
*/ */
template <class ImplementationType> template <class ImplementationType>
FileElementIterator<typename GenericFileElement<ImplementationType>::implementationType> GenericFileElement<ImplementationType>::begin() FileElementIterator<ImplementationType> GenericFileElement<ImplementationType>::begin()
{ {
return FileElementIterator<implementationType>(firstChild()); return FileElementIterator<ImplementationType>(firstChild());
} }
/*! /*!
* \brief Returns an iterator for iterating over the element's childs (constant). * \brief Returns an iterator for iterating over the element's childs (constant).
*/ */
template <class ImplementationType> template <class ImplementationType>
const FileElementIterator<typename GenericFileElement<ImplementationType>::implementationType> GenericFileElement<ImplementationType>::begin() const const FileElementIterator<ImplementationType> GenericFileElement<ImplementationType>::begin() const
{ {
return FileElementIterator<implementationType>(firstChild()); return FileElementIterator<ImplementationType>(firstChild());
} }
/*! /*!
* \brief Returns an invalid iterator. * \brief Returns an invalid iterator.
*/ */
template <class ImplementationType> template <class ImplementationType>
FileElementIterator<typename GenericFileElement<ImplementationType>::implementationType> GenericFileElement<ImplementationType>::end() FileElementIterator<ImplementationType> GenericFileElement<ImplementationType>::end()
{ {
return FileElementIterator<ImplementationType>(); return FileElementIterator<ImplementationType>();
} }
@ -645,7 +640,7 @@ FileElementIterator<typename GenericFileElement<ImplementationType>::implementat
* \brief Returns an invalid iterator. * \brief Returns an invalid iterator.
*/ */
template <class ImplementationType> template <class ImplementationType>
const FileElementIterator<typename GenericFileElement<ImplementationType>::implementationType> GenericFileElement<ImplementationType>::end() const const FileElementIterator<ImplementationType> GenericFileElement<ImplementationType>::end() const
{ {
return FileElementIterator<ImplementationType>(); return FileElementIterator<ImplementationType>();
} }
@ -695,7 +690,7 @@ inline bool GenericFileElement<ImplementationType>::isParsed() const
template <class ImplementationType> template <class ImplementationType>
void GenericFileElement<ImplementationType>::clear() void GenericFileElement<ImplementationType>::clear()
{ {
m_id = identifierType(); m_id = IdentifierType();
//m_startOffset = 0; //m_startOffset = 0;
m_idLength = 0; m_idLength = 0;
m_dataSize = 0; m_dataSize = 0;
@ -906,10 +901,10 @@ void GenericFileElement<ImplementationType>::copyInternal(std::ostream &targetSt
* \remarks A new first child is constructed. A possibly existing subtree is invalidated. * \remarks A new first child is constructed. A possibly existing subtree is invalidated.
*/ */
template <class ImplementationType> template <class ImplementationType>
typename GenericFileElement<ImplementationType>::implementationType *GenericFileElement<ImplementationType>::denoteFirstChild(uint32 relativeFirstChildOffset) ImplementationType *GenericFileElement<ImplementationType>::denoteFirstChild(uint32 relativeFirstChildOffset)
{ {
if(relativeFirstChildOffset + minimumElementSize() <= totalSize()) { if(relativeFirstChildOffset + minimumElementSize() <= totalSize()) {
m_firstChild.reset(new implementationType(static_cast<implementationType &>(*this), startOffset() + relativeFirstChildOffset)); m_firstChild.reset(new ImplementationType(static_cast<ImplementationType &>(*this), startOffset() + relativeFirstChildOffset));
} else { } else {
m_firstChild.reset(); m_firstChild.reset();
} }
@ -922,7 +917,7 @@ typename GenericFileElement<ImplementationType>::implementationType *GenericFile
template <class ImplementationType> template <class ImplementationType>
constexpr uint32 GenericFileElement<ImplementationType>::maximumIdLengthSupported() constexpr uint32 GenericFileElement<ImplementationType>::maximumIdLengthSupported()
{ {
return sizeof(identifierType); return sizeof(IdentifierType);
} }
/*! /*!
@ -931,7 +926,7 @@ constexpr uint32 GenericFileElement<ImplementationType>::maximumIdLengthSupporte
template <class ImplementationType> template <class ImplementationType>
constexpr uint32 GenericFileElement<ImplementationType>::maximumSizeLengthSupported() constexpr uint32 GenericFileElement<ImplementationType>::maximumSizeLengthSupported()
{ {
return sizeof(dataSizeType); return sizeof(DataSizeType);
} }
/*! /*!

View File

@ -32,19 +32,19 @@ class TagFieldTraits
template <class ImplementationType> template <class ImplementationType>
class TAG_PARSER_EXPORT TagField class TAG_PARSER_EXPORT TagField
{ {
public:
friend class TagFieldTraits<ImplementationType>; friend class TagFieldTraits<ImplementationType>;
typedef typename TagFieldTraits<ImplementationType>::implementationType implementationType;
typedef typename TagFieldTraits<ImplementationType>::identifierType identifierType; public:
typedef typename TagFieldTraits<ImplementationType>::typeInfoType typeInfoType; typedef typename TagFieldTraits<ImplementationType>::IdentifierType IdentifierType;
typedef typename TagFieldTraits<ImplementationType>::TypeInfoType TypeInfoType;
TagField(); TagField();
TagField(const identifierType &id, const TagValue &value); TagField(const IdentifierType &id, const TagValue &value);
~TagField(); ~TagField();
const identifierType &id() const; const IdentifierType &id() const;
std::string idToString() const; std::string idToString() const;
void setId(const identifierType &id); void setId(const IdentifierType &id);
void clearId(); void clearId();
TagValue &value(); TagValue &value();
@ -52,8 +52,8 @@ public:
void setValue(const TagValue &value); void setValue(const TagValue &value);
void clearValue(); void clearValue();
const typeInfoType &typeInfo() const; const TypeInfoType &typeInfo() const;
void setTypeInfo(const typeInfoType &typeInfo); void setTypeInfo(const TypeInfoType &typeInfo);
void removeTypeInfo(); void removeTypeInfo();
bool isTypeInfoAssigned() const; bool isTypeInfoAssigned() const;
@ -72,9 +72,9 @@ private:
void cleared(); void cleared();
private: private:
identifierType m_id; IdentifierType m_id;
TagValue m_value; TagValue m_value;
typeInfoType m_typeInfo; TypeInfoType m_typeInfo;
bool m_typeInfoAssigned; bool m_typeInfoAssigned;
bool m_default; bool m_default;
std::vector<ImplementationType> m_nestedFields; std::vector<ImplementationType> m_nestedFields;
@ -85,9 +85,9 @@ private:
*/ */
template <class ImplementationType> template <class ImplementationType>
TagField<ImplementationType>::TagField() : TagField<ImplementationType>::TagField() :
m_id(identifierType()), m_id(IdentifierType()),
m_value(TagValue()), m_value(TagValue()),
m_typeInfo(typeInfoType()), m_typeInfo(TypeInfoType()),
m_typeInfoAssigned(false), m_typeInfoAssigned(false),
m_default(false) m_default(false)
{} {}
@ -96,10 +96,10 @@ TagField<ImplementationType>::TagField() :
* \brief Constructs a new TagField with the specified \a id and \a value. * \brief Constructs a new TagField with the specified \a id and \a value.
*/ */
template <class ImplementationType> template <class ImplementationType>
TagField<ImplementationType>::TagField(const identifierType &id, const TagValue &value) : TagField<ImplementationType>::TagField(const IdentifierType &id, const TagValue &value) :
m_id(id), m_id(id),
m_value(value), m_value(value),
m_typeInfo(typeInfoType()), m_typeInfo(TypeInfoType()),
m_typeInfoAssigned(false), m_typeInfoAssigned(false),
m_default(false) m_default(false)
{} {}
@ -115,7 +115,7 @@ TagField<ImplementationType>::~TagField()
* \brief Returns the id of the current TagField. * \brief Returns the id of the current TagField.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline const typename TagField<ImplementationType>::identifierType &TagField<ImplementationType>::id() const inline const typename TagField<ImplementationType>::IdentifierType &TagField<ImplementationType>::id() const
{ {
return m_id; return m_id;
} }
@ -130,7 +130,7 @@ inline std::string TagField<ImplementationType>::idToString() const
* \brief Sets the id of the current Tag Field. * \brief Sets the id of the current Tag Field.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline void TagField<ImplementationType>::setId(const identifierType &id) inline void TagField<ImplementationType>::setId(const IdentifierType &id)
{ {
m_id = id; m_id = id;
} }
@ -141,7 +141,7 @@ inline void TagField<ImplementationType>::setId(const identifierType &id)
template <class ImplementationType> template <class ImplementationType>
inline void TagField<ImplementationType>::clearId() inline void TagField<ImplementationType>::clearId()
{ {
m_id = identifierType(); m_id = IdentifierType();
} }
/*! /*!
@ -184,7 +184,7 @@ inline void TagField<ImplementationType>::clearValue()
* \brief Returns the type info of the current TagField. * \brief Returns the type info of the current TagField.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline const typename TagField<ImplementationType>::typeInfoType &TagField<ImplementationType>::typeInfo() const inline const typename TagField<ImplementationType>::TypeInfoType &TagField<ImplementationType>::typeInfo() const
{ {
return m_typeInfo; return m_typeInfo;
} }
@ -193,7 +193,7 @@ inline const typename TagField<ImplementationType>::typeInfoType &TagField<Imple
* \brief Sets the type info of the current TagField. * \brief Sets the type info of the current TagField.
*/ */
template <class ImplementationType> template <class ImplementationType>
inline void TagField<ImplementationType>::setTypeInfo(const typeInfoType &typeInfo) inline void TagField<ImplementationType>::setTypeInfo(const TypeInfoType &typeInfo)
{ {
m_typeInfo = typeInfo; m_typeInfo = typeInfo;
m_typeInfoAssigned = true; m_typeInfoAssigned = true;
@ -205,7 +205,7 @@ inline void TagField<ImplementationType>::setTypeInfo(const typeInfoType &typeIn
template <class ImplementationType> template <class ImplementationType>
inline void TagField<ImplementationType>::removeTypeInfo() inline void TagField<ImplementationType>::removeTypeInfo()
{ {
m_typeInfo = typeInfoType(); m_typeInfo = TypeInfoType();
m_typeInfoAssigned = false; m_typeInfoAssigned = false;
} }
@ -244,7 +244,7 @@ void TagField<ImplementationType>::clear()
{ {
clearId(); clearId();
clearValue(); clearValue();
m_typeInfo = typeInfoType(); m_typeInfo = TypeInfoType();
m_typeInfoAssigned = false; m_typeInfoAssigned = false;
m_default = true; m_default = true;
static_cast<ImplementationType *>(this)->cleared(); static_cast<ImplementationType *>(this)->cleared();

View File

@ -50,7 +50,7 @@ Id3v2Frame::Id3v2Frame() :
/*! /*!
* \brief Constructs a new Id3v2Frame with the specified \a id, \a value, \a group and \a flag. * \brief Constructs a new Id3v2Frame with the specified \a id, \a value, \a group and \a flag.
*/ */
Id3v2Frame::Id3v2Frame(const identifierType &id, const TagValue &value, const byte group, const int16 flag) : Id3v2Frame::Id3v2Frame(const IdentifierType &id, const TagValue &value, const byte group, const int16 flag) :
TagField<Id3v2Frame>(id, value), TagField<Id3v2Frame>(id, value),
m_flag(flag), m_flag(flag),
m_group(group), m_group(group),

View File

@ -81,20 +81,8 @@ template <>
class TAG_PARSER_EXPORT TagFieldTraits<Id3v2Frame> class TAG_PARSER_EXPORT TagFieldTraits<Id3v2Frame>
{ {
public: public:
/*! typedef uint32 IdentifierType;
* \brief Fields in an ID3 tag are identified by 32-bit unsigned integers. typedef byte TypeInfoType;
*/
typedef uint32 identifierType;
/*!
* \brief The type info is stored using bytes.
*/
typedef byte typeInfoType;
/*!
* \brief The implementation type is Id3v2Frame.
*/
typedef Id3v2Frame implementationType;
}; };
class TAG_PARSER_EXPORT Id3v2Frame : public TagField<Id3v2Frame>, public StatusProvider class TAG_PARSER_EXPORT Id3v2Frame : public TagField<Id3v2Frame>, public StatusProvider
@ -103,7 +91,7 @@ class TAG_PARSER_EXPORT Id3v2Frame : public TagField<Id3v2Frame>, public StatusP
public: public:
Id3v2Frame(); Id3v2Frame();
Id3v2Frame(const identifierType &id, const TagValue &value, const byte group = 0, const int16 flag = 0); Id3v2Frame(const IdentifierType &id, const TagValue &value, const byte group = 0, const int16 flag = 0);
// parsing/making // parsing/making
void parse(IoUtilities::BinaryReader &reader, const uint32 version, const uint32 maximalSize = 0); void parse(IoUtilities::BinaryReader &reader, const uint32 version, const uint32 maximalSize = 0);
@ -153,8 +141,8 @@ public:
void makeCommentConsideringVersion(std::unique_ptr<char[]> &buffer, uint32 &bufferSize, const TagValue &comment, byte version); void makeCommentConsideringVersion(std::unique_ptr<char[]> &buffer, uint32 &bufferSize, const TagValue &comment, byte version);
void makeComment(std::unique_ptr<char[]> &buffer, uint32 &bufferSize, const TagValue &comment); void makeComment(std::unique_ptr<char[]> &buffer, uint32 &bufferSize, const TagValue &comment);
static identifierType fieldIdFromString(const char *idString, std::size_t idStringSize = std::string::npos); static IdentifierType fieldIdFromString(const char *idString, std::size_t idStringSize = std::string::npos);
static std::string fieldIdToString(identifierType id); static std::string fieldIdToString(IdentifierType id);
protected: protected:
void cleared(); void cleared();
@ -334,7 +322,7 @@ inline bool Id3v2Frame::supportsNestedFields() const
/*! /*!
* \brief Converts the specified ID string representation to an actual ID. * \brief Converts the specified ID string representation to an actual ID.
*/ */
inline Id3v2Frame::identifierType Id3v2Frame::fieldIdFromString(const char *idString, std::size_t idStringSize) inline Id3v2Frame::IdentifierType Id3v2Frame::fieldIdFromString(const char *idString, std::size_t idStringSize)
{ {
switch(idStringSize != std::string::npos ? idStringSize : std::strlen(idString)) { switch(idStringSize != std::string::npos ? idStringSize : std::strlen(idString)) {
case 3: case 3:
@ -349,7 +337,7 @@ inline Id3v2Frame::identifierType Id3v2Frame::fieldIdFromString(const char *idSt
/*! /*!
* \brief Returns the string representation for the specified \a id. * \brief Returns the string representation for the specified \a id.
*/ */
inline std::string Id3v2Frame::fieldIdToString(Id3v2Frame::identifierType id) inline std::string Id3v2Frame::fieldIdToString(Id3v2Frame::IdentifierType id)
{ {
return ConversionUtilities::interpretIntegerAsString<uint32>(id, Id3v2FrameIds::isLongId(id) ? 0 : 1); return ConversionUtilities::interpretIntegerAsString<uint32>(id, Id3v2FrameIds::isLongId(id) ? 0 : 1);
} }

View File

@ -17,7 +17,7 @@ namespace Media {
* \brief Implementation of Media::Tag for ID3v2 tags. * \brief Implementation of Media::Tag for ID3v2 tags.
*/ */
Id3v2Tag::identifierType Id3v2Tag::internallyGetFieldId(KnownField field) const Id3v2Tag::IdentifierType Id3v2Tag::internallyGetFieldId(KnownField field) const
{ {
using namespace Id3v2FrameIds; using namespace Id3v2FrameIds;
if(m_majorVersion >= 3) { if(m_majorVersion >= 3) {
@ -78,7 +78,7 @@ Id3v2Tag::identifierType Id3v2Tag::internallyGetFieldId(KnownField field) const
return 0; return 0;
} }
KnownField Id3v2Tag::internallyGetKnownField(const identifierType &id) const KnownField Id3v2Tag::internallyGetKnownField(const IdentifierType &id) const
{ {
using namespace Id3v2FrameIds; using namespace Id3v2FrameIds;
switch(id) { switch(id) {

View File

@ -59,9 +59,8 @@ template <>
class TAG_PARSER_EXPORT FieldMapBasedTagTraits<Id3v2Tag> class TAG_PARSER_EXPORT FieldMapBasedTagTraits<Id3v2Tag>
{ {
public: public:
typedef Id3v2Tag implementationType; typedef Id3v2Frame FieldType;
typedef Id3v2Frame fieldType; typedef FrameComparer Compare;
typedef FrameComparer compare;
}; };
class TAG_PARSER_EXPORT Id3v2Tag : public FieldMapBasedTag<Id3v2Tag> class TAG_PARSER_EXPORT Id3v2Tag : public FieldMapBasedTag<Id3v2Tag>
@ -96,8 +95,8 @@ public:
uint32 paddingSize() const; uint32 paddingSize() const;
protected: protected:
identifierType internallyGetFieldId(KnownField field) const; IdentifierType internallyGetFieldId(KnownField field) const;
KnownField internallyGetKnownField(const identifierType &id) const; KnownField internallyGetKnownField(const IdentifierType &id) const;
TagDataType internallyGetProposedDataType(const uint32 &id) const; TagDataType internallyGetProposedDataType(const uint32 &id) const;
private: private:

View File

@ -81,11 +81,11 @@ void EbmlElement::internalParse()
char buf[maximumIdLengthSupported() > maximumSizeLengthSupported() ? maximumIdLengthSupported() : maximumSizeLengthSupported()] = {0}; char buf[maximumIdLengthSupported() > maximumSizeLengthSupported() ? maximumIdLengthSupported() : maximumSizeLengthSupported()] = {0};
byte beg = static_cast<byte>(stream().peek()), mask = 0x80; byte beg = static_cast<byte>(stream().peek()), mask = 0x80;
m_idLength = 1; m_idLength = 1;
while(m_idLength <= GenericFileElement<implementationType>::maximumIdLengthSupported() && (beg & mask) == 0) { while(m_idLength <= maximumIdLengthSupported() && (beg & mask) == 0) {
++m_idLength; ++m_idLength;
mask >>= 1; mask >>= 1;
} }
if(m_idLength > GenericFileElement<implementationType>::maximumIdLengthSupported()) { if(m_idLength > maximumIdLengthSupported()) {
if(!skipped) { if(!skipped) {
addNotification(NotificationType::Critical, argsToString("EBML ID length at ", startOffset(), " is not supported, trying to skip."), context); addNotification(NotificationType::Critical, argsToString("EBML ID length at ", startOffset(), " is not supported, trying to skip."), context);
} }
@ -97,7 +97,7 @@ void EbmlElement::internalParse()
} }
continue; // try again continue; // try again
} }
reader().read(buf + (GenericFileElement<implementationType>::maximumIdLengthSupported() - m_idLength), m_idLength); reader().read(buf + (maximumIdLengthSupported() - m_idLength), m_idLength);
m_id = BE::toUInt32(buf); m_id = BE::toUInt32(buf);
// read size // read size
@ -108,11 +108,11 @@ void EbmlElement::internalParse()
// -> just assume the element takes the maximum available size // -> just assume the element takes the maximum available size
m_dataSize = maxTotalSize() - headerSize(); m_dataSize = maxTotalSize() - headerSize();
} else { } else {
while(m_sizeLength <= GenericFileElement<implementationType>::maximumSizeLengthSupported() && (beg & mask) == 0) { while(m_sizeLength <= maximumSizeLengthSupported() && (beg & mask) == 0) {
++m_sizeLength; ++m_sizeLength;
mask >>= 1; mask >>= 1;
} }
if(m_sizeLength > GenericFileElement<implementationType>::maximumSizeLengthSupported()) { if(m_sizeLength > maximumSizeLengthSupported()) {
if(!skipped) { if(!skipped) {
addNotification(NotificationType::Critical, "EBML size length is not supported.", parsingContext()); addNotification(NotificationType::Critical, "EBML size length is not supported.", parsingContext());
} }
@ -125,9 +125,10 @@ void EbmlElement::internalParse()
continue; // try again continue; // try again
} }
// read size into buffer // read size into buffer
memset(buf, 0, sizeof(dataSizeType)); // reset buffer memset(buf, 0, sizeof(DataSizeType)); // reset buffer
reader().read(buf + (GenericFileElement<implementationType>::maximumSizeLengthSupported() - m_sizeLength), m_sizeLength); reader().read(buf + (maximumSizeLengthSupported() - m_sizeLength), m_sizeLength);
*(buf + (GenericFileElement<implementationType>::maximumSizeLengthSupported() - m_sizeLength)) ^= mask; // xor the first byte in buffer which has been read from the file with mask // xor the first byte in buffer which has been read from the file with mask
*(buf + (maximumSizeLengthSupported() - m_sizeLength)) ^= mask;
m_dataSize = ConversionUtilities::BE::toUInt64(buf); m_dataSize = ConversionUtilities::BE::toUInt64(buf);
// check if element is truncated // check if element is truncated
if(totalSize() > maxTotalSize()) { if(totalSize() > maxTotalSize()) {
@ -223,7 +224,7 @@ float64 EbmlElement::readFloat()
* \brief Returns the length of the specified \a id in byte. * \brief Returns the length of the specified \a id in byte.
* \throws Throws InvalidDataException() if \a id can not be represented. * \throws Throws InvalidDataException() if \a id can not be represented.
*/ */
byte EbmlElement::calculateIdLength(GenericFileElement::identifierType id) byte EbmlElement::calculateIdLength(GenericFileElement::IdentifierType id)
{ {
if(id <= 0xFF) { if(id <= 0xFF) {
return 1; return 1;
@ -271,7 +272,7 @@ byte EbmlElement::calculateSizeDenotationLength(uint64 size)
* \returns Returns the number of bytes written to \a buff. * \returns Returns the number of bytes written to \a buff.
* \throws Throws InvalidDataException() if \a id can not be represented. * \throws Throws InvalidDataException() if \a id can not be represented.
*/ */
byte EbmlElement::makeId(GenericFileElement::identifierType id, char *buff) byte EbmlElement::makeId(GenericFileElement::IdentifierType id, char *buff)
{ {
if(id <= 0xFF) { if(id <= 0xFF) {
*buff = static_cast<byte>(id); *buff = static_cast<byte>(id);
@ -465,7 +466,7 @@ byte EbmlElement::makeUInteger(uint64 value, char *buff, byte minBytes)
* \param id Specifies the element ID. * \param id Specifies the element ID.
* \param content Specifies the value of the element as unsigned integer. * \param content Specifies the value of the element as unsigned integer.
*/ */
void EbmlElement::makeSimpleElement(ostream &stream, identifierType id, uint64 content) void EbmlElement::makeSimpleElement(ostream &stream, IdentifierType id, uint64 content)
{ {
char buff1[8]; char buff1[8];
char buff2[8]; char buff2[8];
@ -483,7 +484,7 @@ void EbmlElement::makeSimpleElement(ostream &stream, identifierType id, uint64 c
* \param id Specifies the element ID. * \param id Specifies the element ID.
* \param content Specifies the value of the element as string. * \param content Specifies the value of the element as string.
*/ */
void EbmlElement::makeSimpleElement(std::ostream &stream, GenericFileElement::identifierType id, const std::string &content) void EbmlElement::makeSimpleElement(std::ostream &stream, GenericFileElement::IdentifierType id, const std::string &content)
{ {
char buff1[8]; char buff1[8];
byte sizeLength = EbmlElement::makeId(id, buff1); byte sizeLength = EbmlElement::makeId(id, buff1);
@ -500,7 +501,7 @@ void EbmlElement::makeSimpleElement(std::ostream &stream, GenericFileElement::id
* \param data Specifies the data of the element. * \param data Specifies the data of the element.
* \param dataSize Specifies the size of \a data. * \param dataSize Specifies the size of \a data.
*/ */
void EbmlElement::makeSimpleElement(ostream &stream, GenericFileElement::identifierType id, const char *data, std::size_t dataSize) void EbmlElement::makeSimpleElement(ostream &stream, GenericFileElement::IdentifierType id, const char *data, std::size_t dataSize)
{ {
char buff1[8]; char buff1[8];
byte sizeLength = EbmlElement::makeId(id, buff1); byte sizeLength = EbmlElement::makeId(id, buff1);

View File

@ -26,25 +26,9 @@ template <>
class TAG_PARSER_EXPORT FileElementTraits<EbmlElement> class TAG_PARSER_EXPORT FileElementTraits<EbmlElement>
{ {
public: public:
/*! typedef MatroskaContainer ContainerType;
* \brief The container type used to store such elements is MatroskaContainer. typedef uint32 IdentifierType;
*/ typedef uint64 DataSizeType;
typedef MatroskaContainer containerType;
/*!
* \brief The type used to store element IDs is an unsigned 32-bit integer.
*/
typedef uint32 identifierType;
/*!
* \brief The type used to store element sizes is an unsigned 64-bit integer.
*/
typedef uint64 dataSizeType;
/*!
* \brief The implementation type is EbmlElement.
*/
typedef EbmlElement implementationType;
}; };
class TAG_PARSER_EXPORT EbmlElement : public GenericFileElement<EbmlElement> class TAG_PARSER_EXPORT EbmlElement : public GenericFileElement<EbmlElement>
@ -62,17 +46,17 @@ public:
uint64 readUInteger(); uint64 readUInteger();
float64 readFloat(); float64 readFloat();
static byte calculateIdLength(identifierType id); static byte calculateIdLength(IdentifierType id);
static byte calculateSizeDenotationLength(uint64 size); static byte calculateSizeDenotationLength(uint64 size);
static byte makeId(identifierType id, char *buff); static byte makeId(IdentifierType id, char *buff);
static byte makeSizeDenotation(uint64 size, char *buff); static byte makeSizeDenotation(uint64 size, char *buff);
static byte makeSizeDenotation(uint64 size, char *buff, byte minBytes); static byte makeSizeDenotation(uint64 size, char *buff, byte minBytes);
static byte calculateUIntegerLength(uint64 integer); static byte calculateUIntegerLength(uint64 integer);
static byte makeUInteger(uint64 value, char *buff); static byte makeUInteger(uint64 value, char *buff);
static byte makeUInteger(uint64 value, char *buff, byte minBytes); static byte makeUInteger(uint64 value, char *buff, byte minBytes);
static void makeSimpleElement(std::ostream &stream, identifierType id, uint64 content); static void makeSimpleElement(std::ostream &stream, IdentifierType id, uint64 content);
static void makeSimpleElement(std::ostream &stream, identifierType id, const std::string &content); static void makeSimpleElement(std::ostream &stream, IdentifierType id, const std::string &content);
static void makeSimpleElement(std::ostream &stream, GenericFileElement::identifierType id, const char *data, std::size_t dataSize); static void makeSimpleElement(std::ostream &stream, IdentifierType id, const char *data, std::size_t dataSize);
static uint64 bytesToBeSkipped; static uint64 bytesToBeSkipped;
protected: protected:

View File

@ -124,7 +124,7 @@ MatroskaAttachmentMaker::MatroskaAttachmentMaker(MatroskaAttachment &attachment)
} }
if(attachment.attachedFileElement()) { if(attachment.attachedFileElement()) {
EbmlElement *child; EbmlElement *child;
for(auto id : initializer_list<EbmlElement::identifierType>{MatroskaIds::FileReferral, MatroskaIds::FileUsedStartTime, MatroskaIds::FileUsedEndTime}) { for(auto id : initializer_list<EbmlElement::IdentifierType>{MatroskaIds::FileReferral, MatroskaIds::FileUsedStartTime, MatroskaIds::FileUsedEndTime}) {
if((child = attachment.attachedFileElement()->childById(id))) { if((child = attachment.attachedFileElement()->childById(id))) {
m_attachedFileElementSize += child->totalSize(); m_attachedFileElementSize += child->totalSize();
} }
@ -156,7 +156,7 @@ void MatroskaAttachmentMaker::make(ostream &stream) const
EbmlElement::makeSimpleElement(stream, MatroskaIds::FileUID, attachment().id()); EbmlElement::makeSimpleElement(stream, MatroskaIds::FileUID, attachment().id());
if(attachment().attachedFileElement()) { if(attachment().attachedFileElement()) {
EbmlElement *child; EbmlElement *child;
for(auto id : initializer_list<EbmlElement::identifierType>{MatroskaIds::FileReferral, MatroskaIds::FileUsedStartTime, MatroskaIds::FileUsedEndTime}) { for(auto id : initializer_list<EbmlElement::IdentifierType>{MatroskaIds::FileReferral, MatroskaIds::FileUsedStartTime, MatroskaIds::FileUsedEndTime}) {
if((child = attachment().attachedFileElement()->childById(id))) { if((child = attachment().attachedFileElement()->childById(id))) {
if(child->buffer()) { if(child->buffer()) {
child->copyBuffer(stream); child->copyBuffer(stream);
@ -179,7 +179,7 @@ void MatroskaAttachmentMaker::bufferCurrentAttachments()
{ {
EbmlElement *child; EbmlElement *child;
if(attachment().attachedFileElement()) { if(attachment().attachedFileElement()) {
for(auto id : initializer_list<EbmlElement::identifierType>{MatroskaIds::FileReferral, MatroskaIds::FileUsedStartTime, MatroskaIds::FileUsedEndTime}) { for(auto id : initializer_list<EbmlElement::IdentifierType>{MatroskaIds::FileReferral, MatroskaIds::FileUsedStartTime, MatroskaIds::FileUsedEndTime}) {
if((child = attachment().attachedFileElement()->childById(id))) { if((child = attachment().attachedFileElement()->childById(id))) {
child->makeBuffer(); child->makeBuffer();
} }

View File

@ -93,7 +93,7 @@ void MatroskaContainer::validateIndex()
static const string context("validating Matroska file index (cues)"); static const string context("validating Matroska file index (cues)");
bool cuesElementsFound = false; bool cuesElementsFound = false;
if(m_firstElement) { if(m_firstElement) {
unordered_set<EbmlElement::identifierType> ids; unordered_set<EbmlElement::IdentifierType> ids;
bool cueTimeFound = false, cueTrackPositionsFound = false; bool cueTimeFound = false, cueTrackPositionsFound = false;
unique_ptr<EbmlElement> clusterElement; unique_ptr<EbmlElement> clusterElement;
uint64 pos, prevClusterSize = 0, currentOffset = 0; uint64 pos, prevClusterSize = 0, currentOffset = 0;

View File

@ -180,7 +180,7 @@ uint64 MatroskaSeekInfo::actualSize() const
* *
* \returns Returns an indication whether the actualSize() has changed. * \returns Returns an indication whether the actualSize() has changed.
*/ */
bool MatroskaSeekInfo::push(unsigned int index, EbmlElement::identifierType id, uint64 offset) bool MatroskaSeekInfo::push(unsigned int index, EbmlElement::IdentifierType id, uint64 offset)
{ {
unsigned int currentIndex = 0; unsigned int currentIndex = 0;
for(auto &entry : info()) { for(auto &entry : info()) {
@ -209,7 +209,7 @@ void MatroskaSeekInfo::clear()
/*! /*!
* \brief Returns a pointer to the first pair with the specified \a offset or nullptr if no such pair could be found. * \brief Returns a pointer to the first pair with the specified \a offset or nullptr if no such pair could be found.
*/ */
std::pair<EbmlElement::identifierType, uint64> *MatroskaSeekInfo::findSeekInfo(std::vector<MatroskaSeekInfo> &seekInfos, uint64 offset) std::pair<EbmlElement::IdentifierType, uint64> *MatroskaSeekInfo::findSeekInfo(std::vector<MatroskaSeekInfo> &seekInfos, uint64 offset)
{ {
for(auto &seekInfo : seekInfos) { for(auto &seekInfo : seekInfos) {
for(auto &entry : seekInfo.info()) { for(auto &entry : seekInfo.info()) {

View File

@ -15,25 +15,25 @@ public:
MatroskaSeekInfo(); MatroskaSeekInfo();
EbmlElement *seekHeadElement() const; EbmlElement *seekHeadElement() const;
const std::vector<std::pair<EbmlElement::identifierType, uint64> > &info() const; const std::vector<std::pair<EbmlElement::IdentifierType, uint64> > &info() const;
std::vector<std::pair<EbmlElement::identifierType, uint64> > &info(); std::vector<std::pair<EbmlElement::IdentifierType, uint64> > &info();
void shift(uint64 start, int64 amount); void shift(uint64 start, int64 amount);
void parse(EbmlElement *seekHeadElement); void parse(EbmlElement *seekHeadElement);
void make(std::ostream &stream); void make(std::ostream &stream);
uint64 minSize() const; uint64 minSize() const;
uint64 maxSize() const; uint64 maxSize() const;
uint64 actualSize() const; uint64 actualSize() const;
bool push(unsigned int index, EbmlElement::identifierType id, uint64 offset); bool push(unsigned int index, EbmlElement::IdentifierType id, uint64 offset);
void clear(); void clear();
// these methods seem to be not needed anymore // these methods seem to be not needed anymore
static std::pair<EbmlElement::identifierType, uint64> *findSeekInfo(std::vector<MatroskaSeekInfo> &seekInfos, uint64 offset); static std::pair<EbmlElement::IdentifierType, uint64> *findSeekInfo(std::vector<MatroskaSeekInfo> &seekInfos, uint64 offset);
static bool updateSeekInfo(const std::vector<MatroskaSeekInfo> &oldSeekInfos, std::vector<MatroskaSeekInfo> &newSeekInfos, uint64 oldOffset, uint64 newOffset); static bool updateSeekInfo(const std::vector<MatroskaSeekInfo> &oldSeekInfos, std::vector<MatroskaSeekInfo> &newSeekInfos, uint64 oldOffset, uint64 newOffset);
static bool updateSeekInfo(std::vector<MatroskaSeekInfo> &newSeekInfos, uint64 oldOffset, uint64 newOffset); static bool updateSeekInfo(std::vector<MatroskaSeekInfo> &newSeekInfos, uint64 oldOffset, uint64 newOffset);
private: private:
EbmlElement *m_seekHeadElement; EbmlElement *m_seekHeadElement;
std::vector<std::pair<EbmlElement::identifierType, uint64> > m_info; std::vector<std::pair<EbmlElement::IdentifierType, uint64> > m_info;
}; };
/*! /*!
@ -55,7 +55,7 @@ inline EbmlElement *MatroskaSeekInfo::seekHeadElement() const
* \brief Returns the seek information gathered when the parse() method was called. * \brief Returns the seek information gathered when the parse() method was called.
* \returns Returns the seek information as pairs of element IDs and the associated offsets (relative to the beginning of the file). * \returns Returns the seek information as pairs of element IDs and the associated offsets (relative to the beginning of the file).
*/ */
inline const std::vector<std::pair<EbmlElement::identifierType, uint64> > &MatroskaSeekInfo::info() const inline const std::vector<std::pair<EbmlElement::IdentifierType, uint64> > &MatroskaSeekInfo::info() const
{ {
return m_info; return m_info;
} }
@ -64,7 +64,7 @@ inline const std::vector<std::pair<EbmlElement::identifierType, uint64> > &Matro
* \brief Returns a mutable version of the seek information gathered when the parse() method was called. * \brief Returns a mutable version of the seek information gathered when the parse() method was called.
* \returns Returns the seek information as pairs of element IDs and the associated offsets (relative to the beginning of the file). * \returns Returns the seek information as pairs of element IDs and the associated offsets (relative to the beginning of the file).
*/ */
inline std::vector<std::pair<EbmlElement::identifierType, uint64> > &MatroskaSeekInfo::info() inline std::vector<std::pair<EbmlElement::IdentifierType, uint64> > &MatroskaSeekInfo::info()
{ {
return m_info; return m_info;
} }

View File

@ -15,7 +15,7 @@ namespace Media {
* \brief Implementation of Media::Tag for the Matroska container. * \brief Implementation of Media::Tag for the Matroska container.
*/ */
MatroskaTag::identifierType MatroskaTag::internallyGetFieldId(KnownField field) const MatroskaTag::IdentifierType MatroskaTag::internallyGetFieldId(KnownField field) const
{ {
using namespace MatroskaTagIds; using namespace MatroskaTagIds;
switch(field) { switch(field) {
@ -45,7 +45,7 @@ MatroskaTag::identifierType MatroskaTag::internallyGetFieldId(KnownField field)
} }
} }
KnownField MatroskaTag::internallyGetKnownField(const identifierType &id) const KnownField MatroskaTag::internallyGetKnownField(const IdentifierType &id) const
{ {
using namespace MatroskaTagIds; using namespace MatroskaTagIds;
static const map<string, KnownField> map({ static const map<string, KnownField> map({

View File

@ -54,9 +54,8 @@ template <>
class TAG_PARSER_EXPORT FieldMapBasedTagTraits<MatroskaTag> class TAG_PARSER_EXPORT FieldMapBasedTagTraits<MatroskaTag>
{ {
public: public:
typedef MatroskaTag implementationType; typedef MatroskaTagField FieldType;
typedef MatroskaTagField fieldType; typedef std::less<typename FieldType::IdentifierType> Compare;
typedef std::less<typename fieldType::identifierType> compare;
}; };
class TAG_PARSER_EXPORT MatroskaTag : public FieldMapBasedTag<MatroskaTag> class TAG_PARSER_EXPORT MatroskaTag : public FieldMapBasedTag<MatroskaTag>
@ -78,8 +77,8 @@ public:
void make(std::ostream &stream); void make(std::ostream &stream);
protected: protected:
identifierType internallyGetFieldId(KnownField field) const; IdentifierType internallyGetFieldId(KnownField field) const;
KnownField internallyGetKnownField(const identifierType &id) const; KnownField internallyGetKnownField(const IdentifierType &id) const;
private: private:
void parseTargets(EbmlElement &targetsElement); void parseTargets(EbmlElement &targetsElement);

View File

@ -16,21 +16,8 @@ template <>
class TAG_PARSER_EXPORT TagFieldTraits<MatroskaTagField> class TAG_PARSER_EXPORT TagFieldTraits<MatroskaTagField>
{ {
public: public:
/*! typedef std::string IdentifierType;
* \brief Fields in a Matroska tag are identified by strings. typedef std::string TypeInfoType;
*/
typedef std::string identifierType;
/*!
* \brief The type info is stored using strings.
*/
typedef std::string typeInfoType;
/*!
* \brief The implementation type is EbmlElement.
*/
typedef MatroskaTagField implementationType;
static bool supportsNestedFields(); static bool supportsNestedFields();
}; };

View File

@ -27,21 +27,21 @@ namespace Media {
/*! /*!
* \brief Constructs a new top level atom with the specified \a container at the specified \a startOffset. * \brief Constructs a new top level atom with the specified \a container at the specified \a startOffset.
*/ */
Mp4Atom::Mp4Atom(GenericFileElement::containerType &container, uint64 startOffset) : Mp4Atom::Mp4Atom(GenericFileElement::ContainerType &container, uint64 startOffset) :
GenericFileElement<Mp4Atom>(container, startOffset) GenericFileElement<Mp4Atom>(container, startOffset)
{} {}
/*! /*!
* \brief Constructs a new top level atom with the specified \a container at the specified \a startOffset. * \brief Constructs a new top level atom with the specified \a container at the specified \a startOffset.
*/ */
Mp4Atom::Mp4Atom(GenericFileElement::containerType &container, uint64 startOffset, uint64 maxSize) : Mp4Atom::Mp4Atom(GenericFileElement::ContainerType &container, uint64 startOffset, uint64 maxSize) :
GenericFileElement<Mp4Atom>(container, startOffset, maxSize) GenericFileElement<Mp4Atom>(container, startOffset, maxSize)
{} {}
/*! /*!
* \brief Constructs a new sub level atom with the specified \a parent at the specified \a startOffset. * \brief Constructs a new sub level atom with the specified \a parent at the specified \a startOffset.
*/ */
Mp4Atom::Mp4Atom(GenericFileElement::implementationType &parent, uint64 startOffset) : Mp4Atom::Mp4Atom(Mp4Atom &parent, uint64 startOffset) :
GenericFileElement<Mp4Atom>(parent, startOffset) GenericFileElement<Mp4Atom>(parent, startOffset)
{} {}

View File

@ -25,25 +25,9 @@ template <>
class TAG_PARSER_EXPORT FileElementTraits<Mp4Atom> class TAG_PARSER_EXPORT FileElementTraits<Mp4Atom>
{ {
public: public:
/*! typedef Mp4Container ContainerType;
* \brief The container type used to store such elements is Mp4Container. typedef uint32 IdentifierType;
*/ typedef uint64 DataSizeType;
typedef Mp4Container containerType;
/*!
* \brief The type used to store atom IDs is an unsigned 32-bit integer.
*/
typedef uint32 identifierType;
/*!
* \brief The type used to store element sizes is an unsigned 64-bit integer.
*/
typedef uint64 dataSizeType;
/*!
* \brief The implementation type is Mp4Atom.
*/
typedef Mp4Atom implementationType;
/*! /*!
* \brief Returns the minimal atom size which is 8 byte. * \brief Returns the minimal atom size which is 8 byte.
@ -59,7 +43,7 @@ class TAG_PARSER_EXPORT Mp4Atom : public GenericFileElement<Mp4Atom>
friend class GenericFileElement<Mp4Atom>; friend class GenericFileElement<Mp4Atom>;
public: public:
Mp4Atom(containerType& container, uint64 startOffset); Mp4Atom(ContainerType &container, uint64 startOffset);
std::string idToString() const; std::string idToString() const;
bool isParent() const; bool isParent() const;
@ -72,8 +56,8 @@ public:
static void makeHeader(uint64 size, uint32 id, IoUtilities::BinaryWriter &writer); static void makeHeader(uint64 size, uint32 id, IoUtilities::BinaryWriter &writer);
protected: protected:
Mp4Atom(containerType& container, uint64 startOffset, uint64 maxSize); Mp4Atom(ContainerType &container, uint64 startOffset, uint64 maxSize);
Mp4Atom(implementationType &parent, uint64 startOffset); Mp4Atom(Mp4Atom &parent, uint64 startOffset);
void internalParse(); void internalParse();
@ -86,7 +70,7 @@ private:
*/ */
inline std::string Mp4Atom::idToString() const inline std::string Mp4Atom::idToString() const
{ {
auto idString = ConversionUtilities::interpretIntegerAsString<identifierType>(id()); auto idString = ConversionUtilities::interpretIntegerAsString<IdentifierType>(id());
for(char &c : idString) { for(char &c : idString) {
if(c < ' ') { if(c < ' ') {
c = '?'; c = '?';

View File

@ -119,7 +119,7 @@ const TagValue &Mp4Tag::value(const string mean, const string name) const
return (this->*static_cast<const TagValue &(Mp4Tag::*)(const string &, const string &) const>(&Mp4Tag::value))(mean, name); return (this->*static_cast<const TagValue &(Mp4Tag::*)(const string &, const string &) const>(&Mp4Tag::value))(mean, name);
} }
Mp4Tag::identifierType Mp4Tag::internallyGetFieldId(KnownField field) const Mp4Tag::IdentifierType Mp4Tag::internallyGetFieldId(KnownField field) const
{ {
using namespace Mp4TagAtomIds; using namespace Mp4TagAtomIds;
switch(field) { switch(field) {
@ -146,7 +146,7 @@ Mp4Tag::identifierType Mp4Tag::internallyGetFieldId(KnownField field) const
} }
} }
KnownField Mp4Tag::internallyGetKnownField(const identifierType &id) const KnownField Mp4Tag::internallyGetKnownField(const IdentifierType &id) const
{ {
using namespace Mp4TagAtomIds; using namespace Mp4TagAtomIds;
switch(id) { switch(id) {
@ -244,7 +244,7 @@ bool Mp4Tag::setValue(const char *mean, const char *name, const TagValue &value)
return true; return true;
} }
} }
fields().insert(make_pair(Mp4TagAtomIds::Extended, fieldType(mean, name, value))); fields().insert(make_pair(Mp4TagAtomIds::Extended, FieldType(mean, name, value)));
return true; return true;
} }
@ -320,7 +320,7 @@ void Mp4Tag::parse(Mp4Atom &metaAtom)
child->parse(); child->parse();
tagField.invalidateNotifications(); tagField.invalidateNotifications();
tagField.reparse(*child); tagField.reparse(*child);
fields().insert(pair<fieldType::identifierType, fieldType>(child->id(), tagField)); fields().emplace(child->id(), tagField);
} catch(const Failure &) { } catch(const Failure &) {
} }
addNotifications(context, *child); addNotifications(context, *child);

View File

@ -94,9 +94,8 @@ template <>
class TAG_PARSER_EXPORT FieldMapBasedTagTraits<Mp4Tag> class TAG_PARSER_EXPORT FieldMapBasedTagTraits<Mp4Tag>
{ {
public: public:
typedef Mp4Tag implementationType; typedef Mp4TagField FieldType;
typedef Mp4TagField fieldType; typedef std::less<typename FieldType::IdentifierType> Compare;
typedef std::less<typename fieldType::identifierType> compare;
}; };
class TAG_PARSER_EXPORT Mp4Tag : public FieldMapBasedTag<Mp4Tag> class TAG_PARSER_EXPORT Mp4Tag : public FieldMapBasedTag<Mp4Tag>
@ -138,8 +137,8 @@ public:
void make(std::ostream &stream); void make(std::ostream &stream);
protected: protected:
identifierType internallyGetFieldId(KnownField field) const; IdentifierType internallyGetFieldId(KnownField field) const;
KnownField internallyGetKnownField(const identifierType &id) const; KnownField internallyGetKnownField(const IdentifierType &id) const;
}; };

View File

@ -36,7 +36,7 @@ Mp4TagField::Mp4TagField() :
/*! /*!
* \brief Constructs a new Mp4TagField with the specified \a id and \a value. * \brief Constructs a new Mp4TagField with the specified \a id and \a value.
*/ */
Mp4TagField::Mp4TagField(identifierType id, const TagValue &value) : Mp4TagField::Mp4TagField(IdentifierType id, const TagValue &value) :
TagField<Mp4TagField>(id, value), TagField<Mp4TagField>(id, value),
m_parsedRawDataType(RawDataType::Reserved), m_parsedRawDataType(RawDataType::Reserved),
m_countryIndicator(0), m_countryIndicator(0),

View File

@ -57,20 +57,8 @@ template <>
class TAG_PARSER_EXPORT TagFieldTraits<Mp4TagField> class TAG_PARSER_EXPORT TagFieldTraits<Mp4TagField>
{ {
public: public:
/*! typedef uint32 IdentifierType;
* \brief Fields in a iTunes-style MP4 tag are identified by 32-bit unsigned integers. typedef uint32 TypeInfoType;
*/
typedef uint32 identifierType;
/*!
* \brief The type info is stored using 32-bit unsigned integers.
*/
typedef uint32 typeInfoType;
/*!
* \brief The implementation type is Mp4TagField.
*/
typedef Mp4TagField implementationType;
}; };
class Mp4Atom; class Mp4Atom;
@ -117,7 +105,7 @@ class TAG_PARSER_EXPORT Mp4TagField : public TagField<Mp4TagField>, public Statu
public: public:
Mp4TagField(); Mp4TagField();
Mp4TagField(identifierType id, const TagValue &value); Mp4TagField(IdentifierType id, const TagValue &value);
Mp4TagField(const std::string &mean, const std::string &name, const TagValue &value); Mp4TagField(const std::string &mean, const std::string &name, const TagValue &value);
void reparse(Mp4Atom &ilstChild); void reparse(Mp4Atom &ilstChild);
@ -136,8 +124,8 @@ public:
std::vector<uint32> expectedRawDataTypes() const; std::vector<uint32> expectedRawDataTypes() const;
uint32 appropriateRawDataType() const; uint32 appropriateRawDataType() const;
static identifierType fieldIdFromString(const char *idString, std::size_t idStringSize = std::string::npos); static IdentifierType fieldIdFromString(const char *idString, std::size_t idStringSize = std::string::npos);
static std::string fieldIdToString(identifierType id); static std::string fieldIdToString(IdentifierType id);
protected: protected:
void cleared(); void cleared();
@ -227,7 +215,7 @@ inline bool Mp4TagField::supportsNestedFields() const
* \remarks The specified \a idString is assumed to be UTF-8 encoded. In order to get the ©-sign * \remarks The specified \a idString is assumed to be UTF-8 encoded. In order to get the ©-sign
* correctly, it is converted to Latin-1. * correctly, it is converted to Latin-1.
*/ */
inline Mp4TagField::identifierType Mp4TagField::fieldIdFromString(const char *idString, std::size_t idStringSize) inline Mp4TagField::IdentifierType Mp4TagField::fieldIdFromString(const char *idString, std::size_t idStringSize)
{ {
const auto latin1 = ConversionUtilities::convertUtf8ToLatin1(idString, idStringSize != std::string::npos ? idStringSize : std::strlen(idString)); const auto latin1 = ConversionUtilities::convertUtf8ToLatin1(idString, idStringSize != std::string::npos ? idStringSize : std::strlen(idString));
switch(latin1.second) { switch(latin1.second) {
@ -243,7 +231,7 @@ inline Mp4TagField::identifierType Mp4TagField::fieldIdFromString(const char *id
* \remarks The specified \a id is considered Latin-1 encoded. In order to get the ©-sign * \remarks The specified \a id is considered Latin-1 encoded. In order to get the ©-sign
* correctly, it is converted to UTF-8. * correctly, it is converted to UTF-8.
*/ */
inline std::string Mp4TagField::fieldIdToString(Mp4TagField::identifierType id) inline std::string Mp4TagField::fieldIdToString(Mp4TagField::IdentifierType id)
{ {
const auto utf8 = ConversionUtilities::convertLatin1ToUtf8(ConversionUtilities::interpretIntegerAsString<uint32>(id).data(), 4); const auto utf8 = ConversionUtilities::convertLatin1ToUtf8(ConversionUtilities::interpretIntegerAsString<uint32>(id).data(), 4);
return std::string(utf8.first.get(), utf8.second); return std::string(utf8.first.get(), utf8.second);

View File

@ -20,14 +20,14 @@ namespace Media {
* \brief Constructs a new top level descriptor with the specified \a container at the specified \a startOffset * \brief Constructs a new top level descriptor with the specified \a container at the specified \a startOffset
* and with the specified \a maxSize. * and with the specified \a maxSize.
*/ */
Mpeg4Descriptor::Mpeg4Descriptor(containerType &container, uint64 startOffset, uint64 maxSize) : Mpeg4Descriptor::Mpeg4Descriptor(ContainerType &container, uint64 startOffset, uint64 maxSize) :
GenericFileElement<Mpeg4Descriptor>(container, startOffset, maxSize) GenericFileElement<Mpeg4Descriptor>(container, startOffset, maxSize)
{} {}
/*! /*!
* \brief Constructs a new sub level descriptor with the specified \a parent at the specified \a startOffset. * \brief Constructs a new sub level descriptor with the specified \a parent at the specified \a startOffset.
*/ */
Mpeg4Descriptor::Mpeg4Descriptor(implementationType &parent, uint64 startOffset) : Mpeg4Descriptor::Mpeg4Descriptor(Mpeg4Descriptor &parent, uint64 startOffset) :
GenericFileElement<Mpeg4Descriptor>(parent, startOffset) GenericFileElement<Mpeg4Descriptor>(parent, startOffset)
{} {}
@ -75,12 +75,12 @@ void Mpeg4Descriptor::internalParse()
m_dataSize = maxTotalSize(); // using max size instead m_dataSize = maxTotalSize(); // using max size instead
} }
m_firstChild.reset(); m_firstChild.reset();
implementationType *sibling = nullptr; Mpeg4Descriptor *sibling = nullptr;
if(totalSize() < maxTotalSize()) { if(totalSize() < maxTotalSize()) {
if(parent()) { if(parent()) {
sibling = new implementationType(*(parent()), startOffset() + totalSize()); sibling = new Mpeg4Descriptor(*(parent()), startOffset() + totalSize());
} else { } else {
sibling = new implementationType(container(), startOffset() + totalSize(), maxTotalSize() - totalSize()); sibling = new Mpeg4Descriptor(container(), startOffset() + totalSize(), maxTotalSize() - totalSize());
} }
} }
m_nextSibling.reset(sibling); m_nextSibling.reset(sibling);

View File

@ -17,25 +17,9 @@ template <>
class TAG_PARSER_EXPORT FileElementTraits<Mpeg4Descriptor> class TAG_PARSER_EXPORT FileElementTraits<Mpeg4Descriptor>
{ {
public: public:
/*! typedef Mp4Container ContainerType;
* \brief The container type used to store such elements is Mp4Container. typedef byte IdentifierType;
*/ typedef uint32 DataSizeType;
typedef Mp4Container containerType;
/*!
* \brief The type used to store atom IDs is an unsigned 32-bit integer.
*/
typedef byte identifierType;
/*!
* \brief The type used to store element sizes is an unsigned 32-bit integer.
*/
typedef uint32 dataSizeType;
/*!
* \brief The implementation type is Mp4Atom.
*/
typedef Mpeg4Descriptor implementationType;
/*! /*!
* \brief Returns the minimal descriptor size which is 2 byte. * \brief Returns the minimal descriptor size which is 2 byte.
@ -51,7 +35,7 @@ class TAG_PARSER_EXPORT Mpeg4Descriptor : public GenericFileElement<Mpeg4Descrip
friend class GenericFileElement<Mpeg4Descriptor>; friend class GenericFileElement<Mpeg4Descriptor>;
public: public:
Mpeg4Descriptor(containerType& container, uint64 startOffset, uint64 maxSize); Mpeg4Descriptor(ContainerType &container, uint64 startOffset, uint64 maxSize);
std::string idToString() const; std::string idToString() const;
bool isParent() const; bool isParent() const;
@ -59,7 +43,7 @@ public:
uint64 firstChildOffset() const; uint64 firstChildOffset() const;
protected: protected:
Mpeg4Descriptor(implementationType &parent, uint64 startOffset); Mpeg4Descriptor(Mpeg4Descriptor &parent, uint64 startOffset);
void internalParse(); void internalParse();

View File

@ -44,7 +44,7 @@ bool VorbisComment::setValue(KnownField field, const TagValue &value)
} }
} }
VorbisComment::identifierType VorbisComment::internallyGetFieldId(KnownField field) const VorbisComment::IdentifierType VorbisComment::internallyGetFieldId(KnownField field) const
{ {
using namespace VorbisCommentIds; using namespace VorbisCommentIds;
switch(field) { switch(field) {
@ -70,7 +70,7 @@ VorbisComment::identifierType VorbisComment::internallyGetFieldId(KnownField fie
} }
} }
KnownField VorbisComment::internallyGetKnownField(const identifierType &id) const KnownField VorbisComment::internallyGetKnownField(const IdentifierType &id) const
{ {
using namespace VorbisCommentIds; using namespace VorbisCommentIds;
static const map<string, KnownField> fieldMap({ static const map<string, KnownField> fieldMap({
@ -145,7 +145,7 @@ void VorbisComment::internalParse(StreamType &stream, uint64 maxSize, VorbisComm
// read fields // read fields
try { try {
field.parse(stream, maxSize); field.parse(stream, maxSize);
fields().insert(pair<fieldType::identifierType, fieldType>(fieldId, field)); fields().emplace(fieldId, field);
} catch(const TruncatedDataException &) { } catch(const TruncatedDataException &) {
addNotifications(field); addNotifications(field);
throw; throw;

View File

@ -19,9 +19,8 @@ template <>
class TAG_PARSER_EXPORT FieldMapBasedTagTraits<VorbisComment> class TAG_PARSER_EXPORT FieldMapBasedTagTraits<VorbisComment>
{ {
public: public:
typedef VorbisComment implementationType; typedef VorbisCommentField FieldType;
typedef VorbisCommentField fieldType; typedef CaseInsensitiveStringComparer Compare;
typedef CaseInsensitiveStringComparer compare;
}; };
class TAG_PARSER_EXPORT VorbisComment : public FieldMapBasedTag<VorbisComment> class TAG_PARSER_EXPORT VorbisComment : public FieldMapBasedTag<VorbisComment>
@ -49,8 +48,8 @@ public:
void setVendor(const TagValue &vendor); void setVendor(const TagValue &vendor);
protected: protected:
identifierType internallyGetFieldId(KnownField field) const; IdentifierType internallyGetFieldId(KnownField field) const;
KnownField internallyGetKnownField(const identifierType &id) const; KnownField internallyGetKnownField(const IdentifierType &id) const;
private: private:
template<class StreamType> template<class StreamType>

View File

@ -38,7 +38,7 @@ VorbisCommentField::VorbisCommentField()
/*! /*!
* \brief Constructs a new Vorbis comment with the specified \a id and \a value. * \brief Constructs a new Vorbis comment with the specified \a id and \a value.
*/ */
VorbisCommentField::VorbisCommentField(const identifierType &id, const TagValue &value) : VorbisCommentField::VorbisCommentField(const IdentifierType &id, const TagValue &value) :
TagField<VorbisCommentField>(id, value) TagField<VorbisCommentField>(id, value)
{} {}

View File

@ -41,18 +41,8 @@ template <>
class TAG_PARSER_EXPORT TagFieldTraits<VorbisCommentField> class TAG_PARSER_EXPORT TagFieldTraits<VorbisCommentField>
{ {
public: public:
/*! typedef std::string IdentifierType;
* \brief Fields in a Vorbis comment are identified by 32-bit unsigned integers. typedef uint32 TypeInfoType;
*/
typedef std::string identifierType;
/*!
* \brief The type info is stored using 32-bit unsigned integers.
*/
typedef uint32 typeInfoType;
/*!
* \brief The implementation type is VorbisCommentField.
*/
typedef VorbisCommentField implementationType;
}; };
class OggIterator; class OggIterator;
@ -63,7 +53,7 @@ class TAG_PARSER_EXPORT VorbisCommentField : public TagField<VorbisCommentField>
public: public:
VorbisCommentField(); VorbisCommentField();
VorbisCommentField(const identifierType &id, const TagValue &value); VorbisCommentField(const IdentifierType &id, const TagValue &value);
void parse(OggIterator &iterator); void parse(OggIterator &iterator);
void parse(OggIterator &iterator, uint64 &maxSize); void parse(OggIterator &iterator, uint64 &maxSize);