From: Emmanuel Rodriguez Date: Wed, 6 May 2009 15:08:19 +0000 (+0200) Subject: Implement SvChamplainMapSourceDesc X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a32cab51f09f45c89f6c3c77568a7ef3b7e05a89;p=libchamplain Implement SvChamplainMapSourceDesc --- diff --git a/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs b/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs index 577ba8d..5befcd2 100644 --- a/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs +++ b/bindings/perl/Champlain/xs/ChamplainMapSourceFactory.xs @@ -36,6 +36,87 @@ newSVChamplainMapSourceDesc (ChamplainMapSourceDesc *desc) { } +ChamplainMapSourceDesc* +SvChamplainMapSourceDesc (SV *data) { + HV *hash; + SV **s; + ChamplainMapSourceDesc *desc; + gboolean is_valid = TRUE; + + if ((!data) || (!SvOK(data)) || (!SvRV(data)) || (SvTYPE(SvRV(data)) != SVt_PVHV)) { + croak("SvChamplainMapSourceDesc: value must be an hashref"); + } + + hash = (HV *) SvRV(data); + + /* + * We must set at least one of the following keys: + * - text + * - uris + * - filename + */ + desc = g_new0(ChamplainMapSourceDesc, 1); + + if (! ((s = hv_fetch(hash, "id", 2, 0)) && SvOK(*s))) { + desc->id = SvGChar(*s); + } + else { + g_free(desc); + croak("SvChamplainMapSourceDesc: requires the key: 'id'"); + } + + if (! ((s = hv_fetch(hash, "name", 4, 0)) && SvOK(*s))) { + desc->name = SvGChar(*s); + } + else { + g_free(desc); + croak("SvChamplainMapSourceDesc: requires the key: 'name'"); + } + + if (! ((s = hv_fetch(hash, "license", 7, 0)) && SvOK(*s))) { + desc->license = SvGChar(*s); + } + else { + g_free(desc); + croak("SvChamplainMapSourceDesc: requires the key: 'license'"); + } + + if (! ((s = hv_fetch(hash, "license_uri", 11, 0)) && SvOK(*s))) { + desc->license_uri = SvGChar(*s); + } + else { + g_free(desc); + croak("SvChamplainMapSourceDesc: requires the key: 'license_uri'"); + } + + if (! ((s = hv_fetch(hash, "min_zoom_level", 14, 0)) && SvOK(*s))) { + desc->min_zoom_level = (gint)SvIV(*s); + } + else { + g_free(desc); + croak("SvChamplainMapSourceDesc: requires the key: 'min_zoom_level'"); + } + + if (! ((s = hv_fetch(hash, "max_zoom_level", 14, 0)) && SvOK(*s))) { + desc->max_zoom_level = (gint)SvIV(*s); + } + else { + g_free(desc); + croak("SvChamplainMapSourceDesc: requires the key: 'max_zoom_level'"); + } + + if (! ((s = hv_fetch(hash, "projection", 10, 0)) && SvOK(*s))) { + desc->projection = SvChamplainMapProjection(*s); + } + else { + g_free(desc); + croak("SvChamplainMapSourceDesc: requires the key: 'projection'"); + } + + return desc; +} + + MODULE = Champlain::MapSourceFactory PACKAGE = Champlain::MapSourceFactory PREFIX = champlain_map_source_factory_