[Vala] Inheriting from a GLib.HashTable



Hello
I've got a little problem inheriting from GLib.HashTable:
If I try to compile the following code example:

----
public class HTable<K,V> : GLib.HashTable<K,V> {
  public HTable(HashFunc hash_func, EqualFunc key_equal_func) {
    base(hash_func, key_equal_func);
  }

  public int item_count {
    get {
      return (int)this.size();
    }
  }
}

public static int main() {
  HTable<string,string> ht = new HTable<string,string>(str_hash,
str_equal);
  return 0;
}
----

I get the following CCode:

----
 ...
typedef GHashTable HTable;
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var =
(g_hash_table_unref (var), NULL)))

HTable* htable_new (GHashFunc hash_func, GEqualFunc key_equal_func);
HTable* htable_new (GHashFunc hash_func, GEqualFunc key_equal_func);
gint htable_get_item_count (HTable* self);
gint _vala_main (void);

HTable* htable_new (GHashFunc hash_func, GEqualFunc key_equal_func) {
  HTable* self;
  self = (HTable*) g_hash_table_new_full (hash_func, key_equal_func);
  return self;
}

gint htable_get_item_count (HTable* self) {
  gint result;
  g_return_val_if_fail (self != NULL, 0);
  result = (gint) g_hash_table_size ((GHashTable*) self);
  return result;
}

gint _vala_main (void) {
  gint result = 0;
  HTable* ht;
  ht = htable_new (g_str_hash, g_str_equal);
  result = 0;
  _g_hash_table_unref0 (ht);
  return result;
}

int main (int argc, char ** argv) {
  g_type_init ();
  return _vala_main ();
}

----

The c-compiler complains that g_hash_table_new_full has too few
arguments. 
When directly creating a GLib.HashTable, g_hash_table_new_full function
is used correctly but when inheriting from GLib.HashTable it is not(the
DestroyNotify functions are missing). 

Unfortunately I have to chain up to the base class to hand over the
hash/equal functions.
I used vala-0.9.7 release.
How can all this be done correctly?

Regards
Jörn

PS: I also don't understand why the generated Ccode contains the
declaration for htable_new twice.





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