After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 663337 - Allow to get Type of generic parameters in Collections, Maps and MultiMaps
Allow to get Type of generic parameters in Collections, Maps and MultiMaps
Status: RESOLVED FIXED
Product: libgee
Classification: Platform
Component: general
git master
Other Linux
: Normal trivial
: 0.7
Assigned To: libgee-maint
libgee-maint
: 663339 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2011-11-03 17:38 UTC by Travis Reitter
Modified: 2011-12-19 17:07 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Travis Reitter 2011-11-03 17:38:24 UTC
AbstractCollection<T> has a useful public data member:
Type element_type = T.get_type ();

(get_type() above only works for objects, but you get the idea)

This makes it possible to handle AbstractCollections in an extra-generic way like:

/* note that we don't specify the generic type for ac */
void some_func (AbstractCollection ac)
{
  if (ac.element_type == typeof (string))
    handle_string ();
  else if (ac.is_a (typeof (SomeInterface))
    handle_some_interface ();
  else if (ac.element_type == typeof (Object))
    handle_plain_objects ();
  else
    ...
}

However, MultiMap doesn't derive from AbstractCollection, so it doesn't have element_type. So to do the equivalent of above, it's necessary to first do:

var multi_map_keys = prop_value_multi_map.get_keys ();
var key_type = multi_map_keys.element_type;
var multi_map_values = prop_value_multi_map.get_values ();
var value_type = multi_map_values.element_type;

At least in the values case, this allocates a new ArrayList, iterates all the values, and various other things that add unnecessary computation.

So, please add the following members to MultiMap/AbstractMultiMap/HashMultiMap:

Type key_type = K.get_type ();
Type value_type = V.get_type ();
Comment 1 Maciej (Matthew) Piechotka 2011-11-03 18:07:00 UTC
*** Bug 663339 has been marked as a duplicate of this bug. ***
Comment 2 Maciej (Matthew) Piechotka 2011-11-05 21:20:30 UTC
Sorry for delay. It sounds like a good idea to use it in interface. It looks like it have been done before in Collection but I prefer to check why it was removed (and left only in AbstractCollection).
Comment 3 Travis Reitter 2011-12-01 18:17:59 UTC
Also add Iterator to the list. I'm using an Iterator from some Javascript/gjs code now, and it'd be much nicer if I didn't have to explicitly state the element type in my binding.
Comment 4 Maciej (Matthew) Piechotka 2011-12-19 17:07:46 UTC
commit b62ed44ad3be999ef1d663845589bbf9f31072b6
Author: Maciej Piechotka <uzytkownik2@gmail.com>
Date:   Mon Dec 19 17:58:29 2011 +0100

    Add *_type property for all collections, fixes bug #663337