reuse boost::any's type_index type

This commit is contained in:
Robert Haschke 2018-06-01 07:18:47 +02:00
parent 2e9932cfbc
commit abea2ee82b
2 changed files with 8 additions and 7 deletions

View File

@ -77,9 +77,10 @@ boost::any fromName(const PropertyMap& other, const std::string& other_name);
class Property { class Property {
friend class PropertyMap; friend class PropertyMap;
typedef decltype(std::declval<boost::any>().type()) type_index;
typedef std::function<std::string(const boost::any& v)> SerializeFunction; typedef std::function<std::string(const boost::any& v)> 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); const Property::SerializeFunction &serialize);
template <typename T> template <typename T>
@ -153,7 +154,7 @@ public:
private: private:
std::string description_; std::string description_;
std::type_index type_index_; type_index type_index_;
boost::any default_; boost::any default_;
boost::any value_; boost::any value_;
@ -201,7 +202,7 @@ class PropertyMap
typedef std::map<std::string, Property>::const_iterator const_iterator; typedef std::map<std::string, Property>::const_iterator const_iterator;
/// implementation of declare methods /// 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 std::string& description,
const boost::any& default_value, const boost::any& default_value,
const Property::SerializeFunction &serialize); const Property::SerializeFunction &serialize);

View File

@ -43,7 +43,7 @@
namespace moveit { namespace moveit {
namespace task_constructor { 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) const Property::SerializeFunction &serialize)
: description_(description) : description_(description)
, type_index_(type_index) , type_index_(type_index)
@ -52,7 +52,7 @@ Property::Property(const std::type_index& type_index, const std::string& descrip
, serialize_(serialize) , serialize_(serialize)
{ {
// default value's type should match declared type by construction // 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) { 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) 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()); throw Property::type_error(value.type().name(), type_index_.name());
value_ = value; 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 std::string &description, const boost::any &default_value,
const Property::SerializeFunction &serialize) const Property::SerializeFunction &serialize)
{ {