mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
Use nested namespaces (C++17 feature)
This commit is contained in:
@@ -24,257 +24,254 @@ using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
namespace BlackMisc
|
||||
namespace BlackMisc::Simulation
|
||||
{
|
||||
namespace Simulation
|
||||
CSimulatedAircraftList::CSimulatedAircraftList() { }
|
||||
|
||||
CSimulatedAircraftList::CSimulatedAircraftList(const CSequence<CSimulatedAircraft> &other) :
|
||||
CSequence<CSimulatedAircraft>(other)
|
||||
{ }
|
||||
|
||||
CUserList CSimulatedAircraftList::getPilots() const
|
||||
{
|
||||
CSimulatedAircraftList::CSimulatedAircraftList() { }
|
||||
return this->findBy(Predicates::MemberValid(&CSimulatedAircraft::getPilot)).transform(Predicates::MemberTransform(&CSimulatedAircraft::getPilot));
|
||||
}
|
||||
|
||||
CSimulatedAircraftList::CSimulatedAircraftList(const CSequence<CSimulatedAircraft> &other) :
|
||||
CSequence<CSimulatedAircraft>(other)
|
||||
{ }
|
||||
CAircraftModelList CSimulatedAircraftList::getModels() const
|
||||
{
|
||||
return this->transform(Predicates::MemberTransform(&CSimulatedAircraft::getModel));
|
||||
}
|
||||
|
||||
CUserList CSimulatedAircraftList::getPilots() const
|
||||
CSimulatedAircraftList CSimulatedAircraftList::findByEnabled(bool enabled) const
|
||||
{
|
||||
return this->findBy(&CSimulatedAircraft::isEnabled, enabled);
|
||||
}
|
||||
|
||||
CSimulatedAircraftList CSimulatedAircraftList::findByRendered(bool rendered) const
|
||||
{
|
||||
return this->findBy(&CSimulatedAircraft::isRendered, rendered);
|
||||
}
|
||||
|
||||
CSimulatedAircraftList CSimulatedAircraftList::findByVtol(bool vtol) const
|
||||
{
|
||||
return this->findBy(&CSimulatedAircraft::isVtol, vtol);
|
||||
}
|
||||
|
||||
CCallsignSet CSimulatedAircraftList::getCallsignsWithSynchronizedParts() const
|
||||
{
|
||||
CCallsignSet csl;
|
||||
for (const CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
return this->findBy(Predicates::MemberValid(&CSimulatedAircraft::getPilot)).transform(Predicates::MemberTransform(&CSimulatedAircraft::getPilot));
|
||||
if (!aircraft.isPartsSynchronized()) { continue; }
|
||||
csl.push_back(aircraft.getCallsign());
|
||||
}
|
||||
return csl;
|
||||
}
|
||||
|
||||
CAircraftModelList CSimulatedAircraftList::getModels() const
|
||||
bool CSimulatedAircraftList::updateWithVatsimDataFileData(CSimulatedAircraft &aircraftToBeUpdated) const
|
||||
{
|
||||
if (this->isEmpty()) return false;
|
||||
if (aircraftToBeUpdated.hasRealName() && aircraftToBeUpdated.hasId() && aircraftToBeUpdated.hasAircraftAndAirlineDesignator()) { return false; }
|
||||
|
||||
CSimulatedAircraft currentDataFileAircraft = this->findFirstByCallsign(aircraftToBeUpdated.getCallsign());
|
||||
if (currentDataFileAircraft.getCallsign().isEmpty()) return false;
|
||||
|
||||
CUser user = aircraftToBeUpdated.getPilot();
|
||||
user.updateMissingParts(currentDataFileAircraft.getPilot());
|
||||
aircraftToBeUpdated.setPilot(user);
|
||||
|
||||
CAircraftIcaoCode aircraftIcao = aircraftToBeUpdated.getAircraftIcaoCode();
|
||||
CAirlineIcaoCode airlineIcao = aircraftToBeUpdated.getAirlineIcaoCode();
|
||||
aircraftIcao.updateMissingParts(currentDataFileAircraft.getAircraftIcaoCode());
|
||||
airlineIcao.updateMissingParts(currentDataFileAircraft.getAirlineIcaoCode());
|
||||
aircraftToBeUpdated.setIcaoCodes(aircraftIcao, airlineIcao);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSimulatedAircraftList::markAllAsNotRendered()
|
||||
{
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
return this->transform(Predicates::MemberTransform(&CSimulatedAircraft::getModel));
|
||||
if (!aircraft.isRendered()) { continue; }
|
||||
aircraft.setRendered(false);
|
||||
}
|
||||
}
|
||||
|
||||
CSimulatedAircraftList CSimulatedAircraftList::findByEnabled(bool enabled) const
|
||||
int CSimulatedAircraftList::setRendered(const CCallsign &callsign, bool rendered, bool onlyFirst)
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
return this->findBy(&CSimulatedAircraft::isEnabled, enabled);
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setRendered(rendered);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
CSimulatedAircraftList CSimulatedAircraftList::findByRendered(bool rendered) const
|
||||
int CSimulatedAircraftList::setCG(const CCallsign &callsign, const CLength &cg, bool onlyFirst)
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
return this->findBy(&CSimulatedAircraft::isRendered, rendered);
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setCG(cg);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
CSimulatedAircraftList CSimulatedAircraftList::findByVtol(bool vtol) const
|
||||
int CSimulatedAircraftList::setFastPositionUpdates(const CCallsign &callsign, bool fastPositions, bool onlyFirst)
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
return this->findBy(&CSimulatedAircraft::isVtol, vtol);
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setFastPositionUpdates(fastPositions);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
CCallsignSet CSimulatedAircraftList::getCallsignsWithSynchronizedParts() const
|
||||
int CSimulatedAircraftList::setEnabled(const CCallsign &callsign, bool enabled, bool onlyFirst)
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
CCallsignSet csl;
|
||||
for (const CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (!aircraft.isPartsSynchronized()) { continue; }
|
||||
csl.push_back(aircraft.getCallsign());
|
||||
}
|
||||
return csl;
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setEnabled(enabled);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
bool CSimulatedAircraftList::updateWithVatsimDataFileData(CSimulatedAircraft &aircraftToBeUpdated) const
|
||||
int CSimulatedAircraftList::setAircraftModel(const CCallsign &callsign, const CAircraftModel &model, bool onlyFirst)
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (this->isEmpty()) return false;
|
||||
if (aircraftToBeUpdated.hasRealName() && aircraftToBeUpdated.hasId() && aircraftToBeUpdated.hasAircraftAndAirlineDesignator()) { return false; }
|
||||
|
||||
CSimulatedAircraft currentDataFileAircraft = this->findFirstByCallsign(aircraftToBeUpdated.getCallsign());
|
||||
if (currentDataFileAircraft.getCallsign().isEmpty()) return false;
|
||||
|
||||
CUser user = aircraftToBeUpdated.getPilot();
|
||||
user.updateMissingParts(currentDataFileAircraft.getPilot());
|
||||
aircraftToBeUpdated.setPilot(user);
|
||||
|
||||
CAircraftIcaoCode aircraftIcao = aircraftToBeUpdated.getAircraftIcaoCode();
|
||||
CAirlineIcaoCode airlineIcao = aircraftToBeUpdated.getAirlineIcaoCode();
|
||||
aircraftIcao.updateMissingParts(currentDataFileAircraft.getAircraftIcaoCode());
|
||||
airlineIcao.updateMissingParts(currentDataFileAircraft.getAirlineIcaoCode());
|
||||
aircraftToBeUpdated.setIcaoCodes(aircraftIcao, airlineIcao);
|
||||
return true;
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setModel(model);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
void CSimulatedAircraftList::markAllAsNotRendered()
|
||||
int CSimulatedAircraftList::setAircraftPartsSynchronized(const CCallsign &callsign, const CAircraftParts &parts, bool onlyFirst)
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (!aircraft.isRendered()) { continue; }
|
||||
aircraft.setRendered(false);
|
||||
}
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setParts(parts);
|
||||
aircraft.setPartsSynchronized(true);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int CSimulatedAircraftList::setRendered(const CCallsign &callsign, bool rendered, bool onlyFirst)
|
||||
int CSimulatedAircraftList::setAircraftSituation(const CCallsign &callsign, const CAircraftSituation &situation, bool onlyFirst)
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setRendered(rendered);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setSituation(situation); // also sets setSupportingGndFlag
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int CSimulatedAircraftList::setCG(const CCallsign &callsign, const CLength &cg, bool onlyFirst)
|
||||
int CSimulatedAircraftList::setGroundElevationChecked(const CCallsign &callsign, const CElevationPlane &elevation, CAircraftSituation::GndElevationInfo info, bool onlyFirst)
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setCG(cg);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setGroundElevationChecked(elevation, info);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int CSimulatedAircraftList::setFastPositionUpdates(const CCallsign &callsign, bool fastPositions, bool onlyFirst)
|
||||
bool CSimulatedAircraftList::isEnabled(const CCallsign &callsign) const
|
||||
{
|
||||
for (const CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setFastPositionUpdates(fastPositions);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
return aircraft.isEnabled();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int CSimulatedAircraftList::setEnabled(const CCallsign &callsign, bool enabled, bool onlyFirst)
|
||||
bool CSimulatedAircraftList::isRendered(const CCallsign &callsign) const
|
||||
{
|
||||
for (const CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setEnabled(enabled);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
return aircraft.isRendered();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int CSimulatedAircraftList::setAircraftModel(const CCallsign &callsign, const CAircraftModel &model, bool onlyFirst)
|
||||
bool CSimulatedAircraftList::replaceOrAddByCallsign(const CSimulatedAircraft &aircraft)
|
||||
{
|
||||
const CCallsign cs(aircraft.getCallsign());
|
||||
if (cs.isEmpty()) { return false; }
|
||||
|
||||
if (this->containsCallsign(cs))
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setModel(model);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
int c = this->replaceIf(&CSimulatedAircraft::getCallsign, cs, aircraft);
|
||||
return c > 0;
|
||||
}
|
||||
this->push_back(aircraft);
|
||||
return true;
|
||||
}
|
||||
|
||||
int CSimulatedAircraftList::setAircraftPartsSynchronized(const CCallsign &callsign, const CAircraftParts &parts, bool onlyFirst)
|
||||
int CSimulatedAircraftList::countEnabled() const
|
||||
{
|
||||
int c = 0;
|
||||
for (const CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setParts(parts);
|
||||
aircraft.setPartsSynchronized(true);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
if (aircraft.isEnabled()) { c++; }
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int CSimulatedAircraftList::setAircraftSituation(const CCallsign &callsign, const CAircraftSituation &situation, bool onlyFirst)
|
||||
int CSimulatedAircraftList::countRendered() const
|
||||
{
|
||||
int c = 0;
|
||||
for (const CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setSituation(situation); // also sets setSupportingGndFlag
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
if (aircraft.isRendered()) { c++; }
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int CSimulatedAircraftList::setGroundElevationChecked(const CCallsign &callsign, const CElevationPlane &elevation, CAircraftSituation::GndElevationInfo info, bool onlyFirst)
|
||||
int CSimulatedAircraftList::countAircraftPartsSynchronized() const
|
||||
{
|
||||
int c = 0;
|
||||
for (const CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
int c = 0;
|
||||
for (CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
aircraft.setGroundElevationChecked(elevation, info);
|
||||
c++;
|
||||
if (onlyFirst) break;
|
||||
}
|
||||
return c;
|
||||
if (aircraft.isPartsSynchronized()) { c++; }
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
bool CSimulatedAircraftList::isEnabled(const CCallsign &callsign) const
|
||||
void CSimulatedAircraftList::sortByDistanceToReferencePositionRenderedCallsign()
|
||||
{
|
||||
this->sort([ & ](const CSimulatedAircraft & a, const CSimulatedAircraft & b)
|
||||
{
|
||||
for (const CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
return aircraft.isEnabled();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSimulatedAircraftList::isRendered(const CCallsign &callsign) const
|
||||
{
|
||||
for (const CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (aircraft.getCallsign() != callsign) { continue; }
|
||||
return aircraft.isRendered();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CSimulatedAircraftList::replaceOrAddByCallsign(const CSimulatedAircraft &aircraft)
|
||||
{
|
||||
const CCallsign cs(aircraft.getCallsign());
|
||||
if (cs.isEmpty()) { return false; }
|
||||
|
||||
if (this->containsCallsign(cs))
|
||||
{
|
||||
int c = this->replaceIf(&CSimulatedAircraft::getCallsign, cs, aircraft);
|
||||
return c > 0;
|
||||
}
|
||||
this->push_back(aircraft);
|
||||
return true;
|
||||
}
|
||||
|
||||
int CSimulatedAircraftList::countEnabled() const
|
||||
{
|
||||
int c = 0;
|
||||
for (const CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (aircraft.isEnabled()) { c++; }
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int CSimulatedAircraftList::countRendered() const
|
||||
{
|
||||
int c = 0;
|
||||
for (const CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (aircraft.isRendered()) { c++; }
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int CSimulatedAircraftList::countAircraftPartsSynchronized() const
|
||||
{
|
||||
int c = 0;
|
||||
for (const CSimulatedAircraft &aircraft : (*this))
|
||||
{
|
||||
if (aircraft.isPartsSynchronized()) { c++; }
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
void CSimulatedAircraftList::sortByDistanceToReferencePositionRenderedCallsign()
|
||||
{
|
||||
this->sort([ & ](const CSimulatedAircraft & a, const CSimulatedAircraft & b)
|
||||
{
|
||||
if (a.getRelativeDistance() != b.getRelativeDistance()) { return a.getRelativeDistance() < b.getRelativeDistance(); }
|
||||
if (a.isRendered() != b.isRendered()) { return a.isRendered(); } // get the rendered first
|
||||
return a.getCallsignAsString() < b.getCallsignAsString();
|
||||
});
|
||||
}
|
||||
} // namespace
|
||||
if (a.getRelativeDistance() != b.getRelativeDistance()) { return a.getRelativeDistance() < b.getRelativeDistance(); }
|
||||
if (a.isRendered() != b.isRendered()) { return a.isRendered(); } // get the rendered first
|
||||
return a.getCallsignAsString() < b.getCallsignAsString();
|
||||
});
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user