Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit 66c8e970 authored by Hossain Mahmud's avatar Hossain Mahmud
Browse files

manual process to handle processorfactory with two distinct ProcessorRegistrar

parent 497a9126
......@@ -32,6 +32,7 @@
#include "core/properties/floatingpointproperty.h"
#include "modules/modulesapi.h"
#include "modules/processorfactory.h"
namespace campvis {
/**
......@@ -49,9 +50,13 @@ namespace campvis {
* Destructor
**/
virtual ~LightSourceProvider();
/**
* To be used in ProcessorFactory static methods
*/
static const std::string getId() { return "LightSourceProvider"; };
/// \see AbstractProcessor::getName()
virtual const std::string getName() const { return "LightSourceProvider"; };
virtual const std::string getName() const { return getId(); };
/// \see AbstractProcessor::getDescription()
virtual const std::string getDescription() const { return "Creates LightSourceData and stores it in the DataContainer."; };
/// \see AbstractProcessor::getAuthor()
......@@ -74,6 +79,8 @@ namespace campvis {
static const std::string loggerCat_;
};
// Instantiate template to register the pipelines.
template class ProcessorRegistrar<LightSourceProvider>;
}
#endif // LIGHTSOURCEPROVIDER_H__
......@@ -53,7 +53,9 @@ namespace campvis {
tbb::spin_mutex::scoped_lock lock(_mutex);
std::vector<std::string> toReturn;
toReturn.reserve(_processorMap.size());
toReturn.reserve(_processorMap2.size()+_processorMap.size());
for (auto it = _processorMap2.begin(); it != _processorMap2.end(); ++it)
toReturn.push_back(it->first);
for (auto it = _processorMap.begin(); it != _processorMap.end(); ++it)
toReturn.push_back(it->first);
return toReturn;
......@@ -61,12 +63,20 @@ namespace campvis {
AbstractProcessor* ProcessorFactory::createProcessor(const std::string& id, IVec2Property* viewPortSizeProp) const {
tbb::spin_mutex::scoped_lock lock(_mutex);
auto it = _processorMap.find(id);
if (it == _processorMap.end())
return nullptr;
else
return (it->second)(viewPortSizeProp);
if (viewPortSizeProp != nullptr) {
auto it = _processorMap2.find(id);
if (it == _processorMap2.end())
return nullptr;
else
return (it->second)(viewPortSizeProp);
} else {
auto it = _processorMap.find(id);
if (it == _processorMap.end())
return nullptr;
else
return (it->second)();
}
}
}
......@@ -63,7 +63,7 @@ namespace campvis {
std::vector<std::string> getRegisteredProcessors() const;
AbstractProcessor* createProcessor(const std::string& id, IVec2Property* viewPortSizeProp) const;
AbstractProcessor* createProcessor(const std::string& id, IVec2Property* viewPortSizeProp = 0) const;
/**
* Statically registers the processor of type T using \a callee as factory method.
......@@ -72,7 +72,22 @@ namespace campvis {
* \return The registration index.
*/
template<typename T>
size_t registerProcessor(std::function<AbstractProcessor*(IVec2Property*)> callee) {
size_t registerProcessor2(std::function<AbstractProcessor*(IVec2Property*)> callee) {
tbb::spin_mutex::scoped_lock lock(_mutex);
auto it = _processorMap2.lower_bound(T::getId());
if (it == _processorMap2.end() || it->first != T::getId()) {
_processorMap2.insert(it, std::make_pair(T::getId(), callee));
}
else {
cgtAssert(false, "Registered two processors with the same ID.");
}
return _processorMap2.size();
}
template<typename T>
size_t registerProcessor(std::function<AbstractProcessor*()> callee) {
tbb::spin_mutex::scoped_lock lock(_mutex);
auto it = _processorMap.lower_bound(T::getId());
......@@ -85,14 +100,12 @@ namespace campvis {
return _processorMap.size();
}
private:
mutable tbb::spin_mutex _mutex;
static tbb::atomic<ProcessorFactory*> _singleton; ///< the singleton object
std::map< std::string, std::function<AbstractProcessor*(IVec2Property*)>> _processorMap;
std::map< std::string, std::function<AbstractProcessor*()>> _processorMap;
std::map< std::string, std::function<AbstractProcessor*(IVec2Property*)>> _processorMap2;
};
......@@ -103,14 +116,25 @@ namespace campvis {
public:
/**
* Static factory method for creating the processor of type T.
* \param args DataContainer for the created processor to work on.
* \return A newly created processor of type T. Caller has to take ownership of the pointer.
*/
//static AbstractProcessor* create() {
// return new T();
//}
static AbstractProcessor* create() {
return new T();
}
private:
/// static helper field to ensure registration at static initialization time.
static const size_t _factoryId;
};
template<typename T>
class ProcessorRegistrar2 {
public:
/**
* Static factory method for creating the processor of type T.
* \param viewPortSizeProp viewPortSizeProp for the created processor to work on.
* \return A newly created processor of type T. Caller has to take ownership of the pointer.
*/
static AbstractProcessor* create(IVec2Property* viewPortSizeProp) {
return new T(viewPortSizeProp);
}
......@@ -122,6 +146,8 @@ namespace campvis {
template<typename T>
const size_t ProcessorRegistrar<T>::_factoryId = ProcessorFactory::getRef().registerProcessor<T>(&ProcessorRegistrar<T>::create);
template<typename T>
const size_t ProcessorRegistrar2<T>::_factoryId = ProcessorFactory::getRef().registerProcessor2<T>(&ProcessorRegistrar2<T>::create);
}
......
......@@ -184,7 +184,7 @@ namespace campvis {
};
// Instantiate template to register the pipelines.
template class ProcessorRegistrar<VolumeExplorer>;
template class ProcessorRegistrar2<VolumeExplorer>;
}
#endif // VOLUMEEXPLORER_H__
......@@ -131,7 +131,7 @@ namespace campvis {
};
// Instantiate template to register the pipelines.
template class ProcessorRegistrar<VolumeRenderer>;
template class ProcessorRegistrar2<VolumeRenderer>;
}
#endif // VOLUMERENDERER_H__
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