[Vala] error in generics: Foreach: Cannot convert from `G' to `Info.ContactTypeInfo'
- From: Alexey Lubimov <avl l14 ru>
- To: vala-list gnome org
- Subject: [Vala] error in generics: Foreach: Cannot convert from `G' to `Info.ContactTypeInfo'
- Date: Tue, 26 Aug 2008 12:15:17 +0400
base generic class
namespace Info {
public class GenericList <G> : GLib.Object,Gee.Iterable<G> {
//ArrayList
public Gee.ArrayList <G> items;
construct {
this.items = new Gee.ArrayList<G>();
}
public Type get_element_type () {
return typeof (G);
}
public Gee.Iterator<G> iterator () {
return items.iterator();
}
}
}
derrived class
namespace Info{
public class ContactTypeList : GenericList <ContactTypeInfo> {
public void refresh()
{
foreach (ContactTypeInfo item in items)
{}
}
}
}
but vala cannot resolve Gee.ArrayList <G> items to Gee.ArrayList
<ContactTypeInfo> items
Error:
ContactTypeList.vala:49.7-49.45: error: Foreach: Cannot convert from `G'
to `Info.ContactTypeInfo'
namespace Info {
public class ContactTypeInfo: GenericInfo {
}
}
namespace Info{
public static enum CONTACT_TYPE_COLS{
ID = 0,
NAME,
DESCRIPTION,
ICON,
NUM_COLS
}
public class ContactTypeList : GenericList <ContactTypeInfo> {
public Gtk.ListStore list_store_items;
construct {
list_store_items = new Gtk.ListStore (CONTACT_TYPE_COLS.NUM_COLS,
typeof(int64), //0.id
typeof(string), //1.name
typeof(string), //2.Description
typeof(string)); // 3.icon stock-id
}
public Gtk.TreeIter add_to_store (ContactTypeInfo item) {
Gtk.TreeIter retval;
list_store_items.append(out retval);
set(retval,item);
return retval;
}
public void set (Gtk.TreeIter iter,ContactTypeInfo item)
{
list_store_items.set (iter,
CONTACT_TYPE_COLS.NAME,item.name,
CONTACT_TYPE_COLS.DESCRIPTION,item.description,
CONTACT_TYPE_COLS.ICON,item.stock_id,
CONTACT_TYPE_COLS.ID,item.id);
}
public void refresh()
{
Gtk.TreeIter node;
list_store_items.clear();
foreach (ContactTypeInfo item in items)
node = add_to_store(item);
}
}
}
}
namespace Info {
public class GenericInfo:GLib.Object {
public int64 id=ID_NOT_DEFINED;
public string name="";
public string description="";
public string stock_id = "";
private static const string info_str_pattern ="id: %lld, name: %s, description: %s";
construct {
id=ID_NOT_DEFINED;
name="";
description="";
stock_id = "gtk-new";
}
public virtual string to_string ()
{
return info_str_pattern.printf(id,name,description);
}
}
}
namespace Info {
public class GenericList <G> : GLib.Object,Gee.Iterable<G> {
public Gee.ArrayList <G> items;
construct {
this.items = new Gee.ArrayList<G>();
}
public void append(G item) {
items.add(item);
}
public void remove_at (int index){
items.remove_at(index);
}
public void add (G item){
items.add (item);
}
public Type get_element_type () {
return typeof (G);
}
public Gee.Iterator<G> iterator () {
return items.iterator();
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]