mirror of
https://github.com/taglib/taglib.git
synced 2025-05-27 21:20:26 -04:00
Braced list initialization for StringList and ByteVectorList (#1154)
Additionally, provide operator==() and operator!=() for Map and operator<<() for ByteVectorList to facilitate the writing of tests.
This commit is contained in:
parent
21b08c0dcb
commit
41077aa57e
@ -72,6 +72,11 @@ ByteVectorList::ByteVectorList(const ByteVectorList &l) :
|
||||
{
|
||||
}
|
||||
|
||||
ByteVectorList::ByteVectorList(std::initializer_list<ByteVector> init) :
|
||||
List<ByteVector>(init)
|
||||
{
|
||||
}
|
||||
|
||||
ByteVectorList &ByteVectorList::operator=(const ByteVectorList &l)
|
||||
{
|
||||
if(this == &l)
|
||||
@ -81,6 +86,12 @@ ByteVectorList &ByteVectorList::operator=(const ByteVectorList &l)
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteVectorList &ByteVectorList::operator=(std::initializer_list<ByteVector> init)
|
||||
{
|
||||
List<ByteVector>::operator=(init);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ByteVector ByteVectorList::toByteVector(const ByteVector &separator) const
|
||||
{
|
||||
ByteVector v;
|
||||
@ -93,3 +104,18 @@ ByteVector ByteVectorList::toByteVector(const ByteVector &separator) const
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// related functions
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::ostream &operator<<(std::ostream &s, const ByteVectorList &l)
|
||||
{
|
||||
for(auto it = l.begin(); it != l.end(); ++it) {
|
||||
if(it != l.begin()) {
|
||||
s << ' ';
|
||||
}
|
||||
s << *it;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
@ -59,7 +59,13 @@ namespace TagLib {
|
||||
*/
|
||||
ByteVectorList(const ByteVectorList &l);
|
||||
|
||||
/*!
|
||||
* Construct a ByteVectorList with the contents of the braced initializer list.
|
||||
*/
|
||||
ByteVectorList(std::initializer_list<ByteVector> init);
|
||||
|
||||
ByteVectorList &operator=(const ByteVectorList &);
|
||||
ByteVectorList &operator=(std::initializer_list<ByteVector> init);
|
||||
|
||||
/*!
|
||||
* Convert the ByteVectorList to a ByteVector separated by \a separator. By
|
||||
@ -83,4 +89,10 @@ namespace TagLib {
|
||||
|
||||
} // namespace TagLib
|
||||
|
||||
/*!
|
||||
* \related TagLib::ByteVectorList
|
||||
* Send the ByteVectorList to an output stream.
|
||||
*/
|
||||
std::ostream TAGLIB_EXPORT &operator<<(std::ostream &s, const TagLib::ByteVectorList &l);
|
||||
|
||||
#endif
|
||||
|
@ -73,7 +73,7 @@ namespace TagLib {
|
||||
List(const List<T> &l);
|
||||
|
||||
/*!
|
||||
* Construct a List with the contents of the braced initiliazer list
|
||||
* Construct a List with the contents of the braced initializer list.
|
||||
*/
|
||||
List(std::initializer_list<T> init);
|
||||
|
||||
|
@ -212,6 +212,17 @@ namespace TagLib {
|
||||
*/
|
||||
void swap(Map<Key, T> &m);
|
||||
|
||||
/*!
|
||||
* Compares this map with \a m and returns true if all of the elements are
|
||||
* the same.
|
||||
*/
|
||||
bool operator==(const Map<Key, T> &m) const;
|
||||
|
||||
/*!
|
||||
* Compares this map with \a m and returns true if the maps differ.
|
||||
*/
|
||||
bool operator!=(const Map<Key, T> &m) const;
|
||||
|
||||
protected:
|
||||
/*
|
||||
* If this List is being shared via implicit sharing, do a deep copy of the
|
||||
|
@ -205,6 +205,18 @@ void Map<Key, T>::swap(Map<Key, T> &m)
|
||||
swap(d, m.d);
|
||||
}
|
||||
|
||||
template <class Key, class T>
|
||||
bool Map<Key, T>::operator==(const Map<Key, T> &m) const
|
||||
{
|
||||
return d->map == m.d->map;
|
||||
}
|
||||
|
||||
template <class Key, class T>
|
||||
bool Map<Key, T>::operator!=(const Map<Key, T> &m) const
|
||||
{
|
||||
return d->map != m.d->map;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// protected members
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -61,6 +61,11 @@ StringList::StringList(const StringList &l) :
|
||||
{
|
||||
}
|
||||
|
||||
StringList::StringList(std::initializer_list<String> init) :
|
||||
List<String>(init)
|
||||
{
|
||||
}
|
||||
|
||||
StringList &StringList::operator=(const StringList &l)
|
||||
{
|
||||
if(this == &l)
|
||||
@ -70,6 +75,12 @@ StringList &StringList::operator=(const StringList &l)
|
||||
return *this;
|
||||
}
|
||||
|
||||
StringList &StringList::operator=(std::initializer_list<String> init)
|
||||
{
|
||||
List<String>::operator=(init);
|
||||
return *this;
|
||||
}
|
||||
|
||||
StringList::StringList(const String &s)
|
||||
{
|
||||
append(s);
|
||||
|
@ -58,7 +58,13 @@ namespace TagLib {
|
||||
*/
|
||||
StringList(const StringList &l);
|
||||
|
||||
/*!
|
||||
* Construct a StringList with the contents of the braced initializer list.
|
||||
*/
|
||||
StringList(std::initializer_list<String> init);
|
||||
|
||||
StringList &operator=(const StringList &);
|
||||
StringList &operator=(std::initializer_list<String> init);
|
||||
|
||||
/*!
|
||||
* Constructs a StringList with \a s as a member.
|
||||
|
Loading…
Reference in New Issue
Block a user