diff --git a/tests/toolkit-test.cpp b/tests/toolkit-test.cpp index e5b8ae3f..85503c1b 100644 --- a/tests/toolkit-test.cpp +++ b/tests/toolkit-test.cpp @@ -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() diff --git a/toolkit/tbytevector.cpp b/toolkit/tbytevector.cpp index 7dff7462..3deb8958 100644 --- a/toolkit/tbytevector.cpp +++ b/toolkit/tbytevector.cpp @@ -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 diff --git a/toolkit/tbytevector.h b/toolkit/tbytevector.h index b7d88f41..5dbab36b 100644 --- a/toolkit/tbytevector.h +++ b/toolkit/tbytevector.h @@ -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. diff --git a/toolkit/tlist.h b/toolkit/tlist.h index 1aed47a6..1c29533a 100644 --- a/toolkit/tlist.h +++ b/toolkit/tlist.h @@ -99,14 +99,14 @@ namespace TagLib { /*! * Inserts a copy of \a value before \a it. */ - void insert(Iterator it, const T &value); + List &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 &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 &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 &erase(Iterator it); /*! * Returns a reference to the first item in the list. diff --git a/toolkit/tlist.tcc b/toolkit/tlist.tcc index ca410c42..d17faca1 100644 --- a/toolkit/tlist.tcc +++ b/toolkit/tlist.tcc @@ -128,22 +128,24 @@ typename List::ConstIterator List::end() const } template -void List::insert(Iterator it, const T &item) +List &List::insert(Iterator it, const T &item) { detach(); d->list.insert(it, item); + return *this; } template -void List::sortedInsert(const T &value, bool unique) +List &List::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 @@ -179,10 +181,11 @@ List &List::prepend(const List &l) } template -void List::clear() +List &List::clear() { detach(); d->clear(); + return *this; } template @@ -216,9 +219,10 @@ bool List::contains(const T &value) const } template -void List::erase(Iterator it) +List &List::erase(Iterator it) { d->list.erase(it); + return *this; } template diff --git a/toolkit/tmap.h b/toolkit/tmap.h index f67bcbaa..55731ee4 100644 --- a/toolkit/tmap.h +++ b/toolkit/tmap.h @@ -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 &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 &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 &erase(Iterator it); /*! * Returns a reference to the value associated with \a key. diff --git a/toolkit/tmap.tcc b/toolkit/tmap.tcc index fff5f664..b9787a0f 100644 --- a/toolkit/tmap.tcc +++ b/toolkit/tmap.tcc @@ -81,18 +81,20 @@ typename Map::ConstIterator Map::end() const } template -void Map::insert(const Key &key, const T &value) +Map &Map::insert(const Key &key, const T &value) { detach(); std::pair item(key, value); d->map.insert(item); + return *this; } template -void Map::clear() +Map &Map::clear() { detach(); d->map.clear(); + return *this; } template @@ -120,9 +122,10 @@ bool Map::contains(const Key &key) const } template -void Map::erase(Iterator it) +Map &Map::erase(Iterator it) { d->map.erase(it); + return *this; } template