Ref T267, allow to call "convertFromMemoizedJson", but also convert via "convertFromJson"

The variant convertFromMemoizedJson trait did already do something similar, calling "convertFromJson" if the memoized version is not avilable. Now the function also "decides" based on the passed data itself.
This commit is contained in:
Klaus Basan
2018-05-15 02:53:35 +02:00
parent 98bc0a7d6e
commit 50a625d2bc
6 changed files with 37 additions and 19 deletions

View File

@@ -977,7 +977,7 @@ namespace BlackMisc
return json;
}
void CAircraftModelList::convertFromMemoizedJson(const QJsonObject &json)
void CAircraftModelList::convertFromMemoizedJson(const QJsonObject &json, bool fallbackToConvertToJson)
{
clear();
QJsonValue value = json.value("containerbase");
@@ -988,9 +988,25 @@ namespace BlackMisc
const QJsonValue aircraftIcaos = json.value("aircraftIcaos");
const QJsonValue liveries = json.value("liveries");
const QJsonValue distributors = json.value("distributors");
if (aircraftIcaos.isUndefined()) { throw CJsonException("Missing 'aircraftIcaos'"); }
if (liveries.isUndefined()) { throw CJsonException("Missing 'liveries'"); }
if (distributors.isUndefined()) { throw CJsonException("Missing 'distributors'"); }
const bool undefAc = aircraftIcaos.isUndefined();
const bool undefLiv = liveries.isUndefined();
const bool undefDist = distributors.isUndefined();
const bool undefAll = undefAc && undefDist && undefLiv;
if (fallbackToConvertToJson && undefAll)
{
this->convertFromJson(json);
return;
}
else
{
if (undefAc) { throw CJsonException("Missing 'aircraftIcaos'"); }
if (undefLiv) { throw CJsonException("Missing 'liveries'"); }
if (undefDist) { throw CJsonException("Missing 'distributors'"); }
}
// convert
{
CJsonScope scope("aircraftIcaos");
Q_UNUSED(scope);