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() {}
13 
14  CDbInfoList::CDbInfoList(const CSequence<CDbInfo> &other) : CSequence<CDbInfo>(other) {}
15 
16  CDbInfo CDbInfoList::findFirstByEntityOrDefault(CEntityFlags::Entity entity) const
17  {
18  for (const CDbInfo &info : *this)
19  {
20  if (info.matchesEntity(entity)) { return info; }
21  }
22  return CDbInfo();
23  }
24 
25  CDbInfoList CDbInfoList::fromDatabaseJson(const QJsonArray &array)
26  {
27  CDbInfoList infoObjects;
28  for (const QJsonValue &value : array)
29  {
30  const CDbInfo info(CDbInfo::fromDatabaseJson(value.toObject()));
31  infoObjects.push_back(info);
32  }
33  infoObjects.sortByKey(); // make sure the data are in proper order
34  return infoObjects;
35  }
36 } // 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:25
CDbInfo findFirstByEntityOrDefault(swift::misc::network::CEntityFlags::Entity entity) const
Find by entity.
Definition: dbinfolist.cpp:16
#define SWIFT_DEFINE_SEQUENCE_MIXINS(Namespace, T, List)
Explicit template definition of mixins for a CSequence subclass.
Definition: sequence.h:63