]> granicus.if.org Git - taglib/commitdiff
A couple of things pointed out by a colleage -- fix ByteVector::size()
authorScott Wheeler <wheeler@kde.org>
Mon, 12 Sep 2005 16:52:07 +0000 (16:52 +0000)
committerScott Wheeler <wheeler@kde.org>
Mon, 12 Sep 2005 16:52:07 +0000 (16:52 +0000)
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

tests/toolkit-test.cpp
toolkit/tbytevector.cpp
toolkit/tbytevector.h
toolkit/tlist.h
toolkit/tlist.tcc
toolkit/tmap.h
toolkit/tmap.tcc

index e5b8ae3f0562b6d096be4b41e4515352dcb718e1..85503c1b3f1e71653d9118f9a44e540ecab9afc5 100644 (file)
@@ -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()
index 7dff7462a760b5e3b98db2de6358499e81eba89e..3deb8958881027b58cbece3cf3d8eb4a5cdb25cb 100644 (file)
@@ -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
index b7d88f41ecd896e49d74cb32e7db44fa9dd4bf91..5dbab36b5895190fd0bec653175dfbcf9251209a 100644 (file)
@@ -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.
index 1aed47a63de2bda82c22375d67da14a2478cd7d7..1c29533ac340d5e7811e8f848c1c247e31543393 100644 (file)
@@ -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.
index ca410c4299253b88a7e845352e0b759b740fd713..d17faca18b0c621109452418c043ccac5fbb6dcb 100644 (file)
@@ -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>
index f67bcbaad43b00a3220723430f707de611dfa48a..55731ee4a82e715d5af203914de22e71971a3400 100644 (file)
@@ -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.
index fff5f66495543d1b7b739b70d77887c72cc187b1..b9787a0f4dc66d5dddf2f3b84a4944b0e0d319f7 100644 (file)
@@ -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>