From d44277d7ac7acc621442fe7ef4555f568fbe88d0 Mon Sep 17 00:00:00 2001 From: Brent Stapleton Date: Tue, 30 Apr 2019 10:22:46 -0700 Subject: prop_tree: formatting property tree files - Ran clang-format - Fixed typos - Updated copyright headers clang-format -i --style=file \ host/include/uhd/property_tree.hpp \ host/include/uhd/property_tree.ipp clang-format -i --style=file \ host/lib/property_tree.cpp host/tests/property_test.cpp --- host/include/uhd/property_tree.hpp | 16 +++-- host/include/uhd/property_tree.ipp | 142 ++++++++++++++++++++++++------------- 2 files changed, 101 insertions(+), 57 deletions(-) (limited to 'host/include') diff --git a/host/include/uhd/property_tree.hpp b/host/include/uhd/property_tree.hpp index 18091511e..42e73458f 100644 --- a/host/include/uhd/property_tree.hpp +++ b/host/include/uhd/property_tree.hpp @@ -1,6 +1,7 @@ // // Copyright 2011,2014-2016 Ettus Research // Copyright 2018 Ettus Research, a National Instruments Company +// Copyright 2019 Ettus Research, a National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -34,8 +35,8 @@ namespace uhd { * in a desired value and produces a coerced value. * A property must have *exactly one* coercer. * 2. Manual coercion: Manually calling the set_coerced - * API fnction to coerce the value of the propery. In - * order to use manual coercion, the propery must be + * API function to coerce the value of the property. In + * order to use manual coercion, the property must be * created with the MANUAL_COERCE mode. * If the coerce mode for a property is AUTO_COERCE then * it always has a coercer. If the set_coercer API is @@ -53,7 +54,7 @@ namespace uhd { * callback to get the value of the property. Calling * get on the property will always call the publisher and * the cached desired and coerced values are updated only - * using set* calls. A preprty must have *at most one* + * using set* calls. A property must have *at most one* * publisher. It is legal to have both a coercer * and publisher for a property but the only way to access * the desired and coerced values in that case would be by @@ -64,7 +65,8 @@ namespace uhd { * - T must have a copy constructor * - T must have an assignment operator */ -template class property : uhd::noncopyable +template +class property : uhd::noncopyable { public: typedef boost::function subscriber_type; @@ -181,7 +183,8 @@ public: virtual bool empty(void) const = 0; }; -template property::~property(void) +template +property::~property(void) { /* NOP */ } @@ -237,7 +240,8 @@ public: property& create(const fs_path& path, coerce_mode_t coerce_mode = AUTO_COERCE); //! Get access to a property in the tree - template property& access(const fs_path& path); + template + property& access(const fs_path& path); private: //! Internal create property with wild-card type diff --git a/host/include/uhd/property_tree.ipp b/host/include/uhd/property_tree.ipp index c3203a63b..de1ac28c0 100644 --- a/host/include/uhd/property_tree.ipp +++ b/host/include/uhd/property_tree.ipp @@ -1,6 +1,7 @@ // // Copyright 2011,2014-2016 Ettus Research // Copyright 2018 Ettus Research, a National Instruments Company +// Copyright 2019 Ettus Research, a National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -16,105 +17,137 @@ /*********************************************************************** * Implement templated property impl **********************************************************************/ -namespace uhd{ namespace /*anon*/{ +namespace uhd { namespace /*anon*/ { -template class property_impl : public property{ +template +class property_impl : public property +{ public: - property_impl(property_tree::coerce_mode_t mode) : _coerce_mode(mode){ + property_impl(property_tree::coerce_mode_t mode) : _coerce_mode(mode) + { if (_coerce_mode == property_tree::AUTO_COERCE) { _coercer = DEFAULT_COERCER; } } - ~property_impl(void){ + ~property_impl(void) + { /* NOP */ } - property &set_coercer(const typename property::coercer_type &coercer){ - if (not _coercer.empty()) uhd::assertion_error("cannot register more than one coercer for a property"); - if (_coerce_mode == property_tree::MANUAL_COERCE) uhd::assertion_error("cannot register coercer for a manually coerced property"); + property& set_coercer(const typename property::coercer_type& coercer) + { + if (not _coercer.empty()) + uhd::assertion_error("cannot register more than one coercer for a property"); + if (_coerce_mode == property_tree::MANUAL_COERCE) + uhd::assertion_error( + "cannot register coercer for a manually coerced property"); _coercer = coercer; return *this; } - property &set_publisher(const typename property::publisher_type &publisher){ - if (not _publisher.empty()) uhd::assertion_error("cannot register more than one publisher for a property"); + property& set_publisher(const typename property::publisher_type& publisher) + { + if (not _publisher.empty()) + uhd::assertion_error( + "cannot register more than one publisher for a property"); _publisher = publisher; return *this; } - property &add_desired_subscriber(const typename property::subscriber_type &subscriber){ + property& add_desired_subscriber( + const typename property::subscriber_type& subscriber) + { _desired_subscribers.push_back(subscriber); return *this; } - property &add_coerced_subscriber(const typename property::subscriber_type &subscriber){ + property& add_coerced_subscriber( + const typename property::subscriber_type& subscriber) + { _coerced_subscribers.push_back(subscriber); return *this; } - property &update(void){ + property& update(void) + { this->set(this->get()); return *this; } - void _set_coerced(const T &value){ + void _set_coerced(const T& value) + { init_or_set_value(_coerced_value, value); - BOOST_FOREACH(typename property::subscriber_type &csub, _coerced_subscribers){ - csub(get_value_ref(_coerced_value)); //let errors propagate + BOOST_FOREACH ( + typename property::subscriber_type& csub, _coerced_subscribers) { + csub(get_value_ref(_coerced_value)); // let errors propagate } } - property &set(const T &value){ + property& set(const T& value) + { init_or_set_value(_value, value); - BOOST_FOREACH(typename property::subscriber_type &dsub, _desired_subscribers){ - dsub(get_value_ref(_value)); //let errors propagate + BOOST_FOREACH ( + typename property::subscriber_type& dsub, _desired_subscribers) { + dsub(get_value_ref(_value)); // let errors propagate } if (not _coercer.empty()) { _set_coerced(_coercer(get_value_ref(_value))); } else { - if (_coerce_mode == property_tree::AUTO_COERCE) uhd::assertion_error("coercer missing for an auto coerced property"); + if (_coerce_mode == property_tree::AUTO_COERCE) + uhd::assertion_error("coercer missing for an auto coerced property"); } return *this; } - property &set_coerced(const T &value){ - if (_coerce_mode == property_tree::AUTO_COERCE) uhd::assertion_error("cannot set coerced value an auto coerced property"); + property& set_coerced(const T& value) + { + if (_coerce_mode == property_tree::AUTO_COERCE) + uhd::assertion_error("cannot set coerced value an auto coerced property"); _set_coerced(value); return *this; } - const T get(void) const{ + const T get(void) const + { if (empty()) { throw uhd::runtime_error("Cannot get() on an uninitialized (empty) property"); } if (not _publisher.empty()) { return _publisher(); } else { - if (_coerced_value.get() == NULL and _coerce_mode == property_tree::MANUAL_COERCE) - throw uhd::runtime_error("uninitialized coerced value for manually coerced attribute"); + if (_coerced_value.get() == NULL + and _coerce_mode == property_tree::MANUAL_COERCE) + throw uhd::runtime_error( + "uninitialized coerced value for manually coerced attribute"); return get_value_ref(_coerced_value); } } - const T get_desired(void) const{ - if (_value.get() == NULL) throw uhd::runtime_error("Cannot get_desired() on an uninitialized (empty) property"); + const T get_desired(void) const + { + if (_value.get() == NULL) + throw uhd::runtime_error( + "Cannot get_desired() on an uninitialized (empty) property"); return get_value_ref(_value); } - bool empty(void) const{ + bool empty(void) const + { return _publisher.empty() and _value.get() == NULL; } private: - static T DEFAULT_COERCER(const T& value) { + static T DEFAULT_COERCER(const T& value) + { return value; } - static void init_or_set_value(boost::scoped_ptr& scoped_value, const T& init_val) { + static void init_or_set_value(boost::scoped_ptr& scoped_value, const T& init_val) + { if (scoped_value.get() == NULL) { scoped_value.reset(new T(init_val)); } else { @@ -122,36 +155,43 @@ private: } } - static const T& get_value_ref(const boost::scoped_ptr& scoped_value) { - if (scoped_value.get() == NULL) throw uhd::assertion_error("Cannot use uninitialized property data"); + static const T& get_value_ref(const boost::scoped_ptr& scoped_value) + { + if (scoped_value.get() == NULL) + throw uhd::assertion_error("Cannot use uninitialized property data"); return *scoped_value.get(); } - const property_tree::coerce_mode_t _coerce_mode; - std::vector::subscriber_type> _desired_subscribers; - std::vector::subscriber_type> _coerced_subscribers; - typename property::publisher_type _publisher; - typename property::coercer_type _coercer; - boost::scoped_ptr _value; - boost::scoped_ptr _coerced_value; + const property_tree::coerce_mode_t _coerce_mode; + std::vector::subscriber_type> _desired_subscribers; + std::vector::subscriber_type> _coerced_subscribers; + typename property::publisher_type _publisher; + typename property::coercer_type _coercer; + boost::scoped_ptr _value; + boost::scoped_ptr _coerced_value; }; -}} //namespace uhd::/*anon*/ +}} // namespace uhd:: /*********************************************************************** * Implement templated methods for the property tree **********************************************************************/ -namespace uhd{ - - template property &property_tree::create(const fs_path &path, coerce_mode_t coerce_mode){ - this->_create(path, typename boost::shared_ptr >(new property_impl(coerce_mode))); - return this->access(path); - } - - template property &property_tree::access(const fs_path &path){ - return *boost::static_pointer_cast >(this->_access(path)); - } - -} //namespace uhd +namespace uhd { + +template +property& property_tree::create(const fs_path& path, coerce_mode_t coerce_mode) +{ + this->_create(path, + typename boost::shared_ptr >(new property_impl(coerce_mode))); + return this->access(path); +} + +template +property& property_tree::access(const fs_path& path) +{ + return *boost::static_pointer_cast >(this->_access(path)); +} + +} // namespace uhd #endif /* INCLUDED_UHD_PROPERTY_TREE_IPP */ -- cgit v1.2.3