Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit 7935d621 authored by KLOCZKO Thibaud's avatar KLOCZKO Thibaud
Browse files

Replace inheritance by composition to avoid MOC problems.

parent 7b46ed8d
......@@ -71,7 +71,6 @@ public:
#define DTK_DECLARE_PLUGIN_FACTORY(type, Export) \
class Export type##PluginFactory : public dtkCorePluginFactory<type> \
{ \
Q_OBJECT \
}; \
\
template <typename T> type *type##Creator(void) { return new T; };
......
......@@ -4,24 +4,36 @@
* Created: jeu. avril 3 08:44:47 2014 (+0200)
*/
#include "dtkCorePluginFactory.h"
#include "dtkObjectManager.h"
#include <QtCore>
/*!
\class dtkCorePluginFactoryBase
\class dtkCorePluginFactoryPrivate
\inmodule dtkCore
\brief The dtkCorePluginFactoryBase class add signals to register object to object manager.
\brief The dtkCorePluginFactoryPrivate class add signals to register object to object manager.
*/
#include "dtkCorePluginFactory.h"
/*! \fn void dtkCorePluginFactoryBase::touch(int type, void *t)
/*! \fn void dtkCorePluginFactoryPrivate::touch(int type, void *t)
Emits signal created(QVariant).
The QVariant is defined by the QMetaType \a type and the address of the object \a t.
*/
void dtkCorePluginFactoryBase::touch(int type, void *t) const
void dtkCorePluginFactoryPrivate::touch(int type, void *t) const
{
emit created(QVariant(type, t));
}
/*! \fn void dtkCorePluginFactoryPrivate::connect(dtkObjectManager *manager)
Enables connection to \a manager.
*/
void dtkCorePluginFactoryPrivate::connect(dtkObjectManager *manager) const
{
QObject::connect(this, SIGNAL(created(const QVariant&)), manager, SLOT(add(const QVariant&)));
}
/*!
\class dtkCorePluginFactory
\inmodule dtkCore
......
......@@ -19,19 +19,24 @@
#include <dtkCoreExport.h>
class dtkObjectManager;
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class DTKCORE_EXPORT dtkCorePluginFactoryBase : public QObject
class DTKCORE_EXPORT dtkCorePluginFactoryPrivate : public QObject
{
Q_OBJECT
signals:
void created(const QVariant&) const;
protected:
public:
void touch(int type, void *t) const;
public:
void connect(dtkObjectManager *manager) const;
};
// ///////////////////////////////////////////////////////////////////
......@@ -40,7 +45,7 @@ protected:
template <typename T> class dtkCorePluginTuner;
template <typename T> class dtkCorePluginFactory : public dtkCorePluginFactoryBase
template <typename T> class dtkCorePluginFactory : public QObject
{
public:
dtkCorePluginFactory(void);
......@@ -61,9 +66,15 @@ public:
public:
QStringList keys(void) const;
public:
void connect(dtkObjectManager *manager) const;
private:
QHash<QString, creator> creators;
QHash<QString, tunerCreator> tuner_creators;
private:
dtkCorePluginFactoryPrivate *m_d;
};
// ///////////////////////////////////////////////////////////////////
......
......@@ -14,22 +14,18 @@
#pragma once
// ///////////////////////////////////////////////////////////////////
// dtkCorePluginFactoryBase implementation
// ///////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////
// dtkCorePluginFactory implementation
// ///////////////////////////////////////////////////////////////////
template <typename T> dtkCorePluginFactory<T>::dtkCorePluginFactory(void)
template <typename T> dtkCorePluginFactory<T>::dtkCorePluginFactory(void) : m_d(new dtkCorePluginFactoryPrivate)
{
}
template <typename T> dtkCorePluginFactory<T>::~dtkCorePluginFactory(void)
{
delete m_d;
}
// /////////////////////////////////////////////////////////////////
......@@ -62,12 +58,13 @@ template <typename T> void dtkCorePluginFactory<T>::recordTuner(const QString& k
template <typename T> T *dtkCorePluginFactory<T>::create(const QString& key) const
{
if (!this->creators.contains(key))
return NULL;
T *obj = this->creators.value(key)();
if (obj)
this->dtkCorePluginFactoryBase::touch(qMetaTypeId<T *>(), obj);
T *obj = nullptr;
if (this->creators.contains(key)) {
obj = this->creators.value(key)();
if (obj) {
m_d->touch(qMetaTypeId<T *>(), obj);
}
}
return obj;
}
......@@ -90,5 +87,14 @@ template <typename T> QStringList dtkCorePluginFactory<T>::keys(void) const
return this->creators.keys();
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
template <typename T> void dtkCorePluginFactory<T>::connect(dtkObjectManager *manager) const
{
m_d->connect(manager);
}
//
// dtkCorePluginFactory_t.h ends here
......@@ -17,6 +17,8 @@ project(dtkCoreTest)
set(${PROJECT_NAME}_HEADERS
dtkArrayTest.h
dtkCorePluginFactoryTest.h
dtkCorePluginFactoryTestConcept.h
dtkHashTest.h
dtkHelperFunctionTest.h
dtkIteratorTest.h
......@@ -36,6 +38,7 @@ endif(DTK_BUILD_DISTRIBUTED)
set(${PROJECT_NAME}_SOURCES
dtkArrayTest.cpp
dtkCorePluginFactoryTest.cpp
dtkHashTest.cpp
dtkHelperFunctionTest.cpp
dtkIteratorTest.cpp
......@@ -92,6 +95,7 @@ endif(DTK_BUILD_DISTRIBUTED)
## ###################################################################
add_test(dtkArrayTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/dtkCoreTest dtkArrayTest)
add_test(dtkCorePluginFactoryTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/dtkCoreTest dtkCorePluginFactoryTest)
add_test(dtkHashTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/dtkCoreTest dtkHashTest)
add_test(dtkHelperFunctionTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/dtkCoreTest dtkHelperFunctionTest)
add_test(dtkIteratorTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/dtkCoreTest dtkIteratorTest)
......
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#include "dtkCorePluginFactoryTest.h"
#include "dtkCorePluginFactoryTestConcept.h"
#include <QtTest>
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkCorePluginFactoryTestConceptPlugin : public dtkCorePluginFactoryTestConcept
{
public:
~dtkCorePluginFactoryTestConceptPlugin(void) {}
public:
QString name(void) const { return "dtkCorePluginFactoryTestConceptPlugin"; }
};
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkCorePluginFactoryTestCasePrivate
{
public:
dtkCorePluginFactoryTestConceptPluginFactory factory;
};
dtkCorePluginFactoryTestConcept *dtkCorePluginFactoryTestConceptPluginCreator(void)
{
return new dtkCorePluginFactoryTestConceptPlugin;
}
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
dtkCorePluginFactoryTestCase::dtkCorePluginFactoryTestCase(void) : d(new dtkCorePluginFactoryTestCasePrivate)
{
}
dtkCorePluginFactoryTestCase::~dtkCorePluginFactoryTestCase(void)
{
delete d;
}
void dtkCorePluginFactoryTestCase::initTestCase(void)
{
d->factory.record("dtkCorePluginFactoryTestConceptPlugin", dtkCorePluginFactoryTestConceptPluginCreator);
}
void dtkCorePluginFactoryTestCase::init(void)
{
}
void dtkCorePluginFactoryTestCase::testBasic(void)
{
dtkCorePluginFactoryTestConcept *concept = d->factory.create("dtkCorePluginFactoryTestConceptPlugin");
QVERIFY(concept);
QCOMPARE(QString("dtkCorePluginFactoryTestConceptPlugin"), concept->name());
}
void dtkCorePluginFactoryTestCase::cleanup(void)
{
}
void dtkCorePluginFactoryTestCase::cleanupTestCase(void)
{
}
DTKTEST_MAIN_NOGUI(dtkCorePluginFactoryTest, dtkCorePluginFactoryTestCase)
//
// dtkCorePluginFactoryTest.cpp ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkTest>
class dtkCorePluginFactoryTestCase : public QObject
{
Q_OBJECT
public:
dtkCorePluginFactoryTestCase(void);
virtual ~dtkCorePluginFactoryTestCase(void);
private slots:
void initTestCase(void);
void init(void);
private slots:
void testBasic(void);
private slots:
void cleanupTestCase(void);
void cleanup(void);
private:
class dtkCorePluginFactoryTestCasePrivate *d;
};
//
// dtkCorePluginFactoryTest.h ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#pragma once
#include <dtkCore>
#define DTKCOREPLUGINFACTORYTEST_EXPORT
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
class dtkCorePluginFactoryTestConcept
{
public:
virtual ~dtkCorePluginFactoryTestConcept(void) {}
public:
virtual QString name(void) const = 0;
};
DTK_DECLARE_OBJECT(dtkCorePluginFactoryTestConcept *)
DTK_DECLARE_PLUGIN_FACTORY(dtkCorePluginFactoryTestConcept, DTKCOREPLUGINFACTORYTEST_EXPORT)
//
// dtkCorePluginFactoryTestConcept.h ends here
......@@ -35,7 +35,7 @@ dtkObjectManagerTestCase::~dtkObjectManagerTestCase(void)
void dtkObjectManagerTestCase::initTestCase(void)
{
connect(&dtkDistributed::communicator::pluginFactory(), SIGNAL(created(const QVariant&)), dtkObjectManager::instance(), SLOT(add(const QVariant&)));
dtkDistributed::communicator::pluginFactory().connect(dtkObjectManager::instance());
dtkDistributed::communicator::initialize();
dtkDistributedCommunicator *communicator_1 = dtkDistributed::communicator::pluginFactory().create("qthread");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment