Re: [Vala] Personal iterable, collection, list classes



Are there any plans to include libgee within glib, as a separate module like GIO?

On Mon, Aug 18, 2008 at 11:25 AM, Daniel Lucraft <dan fluentradical com> wrote:

Hi Alessandro,

because you are wrapping an already iterable object
(your 'objects' property) you can do this very simply
by returning the iterator for that collection:

public class MyList : Object, Iterable<MyObject> {
 protected ArrayList<MyObject> objects;

 public Type get_element_type () {
   return typeof (MyObject);
 }

 public Gee.Iterator<MyObject> iterator () {
   return objects.iterator();
 }
}

...

foreach(MyObject m in my_list) {
 ...
}

best,
Dan


--- Alessandro Pellizzari <alex amiran it> wrote:

> Hi all,
>
> I would like to create a couple of classes and use
> them as collections.
> For example:
>
> public class MyList()
> {
>  protected List<MyObject> objects = new
> ArrayList<MyObject>;
>  ...
> }
>
> public class MyObject()
> {
>  protected string mydata;
> }
>
>
> And I would like to code like this:
>
> var l = new MyList();
> l.populate(blah blah);
> foreach(MyObject o in l) {
>  printf(o.getData());
> }
>
>
> First of all: is it possible?
> And, if yes, how? :)
> What classes/interfaces should I inherit from?
>
> Thank you very much.
>
> --
> Alessandro Pellizzari
>
>
> _______________________________________________
> Vala-list mailing list
> Vala-list gnome org
> http://mail.gnome.org/mailman/listinfo/vala-list
>



_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list



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