diff --git a/include/ur_rtde_driver/rtde/data_package.h b/include/ur_rtde_driver/rtde/data_package.h index a3b881e..5b9cfeb 100644 --- a/include/ur_rtde_driver/rtde/data_package.h +++ b/include/ur_rtde_driver/rtde/data_package.h @@ -57,7 +57,6 @@ struct StringVisitor : public boost::static_visitor } }; - class DataPackage : public RTDEPackage { public: @@ -73,6 +72,31 @@ public: virtual bool parseWith(comm::BinParser& bp); virtual std::string toString() const; + template + /*! + * \brief Get a data field from the DataPackage. + * + * The data package contains a lot of different data fields, depending on the recipe. + * + * \param name The string identifier for the data field as used in the documentation. + * \param val Target variable. Make sure, it's the correct type. + * + * \returns True on success, false if the field cannot be found inside the package. + */ + bool getData(const std::string& name, T& val) + { + if (data_.find(name) != data_.end()) + { + // TODO: Can we check this somehow? + val = boost::strict_get(data_[name]); + } + else + { + return false; + } + return true; + } + private: // Const would be better here static std::unordered_map type_list_;