diff --git a/src/Add-ons/Addon.cxx b/src/Add-ons/Addon.cxx index ab8915919..7aef87e91 100644 --- a/src/Add-ons/Addon.cxx +++ b/src/Add-ons/Addon.cxx @@ -25,12 +25,15 @@ #include #include +#include + #include #include #include #include #include #include +#include #include
#include @@ -51,6 +54,31 @@ namespace flightgear namespace addons { +// *************************************************************************** +// * QualifiedUrl * +// *************************************************************************** + +QualifiedUrl::QualifiedUrl(UrlType type, std::string url) + : _type(type), + _url(std::move(url)) +{ } + +UrlType QualifiedUrl::getType() const +{ return _type; } + +void QualifiedUrl::setType(UrlType type) +{ _type = type; } + +std::string QualifiedUrl::getUrl() const +{ return _url; } + +void QualifiedUrl::setUrl(const std::string& url) +{ _url = url; } + +// *************************************************************************** +// * Addon * +// *************************************************************************** + Addon::Addon(std::string id, AddonVersion version, SGPath basePath, std::string minFGVersionRequired, std::string maxFGVersionRequired, SGPropertyNode* addonNode) @@ -506,6 +534,29 @@ Addon::parseLicenseNode(const SGPath& addonPath, SGPropertyNode* addonNode) return std::make_tuple(licenseDesignation, licenseFile, licenseUrl); } +std::map Addon::getUrls() const +{ + std::map res; + + auto appendIfNonEmpty = [&res](UrlType type, const string& url) { + if (!url.empty()) { + auto emplaceRetval = res.emplace(type, QualifiedUrl(type, url)); + // We start with an empty std::map<> and don't call this lambda more + // than once for the same type, therefore the same key can't be seen + // twice. + assert(emplaceRetval.second); + SG_UNUSED(emplaceRetval); // 'cause asserts are removed in Release builds + } + }; + + appendIfNonEmpty(UrlType::homePage, getHomePage()); + appendIfNonEmpty(UrlType::download, getDownloadUrl()); + appendIfNonEmpty(UrlType::support, getSupportUrl()); + appendIfNonEmpty(UrlType::codeRepository, getCodeRepositoryUrl()); + appendIfNonEmpty(UrlType::license, getLicenseUrl()); + + return res; +} // Static method void Addon::setupGhost(nasal::Hash& addonsModule) diff --git a/src/Add-ons/Addon.hxx b/src/Add-ons/Addon.hxx index 599253c82..82ff428d1 100644 --- a/src/Add-ons/Addon.hxx +++ b/src/Add-ons/Addon.hxx @@ -20,6 +20,7 @@ #ifndef FG_ADDON_HXX #define FG_ADDON_HXX +#include #include #include #include @@ -40,6 +41,29 @@ namespace flightgear namespace addons { +enum class UrlType { + homePage, + download, + support, + codeRepository, + license +}; + +class QualifiedUrl { +public: + QualifiedUrl(UrlType type, std::string url); + + UrlType getType() const; + void setType(UrlType type); + + std::string getUrl() const; + void setUrl(const std::string& url); + +private: + UrlType _type; + std::string _url; +}; + class Addon : public SGReferenced { public: // Default constructor. 'minFGVersionRequired' is initialized to "2017.4.0" @@ -131,6 +155,9 @@ public: int getLoadSequenceNumber() const; void setLoadSequenceNumber(int num); + // Get all non-empty URLs pertaining to this add-on + std::map getUrls() const; + // Simple string representation std::string str() const; diff --git a/src/Add-ons/addon_fwd.hxx b/src/Add-ons/addon_fwd.hxx index e16bae0a9..fbfdb55f8 100644 --- a/src/Add-ons/addon_fwd.hxx +++ b/src/Add-ons/addon_fwd.hxx @@ -34,6 +34,9 @@ class AddonManager; class AddonVersion; class AddonVersionSuffix; +enum class UrlType; +class QualifiedUrl; + using AddonRef = SGSharedPtr; using AddonVersionRef = SGSharedPtr;