From f4b60ccd90ce66aa74bdf1de354b64ccbfabfbfb Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Thu, 30 Jan 2020 09:20:44 +0100 Subject: [PATCH] [swift] Code cleanup --- src/Network/Swift/SwiftAircraft.cpp | 4 ++-- src/Network/Swift/SwiftAircraft.h | 4 ++-- src/Network/Swift/SwiftAircraftManager.cpp | 23 +++++++++++----------- src/Network/Swift/SwiftAircraftManager.h | 4 ++-- src/Network/Swift/service.cpp | 16 ++++----------- src/Network/Swift/swift_connection.cxx | 13 ++++++------ src/Network/Swift/swift_connection.hxx | 2 +- src/Network/Swift/traffic.cpp | 2 +- 8 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/Network/Swift/SwiftAircraft.cpp b/src/Network/Swift/SwiftAircraft.cpp index d14f90fa6..58f6008bd 100644 --- a/src/Network/Swift/SwiftAircraft.cpp +++ b/src/Network/Swift/SwiftAircraft.cpp @@ -42,7 +42,7 @@ #include #include -FGSwiftAircraft::FGSwiftAircraft(std::string callsign, std::string modelpath, SGPropertyNode* p) +FGSwiftAircraft::FGSwiftAircraft(const std::string& callsign, const std::string& modelpath, SGPropertyNode* p) { using namespace simgear; _model = SGModelLib::loadModel(modelpath); @@ -112,7 +112,7 @@ double FGSwiftAircraft::getFudgeFactor() return 0; } -inline bool FGSwiftAircraft::operator<(std::string extCallsign) +inline bool FGSwiftAircraft::operator<(const std::string& extCallsign) { return _model->getName().compare(extCallsign); } diff --git a/src/Network/Swift/SwiftAircraft.h b/src/Network/Swift/SwiftAircraft.h index 4b71ef83c..45bc8dd3c 100644 --- a/src/Network/Swift/SwiftAircraft.h +++ b/src/Network/Swift/SwiftAircraft.h @@ -41,7 +41,7 @@ class PagedLOD; class FGSwiftAircraft { public: - FGSwiftAircraft(std::string callsign, std::string modelpath, SGPropertyNode* p); + FGSwiftAircraft(const std::string& callsign, const std::string& modelpath, SGPropertyNode* p); bool updatePosition(SGGeod newPosition, SGVec3d orientation, double groundspeed); ~FGSwiftAircraft(); std::string getName() { return _model->getName(); }; @@ -55,6 +55,6 @@ private: SGPropertyNode* props; osg::ref_ptr _model; SGModelPlacement aip; - inline bool operator<(std::string extCallsign); + inline bool operator<(const std::string& extCallsign); }; #endif \ No newline at end of file diff --git a/src/Network/Swift/SwiftAircraftManager.cpp b/src/Network/Swift/SwiftAircraftManager.cpp index 580f0a9b7..edec49eaf 100644 --- a/src/Network/Swift/SwiftAircraftManager.cpp +++ b/src/Network/Swift/SwiftAircraftManager.cpp @@ -20,16 +20,15 @@ #include "SwiftAircraftManager.h" #include "SwiftAircraft.h" #include
+#include FGSwiftAircraftManager::FGSwiftAircraftManager() -{ -} += default; FGSwiftAircraftManager::~FGSwiftAircraftManager() -{ -} += default; -bool FGSwiftAircraftManager::addPlane(std::string callsign, std::string modelString) +bool FGSwiftAircraftManager::addPlane(const std::string& callsign, std::string modelString) { if (aircraftByCallsign.find(callsign) != aircraftByCallsign.end()) return false; @@ -46,14 +45,14 @@ bool FGSwiftAircraftManager::addPlane(std::string callsign, std::string modelStr } p = root->getNode(typeString,i,true); p->setIntValue("id",i); - FGSwiftAircraft* curAircraft = new FGSwiftAircraft(callsign, modelString, p); + auto* curAircraft = new FGSwiftAircraft(callsign, std::move(modelString), p); aircraftByCallsign.insert(std::pair(callsign, curAircraft)); return true; } void FGSwiftAircraftManager::updatePlanes(std::vector callsigns, std::vector positions, std::vector orientations, std::vector groundspeeds, std::vector onGrounds) { - for (int i = 0; i < callsigns.size(); i++) { + for (long unsigned int i = 0; i < callsigns.size(); i++) { auto it = aircraftByCallsign.find(callsigns.at(i)); if (it != aircraftByCallsign.end()) { it->second->updatePosition(positions.at(i), orientations.at(i), groundspeeds.at(i)); @@ -71,15 +70,15 @@ void FGSwiftAircraftManager::getRemoteAircraftData(std::vector& cal elevationsM.clear(); verticalOffsets.clear(); - for (int i = 0; i < requestedCallsigns.size(); i++) { - auto it = aircraftByCallsign.find(requestedCallsigns.at(i)); + for (const auto & requestedCallsign : requestedCallsigns) { + auto it = aircraftByCallsign.find(requestedCallsign); if (it != aircraftByCallsign.end()) { double latDeg = it->second->getLatDeg(); double lonDeg = it->second->getLongDeg(); double groundElevation = it->second->getGroundElevation(); double fudgeFactor = it->second->getFudgeFactor(); - - callsigns.push_back(requestedCallsigns.at(i)); + (void)fudgeFactor; + callsigns.push_back(requestedCallsign); latitudesDeg.push_back(latDeg); longitudesDeg.push_back(lonDeg); elevationsM.push_back(groundElevation); @@ -89,7 +88,7 @@ void FGSwiftAircraftManager::getRemoteAircraftData(std::vector& cal } -void FGSwiftAircraftManager::removePlane(std::string callsign) +void FGSwiftAircraftManager::removePlane(const std::string& callsign) { auto it = aircraftByCallsign.find(callsign); if (it != aircraftByCallsign.end()) { diff --git a/src/Network/Swift/SwiftAircraftManager.h b/src/Network/Swift/SwiftAircraftManager.h index 9f6991905..b3a1f4452 100644 --- a/src/Network/Swift/SwiftAircraftManager.h +++ b/src/Network/Swift/SwiftAircraftManager.h @@ -29,11 +29,11 @@ public: FGSwiftAircraftManager(); ~FGSwiftAircraftManager(); std::map aircraftByCallsign; - bool addPlane(std::string callsign, std::string modelString); + bool addPlane(const std::string& callsign, std::string modelString); void updatePlanes(std::vector callsigns, std::vector positions, std::vector orientations, std::vector groundspeeds, std::vector onGrounds); void getRemoteAircraftData(std::vector& callsigns, std::vector& latitudesDeg, std::vector& longitudesDeg, std::vector& elevationsM, std::vector& verticalOffsets) const; - void removePlane(std::string callsign); + void removePlane(const std::string& callsign); void removeAllPlanes(); }; #endif \ No newline at end of file diff --git a/src/Network/Swift/service.cpp b/src/Network/Swift/service.cpp index 61b257f80..0d72a4af3 100644 --- a/src/Network/Swift/service.cpp +++ b/src/Network/Swift/service.cpp @@ -19,17 +19,9 @@ #include "service.h" #include
-#include #include -#include #include -#include -#include -#include #include -#include -#include -#include #define FGSWIFTBUS_API_VERSION 1; @@ -169,22 +161,22 @@ bool CService::getAllWheelsOnGround() const int CService::getCom1Active() const { - return com1ActiveNode->getDoubleValue() * 1000; + return (int)com1ActiveNode->getDoubleValue() * 1000; } int CService::getCom1Standby() const { - return com1StandbyNode->getDoubleValue() * 1000; + return (int)com1StandbyNode->getDoubleValue() * 1000; } int CService::getCom2Active() const { - return com2ActiveNode->getDoubleValue() * 1000; + return (int)com2ActiveNode->getDoubleValue() * 1000; } int CService::getCom2Standby() const { - return com2StandbyNode->getDoubleValue() * 1000; + return (int)com2StandbyNode->getDoubleValue() * 1000; } int CService::getTransponderCode() const diff --git a/src/Network/Swift/swift_connection.cxx b/src/Network/Swift/swift_connection.cxx index d8011222c..7ce55e4b4 100644 --- a/src/Network/Swift/swift_connection.cxx +++ b/src/Network/Swift/swift_connection.cxx @@ -51,7 +51,8 @@ bool SwiftConnection::startServer(const SGPropertyNode* arg, SGPropertyNode* roo bool SwiftConnection::stopServer(const SGPropertyNode* arg, SGPropertyNode* root) { - SwiftConnection::plug->~CPlugin(); + delete SwiftConnection::plug; + SwiftConnection::plug = nullptr; fgSetBool("/sim/swift/serverRunning", false); serverRunning = false; return true; @@ -68,9 +69,9 @@ SwiftConnection::~SwiftConnection() shutdown(); } -void SwiftConnection::init(void) +void SwiftConnection::init() { - if (initialized == false) { + if (!initialized) { globals->get_commands()->addCommand("swiftStart", this, &SwiftConnection::startServer); globals->get_commands()->addCommand("swiftStop", this, &SwiftConnection::stopServer); fgSetBool("/sim/swift/available", true); @@ -81,14 +82,14 @@ void SwiftConnection::init(void) void SwiftConnection::update(double delta_time_sec) { - if (serverRunning == true) { + if (serverRunning) { SwiftConnection::plug->fastLoop(); } } -void SwiftConnection::shutdown(void) +void SwiftConnection::shutdown() { - if (initialized == true) { + if (initialized) { globals->get_commands()->removeCommand("swiftStart"); globals->get_commands()->removeCommand("swiftStop"); fgSetBool("/sim/swift/available", false); diff --git a/src/Network/Swift/swift_connection.hxx b/src/Network/Swift/swift_connection.hxx index 088823729..d7732acc3 100644 --- a/src/Network/Swift/swift_connection.hxx +++ b/src/Network/Swift/swift_connection.hxx @@ -52,7 +52,7 @@ public: bool startServer(const SGPropertyNode* arg, SGPropertyNode* root); bool stopServer(const SGPropertyNode* arg, SGPropertyNode* root); - FGSwiftBus::CPlugin* plug; + FGSwiftBus::CPlugin* plug{}; private: bool serverRunning = false; diff --git a/src/Network/Swift/traffic.cpp b/src/Network/Swift/traffic.cpp index 9a6c3f916..2bf8dd9b6 100644 --- a/src/Network/Swift/traffic.cpp +++ b/src/Network/Swift/traffic.cpp @@ -209,7 +209,7 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_) queueDBusCall([=]() { std::vector positions; std::vector orientations; - for (int i = 0; i < latitudes.size(); i++) { + for (long unsigned int i = 0; i < latitudes.size(); i++) { SGGeod newPos; newPos.setLatitudeDeg(latitudes.at(i)); newPos.setLongitudeDeg(longitudes.at(i));