mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
refs #321 Methods to read/write aircraft config packets from/to network
This commit is contained in:
committed by
Klaus Basan
parent
a3e13db2ae
commit
466a9a24ef
@@ -372,3 +372,42 @@ bool BlackMisc::Audio::startWindowsMixer()
|
||||
QStringList parameterlist;
|
||||
return QProcess::startDetached("SndVol.exe", parameterlist);
|
||||
}
|
||||
|
||||
QJsonObject BlackMisc::getIncrementalObject(const QJsonObject &previousObject, const QJsonObject ¤tObject)
|
||||
{
|
||||
QJsonObject incrementalObject = currentObject;
|
||||
for (const auto &key : previousObject.keys())
|
||||
{
|
||||
if (previousObject.value(key).isObject())
|
||||
{
|
||||
auto child = getIncrementalObject(previousObject.value(key).toObject(), currentObject.value(key).toObject());
|
||||
if (child.isEmpty()) incrementalObject.remove(key);
|
||||
else incrementalObject.insert(key, child);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentObject.value(key) == previousObject.value(key))
|
||||
incrementalObject.remove(key);
|
||||
}
|
||||
}
|
||||
return incrementalObject;
|
||||
}
|
||||
|
||||
QJsonObject BlackMisc::applyIncrementalObject(const QJsonObject &previousObject, const QJsonObject &incrementalObject)
|
||||
{
|
||||
QJsonObject currentObject = previousObject;
|
||||
for(const auto &key : incrementalObject.keys())
|
||||
{
|
||||
// If it is not an object, just insert the value
|
||||
if (!incrementalObject.value(key).isObject())
|
||||
{
|
||||
currentObject.insert(key,incrementalObject.value(key));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto child = applyIncrementalObject(currentObject.value(key).toObject(), incrementalObject.value(key).toObject());
|
||||
currentObject.insert(key, child);
|
||||
}
|
||||
}
|
||||
return currentObject;
|
||||
}
|
||||
|
||||
@@ -184,6 +184,14 @@ namespace BlackMisc
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
//! Creates an incremental json object from two existing objects
|
||||
QJsonObject getIncrementalObject(const QJsonObject &previousObject, const QJsonObject ¤tObject);
|
||||
|
||||
//! Merges an incremental json object into an existing one
|
||||
QJsonObject applyIncrementalObject(const QJsonObject &previousObject, const QJsonObject &incrementalObject);
|
||||
|
||||
|
||||
|
||||
} // BlackMisc
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user