New accessors for variant support.

This commit is contained in:
James Turner
2016-01-03 20:57:19 -06:00
parent be0447d4c0
commit 2bb24f43fb
2 changed files with 26 additions and 0 deletions

View File

@@ -167,6 +167,11 @@ std::string Package::qualifiedId() const
return m_catalog->id() + "." + id(); 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 std::string Package::md5() const
{ {
return m_props->getStringValue("md5"); 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()); 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 pkg
} // of namespace simgear } // of namespace simgear

View File

@@ -76,6 +76,11 @@ public:
*/ */
std::string qualifiedId() const; 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, * human-readable name - note this is probably not localised,
* although this is not ruled out for the future. * although this is not ruled out for the future.
@@ -87,6 +92,8 @@ public:
*/ */
std::string nameForVariant(const std::string& vid) const; std::string nameForVariant(const std::string& vid) const;
std::string nameForVariant(const unsigned int vIndex) const;
/** /**
* syntactic sugar to get the localised description * syntactic sugar to get the localised description
*/ */