Reduce namespace polution

master
Jos van den Oever 2017-08-15 13:49:28 +02:00
parent f6db39755c
commit 6ccfe5fe33
9 changed files with 108 additions and 94 deletions

View File

@ -43,16 +43,16 @@ void set_qbytearray(QByteArray* v, qbytearray_t* val) {
}
extern "C" {
PersonInterface* person_new(Person*, void (*)(Person*), void (*)(Person*), void (*)(Person*), void (*)(Person*));
void person_free(PersonInterface*);
void person_user_name_get(PersonInterface*, QString*, qstring_set);
void person_user_name_set(void*, qstring_t);
int person_age_get(PersonInterface*);
bool person_active_get(PersonInterface*);
void person_active_set(void*, bool);
void person_icon_get(PersonInterface*, QByteArray*, qbytearray_set);
void person_icon_set(void*, qbytearray_t);
DirectoryInterface* directory_new(Directory*, void (*)(Directory*),
Person::Private* person_new(Person*, void (*)(Person*), void (*)(Person*), void (*)(Person*), void (*)(Person*));
void person_free(Person::Private*);
void person_user_name_get(const Person::Private*, QString*, qstring_set);
void person_user_name_set(Person::Private*, qstring_t);
int person_age_get(const Person::Private*);
bool person_active_get(const Person::Private*);
void person_active_set(Person::Private*, bool);
void person_icon_get(const Person::Private*, QByteArray*, qbytearray_set);
void person_icon_set(Person::Private*, qbytearray_t);
Directory::Private* directory_new(Directory*, void (*)(Directory*),
void (*)(const Directory*),
void (*)(Directory*),
void (*)(Directory*),
@ -60,10 +60,10 @@ extern "C" {
void (*)(Directory*),
void (*)(Directory*, int, int),
void (*)(Directory*));
void directory_free(DirectoryInterface*);
void directory_path_get(DirectoryInterface*, QString*, qstring_set);
void directory_path_set(void*, qstring_t);
TestTreeInterface* test_tree_new(TestTree*, void (*)(TestTree*),
void directory_free(Directory::Private*);
void directory_path_get(const Directory::Private*, QString*, qstring_set);
void directory_path_set(Directory::Private*, qstring_t);
TestTree::Private* test_tree_new(TestTree*, void (*)(TestTree*),
void (*)(const TestTree*, int, quintptr),
void (*)(TestTree*),
void (*)(TestTree*),
@ -71,9 +71,9 @@ extern "C" {
void (*)(TestTree*),
void (*)(TestTree*, int, quintptr, int, int),
void (*)(TestTree*));
void test_tree_free(TestTreeInterface*);
void test_tree_path_get(TestTreeInterface*, QString*, qstring_set);
void test_tree_path_set(void*, qstring_t);
void test_tree_free(TestTree::Private*);
void test_tree_path_get(const TestTree::Private*, QString*, qstring_set);
void test_tree_path_set(TestTree::Private*, qstring_t);
};
Person::Person(QObject *parent):
QObject(parent),
@ -160,14 +160,14 @@ void Directory::setPath(const QString& v) {
directory_path_set(d, v);
}
extern "C" {
void directory_data_file_name(const DirectoryInterface*, int, QString*, qstring_set);
void directory_data_file_icon(const DirectoryInterface*, int, QByteArray*, qbytearray_set);
void directory_data_file_path(const DirectoryInterface*, int, QString*, qstring_set);
int directory_data_file_permissions(const DirectoryInterface*, int);
void directory_data_file_name(const Directory::Private*, int, QString*, qstring_set);
void directory_data_file_icon(const Directory::Private*, int, QByteArray*, qbytearray_set);
void directory_data_file_path(const Directory::Private*, int, QString*, qstring_set);
int directory_data_file_permissions(const Directory::Private*, int);
int directory_row_count(const DirectoryInterface*);
bool directory_can_fetch_more(const DirectoryInterface*);
void directory_fetch_more(DirectoryInterface*);
int directory_row_count(const Directory::Private*);
bool directory_can_fetch_more(const Directory::Private*);
void directory_fetch_more(Directory::Private*);
}
int Directory::columnCount(const QModelIndex &parent) const
{
@ -310,16 +310,16 @@ void TestTree::setPath(const QString& v) {
test_tree_path_set(d, v);
}
extern "C" {
void test_tree_data_file_name(const TestTreeInterface*, int, quintptr, QString*, qstring_set);
void test_tree_data_file_icon(const TestTreeInterface*, int, quintptr, QByteArray*, qbytearray_set);
void test_tree_data_file_path(const TestTreeInterface*, int, quintptr, QString*, qstring_set);
int test_tree_data_file_permissions(const TestTreeInterface*, int, quintptr);
void test_tree_data_file_name(const TestTree::Private*, int, quintptr, QString*, qstring_set);
void test_tree_data_file_icon(const TestTree::Private*, int, quintptr, QByteArray*, qbytearray_set);
void test_tree_data_file_path(const TestTree::Private*, int, quintptr, QString*, qstring_set);
int test_tree_data_file_permissions(const TestTree::Private*, int, quintptr);
int test_tree_row_count(const TestTreeInterface*, int, quintptr);
bool test_tree_can_fetch_more(const TestTreeInterface*, int, quintptr);
void test_tree_fetch_more(TestTreeInterface*, int, quintptr);
quintptr test_tree_index(const TestTreeInterface*, int, quintptr);
qmodelindex_t test_tree_parent(const TestTreeInterface*, quintptr);
int test_tree_row_count(const TestTree::Private*, int, quintptr);
bool test_tree_can_fetch_more(const TestTree::Private*, int, quintptr);
void test_tree_fetch_more(TestTree::Private*, int, quintptr);
quintptr test_tree_index(const TestTree::Private*, int, quintptr);
qmodelindex_t test_tree_parent(const TestTree::Private*, quintptr);
}
int TestTree::columnCount(const QModelIndex &) const
{

View File

@ -5,11 +5,13 @@
#include <QObject>
#include <QAbstractItemModel>
class PersonInterface;
class Person : public QObject
{
Q_OBJECT
PersonInterface * const d;
public:
class Private;
private:
Private * const d;
Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged FINAL)
Q_PROPERTY(int age READ age NOTIFY ageChanged FINAL)
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged FINAL)
@ -36,11 +38,13 @@ private:
QByteArray m_icon;
};
class DirectoryInterface;
class Directory : public QAbstractItemModel
{
Q_OBJECT
DirectoryInterface * const d;
public:
class Private;
private:
Private * const d;
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged FINAL)
public:
explicit Directory(QObject *parent = nullptr);
@ -66,11 +70,13 @@ private:
QString m_path;
};
class TestTreeInterface;
class TestTree : public QAbstractItemModel
{
Q_OBJECT
TestTreeInterface * const d;
public:
class Private;
private:
Private * const d;
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged FINAL)
public:
explicit TestTree(QObject *parent = nullptr);

View File

@ -43,7 +43,7 @@ void set_qbytearray(QByteArray* v, qbytearray_t* val) {
}
extern "C" {
TreeInterface* tree_new(Tree*, void (*)(Tree*),
Tree::Private* tree_new(Tree*, void (*)(Tree*),
void (*)(const Tree*, int, quintptr),
void (*)(Tree*),
void (*)(Tree*),
@ -51,9 +51,9 @@ extern "C" {
void (*)(Tree*),
void (*)(Tree*, int, quintptr, int, int),
void (*)(Tree*));
void tree_free(TreeInterface*);
void tree_path_get(TreeInterface*, QString*, qstring_set);
void tree_path_set(void*, qstring_t);
void tree_free(Tree::Private*);
void tree_path_get(const Tree::Private*, QString*, qstring_set);
void tree_path_set(Tree::Private*, qstring_t);
};
Tree::Tree(QObject *parent):
QAbstractItemModel(parent),
@ -100,18 +100,18 @@ void Tree::setPath(const QString& v) {
tree_path_set(d, v);
}
extern "C" {
void tree_data_file_name(const TreeInterface*, int, quintptr, QString*, qstring_set);
void tree_data_file_icon(const TreeInterface*, int, quintptr, QByteArray*, qbytearray_set);
void tree_data_file_path(const TreeInterface*, int, quintptr, QString*, qstring_set);
int tree_data_file_permissions(const TreeInterface*, int, quintptr);
int tree_data_file_type(const TreeInterface*, int, quintptr);
qulonglong tree_data_file_size(const TreeInterface*, int, quintptr);
void tree_data_file_name(const Tree::Private*, int, quintptr, QString*, qstring_set);
void tree_data_file_icon(const Tree::Private*, int, quintptr, QByteArray*, qbytearray_set);
void tree_data_file_path(const Tree::Private*, int, quintptr, QString*, qstring_set);
int tree_data_file_permissions(const Tree::Private*, int, quintptr);
int tree_data_file_type(const Tree::Private*, int, quintptr);
qulonglong tree_data_file_size(const Tree::Private*, int, quintptr);
int tree_row_count(const TreeInterface*, int, quintptr);
bool tree_can_fetch_more(const TreeInterface*, int, quintptr);
void tree_fetch_more(TreeInterface*, int, quintptr);
quintptr tree_index(const TreeInterface*, int, quintptr);
qmodelindex_t tree_parent(const TreeInterface*, quintptr);
int tree_row_count(const Tree::Private*, int, quintptr);
bool tree_can_fetch_more(const Tree::Private*, int, quintptr);
void tree_fetch_more(Tree::Private*, int, quintptr);
quintptr tree_index(const Tree::Private*, int, quintptr);
qmodelindex_t tree_parent(const Tree::Private*, quintptr);
}
int Tree::columnCount(const QModelIndex &) const
{

View File

@ -5,11 +5,13 @@
#include <QObject>
#include <QAbstractItemModel>
class TreeInterface;
class Tree : public QAbstractItemModel
{
Q_OBJECT
TreeInterface * const d;
public:
class Private;
private:
Private * const d;
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged FINAL)
public:
explicit Tree(QObject *parent = nullptr);

View File

@ -299,18 +299,18 @@ void writeCppModel(QTextStream& cpp, const Object& o) {
cpp << "extern \"C\" {\n";
for (auto role: o.allRoles) {
if (role.type.isComplex()) {
cpp << QString(" void %2_data_%3(const %1Interface*%5, %4);\n")
cpp << QString(" void %2_data_%3(const %1::Private*%5, %4);\n")
.arg(o.name, lcname, snakeCase(role.name), cGetType(role.type), indexDecl);
} else {
cpp << QString(" %4 %2_data_%3(const %1Interface*%5);\n")
cpp << QString(" %4 %2_data_%3(const %1::Private*%5);\n")
.arg(o.name, lcname, snakeCase(role.name), role.type.cppSetType, indexDecl);
}
}
if (o.type == ObjectType::List) {
cpp << QString(R"(
int %2_row_count(const %1Interface*);
bool %2_can_fetch_more(const %1Interface*);
void %2_fetch_more(%1Interface*);
int %2_row_count(const %1::Private*);
bool %2_can_fetch_more(const %1::Private*);
void %2_fetch_more(%1::Private*);
}
int %1::columnCount(const QModelIndex &parent) const
{
@ -354,11 +354,11 @@ void %1::fetchMore(const QModelIndex &parent)
)").arg(o.name, lcname, QString::number(o.columnRoles.size()));
} else {
cpp << QString(R"(
int %2_row_count(const %1Interface*, int, quintptr);
bool %2_can_fetch_more(const %1Interface*, int, quintptr);
void %2_fetch_more(%1Interface*, int, quintptr);
quintptr %2_index(const %1Interface*, int, quintptr);
qmodelindex_t %2_parent(const %1Interface*, quintptr);
int %2_row_count(const %1::Private*, int, quintptr);
bool %2_can_fetch_more(const %1::Private*, int, quintptr);
void %2_fetch_more(%1::Private*, int, quintptr);
quintptr %2_index(const %1::Private*, int, quintptr);
qmodelindex_t %2_parent(const %1::Private*, quintptr);
}
int %1::columnCount(const QModelIndex &) const
{
@ -458,11 +458,13 @@ QVariant %1::data(const QModelIndex &index, int role) const
void writeHeaderObject(QTextStream& h, const Object& o) {
h << QString(R"(
class %1Interface;
class %1 : public %3
{
Q_OBJEC%2
%1Interface * const d;
public:
class Private;
private:
Private * const d;
)").arg(o.name, "T", baseType(o));
for (auto p: o.properties) {
h << QString(" Q_PROPERTY(%1 %2 READ %2 %3NOTIFY %2Changed FINAL)")
@ -495,7 +497,7 @@ class %1 : public %3
void writeObjectCDecl(QTextStream& cpp, const Object& o) {
const QString lcname(snakeCase(o.name));
cpp << QString(" %1Interface* %2_new(%1*").arg(o.name, lcname);
cpp << QString(" %1::Private* %2_new(%1*").arg(o.name, lcname);
for (int i = 0; i < o.properties.size(); ++i) {
cpp << QString(", void (*)(%1*)").arg(o.name);
}
@ -520,20 +522,20 @@ void writeObjectCDecl(QTextStream& cpp, const Object& o) {
void (*)(%1*))").arg(o.name);
}
cpp << ");" << endl;
cpp << QString(" void %2_free(%1Interface*);").arg(o.name, lcname)
cpp << QString(" void %2_free(%1::Private*);").arg(o.name, lcname)
<< endl;
for (const Property& p: o.properties) {
const QString base = QString("%1_%2").arg(lcname, snakeCase(p.name));
if (p.type.isComplex()) {
cpp << QString(" void %2_get(%1Interface*, %3);")
cpp << QString(" void %2_get(const %1::Private*, %3);")
.arg(o.name, base, cGetType(p.type)) << endl;
} else {
cpp << QString(" %3 %2_get(%1Interface*);")
cpp << QString(" %3 %2_get(const %1::Private*);")
.arg(o.name, base, p.type.name) << endl;
}
if (p.write) {
cpp << QString(" void %1_set(void*, %2);")
.arg(base, p.type.cSetType) << endl;
cpp << QString(" void %2_set(%1::Private*, %3);")
.arg(o.name, base, p.type.cSetType) << endl;
}
}
}

View File

@ -43,10 +43,10 @@ void set_qbytearray(QByteArray* v, qbytearray_t* val) {
}
extern "C" {
PersonInterface* person_new(Person*, void (*)(Person*));
void person_free(PersonInterface*);
void person_user_name_get(PersonInterface*, QString*, qstring_set);
void person_user_name_set(void*, qstring_t);
Person::Private* person_new(Person*, void (*)(Person*));
void person_free(Person::Private*);
void person_user_name_get(const Person::Private*, QString*, qstring_set);
void person_user_name_set(Person::Private*, qstring_t);
};
Person::Person(QObject *parent):
QObject(parent),

View File

@ -5,11 +5,13 @@
#include <QObject>
#include <QAbstractItemModel>
class PersonInterface;
class Person : public QObject
{
Q_OBJECT
PersonInterface * const d;
public:
class Private;
private:
Private * const d;
Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged FINAL)
public:
explicit Person(QObject *parent = nullptr);

View File

@ -43,18 +43,18 @@ void set_qbytearray(QByteArray* v, qbytearray_t* val) {
}
extern "C" {
ObjectInterface* object_new(Object*, void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*));
void object_free(ObjectInterface*);
bool object_boolean_get(ObjectInterface*);
void object_boolean_set(void*, bool);
int object_integer_get(ObjectInterface*);
void object_integer_set(void*, int);
uint object_uinteger_get(ObjectInterface*);
void object_uinteger_set(void*, uint);
void object_string_get(ObjectInterface*, QString*, qstring_set);
void object_string_set(void*, qstring_t);
void object_bytearray_get(ObjectInterface*, QByteArray*, qbytearray_set);
void object_bytearray_set(void*, qbytearray_t);
Object::Private* object_new(Object*, void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*), void (*)(Object*));
void object_free(Object::Private*);
bool object_boolean_get(const Object::Private*);
void object_boolean_set(Object::Private*, bool);
int object_integer_get(const Object::Private*);
void object_integer_set(Object::Private*, int);
uint object_uinteger_get(const Object::Private*);
void object_uinteger_set(Object::Private*, uint);
void object_string_get(const Object::Private*, QString*, qstring_set);
void object_string_set(Object::Private*, qstring_t);
void object_bytearray_get(const Object::Private*, QByteArray*, qbytearray_set);
void object_bytearray_set(Object::Private*, qbytearray_t);
};
Object::Object(QObject *parent):
QObject(parent),

View File

@ -5,11 +5,13 @@
#include <QObject>
#include <QAbstractItemModel>
class ObjectInterface;
class Object : public QObject
{
Q_OBJECT
ObjectInterface * const d;
public:
class Private;
private:
Private * const d;
Q_PROPERTY(bool boolean READ boolean WRITE setBoolean NOTIFY booleanChanged FINAL)
Q_PROPERTY(int integer READ integer WRITE setInteger NOTIFY integerChanged FINAL)
Q_PROPERTY(uint uinteger READ uinteger WRITE setUinteger NOTIFY uintegerChanged FINAL)