Behaviour of has_next (Fwd: dbus/qt qdbusmarshall.cpp,1.5,1.6)

Thiago Macieira thiago.macieira at trolltech.com
Sun May 7 04:13:17 PDT 2006


Hello,

With the help of one user, I have finally figured out why the maps of maps 
weren't working in the QtDBUS bindings. I couldn't figure out why, but I 
thought libdbus-1 was telling me that the map was empty.

It turns out that it wasn't the case. It's the behaviour of 
dbus_message_iter_has_next that differs from the behaviour I expected. So 
I wonder if this isn't a change that should be implemented in the 
library.

Java iterators (and the Qt iterators inspired by Java) have a method 
called hasNext that returns true if there are more elements in this list. 
However, the difference is that hasNext also returns true for a 
one-element list, because there *is* a next element (the first one).

Iterators don't point to elements, but to between them. When an iterator 
is initialised to the beginning of a list, it points to just before the 
first element, so hasNext = true.

This is illustrated by:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/ListIterator.html
http://doc.trolltech.com/4.1/qlistiterator.html#details

And the example code in FlashMX seems to indicate their iterators behave 
the same way too:
http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00002472.html

However, libdbus-1's dbus_message_iter_has_next returns false for a 
one-element list, as illustrated by the following code I had to change:
----------    ----------
@@ -78,8 +77,7 @@

     DBusMessageIter it;
     dbus_message_iter_recurse(arrayIt, &it);
-
-    if (!dbus_message_iter_has_next(&it))
+    if (dbus_message_iter_get_array_len(&it) == 0)
         return list;

     do {
@@ -157,7 +155,7 @@
             DBusMessageIter sub;

             dbus_message_iter_recurse(it, &sub);
-            if (!dbus_message_iter_has_next(&sub))
+            if (dbus_message_iter_get_array_len(&sub) == 0)
                 // empty map
                 return map;
-------------------------------------------------------

Should we change the behaviour in libdbus-1?
-- 
Thiago José Macieira - thiago.macieira AT trolltech.com
Trolltech AS - Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20060507/ea3558a7/attachment.pgp


More information about the dbus mailing list