2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit d15ba3ca authored by Artur Grunau's avatar Artur Grunau
Browse files

PipelineFactory: accept pipelines registered using functors and lambdas

Previously, it was only possible to register a pipeline by providing
a static function that would create it. To make the registration more
flexible, PipelineFactory has been updated to also accept pipelines
registered using functors and lambdas.

References #1
parent 4f6b4ba6
......@@ -54,7 +54,7 @@ namespace campvis {
std::vector<std::string> toReturn;
toReturn.reserve(_pipelineMap.size());
for (std::map<std::string, AbstractPipeline* (*)(DataContainer*)>::const_iterator it = _pipelineMap.begin(); it != _pipelineMap.end(); ++it)
for (std::map< std::string, std::function<AbstractPipeline*(DataContainer*)> >::const_iterator it = _pipelineMap.begin(); it != _pipelineMap.end(); ++it)
toReturn.push_back(it->first);
return toReturn;
}
......@@ -62,11 +62,11 @@ namespace campvis {
AbstractPipeline* PipelineFactory::createPipeline(const std::string& id, DataContainer* dc) const {
tbb::spin_mutex::scoped_lock lock(_mutex);
std::map<std::string, AbstractPipeline* (*)(DataContainer*)>::const_iterator it = _pipelineMap.find(id);
std::map< std::string, std::function<AbstractPipeline*(DataContainer*)> >::const_iterator it = _pipelineMap.find(id);
if (it == _pipelineMap.end())
return 0;
else
return (it->second)(dc);
}
}
\ No newline at end of file
}
......@@ -34,6 +34,7 @@
#include <map>
#include <string>
#include <vector>
#include <functional>
namespace campvis {
class AbstractPipeline;
......@@ -68,10 +69,10 @@ namespace campvis {
* \return The registration index.
*/
template<typename T>
size_t registerPipeline(AbstractPipeline* (* callee)(DataContainer*)) {
size_t registerPipeline(std::function<AbstractPipeline*(DataContainer*)> callee) {
tbb::spin_mutex::scoped_lock lock(_mutex);
std::map<std::string, AbstractPipeline* (*)(DataContainer*)>::iterator it = _pipelineMap.lower_bound(T::getId());
std::map< std::string, std::function<AbstractPipeline*(DataContainer*)> >::iterator it = _pipelineMap.lower_bound(T::getId());
if (it == _pipelineMap.end() || it->first != T::getId()) {
_pipelineMap.insert(it, std::make_pair(T::getId(), callee));
}
......@@ -86,7 +87,7 @@ namespace campvis {
mutable tbb::spin_mutex _mutex;
static tbb::atomic<PipelineFactory*> _singleton; ///< the singleton object
std::map<std::string, AbstractPipeline* (*)(DataContainer*)> _pipelineMap;
std::map< std::string, std::function<AbstractPipeline*(DataContainer*)> > _pipelineMap;
};
......
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