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 6b58827e authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge Committed by Hossain Mahmud
Browse files

Introducing SmartProcessorRegistrar using type traits to deduce the correct ctor call.

parent cf636de1
......@@ -80,7 +80,7 @@ namespace campvis {
};
// Instantiate template to register the pipelines.
template class ProcessorRegistrar<LightSourceProvider>;
template class SmartProcessorRegistrar<LightSourceProvider>;
}
#endif // LIGHTSOURCEPROVIDER_H__
......@@ -35,8 +35,11 @@
#include <map>
#include <string>
#include <type_traits>
#include <vector>
#include <functional>
#include "core/pipeline/visualizationprocessor.h"
#include "core/properties/numericproperty.h"
namespace campvis {
......@@ -81,7 +84,8 @@ namespace campvis {
_processorMap.insert(it, std::make_pair(T::getId(), callee));
}
else {
cgtAssert(false, "Registered two processors with the same ID.");
// do nothing, a double registration may occure due to having the ProcessorRegistrar
// being referenced in both campvis-application and campvis-modules
}
return _processorMap.size();
......@@ -102,7 +106,8 @@ namespace campvis {
_processorMap2.insert(it, std::make_pair(T::getId(), callee));
}
else {
cgtAssert(false, "Registered two processors with the same ID.");
// do nothing, a double registration may occure due to having the ProcessorRegistrar
// being referenced in both campvis-application and campvis-modules
}
return _processorMap2.size();
......@@ -119,9 +124,13 @@ namespace campvis {
// ================================================================================================
template<typename T, bool>
class ProcessorRegistrarSwitch {
};
template<typename T>
class ProcessorRegistrar {
public:
class ProcessorRegistrarSwitch<T, false> {
public:
/**
* Static factory method for creating the processor of type T.
* \return A newly created processor of type T. Caller has to take ownership of the pointer.
......@@ -130,13 +139,16 @@ namespace campvis {
return new T();
}
private:
/// static helper field to ensure registration at static initialization time.
static const size_t _factoryId;
};
template<typename T>
const size_t ProcessorRegistrarSwitch<T, false>::_factoryId = ProcessorFactory::getRef().registerProcessor<T>(&ProcessorRegistrarSwitch<T, false>::create);
template<typename T>
class ProcessorRegistrar2 {
class ProcessorRegistrarSwitch<T, true> {
public:
/**
* Static factory method for creating the processor of type T.
......@@ -147,15 +159,23 @@ namespace campvis {
return new T(viewPortSizeProp);
}
private:
/// static helper field to ensure registration at static initialization time.
static const size_t _factoryId;
};
template<typename T>
const size_t ProcessorRegistrar<T>::_factoryId = ProcessorFactory::getRef().registerProcessor<T>(&ProcessorRegistrar<T>::create);
const size_t ProcessorRegistrarSwitch<T, true>::_factoryId = ProcessorFactory::getRef().registerProcessor2<T>(&ProcessorRegistrarSwitch<T, true>::create);
template<typename T>
class SmartProcessorRegistrar {
static const size_t _helperField;
};
template<typename T>
const size_t ProcessorRegistrar2<T>::_factoryId = ProcessorFactory::getRef().registerProcessor2<T>(&ProcessorRegistrar2<T>::create);
const size_t campvis::SmartProcessorRegistrar<T>::_helperField = ProcessorRegistrarSwitch< T, std::is_base_of<VisualizationProcessor, T>::value >::_factoryId;
}
......
......@@ -184,7 +184,7 @@ namespace campvis {
};
// Instantiate template to register the pipelines.
template class ProcessorRegistrar2<VolumeExplorer>;
template class SmartProcessorRegistrar<VolumeExplorer>;
}
#endif // VOLUMEEXPLORER_H__
......@@ -131,7 +131,7 @@ namespace campvis {
};
// Instantiate template to register the pipelines.
template class ProcessorRegistrar2<VolumeRenderer>;
template class SmartProcessorRegistrar<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