diff options
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/property_tree.hpp | 9 | ||||
-rw-r--r-- | host/include/uhd/property_tree.ipp | 10 |
2 files changed, 14 insertions, 5 deletions
diff --git a/host/include/uhd/property_tree.hpp b/host/include/uhd/property_tree.hpp index b20f3b779..c41a129b1 100644 --- a/host/include/uhd/property_tree.hpp +++ b/host/include/uhd/property_tree.hpp @@ -31,7 +31,7 @@ namespace uhd{ * A templated property interface for holding a value * and registering callbacks when that value changes. */ -template <typename T> class UHD_API property : boost::noncopyable{ +template <typename T> class property : boost::noncopyable{ public: typedef boost::function<void(const T &)> subscriber_type; typedef boost::function<T(void)> publisher_type; @@ -89,6 +89,13 @@ public: * \return the current value in the property */ virtual T get(void) const = 0; + + /*! + * A property is empty if it has never been set. + * A property with a publisher is never empty. + * \return true if the property is empty + */ + virtual bool empty(void) const = 0; }; /*! diff --git a/host/include/uhd/property_tree.ipp b/host/include/uhd/property_tree.ipp index 58ee2339c..868cba475 100644 --- a/host/include/uhd/property_tree.ipp +++ b/host/include/uhd/property_tree.ipp @@ -27,7 +27,7 @@ **********************************************************************/ namespace uhd{ namespace /*anon*/{ -template <typename T> class UHD_API property_impl : public property<T>{ +template <typename T> class property_impl : public property<T>{ public: property<T> &coerce(const typename property<T>::coercer_type &coercer){ @@ -59,12 +59,14 @@ public: } T get(void) const{ - if (_publisher.empty() and _value.get() == NULL) throw uhd::runtime_error( - "Called get() on property with an uninitialized value" - ); + if (empty()) throw uhd::runtime_error("Cannot get() on an empty property"); return _publisher.empty()? *_value : _publisher(); } + bool empty(void) const{ + return _publisher.empty() and _value.get() == NULL; + } + private: std::vector<typename property<T>::subscriber_type> _subscribers; typename property<T>::publisher_type _publisher; |