1
0
Fork 0

Add-ons: use shared_ptr_traits<>::makeStrongRef(...) instead of new Foobar(...)

Replace the previously-written manual calls to "new SomeClass(...)" with
their equivalent using
flightgear::addons::shared_ptr_traits<>::makeStrongRef(). This way, when
SomeClassRef is changed from SGSharedPtr<SomeClass> to
std::shared_ptr<SomeClass>, these calls will magically use
std::make_shared<SomeClass>(...) instead of the "new SomeClass(...)"
call.
This commit is contained in:
Florent Rougon 2018-01-04 18:46:46 +01:00
parent d2cb99ba1d
commit 59d8dea0d7
2 changed files with 9 additions and 3 deletions

View file

@ -92,7 +92,8 @@ Addon::Addon(std::string id, AddonVersion version, SGPath basePath,
std::string minFGVersionRequired, std::string maxFGVersionRequired,
SGPropertyNode* addonNode)
: _id(std::move(id)),
_version(new AddonVersion(std::move(version))),
_version(
shared_ptr_traits<AddonVersionRef>::makeStrongRef(std::move(version))),
_basePath(std::move(basePath)),
_minFGVersionRequired(std::move(minFGVersionRequired)),
_maxFGVersionRequired(std::move(maxFGVersionRequired)),
@ -129,7 +130,10 @@ AddonVersionRef Addon::getVersion() const
{ return _version; }
void Addon::setVersion(const AddonVersion& addonVersion)
{ _version.reset(new AddonVersion(addonVersion)); }
{
using ptr_traits = shared_ptr_traits<AddonVersionRef>;
_version.reset(ptr_traits::makeStrongRef(addonVersion));
}
std::vector<AuthorRef> Addon::getAuthors() const
{ return _authors; }

View file

@ -42,6 +42,7 @@
#include "AddonManager.hxx"
#include "AddonVersion.hxx"
#include "exceptions.hxx"
#include "pointer_traits.hxx"
namespace strutils = simgear::strutils;
@ -110,7 +111,8 @@ AddonManager::loadConfigFileIfExists(const SGPath& configFile)
string
AddonManager::registerAddonMetadata(const SGPath& addonPath)
{
AddonRef addon(new Addon(Addon::fromAddonDir(addonPath)));
using ptr_traits = shared_ptr_traits<AddonRef>;
AddonRef addon = ptr_traits::makeStrongRef(Addon::fromAddonDir(addonPath));
SGPath metadataFile = addon->getMetadataFile();
string addonId = addon->getId();