From abea2ee82bbc959e7db4331d137f236cf3ada03b Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Fri, 1 Jun 2018 07:18:47 +0200 Subject: [PATCH] reuse boost::any's type_index type --- core/include/moveit/task_constructor/properties.h | 7 ++++--- core/src/properties.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/include/moveit/task_constructor/properties.h b/core/include/moveit/task_constructor/properties.h index 6fce3790..107719e1 100644 --- a/core/include/moveit/task_constructor/properties.h +++ b/core/include/moveit/task_constructor/properties.h @@ -77,9 +77,10 @@ boost::any fromName(const PropertyMap& other, const std::string& other_name); class Property { friend class PropertyMap; + typedef decltype(std::declval().type()) type_index; typedef std::function SerializeFunction; - Property(const std::type_index &type_index, const std::string &description, const boost::any &default_value, + Property(const type_index &type_index, const std::string &description, const boost::any &default_value, const Property::SerializeFunction &serialize); template @@ -153,7 +154,7 @@ public: private: std::string description_; - std::type_index type_index_; + type_index type_index_; boost::any default_; boost::any value_; @@ -201,7 +202,7 @@ class PropertyMap typedef std::map::const_iterator const_iterator; /// implementation of declare methods - Property& declare(const std::string& name, const std::type_index& type_index, + Property& declare(const std::string& name, const Property::type_index& type_index, const std::string& description, const boost::any& default_value, const Property::SerializeFunction &serialize); diff --git a/core/src/properties.cpp b/core/src/properties.cpp index 75f6693e..8606f6f1 100644 --- a/core/src/properties.cpp +++ b/core/src/properties.cpp @@ -43,7 +43,7 @@ namespace moveit { namespace task_constructor { -Property::Property(const std::type_index& type_index, const std::string& description, const boost::any& default_value, +Property::Property(const Property::type_index& type_index, const std::string& description, const boost::any& default_value, const Property::SerializeFunction &serialize) : description_(description) , type_index_(type_index) @@ -52,7 +52,7 @@ Property::Property(const std::type_index& type_index, const std::string& descrip , serialize_(serialize) { // default value's type should match declared type by construction - assert(default_.empty() || std::type_index(default_.type()) == type_index_); + assert(default_.empty() || default_.type() == type_index_); } void Property::setValue(const boost::any &value) { @@ -62,7 +62,7 @@ void Property::setValue(const boost::any &value) { void Property::setCurrentValue(const boost::any &value) { - if (!value.empty() && std::type_index(value.type()) != type_index_) + if (!value.empty() && value.type() != type_index_) throw Property::type_error(value.type().name(), type_index_.name()); value_ = value; @@ -107,7 +107,7 @@ void Property::performInitFrom(SourceId source, const PropertyMap &other) } -Property& PropertyMap::declare(const std::string &name, const std::type_index &type_index, +Property& PropertyMap::declare(const std::string &name, const Property::type_index &type_index, const std::string &description, const boost::any &default_value, const Property::SerializeFunction &serialize) {