Commit 5fcf54f3 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

add force option to replace plugin when calling recordPlugin; add

clear method
parent 9496ec38
......@@ -15,7 +15,7 @@ public:
// typedef TYPE *(*creator) ();
public:
void recordPlugin(const QString& key, dtkCorePluginBase *plugin);
void recordPlugin(const QString& key, dtkCorePluginBase *plugin, bool force = false);
public:
TYPE *create(const QString& key) const /Factory/ ;
......
......@@ -55,9 +55,12 @@ public:
public:
void record(const QString& key, creator func);
void recordPlugin(const QString& key, dtkCorePluginBase *plugin);
void recordPlugin(const QString& key, dtkCorePluginBase *plugin, bool force = false);
void record(const QString& key, widget_creator func);
public:
void clear(void);
public:
T *create(const QString& key) const;
......
......@@ -48,11 +48,22 @@ template <typename T> inline void dtkCorePluginFactory<T>::record(const QString&
this->creators.insert(key, func);
}
template <typename T> inline void dtkCorePluginFactory<T>::recordPlugin(const QString& key, dtkCorePluginBase *plugin)
template <typename T> inline void dtkCorePluginFactory<T>::clear(void)
{
this->creators.clear();
this->creators_plugins.clear();
}
template <typename T> inline void dtkCorePluginFactory<T>::recordPlugin(const QString& key, dtkCorePluginBase *plugin, bool force)
{
if (this->creators_plugins.contains(key)) {
qDebug() << Q_FUNC_INFO << "Factory already contains key" << key << ". Nothing is done";
return;
if (!force) {
qDebug() << Q_FUNC_INFO << "Factory already contains key" << key << ". Nothing is done";
return;
} else {
qDebug() << Q_FUNC_INFO << "Factory already contains key" << key << ". replace old plugin";
delete this->creators_plugins[key];
}
}
this->creators_plugins.insert(key, plugin);
......
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