mirror of
https://github.com/moveit/moveit_task_constructor.git
synced 2025-11-04 14:49:57 +08:00
generalize initialization source from enum to int
This commit is contained in:
parent
59fe1e7860
commit
f6253c46a4
@ -61,7 +61,8 @@ enum PropertyInitializerSource {
|
|||||||
/** Property is a wrapper for a boost::any value, also providing a default value and a description.
|
/** Property is a wrapper for a boost::any value, also providing a default value and a description.
|
||||||
*
|
*
|
||||||
* Properties can be configured to be initialized from another PropertyMap - if still undefined.
|
* Properties can be configured to be initialized from another PropertyMap - if still undefined.
|
||||||
* Potential sources are the properties of the parent of a stage, or the properties passed in the interface.
|
* A source id allows to distinguish different initialization methods (e.g. using a different reference
|
||||||
|
* name) as well as to define a priority order between sources.
|
||||||
*
|
*
|
||||||
* Setting the value via setValue() updates both, the current value and the default value.
|
* Setting the value via setValue() updates both, the current value and the default value.
|
||||||
* Using reset() the default value can be restored.
|
* Using reset() the default value can be restored.
|
||||||
@ -71,8 +72,9 @@ class Property {
|
|||||||
friend class PropertyMap;
|
friend class PropertyMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef int SourceId;
|
||||||
typedef std::function<boost::any(const PropertyMap& other)> InitializerFunction;
|
typedef std::function<boost::any(const PropertyMap& other)> InitializerFunction;
|
||||||
typedef std::map<PropertyInitializerSource, InitializerFunction> InitializerMap;
|
typedef std::map<SourceId, 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);
|
||||||
|
|
||||||
@ -96,12 +98,12 @@ 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);
|
Property &configureInitFrom(SourceId source, const InitializerFunction& f);
|
||||||
/// configure initialization from source using given other property name
|
/// configure initialization from source using given other property name
|
||||||
Property &configureInitFrom(PropertyInitializerSource source, const std::string& name);
|
Property &configureInitFrom(SourceId source, const std::string& name);
|
||||||
|
|
||||||
/// set current value using configured initializers
|
/// set current value using configured initializers
|
||||||
void performInitFrom(PropertyInitializerSource source, const PropertyMap& other);
|
void performInitFrom(SourceId source, const PropertyMap& other);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string description_;
|
std::string description_;
|
||||||
@ -144,7 +146,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// allow initialization from given source for listed properties - always using the same name
|
/// allow initialization from given source for listed properties - always using the same name
|
||||||
void configureInitFrom(PropertyInitializerSource source, const std::set<std::string> &properties = {});
|
void configureInitFrom(Property::SourceId source, const std::set<std::string> &properties = {});
|
||||||
|
|
||||||
/// set (and, if neccessary, declare) the value of a property
|
/// set (and, if neccessary, declare) the value of a property
|
||||||
void set(const std::string& name, const boost::any& value);
|
void set(const std::string& name, const boost::any& value);
|
||||||
@ -168,7 +170,7 @@ public:
|
|||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
/// perform initialization of still undefined properties using configured initializers
|
/// perform initialization of still undefined properties using configured initializers
|
||||||
void performInitFrom(PropertyInitializerSource source, const PropertyMap& other, bool enforce = false);
|
void performInitFrom(Property::SourceId source, const PropertyMap& other, bool enforce = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace task_constructor
|
} // namespace task_constructor
|
||||||
|
|||||||
@ -83,19 +83,19 @@ void Property::reset()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Property& Property::configureInitFrom(PropertyInitializerSource source, const Property::InitializerFunction &f)
|
Property& Property::configureInitFrom(SourceId source, const Property::InitializerFunction &f)
|
||||||
{
|
{
|
||||||
initializers_[source] = f;
|
initializers_[source] = f;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Property &Property::configureInitFrom(PropertyInitializerSource source, const std::string &name)
|
Property &Property::configureInitFrom(SourceId source, const std::string &name)
|
||||||
{
|
{
|
||||||
initializers_[source] = [name](const PropertyMap& other) { return fromName(other, name); };
|
initializers_[source] = [name](const PropertyMap& other) { return fromName(other, name); };
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Property::performInitFrom(PropertyInitializerSource source, const PropertyMap &other)
|
void Property::performInitFrom(SourceId source, const PropertyMap &other)
|
||||||
{
|
{
|
||||||
auto it = initializers_.find(source);
|
auto it = initializers_.find(source);
|
||||||
if (it == initializers_.end()) return;
|
if (it == initializers_.end()) return;
|
||||||
@ -121,7 +121,7 @@ Property& PropertyMap::property(const std::string &name)
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertyMap::configureInitFrom(PropertyInitializerSource source, const std::set<std::string> &properties)
|
void PropertyMap::configureInitFrom(Property::SourceId source, const std::set<std::string> &properties)
|
||||||
{
|
{
|
||||||
for (auto &pair : props_) {
|
for (auto &pair : props_) {
|
||||||
if (properties.empty() || properties.count(pair.first))
|
if (properties.empty() || properties.count(pair.first))
|
||||||
@ -170,7 +170,7 @@ void PropertyMap::reset()
|
|||||||
pair.second.reset();
|
pair.second.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertyMap::performInitFrom(PropertyInitializerSource source, const PropertyMap &other, bool enforce)
|
void PropertyMap::performInitFrom(Property::SourceId source, const PropertyMap &other, bool enforce)
|
||||||
{
|
{
|
||||||
for (auto& pair : props_) {
|
for (auto& pair : props_) {
|
||||||
Property &p = pair.second;
|
Property &p = pair.second;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user