Go to the documentation of this file.
36 #ifndef __POINTMATCHER_REGISTRAR_H
37 #define __POINTMATCHER_REGISTRAR_H
41 #include <boost/format.hpp>
42 #include <boost/typeof/typeof.hpp>
45 #ifdef SYSTEM_YAML_CPP
55 #endif // HAVE_YAML_CPP
59 #ifdef SYSTEM_YAML_CPP
60 namespace YAML = ::YAML;
62 namespace YAML = ::YAML_PM;
75 template<
typename Interface>
100 std::shared_ptr<C> instance = std::make_shared<C>(params);
103 for (BOOST_AUTO(it, params.begin()); it != params.end() ;++it)
105 if (instance->parametersUsed.find(it->first) == instance->parametersUsed.end()){
107 (boost::format(
"Parameter %1% for module %2% was set but is not used") % it->first % className).str()
116 return C::description();
120 return C::availableParameters();
130 for (BOOST_AUTO(it, params.begin()); it != params.end() ;++it)
132 (boost::format(
"Parameter %1% was set but module %2% dos not use any parameter") % it->first % className).str()
134 return std::make_shared<C>();
138 return C::description();
166 BOOST_AUTO(it,
classes.find(name));
169 std::cerr <<
"No element named " << name <<
" is registered. Known ones are:\n";
172 (boost::format(
"Trying to instanciate unknown element %1% from registrar") % name).str()
192 return create(name, params);
202 void dump(std::ostream &stream)
const
205 stream <<
"- " << it->first <<
"\n";
209 typename DescriptorMap::const_iterator
begin()
const
214 typename DescriptorMap::const_iterator
end()
const
220 #define REG(name) name##Registrar
221 #define DEF_REGISTRAR(name) PointMatcherSupport::Registrar< name > name##Registrar;
222 #define DEF_REGISTRAR_IFACE(name, ifaceName) PointMatcherSupport::Registrar< ifaceName > name##Registrar;
223 #define ADD_TO_REGISTRAR(name, elementName, element) { \
224 typedef typename PointMatcherSupport::Registrar< name >::template GenericClassDescriptor< element > Desc; \
225 name##Registrar.reg(# elementName, new Desc() ); \
227 #define ADD_TO_REGISTRAR_NO_PARAM(name, elementName, element) { \
228 typedef typename PointMatcherSupport::Registrar< name >::template GenericClassDescriptorNoParam< element > Desc; \
229 name##Registrar.reg(# elementName, new Desc() ); \
233 #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.
void reg(const std::string &name, ClassDescriptor *descriptor)
Register a class by storing an instance of a descriptor helper class.
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.
virtual const Parametrizable::ParametersDoc availableParameters() const =0
Return the available parameters for this class.
std::map< std::string, ClassDescriptor * > DescriptorMap
descriptors for sub-classes of Interface, indexed by their names
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.
const ClassDescriptor * getDescriptor(const std::string &name) const
Return a descriptor following a name, throw an exception if name is invalid.
An exception thrown when one tries to fetch the value of an unexisting parameter.
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.
~Registrar()
Destructor, remove all classes descriptors.
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, 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.
mp2p_icp
Author(s):
autogenerated on Fri Dec 20 2024 03:45:59