swift
Loading...
Searching...
No Matches
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
5
6using namespace swift::misc::network;
7
8SWIFT_DEFINE_SEQUENCE_MIXINS(swift::misc::db, CDbInfo, CDbInfoList)
9
10namespace swift::misc::db
11{
13
14 CDbInfo CDbInfoList::findFirstByEntityOrDefault(CEntityFlags::Entity entity) const
15 {
16 for (const CDbInfo &info : *this)
17 {
18 if (info.matchesEntity(entity))
19 {
20 return info;
21 }
22 }
23 return {};
24 }
25
27 {
28 CDbInfoList infoObjects;
29 for (const QJsonValue &value : array)
30 {
31 const CDbInfo info(CDbInfo::fromDatabaseJson(value.toObject()));
32 infoObjects.push_back(info);
33 }
34 infoObjects.sortByKey(); // make sure the data are in proper order
35 return infoObjects;
36 }
37} // namespace swift::misc::db
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition sequence.h:308
Info about the latest models.
Definition dbinfo.h:22
bool matchesEntity(network::CEntityFlags::Entity entity) const
Matches given entity.
Definition dbinfo.cpp:49
static CDbInfo fromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
From our database JSON format.
Definition dbinfo.cpp:132
CSequence()=default
Default constructor.
CDbInfoList()=default
Default constructor.
static CDbInfoList fromDatabaseJson(const QJsonArray &array)
From our database JSON format.
CDbInfo findFirstByEntityOrDefault(swift::misc::network::CEntityFlags::Entity entity) const
Find by entity.
#define SWIFT_DEFINE_SEQUENCE_MIXINS(Namespace, T, List)
Explicit template definition of mixins for a CSequence subclass.
Definition sequence.h:63