6 #ifndef SWIFT_MISC_AVIATION_CALLSIGNOBJECTLIST_H
7 #define SWIFT_MISC_AVIATION_CALLSIGNOBJECTLIST_H
17 namespace swift::misc::aviation
20 template <
class OBJ,
class CONTAINER>
27 return this->
container().contains(&OBJ::getCallsign, callsign);
32 bool skipEqualValues =
true)
34 return this->
container().applyIf(&OBJ::getCallsign, callsign, variantMap, skipEqualValues);
54 if (this->
container().isEmpty()) {
return QString(); }
56 return callsigns.join(separator);
62 return this->
container().findBy(&OBJ::getCallsign, callsign);
74 return this->
container().findFirstByOrDefault(&OBJ::getCallsign, callsign, ifNotFound);
83 if (current->getCallsign() == callsign) {
return *current; }
92 if (suffix.isEmpty()) {
return r; }
93 const QString sfxUpper(suffix.trimmed().toUpper());
95 [=](
const OBJ &csObj) {
return (csObj.getCallsign().getSuffix() == sfxUpper); });
102 for (
int i = 0; i < this->
container().size(); i++)
104 if (this->
container()[i].getCallsign() == callsign) {
return i; }
112 return this->
container().removeIf(&OBJ::getCallsign, callsign);
118 return this->
container().removeIf([&](
const OBJ &obj) {
return callsigns.
contains(obj.getCallsign()); });
126 for (
const OBJ &csObj : this->
container())
128 const QString s = csObj.getCallsign().getSuffix();
129 if (s.isEmpty()) {
continue; }
130 if (r.contains(s)) { r[s] = r[s] + 1; }
131 else { r.insert(s, 1); }
140 QStringList suffixes;
141 for (
const OBJ &csObj : this->
container())
143 const QString s = csObj.getCallsign().getSuffix();
144 if (s.isEmpty() || suffixes.contains(s, Qt::CaseInsensitive)) {
continue; }
154 copyContainer.sortByCallsign();
157 for (
const OBJ &csObj : copyContainer)
159 if (csObj.getCallsign().isEmpty())
164 if (cs != csObj.getCallsign())
166 cs = csObj.getCallsign();
167 CONTAINER perCallsign({ csObj });
168 result.insert(cs, perCallsign);
170 else { result[cs].push_back(csObj); }
178 const CCallsign cs(otherObject.getCallsign());
179 if (cs.
isEmpty()) {
return 0; }
181 copy.removeByCallsign(cs);
182 copy.push_back(otherObject);
189 if (others.isEmpty()) {
return 0; }
192 for (
const OBJ &obj : others)
195 if (cs.
isEmpty()) {
continue; }
196 copy.removeByCallsign(cs);
208 const CCallsign cs = objectBeforeChanges.getCallsign();
211 if (changedValues.
isEmpty()) {
return 0; }
212 c = this->
container().applyIf(&OBJ::getCallsign, cs, changedValues);
217 if (changedValues.
isEmpty()) { this->
container().push_back(objectBeforeChanges); }
220 OBJ objectAdded(objectBeforeChanges);
221 objectAdded.apply(changedValues);
222 this->
container().push_back(objectAdded);
235 for (
const OBJ &obj : this->
container()) { map.insert(obj.getCallsign(), obj); }
245 if (obj.getCallsign().isEmpty()) {
continue; }
246 hash.insert(obj.getCallsign(), obj);
255 copy.sortByCallsign();
264 const CONTAINER &
container()
const {
return static_cast<const CONTAINER &
>(*this); }
267 CONTAINER &
container() {
return static_cast<CONTAINER &
>(*this); }
iterator push_back(const T &value)
Synonym for insert.
Specialized value object compliant map for variants, based on indexes.
bool isEmpty() const
Is empty?
bool contains(const T &object) const
Return true if there is an element equal to given object. Uses the most efficient implementation avai...
Value object encapsulating information of a callsign.
bool isEmpty() const
Is empty?
Value object for a set of callsigns.
QStringList getCallsignStrings(bool sorted=false) const
The callsign strings.
List of objects with callsign.
int removeByCallsigns(const CCallsignSet &callsigns)
Remove all objects with callsigns.
int firstIndexOfCallsign(const CCallsign &callsign)
First found index of callsign, otherwise -1.
int replaceOrAddObjectsByCallsign(const CONTAINER &others)
Replace or add objects by callsign.
CONTAINER findByCallsign(const CCallsign &callsign) const
Find 0..n stations by callsign.
OBJ findLastByCallsign(const CCallsign &callsign, const OBJ &ifNotFound={}) const
Find the back object by callsign, if none return given one.
const CONTAINER & container() const
Container.
OBJ findFirstByCallsign(const CCallsign &callsign, const OBJ &ifNotFound={}) const
Find the first aircraft by callsign, if none return given one.
QMap< QString, int > getSuffixesAndCount() const
All suffixes with their respective count.
QHash< CCallsign, CONTAINER > splitPerCallsign() const
Split into 0..n containers as per callsign.
int applyIfCallsign(const CCallsign &callsign, const CPropertyIndexVariantMap &variantMap, bool skipEqualValues=true)
Apply for given callsign.
ICallsignObjectList()
Constructor.
QStringList getSuffixes() const
All suffixes, in the order of the list.
CONTAINER & container()
Container.
CONTAINER findBySuffix(const QString &suffix) const
All with given suffix, empty suffixes ignored.
int removeByCallsign(const CCallsign &callsign)
Remove all objects with callsign.
int replaceOrAddObjectByCallsign(const OBJ &otherObject)
Replace or add objects by callsign.
CONTAINER sortedByCallsign() const
Copy of list sorted by callsign.
int incrementalUpdateOrAdd(const OBJ &objectBeforeChanges, const CPropertyIndexVariantMap &changedValues)
Incremental update or add object.
void sortByCallsign()
Sort by callsign.
QString getCallsignsAsString(const QString &separator, bool sorted=false) const
Get callsigns as strings.
swift::misc::aviation::CCallsignSet getCallsigns() const
All callsigns.
bool containsCallsign(const CCallsign &callsign) const
Contains callsign?
CONTAINER findByCallsigns(const CCallsignSet &callsigns) const
Find 0..n aircraft matching any of a set of callsigns.
QHash< CCallsign, OBJ > asCallsignHash() const
Turn into callsign hash.
QMap< CCallsign, OBJ > asCallsignMap() const
Turn into callsign map.
QStringList getCallsignStrings(bool sorted=false) const
Get callsign string list.
auto MemberIsAnyOf(T memberFunc, const C &container)
Returns a predicate that returns true if the value returned by its argument's member function can be ...
T::const_iterator end(const LockFreeReader< T > &reader)
Non-member begin() and end() for so LockFree containers can be used in ranged for loops.