Go to the documentation of this file.
36 #ifndef __POINTMATCHER_REGISTRAR_H
37 #define __POINTMATCHER_REGISTRAR_H
42 #include <yaml-cpp/yaml.h>
43 #include <boost/format.hpp>
44 #include <boost/typeof/typeof.hpp>
58 template<
typename Interface>
83 std::shared_ptr<C> instance = std::make_shared<C>(
params);
86 for (
const auto& param :
params)
88 if (instance->parametersUsed.find(param.first) == instance->parametersUsed.end()){
90 (boost::format(
"Parameter %1% for module %2% was set but is not used") % param.first % className).str()
99 return C::description();
104 return C::availableParameters();
114 for (
const auto& param :
params)
116 (boost::format(
"Parameter %1% was set but module %2% does not use any parameter") % param.first % className).str()
119 return std::make_shared<C>();
124 return C::description();
134 typedef std::map<std::string, std::shared_ptr<ClassDescriptor>>
DescriptorMap;
151 std::cerr <<
"No element named " <<
name <<
" is registered. Known ones are:\n";
154 (boost::format(
"Trying to instanciate unknown element %1% from registrar") %
name).str()
190 void dump(std::ostream &stream)
const
193 stream <<
"- " << it.first <<
"\n";
197 typename DescriptorMap::const_iterator
begin()
const
203 typename DescriptorMap::const_iterator
end()
const
209 #define REG(name) name##Registrar
210 #define DEF_REGISTRAR(name) PointMatcherSupport::Registrar< name > name##Registrar;
211 #define DEF_REGISTRAR_IFACE(name, ifaceName) PointMatcherSupport::Registrar< ifaceName > name##Registrar;
212 #define ADD_TO_REGISTRAR(name, elementName, element) { \
213 typedef typename PointMatcherSupport::Registrar< name >::template GenericClassDescriptor< element > Desc; \
214 name##Registrar.reg(# elementName, std::make_shared<Desc>() ); \
216 #define ADD_TO_REGISTRAR_NO_PARAM(name, elementName, element) { \
217 typedef typename PointMatcherSupport::Registrar< name >::template GenericClassDescriptorNoParam< element > Desc; \
218 name##Registrar.reg(# elementName, std::make_shared<Desc>() ); \
222 #endif // __POINTMATCHER_REGISTRAR_H
const std::string getDescription(const std::string &name) const
Get the description of a class.
virtual const Parametrizable::ParametersDoc availableParameters() const
Return the available parameters for this class.
virtual const std::string description() const
Return the description of this class.
InvalidElement(const std::string &reason)
Construct an invalid-element exception.
The interface for class descriptors.
Interface TargetType
alias to recover the template parameter
DescriptorMap classes
known classes that can be constructed
virtual std::shared_ptr< Interface > createInstance(const std::string &className, const Parametrizable::Parameters ¶ms) const =0
Create an instance of Interface using params.
std::shared_ptr< ClassDescriptor > getDescriptor(const std::string &name) const
Return a descriptor following a name, throw an exception if name is invalid.
virtual const Parametrizable::ParametersDoc availableParameters() const =0
Return the available parameters for this class.
virtual const Parametrizable::ParametersDoc availableParameters() const
Return the available parameters for this class.
std::shared_ptr< Interface > createFromYAML(const YAML::Node &module) const
Create an instance from a YAML node.
std::vector< ParameterDoc > ParametersDoc
The documentation of all parameters.
std::shared_ptr< Interface > create(const std::string &name, const Parametrizable::Parameters ¶ms=Parametrizable::Parameters()) const
Create an instance.
DescriptorMap::const_iterator end() const
end for const iterator over classes descriptions
virtual std::shared_ptr< Interface > createInstance(const std::string &className, const Parametrizable::Parameters ¶ms) const
Create an instance of Interface using params.
void getNameParamsFromYAML(const YAML::Node &module, std::string &name, Parametrizable::Parameters ¶ms)
Retrieve name and parameters from a yaml node.
Parametrizable::InvalidParameter InvalidParameter
DescriptorMap::const_iterator begin() const
begin for const iterator over classes descriptions
virtual std::shared_ptr< Interface > createInstance(const std::string &className, const Parametrizable::Parameters ¶ms) const
Create an instance of Interface using params.
virtual ~ClassDescriptor()
Virtual destructor, do nothing.
const Parametrizable::ParametersDoc getAvailableParameters(const std::string &name) const
Get all available parameters of a class.
A descriptor for a class C that does not provide any parameter.
void dump(std::ostream &stream) const
Print the list of registered classes to stream.
virtual const std::string description() const =0
Return the description of this class.
A descriptor for a class C that provides parameters.
Functions and classes that are not dependant on scalar type are defined in this namespace.
std::map< std::string, std::shared_ptr< ClassDescriptor > > DescriptorMap
descriptors for sub-classes of Interface, indexed by their names
std::map< std::string, Parameter > Parameters
Parameters stored as a map of string->string.
virtual const std::string description() const
Return the description of this class.
An exception thrown when one tries to instanciate an element that does not exist in the registrar.
A factor for subclasses of Interface.
void reg(const std::string &name, std::shared_ptr< ClassDescriptor > descriptor)
Register a class by storing an instance of a descriptor helper class.