Do not use templated types in c bindings
parent
a50863b365
commit
c9b2fda4fb
|
@ -2,10 +2,10 @@
|
||||||
#include "Bindings.h"
|
#include "Bindings.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template <typename T>
|
|
||||||
struct option {
|
struct option_quintptr {
|
||||||
public:
|
public:
|
||||||
T value;
|
quintptr value;
|
||||||
bool some;
|
bool some;
|
||||||
operator QVariant() const {
|
operator QVariant() const {
|
||||||
if (some) {
|
if (some) {
|
||||||
|
@ -14,19 +14,31 @@ namespace {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct qbytearray_t {
|
|
||||||
private:
|
struct option_QString {
|
||||||
const char* data;
|
|
||||||
int len;
|
|
||||||
public:
|
public:
|
||||||
qbytearray_t(const QByteArray& v):
|
QString value;
|
||||||
data(v.data()),
|
bool some;
|
||||||
len(v.size()) {
|
operator QVariant() const {
|
||||||
}
|
if (some) {
|
||||||
operator QByteArray() const {
|
return QVariant(value);
|
||||||
return QByteArray(data, len);
|
}
|
||||||
|
return QVariant();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct option_quint64 {
|
||||||
|
public:
|
||||||
|
quint64 value;
|
||||||
|
bool some;
|
||||||
|
operator QVariant() const {
|
||||||
|
if (some) {
|
||||||
|
return QVariant(value);
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct qstring_t {
|
struct qstring_t {
|
||||||
private:
|
private:
|
||||||
const void* data;
|
const void* data;
|
||||||
|
@ -40,6 +52,29 @@ namespace {
|
||||||
return QString::fromUtf8(static_cast<const char*>(data), len);
|
return QString::fromUtf8(static_cast<const char*>(data), len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
typedef void (*qstring_set)(QString*, qstring_t*);
|
||||||
|
void set_qstring(QString* v, qstring_t* val) {
|
||||||
|
*v = *val;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct qbytearray_t {
|
||||||
|
private:
|
||||||
|
const char* data;
|
||||||
|
int len;
|
||||||
|
public:
|
||||||
|
qbytearray_t(const QByteArray& v):
|
||||||
|
data(v.data()),
|
||||||
|
len(v.size()) {
|
||||||
|
}
|
||||||
|
operator QByteArray() const {
|
||||||
|
return QByteArray(data, len);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
||||||
|
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
||||||
|
*v = *val;
|
||||||
|
}
|
||||||
|
|
||||||
struct qmodelindex_t {
|
struct qmodelindex_t {
|
||||||
int row;
|
int row;
|
||||||
quintptr id;
|
quintptr id;
|
||||||
|
@ -60,15 +95,6 @@ namespace {
|
||||||
{
|
{
|
||||||
emit o->activeChanged();
|
emit o->activeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
|
||||||
void set_qstring(QString* v, qstring_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
|
||||||
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
Demo::Private* demo_new(Demo*, Fibonacci*, void (*)(Fibonacci*), void (*)(Fibonacci*), FibonacciList*,
|
Demo::Private* demo_new(Demo*, Fibonacci*, void (*)(Fibonacci*), void (*)(Fibonacci*), FibonacciList*,
|
||||||
|
@ -84,17 +110,17 @@ extern "C" {
|
||||||
void (*)(FileSystemTree*, quintptr, quintptr),
|
void (*)(FileSystemTree*, quintptr, quintptr),
|
||||||
void (*)(FileSystemTree*),
|
void (*)(FileSystemTree*),
|
||||||
void (*)(FileSystemTree*),
|
void (*)(FileSystemTree*),
|
||||||
void (*)(FileSystemTree*, option<quintptr>, int, int),
|
void (*)(FileSystemTree*, option_quintptr, int, int),
|
||||||
void (*)(FileSystemTree*),
|
void (*)(FileSystemTree*),
|
||||||
void (*)(FileSystemTree*, option<quintptr>, int, int),
|
void (*)(FileSystemTree*, option_quintptr, int, int),
|
||||||
void (*)(FileSystemTree*), Processes*, void (*)(Processes*),
|
void (*)(FileSystemTree*), Processes*, void (*)(Processes*),
|
||||||
void (*)(const Processes*, quintptr, bool),
|
void (*)(const Processes*, quintptr, bool),
|
||||||
void (*)(Processes*, quintptr, quintptr),
|
void (*)(Processes*, quintptr, quintptr),
|
||||||
void (*)(Processes*),
|
void (*)(Processes*),
|
||||||
void (*)(Processes*),
|
void (*)(Processes*),
|
||||||
void (*)(Processes*, option<quintptr>, int, int),
|
void (*)(Processes*, option_quintptr, int, int),
|
||||||
void (*)(Processes*),
|
void (*)(Processes*),
|
||||||
void (*)(Processes*, option<quintptr>, int, int),
|
void (*)(Processes*, option_quintptr, int, int),
|
||||||
void (*)(Processes*), TimeSeries*,
|
void (*)(Processes*), TimeSeries*,
|
||||||
void (*)(const TimeSeries*),
|
void (*)(const TimeSeries*),
|
||||||
void (*)(TimeSeries*, quintptr, quintptr),
|
void (*)(TimeSeries*, quintptr, quintptr),
|
||||||
|
@ -239,7 +265,7 @@ extern "C" {
|
||||||
void file_system_tree_data_file_name(const FileSystemTree::Private*, quintptr, QString*, qstring_set);
|
void file_system_tree_data_file_name(const FileSystemTree::Private*, quintptr, QString*, qstring_set);
|
||||||
void file_system_tree_data_file_path(const FileSystemTree::Private*, quintptr, QString*, qstring_set);
|
void file_system_tree_data_file_path(const FileSystemTree::Private*, quintptr, QString*, qstring_set);
|
||||||
qint32 file_system_tree_data_file_permissions(const FileSystemTree::Private*, quintptr);
|
qint32 file_system_tree_data_file_permissions(const FileSystemTree::Private*, quintptr);
|
||||||
option<quint64> file_system_tree_data_file_size(const FileSystemTree::Private*, quintptr);
|
option_quint64 file_system_tree_data_file_size(const FileSystemTree::Private*, quintptr);
|
||||||
qint32 file_system_tree_data_file_type(const FileSystemTree::Private*, quintptr);
|
qint32 file_system_tree_data_file_type(const FileSystemTree::Private*, quintptr);
|
||||||
void file_system_tree_sort(FileSystemTree::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
|
void file_system_tree_sort(FileSystemTree::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||||
|
|
||||||
|
@ -445,9 +471,9 @@ extern "C" {
|
||||||
void (*)(FileSystemTree*, quintptr, quintptr),
|
void (*)(FileSystemTree*, quintptr, quintptr),
|
||||||
void (*)(FileSystemTree*),
|
void (*)(FileSystemTree*),
|
||||||
void (*)(FileSystemTree*),
|
void (*)(FileSystemTree*),
|
||||||
void (*)(FileSystemTree*, option<quintptr>, int, int),
|
void (*)(FileSystemTree*, option_quintptr, int, int),
|
||||||
void (*)(FileSystemTree*),
|
void (*)(FileSystemTree*),
|
||||||
void (*)(FileSystemTree*, option<quintptr>, int, int),
|
void (*)(FileSystemTree*, option_quintptr, int, int),
|
||||||
void (*)(FileSystemTree*));
|
void (*)(FileSystemTree*));
|
||||||
void file_system_tree_free(FileSystemTree::Private*);
|
void file_system_tree_free(FileSystemTree::Private*);
|
||||||
void file_system_tree_path_get(const FileSystemTree::Private*, QString*, qstring_set);
|
void file_system_tree_path_get(const FileSystemTree::Private*, QString*, qstring_set);
|
||||||
|
@ -663,9 +689,9 @@ extern "C" {
|
||||||
void (*)(Processes*, quintptr, quintptr),
|
void (*)(Processes*, quintptr, quintptr),
|
||||||
void (*)(Processes*),
|
void (*)(Processes*),
|
||||||
void (*)(Processes*),
|
void (*)(Processes*),
|
||||||
void (*)(Processes*, option<quintptr>, int, int),
|
void (*)(Processes*, option_quintptr, int, int),
|
||||||
void (*)(Processes*),
|
void (*)(Processes*),
|
||||||
void (*)(Processes*, option<quintptr>, int, int),
|
void (*)(Processes*, option_quintptr, int, int),
|
||||||
void (*)(Processes*));
|
void (*)(Processes*));
|
||||||
void processes_free(Processes::Private*);
|
void processes_free(Processes::Private*);
|
||||||
bool processes_active_get(const Processes::Private*);
|
bool processes_active_get(const Processes::Private*);
|
||||||
|
@ -922,7 +948,7 @@ Demo::Demo(QObject *parent):
|
||||||
[](FileSystemTree* o) {
|
[](FileSystemTree* o) {
|
||||||
o->endResetModel();
|
o->endResetModel();
|
||||||
},
|
},
|
||||||
[](FileSystemTree* o, option<quintptr> id, int first, int last) {
|
[](FileSystemTree* o, option_quintptr id, int first, int last) {
|
||||||
if (id.some) {
|
if (id.some) {
|
||||||
int row = file_system_tree_row(o->m_d, id.value);
|
int row = file_system_tree_row(o->m_d, id.value);
|
||||||
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
||||||
|
@ -933,7 +959,7 @@ Demo::Demo(QObject *parent):
|
||||||
[](FileSystemTree* o) {
|
[](FileSystemTree* o) {
|
||||||
o->endInsertRows();
|
o->endInsertRows();
|
||||||
},
|
},
|
||||||
[](FileSystemTree* o, option<quintptr> id, int first, int last) {
|
[](FileSystemTree* o, option_quintptr id, int first, int last) {
|
||||||
if (id.some) {
|
if (id.some) {
|
||||||
int row = file_system_tree_row(o->m_d, id.value);
|
int row = file_system_tree_row(o->m_d, id.value);
|
||||||
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
||||||
|
@ -966,7 +992,7 @@ Demo::Demo(QObject *parent):
|
||||||
[](Processes* o) {
|
[](Processes* o) {
|
||||||
o->endResetModel();
|
o->endResetModel();
|
||||||
},
|
},
|
||||||
[](Processes* o, option<quintptr> id, int first, int last) {
|
[](Processes* o, option_quintptr id, int first, int last) {
|
||||||
if (id.some) {
|
if (id.some) {
|
||||||
int row = processes_row(o->m_d, id.value);
|
int row = processes_row(o->m_d, id.value);
|
||||||
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
||||||
|
@ -977,7 +1003,7 @@ Demo::Demo(QObject *parent):
|
||||||
[](Processes* o) {
|
[](Processes* o) {
|
||||||
o->endInsertRows();
|
o->endInsertRows();
|
||||||
},
|
},
|
||||||
[](Processes* o, option<quintptr> id, int first, int last) {
|
[](Processes* o, option_quintptr id, int first, int last) {
|
||||||
if (id.some) {
|
if (id.some) {
|
||||||
int row = processes_row(o->m_d, id.value);
|
int row = processes_row(o->m_d, id.value);
|
||||||
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
||||||
|
@ -1198,7 +1224,7 @@ FileSystemTree::FileSystemTree(QObject *parent):
|
||||||
[](FileSystemTree* o) {
|
[](FileSystemTree* o) {
|
||||||
o->endResetModel();
|
o->endResetModel();
|
||||||
},
|
},
|
||||||
[](FileSystemTree* o, option<quintptr> id, int first, int last) {
|
[](FileSystemTree* o, option_quintptr id, int first, int last) {
|
||||||
if (id.some) {
|
if (id.some) {
|
||||||
int row = file_system_tree_row(o->m_d, id.value);
|
int row = file_system_tree_row(o->m_d, id.value);
|
||||||
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
||||||
|
@ -1209,7 +1235,7 @@ FileSystemTree::FileSystemTree(QObject *parent):
|
||||||
[](FileSystemTree* o) {
|
[](FileSystemTree* o) {
|
||||||
o->endInsertRows();
|
o->endInsertRows();
|
||||||
},
|
},
|
||||||
[](FileSystemTree* o, option<quintptr> id, int first, int last) {
|
[](FileSystemTree* o, option_quintptr id, int first, int last) {
|
||||||
if (id.some) {
|
if (id.some) {
|
||||||
int row = file_system_tree_row(o->m_d, id.value);
|
int row = file_system_tree_row(o->m_d, id.value);
|
||||||
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
||||||
|
@ -1286,7 +1312,7 @@ Processes::Processes(QObject *parent):
|
||||||
[](Processes* o) {
|
[](Processes* o) {
|
||||||
o->endResetModel();
|
o->endResetModel();
|
||||||
},
|
},
|
||||||
[](Processes* o, option<quintptr> id, int first, int last) {
|
[](Processes* o, option_quintptr id, int first, int last) {
|
||||||
if (id.some) {
|
if (id.some) {
|
||||||
int row = processes_row(o->m_d, id.value);
|
int row = processes_row(o->m_d, id.value);
|
||||||
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
||||||
|
@ -1297,7 +1323,7 @@ Processes::Processes(QObject *parent):
|
||||||
[](Processes* o) {
|
[](Processes* o) {
|
||||||
o->endInsertRows();
|
o->endInsertRows();
|
||||||
},
|
},
|
||||||
[](Processes* o, option<quintptr> id, int first, int last) {
|
[](Processes* o, option_quintptr id, int first, int last) {
|
||||||
if (id.some) {
|
if (id.some) {
|
||||||
int row = processes_row(o->m_d, id.value);
|
int row = processes_row(o->m_d, id.value);
|
||||||
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
||||||
|
|
80
src/cpp.cpp
80
src/cpp.cpp
|
@ -7,7 +7,7 @@ template <typename T>
|
||||||
QString cppSetType(const T& p)
|
QString cppSetType(const T& p)
|
||||||
{
|
{
|
||||||
if (p.optional) {
|
if (p.optional) {
|
||||||
return "option<" + p.type.cppSetType + ">";
|
return "option_" + p.type.cppSetType;
|
||||||
}
|
}
|
||||||
return p.type.cppSetType;
|
return p.type.cppSetType;
|
||||||
}
|
}
|
||||||
|
@ -507,9 +507,9 @@ void constructorArgsDecl(QTextStream& cpp, const Object& o, const Configuration&
|
||||||
void (*)(%1*, quintptr, quintptr),
|
void (*)(%1*, quintptr, quintptr),
|
||||||
void (*)(%1*),
|
void (*)(%1*),
|
||||||
void (*)(%1*),
|
void (*)(%1*),
|
||||||
void (*)(%1*, option<quintptr>, int, int),
|
void (*)(%1*, option_quintptr, int, int),
|
||||||
void (*)(%1*),
|
void (*)(%1*),
|
||||||
void (*)(%1*, option<quintptr>, int, int),
|
void (*)(%1*, option_quintptr, int, int),
|
||||||
void (*)(%1*))").arg(o.name);
|
void (*)(%1*))").arg(o.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -580,7 +580,7 @@ void constructorArgs(QTextStream& cpp, const QString& prefix, const Object& o, c
|
||||||
[](%1* o) {
|
[](%1* o) {
|
||||||
o->endResetModel();
|
o->endResetModel();
|
||||||
},
|
},
|
||||||
[](%1* o, option<quintptr> id, int first, int last) {
|
[](%1* o, option_quintptr id, int first, int last) {
|
||||||
if (id.some) {
|
if (id.some) {
|
||||||
int row = %2_row(o->m_d, id.value);
|
int row = %2_row(o->m_d, id.value);
|
||||||
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
||||||
|
@ -591,7 +591,7 @@ void constructorArgs(QTextStream& cpp, const QString& prefix, const Object& o, c
|
||||||
[](%1* o) {
|
[](%1* o) {
|
||||||
o->endInsertRows();
|
o->endInsertRows();
|
||||||
},
|
},
|
||||||
[](%1* o, option<quintptr> id, int first, int last) {
|
[](%1* o, option_quintptr id, int first, int last) {
|
||||||
if (id.some) {
|
if (id.some) {
|
||||||
int row = %2_row(o->m_d, id.value);
|
int row = %2_row(o->m_d, id.value);
|
||||||
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
||||||
|
@ -799,10 +799,12 @@ void writeCpp(const Configuration& conf) {
|
||||||
#include "%1"
|
#include "%1"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template <typename T>
|
)").arg(conf.hFile.fileName());
|
||||||
struct option {
|
for (auto option: conf.optionalTypes()) {
|
||||||
|
cpp << QString(R"(
|
||||||
|
struct option_%1 {
|
||||||
public:
|
public:
|
||||||
T value;
|
%1 value;
|
||||||
bool some;
|
bool some;
|
||||||
operator QVariant() const {
|
operator QVariant() const {
|
||||||
if (some) {
|
if (some) {
|
||||||
|
@ -811,19 +813,10 @@ namespace {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct qbytearray_t {
|
)").arg(option);
|
||||||
private:
|
}
|
||||||
const char* data;
|
if (conf.types().contains("QString")) {
|
||||||
int len;
|
cpp << R"(
|
||||||
public:
|
|
||||||
qbytearray_t(const QByteArray& v):
|
|
||||||
data(v.data()),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QByteArray() const {
|
|
||||||
return QByteArray(data, len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qstring_t {
|
struct qstring_t {
|
||||||
private:
|
private:
|
||||||
const void* data;
|
const void* data;
|
||||||
|
@ -837,11 +830,41 @@ namespace {
|
||||||
return QString::fromUtf8(static_cast<const char*>(data), len);
|
return QString::fromUtf8(static_cast<const char*>(data), len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
typedef void (*qstring_set)(QString*, qstring_t*);
|
||||||
|
void set_qstring(QString* v, qstring_t* val) {
|
||||||
|
*v = *val;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
if (conf.types().contains("QByteArray")) {
|
||||||
|
cpp << R"(
|
||||||
|
struct qbytearray_t {
|
||||||
|
private:
|
||||||
|
const char* data;
|
||||||
|
int len;
|
||||||
|
public:
|
||||||
|
qbytearray_t(const QByteArray& v):
|
||||||
|
data(v.data()),
|
||||||
|
len(v.size()) {
|
||||||
|
}
|
||||||
|
operator QByteArray() const {
|
||||||
|
return QByteArray(data, len);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
||||||
|
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
||||||
|
*v = *val;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
if (conf.hasListOrTree()) {
|
||||||
|
cpp << R"(
|
||||||
struct qmodelindex_t {
|
struct qmodelindex_t {
|
||||||
int row;
|
int row;
|
||||||
quintptr id;
|
quintptr id;
|
||||||
};
|
};
|
||||||
)").arg(conf.hFile.fileName());
|
)";
|
||||||
|
}
|
||||||
|
|
||||||
for (auto o: conf.objects) {
|
for (auto o: conf.objects) {
|
||||||
for (auto p: o.properties) {
|
for (auto p: o.properties) {
|
||||||
|
@ -852,18 +875,7 @@ namespace {
|
||||||
cpp << " {\n emit o->" << p.name << "Changed();\n }\n";
|
cpp << " {\n emit o->" << p.name << "Changed();\n }\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cpp << "}\n";
|
||||||
cpp << R"(
|
|
||||||
}
|
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
|
||||||
void set_qstring(QString* v, qstring_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
|
||||||
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
)";
|
|
||||||
|
|
||||||
for (auto object: conf.objects) {
|
for (auto object: conf.objects) {
|
||||||
if (object.type != ObjectType::Object) {
|
if (object.type != ObjectType::Object) {
|
||||||
|
|
|
@ -34,6 +34,14 @@ struct BindingTypeProperties {
|
||||||
bool isComplex() const {
|
bool isComplex() const {
|
||||||
return name.startsWith("Q");
|
return name.startsWith("Q");
|
||||||
}
|
}
|
||||||
|
bool operator==(const BindingTypeProperties& other) {
|
||||||
|
return type == other.type
|
||||||
|
&& name == other.name
|
||||||
|
&& cppSetType == other.cppSetType
|
||||||
|
&& cSetType == other.cSetType
|
||||||
|
&& rustType == other.rustType
|
||||||
|
&& rustTypeInit == other.rustTypeInit;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Property {
|
struct Property {
|
||||||
|
@ -89,5 +97,43 @@ struct Configuration {
|
||||||
err.flush();
|
err.flush();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
QList<QString> types() const {
|
||||||
|
QList<QString> ops;
|
||||||
|
for (auto o: objects) {
|
||||||
|
for (auto ip: o.properties) {
|
||||||
|
if (!ops.contains(ip.type.name)) {
|
||||||
|
ops.append(ip.type.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto ip: o.itemProperties) {
|
||||||
|
if (!ops.contains(ip.type.name)) {
|
||||||
|
ops.append(ip.type.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ops;
|
||||||
|
}
|
||||||
|
QList<QString> optionalTypes() const {
|
||||||
|
QList<QString> ops;
|
||||||
|
for (auto o: objects) {
|
||||||
|
for (auto ip: o.itemProperties) {
|
||||||
|
if (ip.optional && !ops.contains(ip.type.name)) {
|
||||||
|
ops.append(ip.type.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (o.type != ObjectType::Object && !ops.contains("quintptr")) {
|
||||||
|
ops.append("quintptr");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ops;
|
||||||
|
}
|
||||||
|
bool hasListOrTree() const {
|
||||||
|
for (auto o: objects) {
|
||||||
|
if (o.type == ObjectType::List || o.type == ObjectType::UniformTree) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
#include "test_list_rust.h"
|
#include "test_list_rust.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template <typename T>
|
|
||||||
struct option {
|
struct option_quintptr {
|
||||||
public:
|
public:
|
||||||
T value;
|
quintptr value;
|
||||||
bool some;
|
bool some;
|
||||||
operator QVariant() const {
|
operator QVariant() const {
|
||||||
if (some) {
|
if (some) {
|
||||||
|
@ -14,19 +14,7 @@ namespace {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct qbytearray_t {
|
|
||||||
private:
|
|
||||||
const char* data;
|
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qbytearray_t(const QByteArray& v):
|
|
||||||
data(v.data()),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QByteArray() const {
|
|
||||||
return QByteArray(data, len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qstring_t {
|
struct qstring_t {
|
||||||
private:
|
private:
|
||||||
const void* data;
|
const void* data;
|
||||||
|
@ -40,19 +28,15 @@ namespace {
|
||||||
return QString::fromUtf8(static_cast<const char*>(data), len);
|
return QString::fromUtf8(static_cast<const char*>(data), len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
typedef void (*qstring_set)(QString*, qstring_t*);
|
||||||
|
void set_qstring(QString* v, qstring_t* val) {
|
||||||
|
*v = *val;
|
||||||
|
}
|
||||||
|
|
||||||
struct qmodelindex_t {
|
struct qmodelindex_t {
|
||||||
int row;
|
int row;
|
||||||
quintptr id;
|
quintptr id;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
|
||||||
void set_qstring(QString* v, qstring_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
|
||||||
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void persons_data_user_name(const Persons::Private*, int, QString*, qstring_set);
|
void persons_data_user_name(const Persons::Private*, int, QString*, qstring_set);
|
||||||
|
|
|
@ -2,31 +2,7 @@
|
||||||
#include "test_object_rust.h"
|
#include "test_object_rust.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template <typename T>
|
|
||||||
struct option {
|
|
||||||
public:
|
|
||||||
T value;
|
|
||||||
bool some;
|
|
||||||
operator QVariant() const {
|
|
||||||
if (some) {
|
|
||||||
return QVariant(value);
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qbytearray_t {
|
|
||||||
private:
|
|
||||||
const char* data;
|
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qbytearray_t(const QByteArray& v):
|
|
||||||
data(v.data()),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QByteArray() const {
|
|
||||||
return QByteArray(data, len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qstring_t {
|
struct qstring_t {
|
||||||
private:
|
private:
|
||||||
const void* data;
|
const void* data;
|
||||||
|
@ -40,23 +16,14 @@ namespace {
|
||||||
return QString::fromUtf8(static_cast<const char*>(data), len);
|
return QString::fromUtf8(static_cast<const char*>(data), len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct qmodelindex_t {
|
typedef void (*qstring_set)(QString*, qstring_t*);
|
||||||
int row;
|
void set_qstring(QString* v, qstring_t* val) {
|
||||||
quintptr id;
|
*v = *val;
|
||||||
};
|
}
|
||||||
inline void personUserNameChanged(Person* o)
|
inline void personUserNameChanged(Person* o)
|
||||||
{
|
{
|
||||||
emit o->userNameChanged();
|
emit o->userNameChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
|
||||||
void set_qstring(QString* v, qstring_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
|
||||||
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
Person::Private* person_new(Person*, void (*)(Person*));
|
Person::Private* person_new(Person*, void (*)(Person*));
|
||||||
|
|
|
@ -2,31 +2,7 @@
|
||||||
#include "test_object_types_rust.h"
|
#include "test_object_types_rust.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template <typename T>
|
|
||||||
struct option {
|
|
||||||
public:
|
|
||||||
T value;
|
|
||||||
bool some;
|
|
||||||
operator QVariant() const {
|
|
||||||
if (some) {
|
|
||||||
return QVariant(value);
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qbytearray_t {
|
|
||||||
private:
|
|
||||||
const char* data;
|
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qbytearray_t(const QByteArray& v):
|
|
||||||
data(v.data()),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QByteArray() const {
|
|
||||||
return QByteArray(data, len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qstring_t {
|
struct qstring_t {
|
||||||
private:
|
private:
|
||||||
const void* data;
|
const void* data;
|
||||||
|
@ -40,10 +16,28 @@ namespace {
|
||||||
return QString::fromUtf8(static_cast<const char*>(data), len);
|
return QString::fromUtf8(static_cast<const char*>(data), len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct qmodelindex_t {
|
typedef void (*qstring_set)(QString*, qstring_t*);
|
||||||
int row;
|
void set_qstring(QString* v, qstring_t* val) {
|
||||||
quintptr id;
|
*v = *val;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct qbytearray_t {
|
||||||
|
private:
|
||||||
|
const char* data;
|
||||||
|
int len;
|
||||||
|
public:
|
||||||
|
qbytearray_t(const QByteArray& v):
|
||||||
|
data(v.data()),
|
||||||
|
len(v.size()) {
|
||||||
|
}
|
||||||
|
operator QByteArray() const {
|
||||||
|
return QByteArray(data, len);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
||||||
|
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
||||||
|
*v = *val;
|
||||||
|
}
|
||||||
inline void objectBooleanChanged(Object* o)
|
inline void objectBooleanChanged(Object* o)
|
||||||
{
|
{
|
||||||
emit o->booleanChanged();
|
emit o->booleanChanged();
|
||||||
|
@ -76,15 +70,6 @@ namespace {
|
||||||
{
|
{
|
||||||
emit o->uintegerChanged();
|
emit o->uintegerChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
|
||||||
void set_qstring(QString* v, qstring_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
|
||||||
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
Object::Private* object_new(Object*, void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*));
|
Object::Private* object_new(Object*, void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*));
|
||||||
|
|
|
@ -2,31 +2,7 @@
|
||||||
#include "test_objects_rust.h"
|
#include "test_objects_rust.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template <typename T>
|
|
||||||
struct option {
|
|
||||||
public:
|
|
||||||
T value;
|
|
||||||
bool some;
|
|
||||||
operator QVariant() const {
|
|
||||||
if (some) {
|
|
||||||
return QVariant(value);
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qbytearray_t {
|
|
||||||
private:
|
|
||||||
const char* data;
|
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qbytearray_t(const QByteArray& v):
|
|
||||||
data(v.data()),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QByteArray() const {
|
|
||||||
return QByteArray(data, len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qstring_t {
|
struct qstring_t {
|
||||||
private:
|
private:
|
||||||
const void* data;
|
const void* data;
|
||||||
|
@ -40,23 +16,14 @@ namespace {
|
||||||
return QString::fromUtf8(static_cast<const char*>(data), len);
|
return QString::fromUtf8(static_cast<const char*>(data), len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct qmodelindex_t {
|
typedef void (*qstring_set)(QString*, qstring_t*);
|
||||||
int row;
|
void set_qstring(QString* v, qstring_t* val) {
|
||||||
quintptr id;
|
*v = *val;
|
||||||
};
|
}
|
||||||
inline void innerObjectDescriptionChanged(InnerObject* o)
|
inline void innerObjectDescriptionChanged(InnerObject* o)
|
||||||
{
|
{
|
||||||
emit o->descriptionChanged();
|
emit o->descriptionChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
|
||||||
void set_qstring(QString* v, qstring_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
|
||||||
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
Group::Private* group_new(Group*, Person*, InnerObject*, void (*)(InnerObject*));
|
Group::Private* group_new(Group*, Person*, InnerObject*, void (*)(InnerObject*));
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
#include "test_tree_rust.h"
|
#include "test_tree_rust.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
template <typename T>
|
|
||||||
struct option {
|
struct option_quintptr {
|
||||||
public:
|
public:
|
||||||
T value;
|
quintptr value;
|
||||||
bool some;
|
bool some;
|
||||||
operator QVariant() const {
|
operator QVariant() const {
|
||||||
if (some) {
|
if (some) {
|
||||||
|
@ -14,19 +14,7 @@ namespace {
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
struct qbytearray_t {
|
|
||||||
private:
|
|
||||||
const char* data;
|
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qbytearray_t(const QByteArray& v):
|
|
||||||
data(v.data()),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QByteArray() const {
|
|
||||||
return QByteArray(data, len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qstring_t {
|
struct qstring_t {
|
||||||
private:
|
private:
|
||||||
const void* data;
|
const void* data;
|
||||||
|
@ -40,19 +28,15 @@ namespace {
|
||||||
return QString::fromUtf8(static_cast<const char*>(data), len);
|
return QString::fromUtf8(static_cast<const char*>(data), len);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
typedef void (*qstring_set)(QString*, qstring_t*);
|
||||||
|
void set_qstring(QString* v, qstring_t* val) {
|
||||||
|
*v = *val;
|
||||||
|
}
|
||||||
|
|
||||||
struct qmodelindex_t {
|
struct qmodelindex_t {
|
||||||
int row;
|
int row;
|
||||||
quintptr id;
|
quintptr id;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
|
||||||
void set_qstring(QString* v, qstring_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
|
||||||
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void persons_data_user_name(const Persons::Private*, quintptr, QString*, qstring_set);
|
void persons_data_user_name(const Persons::Private*, quintptr, QString*, qstring_set);
|
||||||
|
@ -206,9 +190,9 @@ extern "C" {
|
||||||
void (*)(Persons*, quintptr, quintptr),
|
void (*)(Persons*, quintptr, quintptr),
|
||||||
void (*)(Persons*),
|
void (*)(Persons*),
|
||||||
void (*)(Persons*),
|
void (*)(Persons*),
|
||||||
void (*)(Persons*, option<quintptr>, int, int),
|
void (*)(Persons*, option_quintptr, int, int),
|
||||||
void (*)(Persons*),
|
void (*)(Persons*),
|
||||||
void (*)(Persons*, option<quintptr>, int, int),
|
void (*)(Persons*, option_quintptr, int, int),
|
||||||
void (*)(Persons*));
|
void (*)(Persons*));
|
||||||
void persons_free(Persons::Private*);
|
void persons_free(Persons::Private*);
|
||||||
};
|
};
|
||||||
|
@ -244,7 +228,7 @@ Persons::Persons(QObject *parent):
|
||||||
[](Persons* o) {
|
[](Persons* o) {
|
||||||
o->endResetModel();
|
o->endResetModel();
|
||||||
},
|
},
|
||||||
[](Persons* o, option<quintptr> id, int first, int last) {
|
[](Persons* o, option_quintptr id, int first, int last) {
|
||||||
if (id.some) {
|
if (id.some) {
|
||||||
int row = persons_row(o->m_d, id.value);
|
int row = persons_row(o->m_d, id.value);
|
||||||
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
||||||
|
@ -255,7 +239,7 @@ Persons::Persons(QObject *parent):
|
||||||
[](Persons* o) {
|
[](Persons* o) {
|
||||||
o->endInsertRows();
|
o->endInsertRows();
|
||||||
},
|
},
|
||||||
[](Persons* o, option<quintptr> id, int first, int last) {
|
[](Persons* o, option_quintptr id, int first, int last) {
|
||||||
if (id.some) {
|
if (id.some) {
|
||||||
int row = persons_row(o->m_d, id.value);
|
int row = persons_row(o->m_d, id.value);
|
||||||
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
||||||
|
|
Loading…
Reference in New Issue