Re: GObject Introspection Enum details



You can try g_registered_type_info_get_type_name(), but mind asking why you want to know?


On Sun, Nov 17, 2013 at 11:33 AM, Aleksey <prolog hermit gmail com> wrote:

Hi guys

 

I am trying to use GIRepository (version 1.38) to retrieve Enumeration details and I'm wondering how to retrieve C-name of Enum. For example, I have GIEnumInfo instance for GBookmarkFileError (https://developer.gnome.org/glib/2.38/glib-Bookmark-file-parser.html#GBookmarkFileError).

Calling g_base_info_get_name gives me BookmarkFileError, not GBookmarkFileError.

After looking at *.gir file contents for GLib, I've found that required value is stored in c:type attribute:

 

<enumeration name="BookmarkFileError"

c:type="GBookmarkFileError"

glib:error-quark="g_bookmark_file_error_quark">

...

</enumeration>

 

so I expected to be able to get the name using g_base_info_get_attribute, however, checking available attributes with g_base_info_iterate_attributes produced no results. Code used to check attributes (no attribute names/values are printed):

 

// print available attributes, taken from GIRepository manual page

void print_attributes(GIBaseInfo *info)

{

GIAttributeIter iter = { 0, };

char * name;

char * value;

while (g_base_info_iterate_attributes (info, &iter, &name, &value)) {

g_print ("attribute name: %s value: %s", name, value);

}

}

 

int main(int argc, char ** argv)

{

GIRepository *repo = g_irepository_get_default();

g_irepository_require(repo, "GLib", NULL, 0, NULL);

gint count = g_irepository_get_n_infos(repo, "GLib");

// find first enum

int i;

GIBaseInfo * info = NULL;

for (i = 0; i < count; i++) {

info = g_irepository_get_info(repo, "GLib", i);

GIInfoType type = g_base_info_get_type(info);

if (type == GI_INFO_TYPE_ENUM) break;

}

 

const gchar * name = g_base_info_get_name(info);

printf("Enum: %s\n", name);

print_attributes(info);

 

return 0;

}

Could you please advise on how is it possible to get C-type name for enum (e.g. GBookmarkFileError).


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




--
  Jasper


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