Use vector for getting/setting multiple values
This commit is contained in:
parent
4335ba724b
commit
334f9f9c60
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <initializer_list>
|
|
||||||
|
|
||||||
namespace Media {
|
namespace Media {
|
||||||
|
|
||||||
|
@ -30,12 +29,12 @@ public:
|
||||||
|
|
||||||
virtual const TagValue &value(const typename FieldType::identifierType &id) const;
|
virtual const TagValue &value(const typename FieldType::identifierType &id) const;
|
||||||
const TagValue &value(KnownField field) const;
|
const TagValue &value(KnownField field) const;
|
||||||
std::list<const TagValue *> values(const typename FieldType::identifierType &id) const;
|
std::vector<const TagValue *> values(const typename FieldType::identifierType &id) const;
|
||||||
std::list<const TagValue *> values(KnownField field) const;
|
std::vector<const TagValue *> values(KnownField field) const;
|
||||||
virtual bool setValue(const typename FieldType::identifierType &id, const TagValue &value);
|
virtual bool setValue(const typename FieldType::identifierType &id, const TagValue &value);
|
||||||
bool setValue(KnownField field, const TagValue &value);
|
bool setValue(KnownField field, const TagValue &value);
|
||||||
bool setValues(const typename FieldType::identifierType &id, std::initializer_list<TagValue> values);
|
bool setValues(const typename FieldType::identifierType &id, const std::vector<TagValue> &values);
|
||||||
bool setValues(KnownField field, std::initializer_list<TagValue> values);
|
bool setValues(KnownField field, const std::vector<TagValue> &values);
|
||||||
bool hasField(KnownField field) const;
|
bool hasField(KnownField field) const;
|
||||||
virtual bool hasField(const typename FieldType::identifierType &id) const;
|
virtual bool hasField(const typename FieldType::identifierType &id) const;
|
||||||
void removeAllFields();
|
void removeAllFields();
|
||||||
|
@ -99,10 +98,10 @@ inline const TagValue &FieldMapBasedTag<FieldType, Compare>::value(KnownField fi
|
||||||
* \sa Tag::values()
|
* \sa Tag::values()
|
||||||
*/
|
*/
|
||||||
template <class FieldType, class Compare>
|
template <class FieldType, class Compare>
|
||||||
inline std::list<const TagValue *> FieldMapBasedTag<FieldType, Compare>::values(const typename FieldType::identifierType &id) const
|
inline std::vector<const TagValue *> FieldMapBasedTag<FieldType, Compare>::values(const typename FieldType::identifierType &id) const
|
||||||
{
|
{
|
||||||
auto range = m_fields.equal_range(id);
|
auto range = m_fields.equal_range(id);
|
||||||
std::list<const TagValue *> values;
|
std::vector<const TagValue *> values;
|
||||||
for(auto i = range.first; i != range.second; ++i) {
|
for(auto i = range.first; i != range.second; ++i) {
|
||||||
if(!i->second.value().isEmpty()) {
|
if(!i->second.value().isEmpty()) {
|
||||||
values.push_back(&i->second.value());
|
values.push_back(&i->second.value());
|
||||||
|
@ -112,7 +111,7 @@ inline std::list<const TagValue *> FieldMapBasedTag<FieldType, Compare>::values(
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class FieldType, class Compare>
|
template <class FieldType, class Compare>
|
||||||
inline std::list<const TagValue *> FieldMapBasedTag<FieldType, Compare>::values(KnownField field) const
|
inline std::vector<const TagValue *> FieldMapBasedTag<FieldType, Compare>::values(KnownField field) const
|
||||||
{
|
{
|
||||||
return values(fieldId(field));
|
return values(fieldId(field));
|
||||||
}
|
}
|
||||||
|
@ -146,7 +145,7 @@ bool FieldMapBasedTag<FieldType, Compare>::setValue(const typename FieldType::id
|
||||||
* \sa Tag::setValues()
|
* \sa Tag::setValues()
|
||||||
*/
|
*/
|
||||||
template <class FieldType, class Compare>
|
template <class FieldType, class Compare>
|
||||||
bool FieldMapBasedTag<FieldType, Compare>::setValues(const typename FieldType::identifierType &id, std::initializer_list<TagValue> values)
|
bool FieldMapBasedTag<FieldType, Compare>::setValues(const typename FieldType::identifierType &id, const std::vector<TagValue> &values)
|
||||||
{
|
{
|
||||||
auto valuesIterator = values.begin();
|
auto valuesIterator = values.begin();
|
||||||
auto range = m_fields.equal_range(id);
|
auto range = m_fields.equal_range(id);
|
||||||
|
@ -171,7 +170,7 @@ bool FieldMapBasedTag<FieldType, Compare>::setValues(const typename FieldType::i
|
||||||
* method will replace all currently assigned values with the specified \a values.
|
* method will replace all currently assigned values with the specified \a values.
|
||||||
*/
|
*/
|
||||||
template <class FieldType, class Compare>
|
template <class FieldType, class Compare>
|
||||||
bool FieldMapBasedTag<FieldType, Compare>::setValues(KnownField field, std::initializer_list<TagValue> values)
|
bool FieldMapBasedTag<FieldType, Compare>::setValues(KnownField field, const std::vector<TagValue> &values)
|
||||||
{
|
{
|
||||||
return setValues(fieldId(field), values);
|
return setValues(fieldId(field), values);
|
||||||
}
|
}
|
||||||
|
|
6
tag.cpp
6
tag.cpp
|
@ -50,9 +50,9 @@ string Tag::toString() const
|
||||||
* - However, the default implementation just returns the first value assuming
|
* - However, the default implementation just returns the first value assuming
|
||||||
* multiple values per field are not supported by the tag.
|
* multiple values per field are not supported by the tag.
|
||||||
*/
|
*/
|
||||||
std::list<const TagValue *> Tag::values(KnownField field) const
|
std::vector<const TagValue *> Tag::values(KnownField field) const
|
||||||
{
|
{
|
||||||
std::list<const TagValue *> values;
|
std::vector<const TagValue *> values;
|
||||||
const TagValue &v = value(field);
|
const TagValue &v = value(field);
|
||||||
if(!v.isEmpty()) {
|
if(!v.isEmpty()) {
|
||||||
values.push_back(&v);
|
values.push_back(&v);
|
||||||
|
@ -68,7 +68,7 @@ std::list<const TagValue *> Tag::values(KnownField field) const
|
||||||
* - However, the default implementation just sets the first value and discards additional values assuming
|
* - However, the default implementation just sets the first value and discards additional values assuming
|
||||||
* multiple values per field are not supported by the tag.
|
* multiple values per field are not supported by the tag.
|
||||||
*/
|
*/
|
||||||
bool Tag::setValues(KnownField field, std::initializer_list<TagValue> values)
|
bool Tag::setValues(KnownField field, const std::vector<TagValue> &values)
|
||||||
{
|
{
|
||||||
return setValue(field, values.size() ? *values.begin() : TagValue());
|
return setValue(field, values.size() ? *values.begin() : TagValue());
|
||||||
}
|
}
|
||||||
|
|
4
tag.h
4
tag.h
|
@ -107,9 +107,9 @@ public:
|
||||||
virtual TagTextEncoding proposedTextEncoding() const;
|
virtual TagTextEncoding proposedTextEncoding() const;
|
||||||
virtual bool canEncodingBeUsed(TagTextEncoding encoding) const;
|
virtual bool canEncodingBeUsed(TagTextEncoding encoding) const;
|
||||||
virtual const TagValue &value(KnownField field) const = 0;
|
virtual const TagValue &value(KnownField field) const = 0;
|
||||||
virtual std::list<const TagValue *> values(KnownField field) const;
|
virtual std::vector<const TagValue *> values(KnownField field) const;
|
||||||
virtual bool setValue(KnownField field, const TagValue &value) = 0;
|
virtual bool setValue(KnownField field, const TagValue &value) = 0;
|
||||||
virtual bool setValues(KnownField field, std::initializer_list<TagValue> values);
|
virtual bool setValues(KnownField field, const std::vector<TagValue> &values);
|
||||||
virtual bool hasField(KnownField field) const = 0;
|
virtual bool hasField(KnownField field) const = 0;
|
||||||
virtual void removeAllFields() = 0;
|
virtual void removeAllFields() = 0;
|
||||||
const std::string &version() const;
|
const std::string &version() const;
|
||||||
|
|
Loading…
Reference in New Issue