From: James Turner Date: Mon, 4 Jan 2016 02:57:19 +0000 (-0600) Subject: New accessors for variant support. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2bb24f43fbacaa198a2dafbe2ed5acb298231b4e;p=simgear.git New accessors for variant support. --- diff --git a/simgear/package/Package.cxx b/simgear/package/Package.cxx index bd25fb3c..b32e2fc3 100644 --- a/simgear/package/Package.cxx +++ b/simgear/package/Package.cxx @@ -167,6 +167,11 @@ std::string Package::qualifiedId() const return m_catalog->id() + "." + id(); } +std::string Package::qualifiedVariantId(const unsigned int variantIndex) const +{ + return m_catalog->id() + "." + variants()[variantIndex]; +} + std::string Package::md5() const { return m_props->getStringValue("md5"); @@ -333,6 +338,20 @@ std::string Package::nameForVariant(const std::string& vid) const throw sg_exception("Unknow variant +" + vid + " in package " + id()); } +std::string Package::nameForVariant(const unsigned int vIndex) const +{ + if (vIndex == 0) + return name(); + + // offset by minus one to allow for index 0 being the primary + SGPropertyNode_ptr var = m_props->getChild("variant", vIndex - 1); + if (var) + return var->getStringValue("name"); + + throw sg_exception("Unknow variant in package " + id()); +} + + } // of namespace pkg } // of namespace simgear diff --git a/simgear/package/Package.hxx b/simgear/package/Package.hxx index 606185fd..840a22cd 100644 --- a/simgear/package/Package.hxx +++ b/simgear/package/Package.hxx @@ -75,6 +75,11 @@ public: * Fully-qualified ID, including our catalog'd ID */ std::string qualifiedId() const; + + /** + * Fully-qualified ID, including our catalog'd ID + */ + std::string qualifiedVariantId(const unsigned int variantIndex) const; /** * human-readable name - note this is probably not localised, @@ -87,6 +92,8 @@ public: */ std::string nameForVariant(const std::string& vid) const; + std::string nameForVariant(const unsigned int vIndex) const; + /** * syntactic sugar to get the localised description */