src/QtRelationalReaderStringHadler.h
author František Kučera <franta-hg@frantovo.cz>
Sat, 29 Sep 2018 00:43:16 +0200
branchv_0
changeset 13 c84042d014c9
child 18 16784291982f
permissions -rw-r--r--
background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
#pragma once
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#include <QObject>
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
#include <relpipe/reader/typedefs.h>
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
#include <relpipe/reader/TypeId.h>
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#include <relpipe/reader/handlers/RelationalReaderStringHandler.h>
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
#include <relpipe/reader/handlers/AttributeMetadata.h>
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
using namespace relpipe::reader;
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
using namespace relpipe::reader::handlers;
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
// signal/slot parameters must be declared here and registered with qRegisterMetaType()
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
Q_DECLARE_METATYPE(string_t)
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
Q_DECLARE_METATYPE(std::vector<AttributeMetadata>)
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
class QtRelationalReaderStringHadler : public QObject, public RelationalReaderStringHadler {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
	Q_OBJECT
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
private:
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	RelationalReaderStringHadler* target;
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
public:
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
	QtRelationalReaderStringHadler(QObject* parent, RelationalReaderStringHadler* target) :
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
	QObject(parent), target(target) {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
		// see Q_DECLARE_METATYPE above
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
		qRegisterMetaType<string_t>();
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
		qRegisterMetaType<std::vector < AttributeMetadata >> ();
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
		QObject::connect(this, &QtRelationalReaderStringHadler::signal_startRelation, this, &QtRelationalReaderStringHadler::slot_startRelation);
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
		QObject::connect(this, &QtRelationalReaderStringHadler::signal_attribute, this, &QtRelationalReaderStringHadler::slot_attribute);
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
		QObject::connect(this, &QtRelationalReaderStringHadler::signal_endOfPipe, this, &QtRelationalReaderStringHadler::slot_endOfPipe);
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	}
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	virtual ~QtRelationalReaderStringHadler() {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	}
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	virtual void startRelation(string_t name, std::vector<AttributeMetadata> attributes) override {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		emit signal_startRelation(name, attributes);
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	}
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	virtual void attribute(const string_t& value) override {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		emit signal_attribute(value);
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	};
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	virtual void endOfPipe() override {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		emit signal_endOfPipe();
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	};
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
signals:
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	void signal_startRelation(string_t name, std::vector<AttributeMetadata> attributes);
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
	void signal_attribute(const string_t& value);
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
	void signal_endOfPipe();
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
private slots:
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
	void slot_startRelation(string_t name, std::vector<AttributeMetadata> attributes) {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
		target->startRelation(name, attributes);
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
	};
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
	void slot_attribute(const string_t& value) {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
		target->attribute(value);
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
	};
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
	void slot_endOfPipe() {
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
		target->endOfPipe();
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
	};
c84042d014c9 background thread for STDIN reading + proxy with signals/slots for passing data to the GUI thread
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
};