swift
dbinfolist.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #include "misc/db/dbinfolist.h"
5 
6 using namespace swift::misc::network;
7 
8 SWIFT_DEFINE_SEQUENCE_MIXINS(swift::misc::db, CDbInfo, CDbInfoList)
9 
10 namespace swift::misc::db
11 {
12  CDbInfoList::CDbInfoList(const CSequence<CDbInfo> &other) : CSequence<CDbInfo>(other) {}
13 
14  CDbInfo CDbInfoList::findFirstByEntityOrDefault(CEntityFlags::Entity entity) const
15  {
16  for (const CDbInfo &info : *this)
17  {
18  if (info.matchesEntity(entity)) { return info; }
19  }
20  return {};
21  }
22 
24  {
25  CDbInfoList infoObjects;
26  for (const QJsonValue &value : array)
27  {
28  const CDbInfo info(CDbInfo::fromDatabaseJson(value.toObject()));
29  infoObjects.push_back(info);
30  }
31  infoObjects.sortByKey(); // make sure the data are in proper order
32  return infoObjects;
33  }
34 } // namespace swift::misc::db
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition: sequence.h:305
Info about the latest models.
Definition: dbinfo.h:22
bool matchesEntity(network::CEntityFlags::Entity entity) const
Matches given entity.
Definition: dbinfo.cpp:46
static CDbInfo fromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
From our database JSON format.
Definition: dbinfo.cpp:120
Value object encapsulating a list of info objects.
Definition: dbinfolist.h:27
static CDbInfoList fromDatabaseJson(const QJsonArray &array)
From our database JSON format.
Definition: dbinfolist.cpp:23
CDbInfo findFirstByEntityOrDefault(swift::misc::network::CEntityFlags::Entity entity) const
Find by entity.
Definition: dbinfolist.cpp:14
#define SWIFT_DEFINE_SEQUENCE_MIXINS(Namespace, T, List)
Explicit template definition of mixins for a CSequence subclass.
Definition: sequence.h:63