remove property name from InitializerFunction's signature

This commit is contained in:
Robert Haschke 2018-02-03 12:21:57 +01:00
parent 0d6dbee215
commit d62b85572a
2 changed files with 10 additions and 11 deletions

View File

@ -50,7 +50,7 @@ namespace task_constructor {
class Property; class Property;
class PropertyMap; class PropertyMap;
/// initializer function, using another name from the passed property map /// initializer function, using given name from the passed property map
boost::any fromName(const PropertyMap& other, const std::string& other_name); boost::any fromName(const PropertyMap& other, const std::string& other_name);
enum PropertyInitializerSource { enum PropertyInitializerSource {
@ -67,7 +67,7 @@ class Property {
friend class PropertyMap; friend class PropertyMap;
public: public:
typedef std::function<boost::any(const PropertyMap& other, const std::string& other_name)> InitializerFunction; typedef std::function<boost::any(const PropertyMap& other)> InitializerFunction;
typedef std::map<PropertyInitializerSource, InitializerFunction> InitializerMap; typedef std::map<PropertyInitializerSource, InitializerFunction> InitializerMap;
Property(const std::type_index& type_index, const std::string& description, const boost::any& default_value); Property(const std::type_index& type_index, const std::string& description, const boost::any& default_value);
@ -80,9 +80,9 @@ public:
std::string typeName() const { return type_index_.name(); } std::string typeName() const { return type_index_.name(); }
/// configure initialization from source using an arbitrary function /// configure initialization from source using an arbitrary function
Property &configureInitFrom(PropertyInitializerSource source, const InitializerFunction& f = fromName); Property &configureInitFrom(PropertyInitializerSource source, const InitializerFunction& f);
/// configure initialization from source using other property name /// configure initialization from source using given other property name
Property &configureInitFrom(PropertyInitializerSource source, const std::string& other_name); Property &configureInitFrom(PropertyInitializerSource source, const std::string& name);
private: private:
std::string description_; std::string description_;

View File

@ -39,6 +39,7 @@
#include <moveit/task_constructor/properties.h> #include <moveit/task_constructor/properties.h>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <ros/console.h> #include <ros/console.h>
#include <functional>
namespace moveit { namespace moveit {
namespace task_constructor { namespace task_constructor {
@ -79,11 +80,9 @@ Property& Property::configureInitFrom(PropertyInitializerSource source, const Pr
return *this; return *this;
} }
Property& Property::configureInitFrom(PropertyInitializerSource source, const std::string &other_name) Property &Property::configureInitFrom(PropertyInitializerSource source, const std::string &name)
{ {
initializers_[source] = [other_name](const PropertyMap& other, const std::string&) { initializers_[source] = [name](const PropertyMap& other) { return fromName(other, name); };
return fromName(other, other_name);
};
return *this; return *this;
} }
@ -109,7 +108,7 @@ void PropertyMap::configureInitFrom(PropertyInitializerSource source, const std:
{ {
for (auto &pair : props_) { for (auto &pair : props_) {
if (properties.empty() || properties.count(pair.first)) if (properties.empty() || properties.count(pair.first))
pair.second.configureInitFrom(source); pair.second.configureInitFrom(source, std::bind(&fromName, std::placeholders::_1, pair.first));
} }
} }
@ -161,7 +160,7 @@ void PropertyMap::performInitFrom(PropertyInitializerSource source, const Proper
Property &p = pair.second; Property &p = pair.second;
auto it = p.initializers_.find(source); auto it = p.initializers_.find(source);
if (it == p.initializers_.end()) continue; if (it == p.initializers_.end()) continue;
const boost::any& value = it->second(other, pair.first); const boost::any& value = it->second(other);
if (value.empty()) continue; if (value.empty()) continue;
typeCheck(value, p.type_index_); typeCheck(value, p.type_index_);