[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[www-devel] revisiting librevenge::RVNGString iterator


Hello,

lately I've been thinking about librevenge::RVNGString::Iter (after
fixing a bug in last()). I see several problems with it:

* It exposes it's members, rather than using pimpl like all the other
public classes. This makes it impossible to do changes to it without
breaking ABI.

* There are 2 ways to use it correctly:

librevenge::RVNGString::Iter iter(str);
iter.rewind();
while (iter.next())
handle(iter());

for (librevenge::RVNGString::Iter iter(str); !iter.last(); iter.next())
handle(iter());

* Neither of these 2 is obvious without reading the code.

* It copies the string, incurring a performance cost. (I assume this is
to avoid lifetime management issues. But it penalizes the typical use
case, not the atypical one.)

As minimum, all these problems should be addressed for librevenge 0.1.0.
But I propose to go even further and replace the current iteration
scheme by C++-style iterator. This would immediately fix the usage
problems, as every C++ programmer should be familiar with it. It would
also allow to iterate RVNGStrings with C++ range-based for loop, like

for (const char *utf8char: str)
handle(utf8char);

The old Iter interface should continue to be available for some time
(either till the release of 0.1.0 or even for the whole life time of
0.1), just hidden behind a macro (e.g.,
LIBREVENGE_ENABLE_LEGACY_ITERATORS), so it wouldn't be necessary to
rewrite all code immediately.

Of course, the other 2 iterators (RVNGPropertyList::Iter and
RVNGPropertyListVector::Iter) should be rewritten too. (And
RVNGStringVector should probably get an iterator interface as well.)

Thoughts? Opinions?

D.

--
To unsubscribe e-mail to: devel+unsubscribe@documentliberation.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.documentliberation.org/www/devel/
All messages sent to this list will be publicly archived and cannot be deleted

Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.