36 #ifndef __POINTMATCHER_REGISTRAR_H 37 #define __POINTMATCHER_REGISTRAR_H 39 #include "Parametrizable.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 DescriptorMap::const_iterator end() const
end for const iterator over classes descriptions
Definition: Registrar.h:214
An exception thrown when one tries to instanciate an element that does not exist in the registrar.
Definition: Registrar.h:69
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< Interface > create(const std::string &name, const Parametrizable::Parameters ¶ms=Parametrizable::Parameters()) const
Create an instance.
Definition: Registrar.h:179
virtual ~ClassDescriptor()
Virtual destructor, do nothing.
Definition: Registrar.h:85
A factor for subclasses of Interface.
Definition: Registrar.h:76
virtual const std::string description() const
Return the description of this class.
Definition: Registrar.h:136
virtual const Parametrizable::ParametersDoc availableParameters() const
Return the available parameters for this class.
Definition: Registrar.h:118
A descriptor for a class C that provides parameters.
Definition: Registrar.h:96
The interface for class descriptors.
Definition: Registrar.h:82
A descriptor for a class C that does not provide any parameter.
Definition: Registrar.h:126
Interface TargetType
alias to recover the template parameter
Definition: Registrar.h:79
virtual std::shared_ptr< Interface > createInstance(const std::string &className, const Parametrizable::Parameters ¶ms) const
Create an instance of Interface using params.
Definition: Registrar.h:128
DescriptorMap classes
known classes that can be constructed
Definition: Registrar.h:148
std::shared_ptr< Interface > createFromYAML(const YAML::Node &module) const
Create an instance from a YAML node.
Definition: Registrar.h:185
std::map< std::string, Parameter > Parameters
Parameters stored as a map of string->string.
Definition: Parametrizable.h:156
Functions and classes that are not dependant on scalar type are defined in this namespace.
Definition: PointMatcher.h:78
void getNameParamsFromYAML(const YAML::Node &module, std::string &name, Parametrizable::Parameters ¶ms)
Retrieve name and parameters from a yaml node.
InvalidElement(const std::string &reason)
Construct an invalid-element exception.
Definition: Registry.cpp:55
virtual std::shared_ptr< Interface > createInstance(const std::string &className, const Parametrizable::Parameters ¶ms) const
Create an instance of Interface using params.
Definition: Registrar.h:98
const ClassDescriptor * getDescriptor(const std::string &name) const
Return a descriptor following a name, throw an exception if name is invalid.
Definition: Registrar.h:164
~Registrar()
Destructor, remove all classes descriptors.
Definition: Registrar.h:152
void reg(const std::string &name, ClassDescriptor *descriptor)
Register a class by storing an instance of a descriptor helper class.
Definition: Registrar.h:158
An exception thrown when one tries to fetch the value of an unexisting parameter.
Definition: Parametrizable.h:101
DescriptorMap::const_iterator begin() const
begin for const iterator over classes descriptions
Definition: Registrar.h:209
virtual const Parametrizable::ParametersDoc availableParameters() const =0
Return the available parameters for this class.
std::vector< ParameterDoc > ParametersDoc
The documentation of all parameters.
Definition: Parametrizable.h:144
virtual const Parametrizable::ParametersDoc availableParameters() const
Return the available parameters for this class.
Definition: Registrar.h:140
std::map< std::string, ClassDescriptor * > DescriptorMap
descriptors for sub-classes of Interface, indexed by their names
Definition: Registrar.h:147
void dump(std::ostream &stream) const
Print the list of registered classes to stream.
Definition: Registrar.h:202
virtual const std::string description() const
Return the description of this class.
Definition: Registrar.h:114
virtual const std::string description() const =0
Return the description of this class.
const std::string getDescription(const std::string &name) const
Get the description of a class.
Definition: Registrar.h:196