diff options
author | Aaron Rossetto <aaron.rossetto@ni.com> | 2019-08-28 08:32:00 -0500 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-11-26 12:21:31 -0800 |
commit | cb9329a681552e6ac6277d16e1627afcbb23e637 (patch) | |
tree | bb87fc4362cb0d683ed41259498888fa71f15d36 /host/include | |
parent | 4f130e3c129111cb8fb044a5cbc007df3628978c (diff) | |
download | uhd-cb9329a681552e6ac6277d16e1627afcbb23e637.tar.gz uhd-cb9329a681552e6ac6277d16e1627afcbb23e637.tar.bz2 uhd-cb9329a681552e6ac6277d16e1627afcbb23e637.zip |
uhd: Check property type at access; error if mismatch
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/property_tree.hpp | 8 | ||||
-rw-r--r-- | host/include/uhd/property_tree.ipp | 7 |
2 files changed, 12 insertions, 3 deletions
diff --git a/host/include/uhd/property_tree.hpp b/host/include/uhd/property_tree.hpp index 11b92393a..d97a5505e 100644 --- a/host/include/uhd/property_tree.hpp +++ b/host/include/uhd/property_tree.hpp @@ -14,6 +14,7 @@ #include <boost/function.hpp> #include <boost/shared_ptr.hpp> #include <boost/utility.hpp> +#include <typeindex> #include <vector> namespace uhd { @@ -252,10 +253,15 @@ private: virtual boost::shared_ptr<void> _pop(const fs_path& path) = 0; //! Internal create property with wild-card type - virtual void _create(const fs_path& path, const boost::shared_ptr<void>& prop) = 0; + virtual void _create(const fs_path& path, const boost::shared_ptr<void>& prop, + std::type_index prop_type) = 0; //! Internal access property with wild-card type virtual boost::shared_ptr<void>& _access(const fs_path& path) const = 0; + + //! Internal access property with wild-card type but with type verification + virtual boost::shared_ptr<void>& _access_with_type_check( + const fs_path& path, std::type_index expected_prop_type) const = 0; }; } // namespace uhd diff --git a/host/include/uhd/property_tree.ipp b/host/include/uhd/property_tree.ipp index ca5d6904f..20ad43fb1 100644 --- a/host/include/uhd/property_tree.ipp +++ b/host/include/uhd/property_tree.ipp @@ -12,6 +12,7 @@ #include <uhd/exception.hpp> #include <boost/foreach.hpp> #include <boost/scoped_ptr.hpp> +#include <typeindex> #include <vector> /*********************************************************************** @@ -182,14 +183,16 @@ template <typename T> property<T>& property_tree::create(const fs_path& path, coerce_mode_t coerce_mode) { this->_create(path, - typename boost::shared_ptr<property<T> >(new property_impl<T>(coerce_mode))); + typename boost::shared_ptr<property<T> >(new property_impl<T>(coerce_mode)), + std::type_index(typeid(T))); return this->access<T>(path); } template <typename T> property<T>& property_tree::access(const fs_path& path) { - return *boost::static_pointer_cast<property<T> >(this->_access(path)); + return *boost::static_pointer_cast<property<T> >( + this->_access_with_type_check(path, std::type_index(typeid(T)))); } template <typename T> |