#include "./tag.h" using namespace std; namespace Media { /*! * \class Media::Tag * \brief The Tag class is used to store, read and write tag information. * * The Tag class only provides the interface and common functionality. It * is meant to be subclassed.This interface does not include parse/make * methods to read/write a tag from/to a stream because the availability * and signature of these methods may differ between the individual * implementations (eg. an Mp4Tag is read from the "meta" Mp4Atom). */ /*! * \brief Constructs a new Tag. */ Tag::Tag() : m_size(0) {} /*! * \brief Destroys the Tag. */ Tag::~Tag() {} /*! * \brief Returns a string representation of the tag. */ string Tag::toString() const { string res; res += typeName(); if(supportsTarget()) { res += " targeting "; res += targetString(); } return res; } /*! * \brief Returns the values of the specified \a field. * \remarks * - There might me more than one value assigned to a \a field. Whereas value() * returns only the first value, this method returns all values. * - However, the default implementation just returns the first value assuming * multiple values per field are not supported by the tag. */ std::list Tag::values(KnownField field) const { std::list values; const TagValue &v = value(field); if(!v.isEmpty()) { values.push_back(&v); } return values; } /*! * \brief Assigns the given \a values to the specified \a field. * \remarks * - There might me more then one value assigned to a \a field. Whereas setValue() only alters the first value, this * method will replace all currently assigned values with the specified \a values. * - However, the default implementation just sets the first value and discards additional values assuming * multiple values per field are not supported by the tag. */ bool Tag::setValues(KnownField field, std::initializer_list values) { return setValue(field, values.size() ? *values.begin() : TagValue()); } /*! * \fn Tag::value() * \brief Returns the value of the specified \a field. * \remarks * - If the specified \a field is not present an empty TagValue will be returned. * - Some tags support more than just one value per field. If there are multiple values * this method just returns the first one. * \sa setValue(), hasField() */ /*! * \fn Tag::setValue() * \brief Assigns the given \a value to the specified \a field. * \remarks * - If an empty \a value is given, the field will be be removed. * - Some tags support more than just one value per field. This method will only * alter the first value. * \sa value(), hasField() */ /*! * \fn Tag::hasField() * \brief Returns an indication whether the specified \a field is present. * * \sa value(), setValue() */ /*! * \fn Tag::removeAllFields() * \brief Removes all fields from the tag. */ /*! * \fn Tag::fieldCount() * \brief Returns the number of present fields. */ /*! * \fn Tag::supportsField() * \brief Returns an indication whether the specified \a field * is supported by the tag. */ /*! * \brief Inserts all compatible values \a from another Tag. * \param from Specifies the Tag the values should be inserted from. * \param overwrite Indicates whether existing values should be overwritten. * \return Returns the number of values that have been inserted. * \remarks The encoding of the inserted text values might not be supported by the tag. * To fix this, call ensureTextValuesAreProperlyEncoded() after insertion. */ unsigned int Tag::insertValues(const Tag &from, bool overwrite) { unsigned int count = 0; for(int i = static_cast(KnownField::Invalid) + 1, last = static_cast(KnownField::Description); i <= last; ++i) { KnownField field = static_cast(i); const TagValue &ownValue = value(field); if(overwrite || ownValue.isEmpty()) { const TagValue &otherValue = from.value(field); if(!otherValue.isEmpty() && setValue(field, otherValue)) { ++count; } } } return count; } /*! * \fn Tag::ensureTextValuesAreProperlyEncoded() * \brief Ensures the encoding of all assigned text values is supported by the tag by * converting the character set if neccessary. */ //bool Tag::setParent(Tag *tag) //{ // if(m_parent != tag) { // // ensure this tag is a valid parent for the specified tag // if(!tag->supportsChild(this)) { // return false; // } // // ensure the new parent is no child of this tag // Tag *newParent = tag->parent(); // while(newParent) { // if(newParent == this) { // return false; // } // newParent = newParent->parent(); // } // // remove this tag from the nested tags of the old parent // if(m_parent) { // m_parent->m_nestedTags.erase(std::remove(m_nestedTags.begin(), m_nestedTags.end(), this)); // } // // add this tag to the nested tags of the new parent // if((m_parent = tag)) { // m_parent->m_nestedTags.push_back(this); // } // } // return true; //} }