/* Copyright (C) 2015 * swift Project Community / Contributors * * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, * including this file, may be copied, modified, propagated, or distributed except according to the terms * contained in the LICENSE file. */ #include "blackmisc/avcallsignobjectlist.h" #include "blackmisc/predicates.h" #include "blackmisc/avatcstationlist.h" #include "blackmisc/avaircraftlist.h" #include "blackmisc/avaircraftsituationlist.h" #include "blackmisc/nwclientlist.h" #include "blackmisc/simulation/simulatedaircraftlist.h" namespace BlackMisc { namespace Aviation { template ICallsignObjectList::ICallsignObjectList() { } template bool ICallsignObjectList::containsCallsign(const CCallsign &callsign) const { return this->getContainer().contains(&OBJ::getCallsign, callsign); } template int ICallsignObjectList::applyIfCallsign(const CCallsign &callsign, const CPropertyIndexVariantMap &variantMap) { return this->getContainer().applyIf(&OBJ::getCallsign, callsign, variantMap); } template CONTAINER ICallsignObjectList::findByCallsign(const CCallsign &callsign) const { return this->getContainer().findBy(&OBJ::getCallsign, callsign); } template CONTAINER ICallsignObjectList::findByCallsigns(const CCallsignList &callsigns) const { return this->getContainer().findBy(Predicates::MemberIsAnyOf(&OBJ::getCallsign, callsigns)); } template OBJ ICallsignObjectList::findFirstByCallsign(const CCallsign &callsign, const OBJ &ifNotFound) const { return this->findByCallsign(callsign).frontOrDefault(ifNotFound); } template OBJ ICallsignObjectList::findBackByCallsign(const CCallsign &callsign, const OBJ &ifNotFound) const { return this->findByCallsign(callsign).backOrDefault(ifNotFound); } template CONTAINER ICallsignObjectList::findBySuffix(const QString &suffix) const { CONTAINER r; if (suffix.isEmpty()) { return r; } QString sfxUpper(suffix.trimmed().toUpper()); r = this->getContainer().findBy([ = ](const OBJ & csObj) -> bool { return (csObj.getCallsign().getSuffix() == sfxUpper); }); return r; } template int ICallsignObjectList::removeByCallsign(const CCallsign &callsign) { return this->getContainer().removeIf(&OBJ::getCallsign, callsign); } template QMap ICallsignObjectList::getSuffixes() const { QMap r; for (const OBJ &csObj : this->getContainer()) { const QString s = csObj.getCallsign().getSuffix(); if (s.isEmpty()) { continue; } if (r.contains(s)) { r[s] = r[s] + 1; } else { r.insert(s, 1); } } return r; } template int ICallsignObjectList::incrementalUpdateOrAdd(const OBJ &objectBeforeChanges, const CPropertyIndexVariantMap &changedValues) { int c; const CCallsign cs = objectBeforeChanges.getCallsign(); if (this->containsCallsign(cs)) { if (changedValues.isEmpty()) { return 0; } c = this->getContainer().applyIf(&OBJ::getCallsign, cs, changedValues); } else { c = 1; if (changedValues.isEmpty()) { this->getContainer().push_back(objectBeforeChanges); } else { OBJ objectAdded(objectBeforeChanges); objectAdded.apply(changedValues); this->getContainer().push_back(objectAdded); } } return c; } // see here for the reason of thess forward instantiations // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class ICallsignObjectList; template class ICallsignObjectList; template class ICallsignObjectList; template class ICallsignObjectList; template class ICallsignObjectList; } // namespace } // namespace