37 #ifndef OMPL_BASE_GENERIC_PARAM_
38 #define OMPL_BASE_GENERIC_PARAM_
41 #include "ompl/util/ClassForward.h"
42 #include <boost/function.hpp>
43 #include <boost/lexical_cast.hpp>
56 OMPL_CLASS_FORWARD(GenericParam);
90 virtual bool setValue(
const std::string &value) = 0;
93 virtual std::string
getValue(
void)
const = 0;
101 setValue(boost::lexical_cast<std::string>(value));
103 catch (boost::bad_lexical_cast &e)
105 OMPL_WARN(
"Invalid value format specified for parameter '%s': %s",
name_.c_str(), e.what());
162 OMPL_ERROR(
"Setter function must be specified for parameter");
175 setter_(boost::lexical_cast<T>(value));
177 catch (boost::bad_lexical_cast &e)
180 OMPL_WARN(
"Invalid value format specified for parameter '%s': %s",
name_.c_str(), e.what());
186 OMPL_DEBUG(
"The value of parameter '%s' was set to: '%s'",
name_.c_str(), value.c_str());
195 return boost::lexical_cast<std::string>(
getter_());
197 catch (boost::bad_lexical_cast &e)
199 OMPL_WARN(
"Unable to parameter '%s' to string: %s",
name_.c_str(), e.what());
229 void add(
const GenericParamPtr ¶m);
232 void remove(
const std::string &name);
250 bool setParam(
const std::string &key,
const std::string &value);
253 bool getParam(
const std::string &key, std::string &value)
const;
260 bool setParams(
const std::map<std::string, std::string> &kv,
bool ignoreUnknown =
false);
263 void getParams(std::map<std::string, std::string> ¶ms)
const;
272 const std::map<std::string, GenericParamPtr>&
getParams(
void)
const;
275 const GenericParamPtr&
getParam(
const std::string &key)
const;
278 bool hasParam(
const std::string &key)
const;
286 return params_.size();
293 void print(std::ostream &out)
const;
297 std::map<std::string, GenericParamPtr> params_;
void print(std::ostream &out) const
Print the parameters to a stream.
bool hasParam(const std::string &key) const
Check whether this set of parameters includes the parameter named key.
boost::function< void(T)> SetterFn
The type for the 'setter' function for this parameter.
std::string name_
The name of the parameter.
void include(const ParamSet &other, const std::string &prefix="")
Include the params of a different ParamSet into this one. Optionally include a prefix for each of the...
const std::string & getName(void) const
Get the name of the parameter.
GenericParam(const std::string &name)
The constructor of a parameter takes the name of the parameter (name)
virtual std::string getValue(void) const =0
Retrieve the value of the parameter, as a string.
Motion planning algorithms often employ parameters to guide their exploration process. (e.g., goal biasing). Motion planners (and some of their components) use this class to declare what the parameters are, in a generic way, so that they can be set externally.
virtual bool setValue(const std::string &value)
Set the value of the parameter. The value is taken in as a string, but converted to the type of that ...
void getParamNames(std::vector< std::string > ¶ms) const
List the names of the known parameters.
bool setParams(const std::map< std::string, std::string > &kv, bool ignoreUnknown=false)
Set the values for a set of parameters. The parameter names are the keys in the map kv...
bool getParam(const std::string &key, std::string &value) const
Get the value of the parameter named key. Store the value as string in value and return true if the p...
This is a helper class that instantiates parameters with different data types.
Maintain a set of parameters.
bool setParam(const std::string &key, const std::string &value)
Algorithms in OMPL often have parameters that can be set externally. While each algorithm will have t...
#define OMPL_ERROR(fmt,...)
Log a formatted error string.
void getParamValues(std::vector< std::string > &vals) const
List the values of the known parameters, in the same order as getParamNames()
SetterFn setter_
The setter function for this parameter.
std::size_t size(void) const
Get the number of parameters maintained by this instance.
GenericParam & operator[](const std::string &key)
Access operator for parameters, by name. If the parameter is not defined, an exception is thrown...
void setName(const std::string &name)
Set the name of the parameter.
#define OMPL_WARN(fmt,...)
Log a formatted warning string.
GenericParam & operator=(const T &value)
Assignment operator by type. This is just for convenience, as it just calls setValue() ...
const std::string & getRangeSuggestion(void) const
Get the suggested range of values.
#define OMPL_DEBUG(fmt,...)
Log a formatted debugging string.
const std::map< std::string, GenericParamPtr > & getParams(void) const
Get the map from parameter names to parameter descriptions.
void declareParam(const std::string &name, const typename SpecificParam< T >::SetterFn &setter, const typename SpecificParam< T >::GetterFn &getter=typename SpecificParam< T >::GetterFn())
This function declares a parameter name, and specifies the setter and getter functions.
boost::function< T()> GetterFn
The type for the 'getter' function for this parameter.
void add(const GenericParamPtr ¶m)
Add a parameter to the set.
void setRangeSuggestion(const std::string &rangeSuggestion)
Set a suggested range.
void clear(void)
Clear all the set parameters.
std::string rangeSuggestion_
Suggested range for the parameter.
SpecificParam(const std::string &name, const SetterFn &setter, const GetterFn &getter=GetterFn())
An explicit instantiation of a parameter name requires the setter function and optionally the getter ...
virtual bool setValue(const std::string &value)=0
Set the value of the parameter. The value is taken in as a string, but converted to the type of that ...
GetterFn getter_
The getter function for this parameter.
virtual std::string getValue(void) const
Retrieve the value of the parameter, as a string.