mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-03 16:25:54 +08:00
refs #784 Use CMemoTable to implement a compact JSON schema for CAircraftModelList.
This commit is contained in:
committed by
Klaus Basan
parent
f6f2d38821
commit
45bb9a2737
@@ -109,6 +109,28 @@ namespace BlackMisc
|
|||||||
return QJsonDocument(this->toDatabaseJson()).toJson(format);
|
return QJsonDocument(this->toDatabaseJson()).toJson(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonObject CAircraftModel::toMemoizedJson(MemoHelper::CMemoizer &helper) const
|
||||||
|
{
|
||||||
|
QJsonObject json;
|
||||||
|
auto meta = introspect<CAircraftModel>().without(MetaFlags<DisabledForJson>());
|
||||||
|
meta.forEachMemberName(*this, [ & ](const auto & member, CExplicitLatin1String name)
|
||||||
|
{
|
||||||
|
auto &&maybeMemo = helper.maybeMemoize(member);
|
||||||
|
json << std::make_pair(name.toJsonKey(), std::cref(maybeMemo));
|
||||||
|
});
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAircraftModel::convertFromMemoizedJson(const QJsonObject &json, const MemoHelper::CUnmemoizer &helper)
|
||||||
|
{
|
||||||
|
auto meta = introspect<CAircraftModel>().without(MetaFlags<DisabledForJson>());
|
||||||
|
meta.forEachMemberName(*this, [ & ](auto & member, CExplicitLatin1String name)
|
||||||
|
{
|
||||||
|
auto it = json.find(name);
|
||||||
|
if (it != json.end()) { it.value() >> helper.maybeUnmemoize(member).get(); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
QString CAircraftModel::asHtmlSummary() const
|
QString CAircraftModel::asHtmlSummary() const
|
||||||
{
|
{
|
||||||
const QString html = "Model: %1<br>Aircraft ICAO: %2<br>Livery: %3";
|
const QString html = "Model: %1<br>Aircraft ICAO: %2<br>Livery: %3";
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#include "blackmisc/blackmiscexport.h"
|
#include "blackmisc/blackmiscexport.h"
|
||||||
#include "blackmisc/db/datastore.h"
|
#include "blackmisc/db/datastore.h"
|
||||||
#include "blackmisc/dictionary.h"
|
#include "blackmisc/dictionary.h"
|
||||||
|
#include "blackmisc/memotable.h"
|
||||||
#include "blackmisc/metaclass.h"
|
#include "blackmisc/metaclass.h"
|
||||||
#include "blackmisc/metaclassprivate.h"
|
#include "blackmisc/metaclassprivate.h"
|
||||||
#include "blackmisc/orderable.h"
|
#include "blackmisc/orderable.h"
|
||||||
@@ -340,6 +341,15 @@ namespace BlackMisc
|
|||||||
//! Validate
|
//! Validate
|
||||||
BlackMisc::CStatusMessageList validate(bool withNestedObjects) const;
|
BlackMisc::CStatusMessageList validate(bool withNestedObjects) const;
|
||||||
|
|
||||||
|
//! Helper class used by implementation.
|
||||||
|
using MemoHelper = CMemoHelper<Aviation::CAircraftIcaoCode, Aviation::CLivery, CDistributor>;
|
||||||
|
|
||||||
|
//! To JSON with memoized members (used by CAircraftModelList)
|
||||||
|
QJsonObject toMemoizedJson(MemoHelper::CMemoizer &) const;
|
||||||
|
|
||||||
|
//! From JSON with memoized members (used by CAircraftModelList)
|
||||||
|
void convertFromMemoizedJson(const QJsonObject &json, const MemoHelper::CUnmemoizer &);
|
||||||
|
|
||||||
//! To database JSON
|
//! To database JSON
|
||||||
QJsonObject toDatabaseJson() const;
|
QJsonObject toDatabaseJson() const;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
#include "blackmisc/aviation/livery.h"
|
#include "blackmisc/aviation/livery.h"
|
||||||
#include "blackmisc/compare.h"
|
#include "blackmisc/compare.h"
|
||||||
#include "blackmisc/iterator.h"
|
#include "blackmisc/iterator.h"
|
||||||
#include "blackmisc/metaclassprivate.h"
|
|
||||||
#include "blackmisc/range.h"
|
#include "blackmisc/range.h"
|
||||||
#include "blackmisc/statusmessage.h"
|
#include "blackmisc/statusmessage.h"
|
||||||
|
|
||||||
@@ -614,6 +613,38 @@ namespace BlackMisc
|
|||||||
return msgs;
|
return msgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonObject CAircraftModelList::toMemoizedJson() const
|
||||||
|
{
|
||||||
|
CAircraftModel::MemoHelper::CMemoizer helper;
|
||||||
|
QJsonArray array;
|
||||||
|
for (auto it = cbegin(); it != cend(); ++it)
|
||||||
|
{
|
||||||
|
array << it->toMemoizedJson(helper);
|
||||||
|
}
|
||||||
|
QJsonObject json;
|
||||||
|
json.insert("containerbase", array);
|
||||||
|
json.insert("aircraftIcaos", helper.getTable<CAircraftIcaoCode>().toJson());
|
||||||
|
json.insert("liveries", helper.getTable<CLivery>().toJson());
|
||||||
|
json.insert("distributors", helper.getTable<CDistributor>().toJson());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CAircraftModelList::convertFromMemoizedJson(const QJsonObject &json)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
QJsonArray array = json.value("containerbase").toArray();
|
||||||
|
CAircraftModel::MemoHelper::CUnmemoizer helper;
|
||||||
|
helper.getTable<CAircraftIcaoCode>().convertFromJson(json.value("aircraftIcaos").toObject());
|
||||||
|
helper.getTable<CLivery>().convertFromJson(json.value("liveries").toObject());
|
||||||
|
helper.getTable<CDistributor>().convertFromJson(json.value("distributors").toObject());
|
||||||
|
for (auto i = array.begin(); i != array.end(); ++i)
|
||||||
|
{
|
||||||
|
CAircraftModel value;
|
||||||
|
value.convertFromMemoizedJson(i->toObject(), helper);
|
||||||
|
insert(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QJsonArray CAircraftModelList::toDatabaseJson() const
|
QJsonArray CAircraftModelList::toDatabaseJson() const
|
||||||
{
|
{
|
||||||
QJsonArray array;
|
QJsonArray array;
|
||||||
|
|||||||
@@ -216,6 +216,12 @@ namespace BlackMisc
|
|||||||
//! Validate distributors
|
//! Validate distributors
|
||||||
CStatusMessageList validateDistributors(const BlackMisc::Simulation::CDistributorList &distributors, CAircraftModelList &validModels, CAircraftModelList &invalidModels) const;
|
CStatusMessageList validateDistributors(const BlackMisc::Simulation::CDistributorList &distributors, CAircraftModelList &validModels, CAircraftModelList &invalidModels) const;
|
||||||
|
|
||||||
|
//! To compact JSON format
|
||||||
|
QJsonObject toMemoizedJson() const;
|
||||||
|
|
||||||
|
//! From compact JSON format
|
||||||
|
void convertFromMemoizedJson(const QJsonObject &json);
|
||||||
|
|
||||||
//! To database JSON
|
//! To database JSON
|
||||||
QJsonArray toDatabaseJson() const;
|
QJsonArray toDatabaseJson() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user