mirror of
https://github.com/taglib/taglib.git
synced 2025-06-03 09:08:09 -04:00
A couple of things pointed out by a colleage -- fix ByteVector::size()
and make the return type semantics consistant for methods that modify the object (specifically, return a reference instead of void). git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@460002 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
parent
5d64692084
commit
603068695c
@ -198,6 +198,11 @@ void testByteVector()
|
||||
|
||||
ByteVector s2("f");
|
||||
printResult(ByteVectorList::split(s2, " ").size() == 1);
|
||||
|
||||
|
||||
printResult(ByteVector().size() == 0);
|
||||
printResult(ByteVector("asdf").clear().size() == 0);
|
||||
printResult(ByteVector("asdf").clear() == ByteVector());
|
||||
}
|
||||
|
||||
void testSynchData()
|
||||
|
@ -316,17 +316,19 @@ ByteVector::~ByteVector()
|
||||
delete d;
|
||||
}
|
||||
|
||||
void ByteVector::setData(const char *data, uint length)
|
||||
ByteVector &ByteVector::setData(const char *data, uint length)
|
||||
{
|
||||
detach();
|
||||
|
||||
resize(length);
|
||||
::memcpy(DATA(d), data, length);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ByteVector::setData(const char *data)
|
||||
ByteVector &ByteVector::setData(const char *data)
|
||||
{
|
||||
setData(data, ::strlen(data));
|
||||
return setData(data, ::strlen(data));
|
||||
}
|
||||
|
||||
char *ByteVector::data()
|
||||
@ -430,19 +432,24 @@ int ByteVector::endsWithPartialMatch(const ByteVector &pattern) const
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ByteVector::append(const ByteVector &v)
|
||||
ByteVector &ByteVector::append(const ByteVector &v)
|
||||
{
|
||||
detach();
|
||||
|
||||
uint originalSize = d->size;
|
||||
resize(d->size + v.d->size);
|
||||
::memcpy(DATA(d) + originalSize, DATA(v.d), v.size());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ByteVector::clear()
|
||||
ByteVector &ByteVector::clear()
|
||||
{
|
||||
detach();
|
||||
d->data.clear();
|
||||
d->size = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
TagLib::uint ByteVector::size() const
|
||||
|
@ -86,13 +86,13 @@ namespace TagLib {
|
||||
/*!
|
||||
* Sets the data for the byte array using the first \a length bytes of \a data
|
||||
*/
|
||||
void setData(const char *data, uint length);
|
||||
ByteVector &setData(const char *data, uint length);
|
||||
|
||||
/*!
|
||||
* Sets the data for the byte array copies \a data up to the first null
|
||||
* byte. The behavior is undefined if \a data is not null terminated.
|
||||
*/
|
||||
void setData(const char *data);
|
||||
ByteVector &setData(const char *data);
|
||||
|
||||
/*!
|
||||
* Returns a pointer to the internal data structure.
|
||||
@ -171,12 +171,12 @@ namespace TagLib {
|
||||
/*!
|
||||
* Appends \a v to the end of the ByteVector.
|
||||
*/
|
||||
void append(const ByteVector &v);
|
||||
ByteVector &append(const ByteVector &v);
|
||||
|
||||
/*!
|
||||
* Clears the data.
|
||||
*/
|
||||
void clear();
|
||||
ByteVector &clear();
|
||||
|
||||
/*!
|
||||
* Returns the size of the array.
|
||||
|
@ -99,14 +99,14 @@ namespace TagLib {
|
||||
/*!
|
||||
* Inserts a copy of \a value before \a it.
|
||||
*/
|
||||
void insert(Iterator it, const T &value);
|
||||
List<T> &insert(Iterator it, const T &value);
|
||||
|
||||
/*!
|
||||
* Inserts the \a value into the list. This assumes that the list is
|
||||
* currently sorted. If \a unique is true then the value will not
|
||||
* be inserted if it is already in the list.
|
||||
*/
|
||||
void sortedInsert(const T &value, bool unique = false);
|
||||
List<T> &sortedInsert(const T &value, bool unique = false);
|
||||
|
||||
/*!
|
||||
* Appends \a item to the end of the list and returns a reference to the
|
||||
@ -138,7 +138,7 @@ namespace TagLib {
|
||||
*
|
||||
* \see setAutoDelete()
|
||||
*/
|
||||
void clear();
|
||||
List<T> &clear();
|
||||
|
||||
/*!
|
||||
* Returns the number of elements in the list.
|
||||
@ -164,7 +164,7 @@ namespace TagLib {
|
||||
/*!
|
||||
* Erase the item at \a it from the list.
|
||||
*/
|
||||
void erase(Iterator it);
|
||||
List<T> &erase(Iterator it);
|
||||
|
||||
/*!
|
||||
* Returns a reference to the first item in the list.
|
||||
|
@ -128,22 +128,24 @@ typename List<T>::ConstIterator List<T>::end() const
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void List<T>::insert(Iterator it, const T &item)
|
||||
List<T> &List<T>::insert(Iterator it, const T &item)
|
||||
{
|
||||
detach();
|
||||
d->list.insert(it, item);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void List<T>::sortedInsert(const T &value, bool unique)
|
||||
List<T> &List<T>::sortedInsert(const T &value, bool unique)
|
||||
{
|
||||
detach();
|
||||
Iterator it = begin();
|
||||
while(it != end() && *it < value)
|
||||
++it;
|
||||
if(unique && it != end() && *it == value)
|
||||
return;
|
||||
return *this;
|
||||
insert(it, value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@ -179,10 +181,11 @@ List<T> &List<T>::prepend(const List<T> &l)
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void List<T>::clear()
|
||||
List<T> &List<T>::clear()
|
||||
{
|
||||
detach();
|
||||
d->clear();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@ -216,9 +219,10 @@ bool List<T>::contains(const T &value) const
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void List<T>::erase(Iterator it)
|
||||
List<T> &List<T>::erase(Iterator it)
|
||||
{
|
||||
d->list.erase(it);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
|
@ -89,13 +89,13 @@ namespace TagLib {
|
||||
* Inserts \a value under \a key in the map. If a value for \a key already
|
||||
* exists it will be overwritten.
|
||||
*/
|
||||
void insert(const Key &key, const T &value);
|
||||
Map<Key, T> &insert(const Key &key, const T &value);
|
||||
|
||||
/*!
|
||||
* Removes all of the elements from elements from the map. This however
|
||||
* will not delete pointers if the mapped type is a pointer type.
|
||||
*/
|
||||
void clear();
|
||||
Map<Key, T> &clear();
|
||||
|
||||
/*!
|
||||
* The number of elements in the map.
|
||||
@ -129,7 +129,7 @@ namespace TagLib {
|
||||
/*!
|
||||
* Erase the item at \a it from the list.
|
||||
*/
|
||||
void erase(Iterator it);
|
||||
Map<Key, T> &erase(Iterator it);
|
||||
|
||||
/*!
|
||||
* Returns a reference to the value associated with \a key.
|
||||
|
@ -81,18 +81,20 @@ typename Map<Key, T>::ConstIterator Map<Key, T>::end() const
|
||||
}
|
||||
|
||||
template <class Key, class T>
|
||||
void Map<Key, T>::insert(const Key &key, const T &value)
|
||||
Map<Key, T> &Map<Key, T>::insert(const Key &key, const T &value)
|
||||
{
|
||||
detach();
|
||||
std::pair<Key, T> item(key, value);
|
||||
d->map.insert(item);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Key, class T>
|
||||
void Map<Key, T>::clear()
|
||||
Map<Key, T> &Map<Key, T>::clear()
|
||||
{
|
||||
detach();
|
||||
d->map.clear();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Key, class T>
|
||||
@ -120,9 +122,10 @@ bool Map<Key, T>::contains(const Key &key) const
|
||||
}
|
||||
|
||||
template <class Key, class T>
|
||||
void Map<Key,T>::erase(Iterator it)
|
||||
Map<Key, T> &Map<Key,T>::erase(Iterator it)
|
||||
{
|
||||
d->map.erase(it);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Key, class T>
|
||||
|
Loading…
x
Reference in New Issue
Block a user