Re: compare function for GValues



Hi Stefan,
I think this might be what you're looking for. It might need to be modified to handle more types, but
for the simple types it should do the job.

-todd

Stefan Kost wrote:

hi hi,

we have lots of methods in our project the looksup list-entries by a gobject
property (the lists node->data entries are gobject instances).
We would like to generalize the code - something like below:

-- pseudo code --

find_by_property(gpointer item,gpointer data) {
GValue value;
g_object_get_property(item,data.key,&value);
//a) compare via
     strcmp(find_by_property(value),find_by_property(data.compare_value));
//b) switch(g_value_get_type(value)) {
//     G_TYPE_STRING: strcmp(value,data.compare_value);
//     default: value==data.compare_value;
//   }
}       
        
struct {
 gchar *key;
 GValue compare_value;
} data;
g_value_init(data.compare_value, G_TYPE_STRING);
g_value_set_string(data.compare_value,id);
data.key="id";
        
node = g_list_find_custom(self->priv->machines, data, find_by_property);
if(node) return(BT_MACHINE(node->data);

-- pseudo code --

Any ideas how to best handle the missing copare function in the GValue system?

Stefan
------------------------------------------------------------------------

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



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