Files
qt6-migration-pipeline/Lts/Common/CodeGen/svc_db_structs.h.grantlee
T

88 lines
2.3 KiB
Plaintext
Executable File

/**
* @RDE_HEADER@
* Template for 'real' structures including insert/update/delete functions for db
* $Id$
* $HeadURL$
* $Author$
*/
{% autoescape off %}
// filename: {{ namespace_abbr }}_db_structs.h
#pragma once
#include <QDateTime>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonValue>
#include <QPointF>
#include <QString>
#include <QVariant>
#include <QVector>
{% if need_point3d %}
#include <LtsUtilsCore/qpoint3d.h>
{% endif %}
{% if need_pgarray %}
#include <LtsUtilsCore/pgarray.h>
{% endif %}
#include <{{ include_prefix }}/{{ namespace_abbr }}_export.h>
#include <{{ include_prefix }}/{{ namespace_abbr }}_enums.hpp>
{% for ext_service in ext_services.member %}
#include <{{ ext_service.baseFilePath }}.hpp>
{% endfor %}
namespace {{ namespace }}
{
namespace Database
{
{% for cpp_struct in cpp_structs %}
// {{ cpp_struct.name }}
struct {{ cpp_struct.name }}
{
{% for m in cpp_struct.cppMember %}{{ m.cppType }} {{ m.cppMemberName }}{% if m.cppDefault %} = {{ m.cppDefault }}{% endif %};
{% endfor %}
};{% endfor %}
{% for data_struct in data_structs %}
// read only struct {{ data_struct.name }}
struct {{ data_struct.name }}
{
{% for m in data_struct.cppMember %}{{ m.cppType }} {{ m.cppMemberName }}{% if m.cppDefault %} = {{ m.cppDefault }}{% endif %};
{% endfor %}
};{% endfor %}
// converting DbStructs to/from JSON
template<typename T>
T fromJson(const QJsonValue &value);
{% for cpp_struct in cpp_structs %}
// {{ cpp_struct.name }}
template <> {{ namespace_abbr_upper }}_{{ library_target }}_EXPORT {{ cpp_struct.name }} fromJson(const QJsonValue &value);
{{ namespace_abbr_upper }}_{{ library_target }}_EXPORT QJsonObject toJson(const {{ cpp_struct.name }} &element);{% endfor %}
// vector of database struct to/from JSON-array
template<typename T>
QJsonArray toJson(const QVector<T> &dataVec)
{
QJsonArray arr;
for (const T &data : dataVec)
arr.append(QJsonValue(toJson(data)));
return arr;
}
template<typename T>
std::vector<T> fromJson(const QJsonArray &arr)
{
std::vector<T> dataVec;
dataVec.reserve(arr.size());
for (const QJsonValue &val : arr)
dataVec.push_back(fromJson<T>(val));
return dataVec;
}
};// namespace Database
} // namespace {{ namespace }}
{% endautoescape %}