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();
}
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

View File

@@ -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
*/