From: Emmanuel Rodriguez Date: Wed, 6 May 2009 14:05:51 +0000 (+0200) Subject: Add newSVChamplainMapSourceDesc() and implement get_list() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=81f2cfe9b82fab85b316efe6348f95e20f9f1a81;p=libchamplain Add newSVChamplainMapSourceDesc() and implement get_list() --- diff --git a/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs b/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs index 1346b5a..577ba8d 100644 --- a/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs +++ b/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs @@ -1,6 +1,41 @@ #include "champlain-perl.h" +SV* +newSVChamplainMapSourceDesc (ChamplainMapSourceDesc *desc) { + HV *hash = NULL; + SV *sv = NULL; + HV *stash = NULL; + + if (desc == NULL) { + return &PL_sv_undef; + } + + hash = newHV(); + sv = newRV_noinc((SV *) hash); + + /* Copy the data members of the struct into the hash */ + hv_store(hash, "id", 2, newSVGChar(desc->id), 0); + hv_store(hash, "name", 4, newSVGChar(desc->name), 0); + hv_store(hash, "license", 7, newSVGChar(desc->license), 0); + hv_store(hash, "license_uri", 11, newSVGChar(desc->license_uri), 0); + hv_store(hash, "min_zoom_level", 14, newSViv(desc->min_zoom_level), 0); + hv_store(hash, "max_zoom_level", 14, newSViv(desc->max_zoom_level), 0); + hv_store(hash, "projection", 10, newSVChamplainMapProjection(desc->projection), 0); + + /* + This is tricky as we have to wrap the C callback into a Perl sub. + hv_store(hash, "constructor", 11, newSVChamplainMapProjection(desc->projection), 0); + */ + + /* Bless this stuff */ + stash = gv_stashpv("Champlain::MapSourceDesc", TRUE); + sv_bless(sv, stash); + + return sv; +} + + MODULE = Champlain::MapSourceFactory PACKAGE = Champlain::MapSourceFactory PREFIX = champlain_map_source_factory_ @@ -19,8 +54,8 @@ champlain_map_source_factory_get_list (ChamplainMapSourceFactory *factory) list = champlain_map_source_factory_get_list(factory); for (item = list; item != NULL; item = item->next) { -// ChamplainMapSourceDesc *desc = CHAMAPLAIN_MAP_SOURCE_DESC(item->data); -// XPUSHs(sv_2mortal(newSVChamplainMapSourceDesc(desc))); + ChamplainMapSourceDesc *desc = CHAMPLAIN_MAP_SOURCE_DESC(item->data); + XPUSHs(sv_2mortal(newSVChamplainMapSourceDesc(desc))); } g_slist_free(list);