Adapts shared tests and common code to generated rtiddsgen API

Updates test suites and Lts/Common consumers to plain member access.
This commit is contained in:
berrux-dev committed 2026-09-21 02:44:07 +02:00
1 parent cf62b17d58
commit e8d07af320
41 files changed
+1076 -235

No files matched your search

@@ -43,7 +43,8 @@ QString DataTopicWrapper::typeFq() const
QString MemberInformationWrapper::ddsToQVariant() const
{
return QStringLiteral("toQVariant(data.") + cppMemberName() + QStringLiteral("())");
// rtiddsgen 7.7 generates plain public members - access them directly.
return QStringLiteral("toQVariant(data.") + cppMemberName() + QStringLiteral(")");
}
QString MemberInformationWrapper::qVariantToDds() const
@@ -51,7 +52,7 @@ QString MemberInformationWrapper::qVariantToDds() const
const QString ddsType =
isOptional() ? (QStringLiteral("dds::core::optional<") + cppDdsType() + QLatin1Char('>')) : (cppDdsType());
return QStringLiteral("data.") + cppMemberName() + QStringLiteral("() = fromQVariant<") + ddsType +
return QStringLiteral("data.") + cppMemberName() + QStringLiteral(" = fromQVariant<") + ddsType +
QStringLiteral(">(q.value(i++))");
}
@@ -61,14 +62,15 @@ QString MemberInformationWrapper::ddsToJsonElement() const
if (cppMemberName().isEmpty())
return QStringLiteral("obj[QStringLiteral(\"") + cppType() + QStringLiteral("\")] = element;");
const QString memberAccess = isCppStruct() ? cppMemberName() : cppMemberName() + QStringLiteral("()");
// rtiddsgen 7.7 generates plain public members for every kind of
// member (struct or not), so no getter call is emitted.
const QString memberAccess = cppMemberName();
if (!isOptional())
return QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") + cppToJsonPre() +
QStringLiteral("element.") + memberAccess + cppToJsonPost();
const QString optionalAccess =
isCppStruct() ? cppMemberName() + QStringLiteral(".is_set()") : cppMemberName() + QStringLiteral("().is_set()");
const QString getValue = isCppStruct() ? cppMemberName() : cppMemberName() + QStringLiteral("()");
const QString optionalAccess = cppMemberName() + QStringLiteral(".is_set()");
const QString getValue = cppMemberName();
return QStringLiteral("if (element.") + optionalAccess + QStringLiteral(") ") +
QStringLiteral("obj[QStringLiteral(\"") + cppMemberName() + QStringLiteral("\")] = ") + cppToJsonPre() +
QStringLiteral("*element.") + getValue + cppToJsonPost();
@@ -86,12 +88,10 @@ QString MemberInformationWrapper::jsonElementToDds() const
if (isOptional())
ret += QStringLiteral("if (!val.isNull()) ");
if (isCppStruct())
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral(" = ") + cppFromJsonPre2() +
QStringLiteral("val") + cppFromJsonPost();
else
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral("(") + cppFromJsonPre2() +
QStringLiteral("val") + cppFromJsonPost() + QStringLiteral(")");
// rtiddsgen 7.7 generates plain public members - assign instead of
// calling a setter.
ret += QStringLiteral("element.") + cppMemberName() + QStringLiteral(" = ") + cppFromJsonPre2() +
QStringLiteral("val") + cppFromJsonPost();
return ret;
}
@@ -874,6 +874,13 @@ bool StructBuilder::fixupQVariantConversions(MemberInformation& mi) const
datatype == QLatin1String("long long"))
{
mi.cpp.type = QStringLiteral("qint64");
// IDL `long long` is int64_t (long) in the rtiddsgen 4.7 output, while the Qt side is
// qint64 (long long). Those are distinct types, so assignments such as
// `optional<int64_t> = optional<qint64>` do not compile. Carry the generated type
// separately, as the sequence<octet> branch below already does, so the DDS-facing code
// emitted from cppDdsType() names the type the struct member really has. The spelling
// is the one rtiddsgen itself writes, matching what the `long` branch does with int32_t.
mi.cpp.ddsType = QStringLiteral("int64_t");
mi.cpp.fromVariantPost = QStringLiteral(".toLongLong()");
mi.cpp.fromJsonPost = QStringLiteral(".toDouble()");
mi.cpp.toJsonPre = QStringLiteral("static_cast<qint64>(");
@@ -1039,7 +1046,7 @@ QVector<MemberInformation> StructBuilder::buildDbTableInformationFromIdlData(con
pre += columnNamePrefix;
pre += member.name + QLatin1Char('_');
ret += buildDbTableInformationFromIdlData(cttiChild, tableName, StructBuilder::camelCaseToUnderline(pre),
cppStructure + member.name + QStringLiteral("()."));
cppStructure + member.name + QStringLiteral("."));
continue;
}
@@ -48,6 +48,18 @@ QJsonValue toJson(qint64 vec)
{
return QJsonValue(QString::number(vec));
}
// IDL 64-bit integers map to int64_t, which is 'long' on LP64 and therefore
// distinct from qint64 ('long long'); without this overload the generic
// toJson(std::vector<T>) is ambiguous for sequence<int64_t> members.
QJsonValue toJson(long vec)
{
return QJsonValue(QString::number(vec));
}
template<>
long fromJson(const QJsonValue &val, type<long>)
{
return val.toString().toLong();
}
// std::string
QJsonValue toJson(const std::string &element)
@@ -198,6 +198,17 @@ long long fromQVariant(const QVariant &val, type<long long>)
return val.toLongLong();
}
// rtiddsgen 4.7 spells the 64 bit integer members int64_t, which is `long` on LP64 and thus
// a different type from the Qt side's qint64 (`long long`). The tag dispatch above is keyed on
// the exact type, so the generated type needs its own conversion even though the two are the
// same width. GrantleeWrappers::cppDdsType() names the generated member type, so this is the
// overload the record replay code instantiates for those members.
template<>
int64_t fromQVariant(const QVariant &val, type<int64_t>)
{
return static_cast<int64_t>(val.toLongLong());
}
template<>
double fromQVariant(const QVariant &val, type<double>)
{
@@ -555,7 +566,7 @@ bool RecordReplayPlugin::write{{ dt.name }}(NSqlQuery &q, QHash<QString, qint64>
for (const auto &sample : samples)
{
const DATA &data = sample.data();
INFO_LOG(m_logger) << "m_dtc{{ dt.name }} {{ dt.recTable.ddsKey.cppMemberName }}: " << data.{{ dt.recTable.ddsKey.cppMemberName }}();
INFO_LOG(m_logger) << "m_dtc{{ dt.name }} {{ dt.recTable.ddsKey.cppMemberName }}: " << data.{{ dt.recTable.ddsKey.cppMemberName }};
{% for row in dt.recTable.cppMember %}
q.bindValue(QStringLiteral(":{{ row.dbColumnName }}"), {{ row.ddsToQVariant }});
@@ -565,7 +576,10 @@ bool RecordReplayPlugin::write{{ dt.name }}(NSqlQuery &q, QHash<QString, qint64>
if (!q.exec())
return false;
minRecordSampleTime = std::min(minRecordSampleTime, data.sampleTime());
// rtiddsgen 4.7 declares sample_time as int64_t (long), while the record
// boundary is qint64 (long long); std::min requires both arguments to be
// the same type, so narrow the generated member explicitly.
minRecordSampleTime = std::min(minRecordSampleTime, static_cast<qint64>(data.sampleTime));
}
}
@@ -645,10 +659,10 @@ bool RecordReplayPlugin::readLastSnapshotFor{{ dt.name }}(NSqlQuery &q, qint64 s
{% endfor %}
if (bIsAlive)
m_{{ dt.nameFlc }}Map.insert(data.sampleTime(), data);
m_{{ dt.nameFlc }}Map.insert(data.sampleTime, data);
else
m_{{ dt.nameFlc }}DisposedMap.insert(data.sampleTime(), data);
m_{{ dt.nameFlc }}Keys.insert(data.{{ dt.key.name }}());
m_{{ dt.nameFlc }}DisposedMap.insert(data.sampleTime, data);
m_{{ dt.nameFlc }}Keys.insert(data.{{ dt.key.name }});
}
m_snapshot{{ dt.name }}MapTime = timeSnapshot;
@@ -677,10 +691,10 @@ bool RecordReplayPlugin::read{{ dt.name }}(NSqlQuery &q, qint64 fromTime, qint64
{% endfor %}
if (bIsAlive)
m_{{ dt.nameFlc }}Map.insert(data.sampleTime(), data);
m_{{ dt.nameFlc }}Map.insert(data.sampleTime, data);
else
m_{{ dt.nameFlc }}DisposedMap.insert(data.sampleTime(), data);
m_{{ dt.nameFlc }}Keys.insert(data.{{ dt.key.name }}());
m_{{ dt.nameFlc }}DisposedMap.insert(data.sampleTime, data);
m_{{ dt.nameFlc }}Keys.insert(data.{{ dt.key.name }});
}
return true;
}
@@ -795,7 +809,7 @@ void RecordReplayPlugin::clearData{{ dt.name }}()
{{ dt.name }} tmpData;
for (auto key : m_{{ dt.nameFlc }}Keys)
{
tmpData.{{ dt.key.name }}(key);
tmpData.{{ dt.key.name }} = key;
m_dts{{ dt.name }}->remove(tmpData);
}
}
@@ -18,8 +18,10 @@
#include <{{ include_prefix }}/{{ namespace_abbr }}_dts_types.h>
#include <{{ include_prefix }}/logger.h>
// TODO: Problem with QT5_WRAP_CPP ...
#include <../../Common/PluginInterfaces/record_replay_plugin.h>
// Resolved from the Lts include root (see include_directories(BEFORE .../Lts)
// in the root CMakeLists); the old <../../Common/...> spelling only worked
// for in-source builds.
#include <Common/PluginInterfaces/record_replay_plugin.h>
#include <LtsUtilsCore/pgarray.h>
@@ -15,8 +15,10 @@
#include <Common/ProjectConfig/project_defines.h>
#include <QtCore/QObject>
// TODO: Problem with QT5_WRAP_CPP ...
#include <../../DDS/Generic/topic_type_plugin.h>
// Resolved from the Lts include root (see include_directories(BEFORE .../Lts)
// in the root CMakeLists); the old <../../DDS/...> spelling only worked for
// in-source builds because moc/gcc do not resolve it relative to this file.
#include <DDS/Generic/topic_type_plugin.h>
namespace {{ namespace }}
{
@@ -2,7 +2,7 @@
#pragma once
#include "ltscoordinate_export.h"
#include <LtsCoordinate/ltscoordinate_export.h>
#include <Core/core.hpp>
#include <LtsCoordTrans/lts_coord_trans.h>
@@ -48,7 +48,7 @@ class LTSCOORDINATE_EXPORT LtsCoordVector
utmVectorRef.reserve(m_geo_coordinates.size());
for (const auto& geoCoord : std::as_const(m_geo_coordinates))
utmVectorRef.push_back(LtsCoordTrans::UtmCoordinate::fromGeographic(geoCoord.lon(), geoCoord.lat(), zone));
utmVectorRef.push_back(LtsCoordTrans::UtmCoordinate::fromGeographic(geoCoord.lon, geoCoord.lat, zone));
}
protected:
@@ -29,13 +29,13 @@ double LtsCoordinate::elevationAt(double defaultElevation, bool* bIsCovered) con
if (!std::isnan(m_elevation))
return m_elevation;
if (m_getElevationCB)
m_elevation = m_getElevationCB(m_geo.lon(), m_geo.lat(), defaultElevation, bIsCovered);
m_elevation = m_getElevationCB(m_geo.lon, m_geo.lat, defaultElevation, bIsCovered);
return m_elevation;
}
void LtsCoordinate::setZValueAccordingElevation(double defaultElevation)
{
m_geo.z(elevationAt(defaultElevation));
m_geo.z = elevationAt(defaultElevation);
}
double LtsCoordinate::elevationAt(const LtsCoordinate& coordinate, double defaultElevation, bool* bIsCovered)
@@ -46,7 +46,7 @@ double LtsCoordinate::elevationAt(const LtsCoordinate& coordinate, double defaul
void LtsCoordinate::replaceZValueByElevationIfValue(double zValueToBeReplaced, double defaultElevation)
{
if ((std::isnan(zValueToBeReplaced) && std::isnan(m_geo.z())) || qFuzzyCompare(m_geo.z(), zValueToBeReplaced))
if ((std::isnan(zValueToBeReplaced) && std::isnan(m_geo.z)) || qFuzzyCompare(m_geo.z, zValueToBeReplaced))
setZValueAccordingElevation(defaultElevation);
}
@@ -79,7 +79,7 @@ void LtsCoordinate::convertGeoToUtm() const
int zone = -1;
if (std::isnan(m_geo.lon()) || std::isnan(m_geo.lat()))
if (std::isnan(m_geo.lon) || std::isnan(m_geo.lat))
{
fprintf(stderr, "Error while fromGeographic, value is NaN\n");
m_utm2D = LtsCoordTrans::UtmCoordinate();
@@ -90,7 +90,7 @@ void LtsCoordinate::convertGeoToUtm() const
++s_conversion_counter;
#endif
m_utm2D = LtsCoordTrans::UtmCoordinate::fromGeographic(m_geo.lon(), m_geo.lat(), zone);
m_utm2D = LtsCoordTrans::UtmCoordinate::fromGeographic(m_geo.lon, m_geo.lat, zone);
Q_ASSERT_X(m_utm2D.zone > 0, "LtsCoordinate", "zone has to be set");
}
@@ -2,7 +2,7 @@
#pragma once
#include "ltscoordinate_export.h"
#include <LtsCoordinate/ltscoordinate_export.h>
#include <Core/core.hpp>
#include <LtsCoordTrans/lts_coord_trans.h>
@@ -35,7 +35,7 @@ class LTSCOORDINATE_EXPORT LtsCoordinate
explicit LtsCoordinate(const Core::GeoPosition& geoPos) : m_geo(geoPos) {}
explicit LtsCoordinate(const Core::GeoPosition2D& geoPos2D) : m_geo(geoPos2D.lon(), geoPos2D.lat(), std::nan("")) {}
explicit LtsCoordinate(const Core::GeoPosition2D& geoPos2D) : m_geo(geoPos2D.lon, geoPos2D.lat, std::nan("")) {}
LtsCoordinate(const LtsCoordTrans::UtmCoordinate& utm2D, double zValue) = delete;
@@ -67,7 +67,7 @@ class LTSCOORDINATE_EXPORT LtsCoordinate
bool hasGeo() const
{
return !(valueIsNullOrNan(m_geo.lon()) || valueIsNullOrNan(m_geo.lat()));
return !(valueIsNullOrNan(m_geo.lon) || valueIsNullOrNan(m_geo.lat));
}
bool hasUtm() const
@@ -95,7 +95,7 @@ class LTSCOORDINATE_EXPORT LtsCoordinate
Core::GeoPosition2D geoPosition2D() const
{
return Core::GeoPosition2D(m_geo.longitude, m_geo.latitude);
return Core::GeoPosition2D(m_geo.lon, m_geo.lat);
}
const LtsCoordTrans::UtmCoordinate& utmCoordinate() const
@@ -107,23 +107,23 @@ class LTSCOORDINATE_EXPORT LtsCoordinate
double& rz()
{
return m_geo.altitude;
return m_geo.z;
}
double z() const
{
return m_geo.z();
return m_geo.z;
}
void setZ(double value)
{
m_geo.z(value);
m_geo.z = value;
}
LtsCoordTrans::UtmCoordinate utmCoordinateDiffZone(int zone) const
{
m_utm2D_differentZone = LtsCoordTrans::UtmCoordinate::fromGeographic(m_geo.lon(), m_geo.lat(), zone);
m_utm2D_differentZone = LtsCoordTrans::UtmCoordinate::fromGeographic(m_geo.lon, m_geo.lat, zone);
return m_utm2D_differentZone;
}
@@ -146,17 +146,17 @@ class LTSCOORDINATE_EXPORT LtsCoordinate
QPointF toGeoPointF() const
{
return QPointF(m_geo.lon(), m_geo.lat());
return QPointF(m_geo.lon, m_geo.lat);
}
QPoint3D toGeoPoint3D() const
{
return QPoint3D(m_geo.lon(), m_geo.lat(), m_geo.z());
return QPoint3D(m_geo.lon, m_geo.lat, m_geo.z);
}
UtmCoordinate3D toUtmCoordinate3D() const
{
return UtmCoordinate3D(utmCoordinate(), m_geo.z());
return UtmCoordinate3D(utmCoordinate(), m_geo.z);
}
using elevationCbFunc = std::function<double(double, double, double, bool*)>;
@@ -174,7 +174,7 @@ class LTSCOORDINATE_EXPORT LtsCoordinate
double heightOverElevation() const
{
return m_geo.z() - elevationAt();
return m_geo.z - elevationAt();
}
double distanceUtm2D(const LtsCoordinate& other) const
@@ -203,13 +203,13 @@ class LTSCOORDINATE_EXPORT LtsCoordinate
void clearGeo() const
{
clearGeoLonLat();
m_geo.z(std::nan(""));
m_geo.z = std::nan("");
}
void clearGeoLonLat() const
{
m_geo.lon(0);
m_geo.lat(0);
m_geo.lon = 0;
m_geo.lat = 0;
}
void clearUtm() const
@@ -245,7 +245,7 @@ class LTSCOORDINATE_EXPORT LtsCoordinate
const auto& utmTemp = utmCoordinateInternal(zone);
pntRef.rx() = utmTemp.x;
pntRef.ry() = utmTemp.y;
pntRef.rz() = m_geo.z();
pntRef.rz() = m_geo.z;
}
protected:
@@ -293,7 +293,9 @@ bool LtsPluginLoader::loadPlugins(PluginType requestedPluginType,
}
const QString jsonIid = iid.value().toString().toLower(); // LOWERCASE ! (pun intended)
const QVector<QStringRef> iidParameters = jsonIid.splitRef(QLatin1Char(':'));
// Qt6: QStringRef/QString::splitRef were removed; QStringView::split
// provides the same zero-copy tokenization.
const QList<QStringView> iidParameters = QStringView{jsonIid}.split(QLatin1Char(':'));
DEBUG_LOG(logger) << "Plugin " << absoluteFilePath << " provides iid '" << jsonIid;
@@ -46,21 +46,15 @@ RequestHelper::RequestHelper(QObject* parent, bool quiet,
}
void RequestHelper::addRequest(const std::function<int64_t()>& requestFunction,
const std::function<void(const FunctionReplyType& baseReply)>& baseReplyHandler)
const std::function<void(const Core::FunctionReply& baseReply)>& baseReplyHandler)
{
m_requestFunctions.append(RequestFunctionContainer(requestFunction, baseReplyHandler));
}
bool RequestHelper::requestReply(const FunctionReplyType& baseReply)
bool RequestHelper::requestReply(const Core::FunctionReply& baseReply)
{
#ifdef BUILD_RTI
// Bei BUILD_RTI=ON: baseReply ist Core::FunctionReply, cast von dds::core::Reference
// Die Implementation erwartet Core::FunctionReplyObject
const Core::FunctionReplyObject fro(baseReply.id(), baseReply.errorString(), baseReply.errorParams());
#else
// Stub-Version: nur id und error string
const Core::FunctionReplyObject fro(baseReply.id(), baseReply.str().c_str());
#endif
// rtiddsgen 7.7 generates plain public members (no getters/setters)
const Core::FunctionReplyObject fro(baseReply.id, baseReply.errorString, baseReply.errorParams);
return _requestReply(fro, &baseReply);
}
@@ -69,7 +63,7 @@ bool RequestHelper::requestReply(const Core::FunctionReplyObject& replyObject)
return _requestReply(replyObject, nullptr);
}
bool RequestHelper::_requestReply(const Core::FunctionReplyObject& fro, const FunctionReplyType* baseReply)
bool RequestHelper::_requestReply(const Core::FunctionReplyObject& fro, const Core::FunctionReply* baseReply)
{
m_errorString = fro.translated();
@@ -100,14 +94,8 @@ bool RequestHelper::_requestReply(const Core::FunctionReplyObject& fro, const Fu
if (baseReply)
m_singleRequestCustomFunctionReply(*baseReply);
else
#ifdef BUILD_RTI
m_singleRequestCustomFunctionReply(
Core::FunctionReply(fro.id(), fro.str(), fro.args(), fro.additionalInfo()));
#else
// Stub-Version: FunctionReply mit passendem Konstruktor
m_singleRequestCustomFunctionReply(
Core::FunctionReply(fro.id(), fro.str(), fro.args(), fro.additionalInfo()));
#endif
}
if (fro.error())
@@ -195,7 +183,7 @@ void RequestHelper::slotNextRequest()
void RequestHelper::startSingleBackgroundRequest(
const std::function<int64_t()>& requestFunction,
const std::function<void(const FunctionReplyType&)>& baseReplyHandler)
const std::function<void(const Core::FunctionReply&)>& baseReplyHandler)
{
m_blockingCall = false;
startSingleRequest(requestFunction, baseReplyHandler);