Skip to content

Commit

Permalink
refactor: remove reference members
Browse files Browse the repository at this point in the history
As per cpp core guidelines C.12 - remove members that are references in favour of
shared pointers with assert.
  • Loading branch information
AndyTWF committed Jan 1, 2023
1 parent a90dddb commit 34311e4
Show file tree
Hide file tree
Showing 42 changed files with 185 additions and 143 deletions.
1 change: 1 addition & 0 deletions src/plugin/bootstrap/PersistenceContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "hold/PublishedHoldCollection.h"
#include "initialaltitude/InitialAltitudeEventHandler.h"
#include "integration/ExternalMessageEventHandler.h"
#include "integration/IntegrationPersistenceContainer.h"
#include "list/PopupListFactory.h"
#include "login/Login.h"
#include "message/UserMessager.h"
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/bootstrap/PersistenceContainer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include "integration/IntegrationPersistenceContainer.h"

namespace UKControllerPlugin {
class UKPlugin;
Expand Down Expand Up @@ -72,6 +71,7 @@ namespace UKControllerPlugin {
} // namespace Hold
namespace Integration {
class ExternalMessageEventHandler;
struct IntegrationPersistenceContainer;
} // namespace Integration
namespace InitialAltitude {
class InitialAltitudeEventHandler;
Expand Down Expand Up @@ -184,7 +184,7 @@ namespace UKControllerPlugin::Bootstrap {
std::unique_ptr<UKControllerPlugin::Api::ApiInterface> api;
std::shared_ptr<UKControllerPluginUtils::Api::ApiFactory> apiFactory;
std::shared_ptr<UKControllerPlugin::TaskManager::TaskRunnerInterface> taskRunner;
std::unique_ptr<UKControllerPlugin::Controller::ActiveCallsignCollection> activeCallsigns;
std::shared_ptr<UKControllerPlugin::Controller::ActiveCallsignCollection> activeCallsigns;
std::unique_ptr<UKControllerPlugin::Flightplan::StoredFlightplanCollection> flightplans;
std::unique_ptr<UKControllerPlugin::Message::UserMessager> userMessager;
std::unique_ptr<UKControllerPlugin::Euroscope::UserSetting> pluginUserSettingHandler;
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/controller/ControllerBootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace UKControllerPlugin::Controller {
container.controllerHierarchyFactory =
std::make_unique<ControllerPositionHierarchyFactory>(*container.controllerPositions);

container.activeCallsigns = std::make_unique<ActiveCallsignCollection>();
container.activeCallsigns = std::make_shared<ActiveCallsignCollection>();
container.controllerHandler->RegisterHandler(
std::make_shared<ActiveCallsignMonitor>(*container.controllerPositions, *container.activeCallsigns));
}
Expand Down
1 change: 1 addition & 0 deletions src/plugin/handoff/HandoffModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "dependency/DependencyLoaderInterface.h"
#include "euroscope/RunwayDialogAwareCollection.h"
#include "flightplan/FlightPlanEventHandlerCollection.h"
#include "integration/IntegrationPersistenceContainer.h"
#include "tag/TagItemCollection.h"

using UKControllerPlugin::Bootstrap::PersistenceContainer;
Expand Down
6 changes: 4 additions & 2 deletions src/plugin/intention/CachedAircraftFirExitGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

namespace UKControllerPlugin::IntentionCode {

CachedAircraftFirExitGenerator::CachedAircraftFirExitGenerator(const FirExitPointCollection& firExitPoints)
CachedAircraftFirExitGenerator::CachedAircraftFirExitGenerator(
std::shared_ptr<const FirExitPointCollection> firExitPoints)
: firExitPoints(firExitPoints)
{
assert(firExitPoints && "FIR exit points not set in CachedAircraftFirExitGenerator");
}

void CachedAircraftFirExitGenerator::AddCacheEntry(const std::shared_ptr<AircraftFirExit>& entry)
Expand Down Expand Up @@ -50,7 +52,7 @@ namespace UKControllerPlugin::IntentionCode {
break;
}

const auto firExitPoint = firExitPoints.PointByIdentifier(flightplanPoint->Identifier());
const auto firExitPoint = firExitPoints->PointByIdentifier(flightplanPoint->Identifier());
if (!firExitPoint) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/intention/CachedAircraftFirExitGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace UKControllerPlugin::IntentionCode {
public Flightplan::FlightPlanEventHandlerInterface
{
public:
CachedAircraftFirExitGenerator(const FirExitPointCollection& firExitPoints);
CachedAircraftFirExitGenerator(std::shared_ptr<const FirExitPointCollection> firExitPoints);
void AddCacheEntry(const std::shared_ptr<AircraftFirExit>& entry);
void FlightPlanEvent(
Euroscope::EuroScopeCFlightPlanInterface& flightPlan,
Expand All @@ -32,7 +32,7 @@ namespace UKControllerPlugin::IntentionCode {

private:
// The FIR exit points
const FirExitPointCollection& firExitPoints;
std::shared_ptr<const FirExitPointCollection> firExitPoints;

// The cache
std::map<std::string, std::shared_ptr<AircraftFirExit>> cache;
Expand Down
9 changes: 6 additions & 3 deletions src/plugin/intention/CachedAircraftIntentionCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
namespace UKControllerPlugin::IntentionCode {

CachedAircraftIntentionCodeGenerator::CachedAircraftIntentionCodeGenerator(
const IntentionCodeCollection& intentionCodes, const IntentionCodeEventHandlerCollection& eventHandlers)
std::shared_ptr<const IntentionCodeCollection> intentionCodes,
std::shared_ptr<const IntentionCodeEventHandlerCollection> eventHandlers)
: intentionCodes(intentionCodes), eventHandlers(eventHandlers)
{
assert(intentionCodes && "intention codes not set in CachedAircraftIntentionCodeGenerator");
assert(eventHandlers && "event handlers codes not set in CachedAircraftIntentionCodeGenerator");
}

void CachedAircraftIntentionCodeGenerator::AddCacheEntry(const std::shared_ptr<AircraftIntentionCode>& entry)
Expand Down Expand Up @@ -46,7 +49,7 @@ namespace UKControllerPlugin::IntentionCode {
intentionCode.callsign = flightplan.GetCallsign();

const auto matchedIntentionCode =
intentionCodes.FirstWhere([&flightplan, &radarTarget](const IntentionCodeModel& code) -> bool {
intentionCodes->FirstWhere([&flightplan, &radarTarget](const IntentionCodeModel& code) -> bool {
return code.Conditions().Passes(flightplan, radarTarget);
});

Expand All @@ -56,7 +59,7 @@ namespace UKControllerPlugin::IntentionCode {

auto cacheItem = std::make_shared<AircraftIntentionCode>(intentionCode);
AddCacheEntry(cacheItem);
eventHandlers.IntentionCodeUpdated(*cacheItem);
eventHandlers->IntentionCodeUpdated(*cacheItem);

return cacheItem;
}
Expand Down
7 changes: 4 additions & 3 deletions src/plugin/intention/CachedAircraftIntentionCodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace UKControllerPlugin::IntentionCode {
{
public:
CachedAircraftIntentionCodeGenerator(
const IntentionCodeCollection& intentionCodes, const IntentionCodeEventHandlerCollection& eventHandlers);
std::shared_ptr<const IntentionCodeCollection> intentionCodes,
std::shared_ptr<const IntentionCodeEventHandlerCollection> eventHandlers);
void AddCacheEntry(const std::shared_ptr<AircraftIntentionCode>& entry);
void FlightPlanEvent(
Euroscope::EuroScopeCFlightPlanInterface& flightPlan,
Expand All @@ -41,10 +42,10 @@ namespace UKControllerPlugin::IntentionCode {

private:
// The intention codes
const IntentionCodeCollection& intentionCodes;
std::shared_ptr<const IntentionCodeCollection> intentionCodes;

// Handles intention code events
const IntentionCodeEventHandlerCollection& eventHandlers;
std::shared_ptr<const IntentionCodeEventHandlerCollection> eventHandlers;

// The cache
std::map<std::string, std::shared_ptr<AircraftIntentionCode>> cache;
Expand Down
7 changes: 4 additions & 3 deletions src/plugin/intention/ControllerPositionStartsWith.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
namespace UKControllerPlugin::IntentionCode {

ControllerPositionStartsWith::ControllerPositionStartsWith(
const UKControllerPlugin::Controller::ActiveCallsignCollection& activeControllers, std::string pattern)
std::shared_ptr<const Controller::ActiveCallsignCollection> activeControllers, std::string pattern)
: activeControllers(activeControllers), pattern(std::move(pattern))
{
assert(activeControllers && "active callsigns not set in ControllerPositionStartsWith");
}

auto ControllerPositionStartsWith::Passes(
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool
{
return activeControllers.UserHasCallsign() &&
activeControllers.GetUserCallsign().GetNormalisedPosition().GetCallsign().substr(0, pattern.size()) ==
return activeControllers->UserHasCallsign() &&
activeControllers->GetUserCallsign().GetNormalisedPosition().GetCallsign().substr(0, pattern.size()) ==
pattern;
}

Expand Down
4 changes: 2 additions & 2 deletions src/plugin/intention/ControllerPositionStartsWith.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ namespace UKControllerPlugin::IntentionCode {
{
public:
ControllerPositionStartsWith(
const UKControllerPlugin::Controller::ActiveCallsignCollection& activeControllers, std::string pattern);
std::shared_ptr<const Controller::ActiveCallsignCollection> activeControllers, std::string pattern);
[[nodiscard]] auto Pattern() const -> const std::string&;
[[nodiscard]] auto Passes(
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;

private:
// Active controllers
const UKControllerPlugin::Controller::ActiveCallsignCollection& activeControllers;
std::shared_ptr<const Controller::ActiveCallsignCollection> activeControllers;

// The airfield pattern to match
std::string pattern;
Expand Down
5 changes: 3 additions & 2 deletions src/plugin/intention/ExitingFirAtPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@

namespace UKControllerPlugin::IntentionCode {

ExitingFirAtPoint::ExitingFirAtPoint(AircraftFirExitGenerator& firExitGenerator, int firExitPointId)
ExitingFirAtPoint::ExitingFirAtPoint(std::shared_ptr<AircraftFirExitGenerator> firExitGenerator, int firExitPointId)
: firExitGenerator(firExitGenerator), firExitPointId(firExitPointId)
{
assert(firExitGenerator && "generator not set in ExitingFirAtPoint");
}

auto ExitingFirAtPoint::Passes(
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool
{
const auto firExit = firExitGenerator.Generate(flightplan);
const auto firExit = firExitGenerator->Generate(flightplan);
if (!firExit) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/intention/ExitingFirAtPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ namespace UKControllerPlugin::IntentionCode {
class ExitingFirAtPoint : public Condition
{
public:
ExitingFirAtPoint(AircraftFirExitGenerator& firExitGenerator, int firExitPointId);
ExitingFirAtPoint(std::shared_ptr<AircraftFirExitGenerator> firExitGenerator, int firExitPointId);
[[nodiscard]] auto ExitPoint() const -> int;
[[nodiscard]] auto Passes(
const Euroscope::EuroScopeCFlightPlanInterface& flightplan,
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget) -> bool override;

private:
// Generates the FIR exit point for an aircraft
AircraftFirExitGenerator& firExitGenerator;
std::shared_ptr<AircraftFirExitGenerator> firExitGenerator;

// The FIR exit point applying to this rule
int firExitPointId;
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/intention/FirExitPointCollectionFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

namespace UKControllerPlugin::IntentionCode {

auto MakeFirExitPointCollection(const nlohmann::json& exitPointData) -> std::unique_ptr<FirExitPointCollection>
auto MakeFirExitPointCollection(const nlohmann::json& exitPointData) -> std::shared_ptr<FirExitPointCollection>
{
auto collection = std::make_unique<FirExitPointCollection>();
auto collection = std::make_shared<FirExitPointCollection>();
if (!exitPointData.is_array()) {
return collection;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/intention/FirExitPointCollectionFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace UKControllerPlugin::IntentionCode {
class FirExitPointCollection;

[[nodiscard]] auto MakeFirExitPointCollection(const nlohmann::json& exitPointData)
-> std::unique_ptr<FirExitPointCollection>;
-> std::shared_ptr<FirExitPointCollection>;
[[nodiscard]] auto ExitPointValid(const nlohmann::json& exitPointData) -> bool;
[[nodiscard]] auto HeadingValid(const std::string& key, const nlohmann::json& exitPointData) -> bool;
} // namespace UKControllerPlugin::IntentionCode
7 changes: 4 additions & 3 deletions src/plugin/intention/IntentionCodeBootstrapProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "bootstrap/ModuleFactories.h"
#include "bootstrap/PersistenceContainer.h"
#include "flightplan/FlightPlanEventHandlerCollection.h"
#include "integration/IntegrationPersistenceContainer.h"
#include "integration/OutboundIntegrationEventHandler.h"
#include "tag/TagItemCollection.h"

Expand All @@ -19,15 +20,15 @@ namespace UKControllerPlugin::IntentionCode {
container.moduleFactories->IntentionCode().CachedFirExitGenerator(*container.dependencyLoader));

// Register integration messages for intention code update events
container.moduleFactories->IntentionCode().IntentionCodeEventHandlers().AddHandler(
container.moduleFactories->IntentionCode().IntentionCodeEventHandlers()->AddHandler(
std::make_shared<SendIntentionCodeUpdatedIntegrationMessage>(
container.moduleFactories->IntentionCode().ExitPointCollection(*container.dependencyLoader),
*container.integrationModuleContainer->outboundMessageHandler));
container.integrationModuleContainer->outboundMessageHandler));

// Register the tag item for intention codes
container.tagHandler->RegisterTagItem(
intentionCodeTagItemId,
std::make_shared<IntentionCodeTagItem>(container.moduleFactories->IntentionCode().IntentionCodeGenerator(
*container.dependencyLoader, *container.activeCallsigns)));
*container.dependencyLoader, container.activeCallsigns)));
}
} // namespace UKControllerPlugin::IntentionCode
19 changes: 10 additions & 9 deletions src/plugin/intention/IntentionCodeCollectionFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ namespace UKControllerPlugin::IntentionCode {

auto MakeIntentionCodeCollection(
const nlohmann::json& codes,
AircraftFirExitGenerator& generator,
const Controller::ActiveCallsignCollection& activeControllers) -> std::unique_ptr<IntentionCodeCollection>
std::shared_ptr<AircraftFirExitGenerator> generator,
std::shared_ptr<const Controller::ActiveCallsignCollection> activeControllers)
-> std::shared_ptr<IntentionCodeCollection>
{
auto collection = std::make_unique<IntentionCodeCollection>();
auto collection = std::make_shared<IntentionCodeCollection>();

if (!codes.is_array()) {
LogWarning("Intention codes dependency is invalid");
Expand All @@ -117,7 +118,7 @@ namespace UKControllerPlugin::IntentionCode {
std::make_unique<FullAirfieldIdentifier>(),
std::make_unique<AllOf>(std::list<std::shared_ptr<Condition>>({})),
std::unique_ptr<IntentionCodeMetadata>(new IntentionCodeMetadata)));
return std::move(collection);
return collection;
}

for (const auto& code : codes) {
Expand All @@ -144,7 +145,7 @@ namespace UKControllerPlugin::IntentionCode {
std::unique_ptr<IntentionCodeMetadata>(new IntentionCodeMetadata)));

LogInfo("Loaded " + std::to_string(collection->Count()) + " intention codes");
return std::move(collection);
return collection;
}

auto MakeCode(const nlohmann::json& code) -> std::unique_ptr<CodeGenerator>
Expand All @@ -158,8 +159,8 @@ namespace UKControllerPlugin::IntentionCode {

auto MakeConditions(
const nlohmann::json& conditions,
AircraftFirExitGenerator& generator,
const Controller::ActiveCallsignCollection& activeControllers,
std::shared_ptr<AircraftFirExitGenerator> generator,
std::shared_ptr<const Controller::ActiveCallsignCollection> activeControllers,
IntentionCodeMetadata& metadata) -> std::list<std::shared_ptr<Condition>>
{
auto conditionList = std::list<std::shared_ptr<Condition>>();
Expand All @@ -172,8 +173,8 @@ namespace UKControllerPlugin::IntentionCode {

auto MakeCondition(
const nlohmann::json& condition,
AircraftFirExitGenerator& generator,
const Controller::ActiveCallsignCollection& activeControllers,
std::shared_ptr<AircraftFirExitGenerator> generator,
std::shared_ptr<const Controller::ActiveCallsignCollection> activeControllers,
IntentionCodeMetadata& metadata) -> std::shared_ptr<Condition>
{
const auto conditionType = condition.at("type").get<std::string>();
Expand Down
13 changes: 7 additions & 6 deletions src/plugin/intention/IntentionCodeCollectionFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ namespace UKControllerPlugin::IntentionCode {

[[nodiscard]] auto MakeIntentionCodeCollection(
const nlohmann::json& codes,
AircraftFirExitGenerator& generator,
const Controller::ActiveCallsignCollection& activeControllers) -> std::unique_ptr<IntentionCodeCollection>;
std::shared_ptr<AircraftFirExitGenerator> generator,
std::shared_ptr<const Controller::ActiveCallsignCollection> activeControllers) ->
std::shared_ptr<IntentionCodeCollection>;
[[nodiscard]] auto MakeCode(const nlohmann::json& code) -> std::unique_ptr<CodeGenerator>;
[[nodiscard]] auto MakeCondition(
const nlohmann::json& conditions,
AircraftFirExitGenerator& generator,
const Controller::ActiveCallsignCollection& activeControllers,
std::shared_ptr<AircraftFirExitGenerator> generator,
std::shared_ptr<const Controller::ActiveCallsignCollection> activeControllers,
IntentionCodeMetadata& metadata) -> std::shared_ptr<Condition>;
[[nodiscard]] auto MakeConditions(
const nlohmann::json& condition,
AircraftFirExitGenerator& generator,
const Controller::ActiveCallsignCollection& activeControllers,
std::shared_ptr<AircraftFirExitGenerator> generator,
std::shared_ptr<const Controller::ActiveCallsignCollection> activeControllers,
IntentionCodeMetadata& metadata) -> std::list<std::shared_ptr<Condition>>;
[[nodiscard]] auto ConditionsValid(const nlohmann::json& conditions) -> bool;
[[nodiscard]] auto ConditionValid(const nlohmann::json& condition) -> bool;
Expand Down

0 comments on commit 34311e4

Please sign in to comment.