1
0
Fork 0

Add-ons: const id; adjust the Addon constructors, remove Addon::setId()

Since the new _storagePath data member internally contains the add-on
id, changing _id after _storagePath has been initialized would make both
data members inconsistent. As changing the add-on id is probably not a
very useful operation, the simplest way to prevent such an inconsistency
from happening is to make Addon's _id data member const (as is already
the case for _storagePath), and thus remove Addon::setId().
Consequently, remove the Addon default constructor too, since add-ons
with an empty id would be ill-formed and couldn't be changed (_id being
const now). This leaves us with one Addon constructor:

Addon(std::string id, AddonVersion version = AddonVersion(),
      SGPath basePath = SGPath(), std::string minFGVersionRequired = "",
      std::string maxFGVersionRequired = "",
      SGPropertyNode* addonNode = nullptr);
This commit is contained in:
Florent Rougon 2018-03-11 23:02:51 +01:00
parent fa72d8dd06
commit 109a59b393
3 changed files with 4 additions and 17 deletions

View file

@ -110,17 +110,9 @@ Addon::Addon(std::string id, AddonVersion version, SGPath basePath,
}
}
Addon::Addon()
: Addon(std::string(), AddonVersion(), SGPath(), std::string(),
std::string(), nullptr)
{ }
std::string Addon::getId() const
{ return _id; }
void Addon::setId(const std::string& addonId)
{ _id = addonId; }
std::string Addon::getName() const
{ return _name; }

View file

@ -77,13 +77,10 @@ private:
class Addon : public SGReferenced
{
public:
// Default constructor. 'minFGVersionRequired' is initialized to "2017.4.0"
// and 'maxFGVersionRequired' to "none".
Addon();
// An empty value for 'minFGVersionRequired' is translated into "2017.4.0".
// An empty value for 'maxFGVersionRequired' is translated into "none".
Addon(std::string id, AddonVersion version, SGPath basePath,
std::string minFGVersionRequired = "",
Addon(std::string id, AddonVersion version = AddonVersion(),
SGPath basePath = SGPath(), std::string minFGVersionRequired = "",
std::string maxFGVersionRequired = "",
SGPropertyNode* addonNode = nullptr);
@ -92,7 +89,6 @@ public:
static Addon fromAddonDir(const SGPath& addonPath);
std::string getId() const;
void setId(const std::string& addonId);
std::string getName() const;
void setName(const std::string& addonName);
@ -205,7 +201,7 @@ private:
// The add-on identifier, in reverse DNS style. The AddonManager refuses to
// register two add-ons with the same id in a given FlightGear session.
std::string _id;
const std::string _id;
// Pretty name for the add-on (not constrained to reverse DNS style)
std::string _name;
// Use a smart pointer to expose the AddonVersion instance to Nasal without

View file

@ -209,9 +209,8 @@ void testAddon()
{
fgtest::initTestGlobals("Addon");
Addon addon;
std::string addonId = "org.FlightGear.addons.MyGreatAddon";
addon.setId(addonId);
Addon addon{addonId};
addon.setVersion(AddonVersion("2017.2.5rc3"));
addon.setBasePath(SGPath("/path/to/MyGreatAddon"));
addon.setMinFGVersionRequired("2017.4.1");