9#ifndef INCLUDED_UHD_PROPERTY_TREE_IPP
10#define INCLUDED_UHD_PROPERTY_TREE_IPP
13#include <boost/foreach.hpp>
14#include <boost/scoped_ptr.hpp>
20namespace uhd {
namespace {
23class property_impl :
public property<T>
29 _coercer = DEFAULT_COERCER;
33 ~property_impl<T>(
void)
40 if (not _coercer.empty())
44 "cannot register coercer for a manually coerced property");
52 if (not _publisher.empty())
54 "cannot register more than one publisher for a property");
56 _publisher = publisher;
60 property<T>& add_desired_subscriber(
63 _desired_subscribers.push_back(subscriber);
67 property<T>& add_coerced_subscriber(
70 _coerced_subscribers.push_back(subscriber);
74 property<T>& update(
void)
76 this->set(this->get());
80 void _set_coerced(
const T& value)
82 init_or_set_value(_coerced_value, value);
85 csub(get_value_ref(_coerced_value));
89 property<T>& set(
const T& value)
91 init_or_set_value(_value, value);
94 dsub(get_value_ref(_value));
96 if (not _coercer.empty()) {
97 _set_coerced(_coercer(get_value_ref(_value)));
105 property<T>& set_coerced(
const T& value)
113 const T get(
void)
const
118 if (not _publisher.empty()) {
121 if (_coerced_value.get() == NULL
124 "uninitialized coerced value for manually coerced attribute");
125 return get_value_ref(_coerced_value);
129 const T get_desired(
void)
const
131 if (_value.get() == NULL)
133 "Cannot get_desired() on an uninitialized (empty) property");
135 return get_value_ref(_value);
138 bool empty(
void)
const
140 return _publisher.empty() and _value.get() == NULL;
144 static T DEFAULT_COERCER(
const T& value)
149 static void init_or_set_value(boost::scoped_ptr<T>& scoped_value,
const T& init_val)
151 if (scoped_value.get() == NULL) {
152 scoped_value.reset(
new T(init_val));
154 *scoped_value = init_val;
158 static const T& get_value_ref(
const boost::scoped_ptr<T>& scoped_value)
160 if (scoped_value.get() == NULL)
162 return *scoped_value.get();
166 std::vector<typename property<T>::subscriber_type> _desired_subscribers;
167 std::vector<typename property<T>::subscriber_type> _coerced_subscribers;
170 boost::scoped_ptr<T> _value;
171 boost::scoped_ptr<T> _coerced_value;
185 typename boost::shared_ptr<
property<T> >(
new property_impl<T>(coerce_mode)));
186 return this->access<T>(path);
192 return *boost::static_pointer_cast<property<T> >(this->_access(path));
198 return boost::static_pointer_cast<property<T> >(this->_pop(path));
property< T > & create(const fs_path &path, coerce_mode_t coerce_mode=AUTO_COERCE)
Create a new property entry in the tree.
Definition property_tree.ipp:182
property< T > & access(const fs_path &path)
Get access to a property in the tree.
Definition property_tree.ipp:190
coerce_mode_t
Definition property_tree.hpp:219
@ AUTO_COERCE
Definition property_tree.hpp:219
@ MANUAL_COERCE
Definition property_tree.hpp:219
boost::shared_ptr< property< T > > pop(const fs_path &path)
Pop a property off the tree, and returns the property.
Definition property_tree.ipp:196
Definition property_tree.hpp:70
boost::function< T(void)> publisher_type
Definition property_tree.hpp:73
boost::function< void(const T &)> subscriber_type
Definition property_tree.hpp:72
boost::function< T(const T &)> coercer_type
Definition property_tree.hpp:74
Definition build_info.hpp:13
Definition exception.hpp:50
Definition property_tree.hpp:200
Definition exception.hpp:134