Re: libthreepointzero



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi!

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

In C++ that would look like that (imagine the template code...):

class Iterator
{
	public:
	T* get_object();
	const T* get_object() const;
}

class List
{
	public:
	Iterator* create_iterator();
	const Iterator* create_iterator() const;
}

That's what I meant. While coding TpzIteratorBi and TpzIteratorRandom it
came into my mind that we should of course also provide a single-linked
list and a vector to be used with those iterators.

Regards,
Johannes

Philip Van Hoof wrote:
> 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;
> 
> 
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFL6i07Dsf+G5b/WsRAg65AKCmpWH9gQ6M6kEWpv/Iem9Rv+hYlwCcDE8Y
uesqzsaOjrn9jprHPFmdtOo=
=5poB
-----END PGP SIGNATURE-----



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