Re: libthreepointzero



On Fri, 2006-10-13 at 13:16 +0200, Johannes Schmid wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi @all!
> (We really need a ML soon!)
> 
> I have had a look at the tinymail code and IMHO some things should be
> changed with the interators:
> 
> There should be more than one iterator:
> 
> Iterator: next(), equal(), is_valid()
> IteratorBi: Iterator + previous()
> IteratorRandom: IteratorBi + nth()

Agree. I don't like your names but you are right that it's better not to
create one iterator interface with all that functionality.

> Of course the latter will be derived from Iterator, at least if this is
> possible somehow using GInterface.

It is. It's called prerequisites in GTypeInterface. It means that the
implementer of the interface should also implement the prerequisites.
Which basically means inheriting interface B from A or in C++, fully
abstract class B inherits from fully abstract class A.

In GTypeInterface you say that implementation C must implement fully
abstract class A (interface A), and fully abstract class A requires that
implementation C also implements fully abstract class B.

in .NET:

interface A {}
interface B : A {}
class C : A {}

in C++

abstract class A {}
abstract class B : A {}
class C : B {}

In GTypeInterface:

interface A {}
interface B prerequisites=A {}
class C : B, A {}



> Usually iterators don't provide a function to get the list back. I think
> we should skip this, it also makes including a real mess. Also, an
> iterator could as well work on a tree or hash table so get_list() is not
> really good.

A forward declaration cleans up that mess, but I agree that you never
really need it. That's mostly because iterators are typically used
locally and not stored for later use. Nor is having the list itself
really useful. While the iterator is alive, you shouldn't prepend nor
append items anyway (else would the iterator become invalid).

Therefore having access to the list is unimportant. I did add the API to
the tinymail interface, but indeed never needed it.

> Last but not least, any list should provide non-const and const iterators

Can you clarify this?

A list can create an instance of an iterator. The const iterator would
be a one-per-list iterator that is always available? I don't really see
a need for that. But feel free to clarify.

Anyway, the reason why it's a new instance each time, is to support
multithreaded looping one list multiple times simultaneously in a
thread-safe way. Per such simultaneous loop, there's one iterator.
Nested loops also create a new iterator.

For example:

Iterator iter = list.CreateIterator();

while (iter.Next ())
{
	Item p = iter.Current ();
	Iterator niter = list.CreateIterator ();
	while (niter.Next ())
	{
		Item i = niter.Current ();
		print p.Name + " and " + i.Name + " are now friends";
		Dispose i;
	}
	Dispose niter;
	Dispose p;
}
Dispose iter;
Dispose list;



-- 
Philip Van Hoof, software developer
home: me at pvanhoof dot be
gnome: pvanhoof at gnome dot org
work: vanhoof at x-tend dot be
blog: http://pvanhoof.be/blog




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