19namespace uhd {
namespace {
22class property_impl :
public property<T>
28 _coercer = DEFAULT_COERCER;
32 ~property_impl<T>(
void)
44 "cannot register coercer for a manually coerced property");
54 "cannot register more than one publisher for a property");
57 _publisher = publisher;
61 property<T>& add_desired_subscriber(
64 _desired_subscribers.push_back(subscriber);
68 property<T>& add_coerced_subscriber(
71 _coerced_subscribers.push_back(subscriber);
75 property<T>& update(
void)
77 this->set(this->get());
81 void _set_coerced(
const T& value)
83 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);
93 dsub(get_value_ref(_value));
96 _set_coerced(_coercer(get_value_ref(_value)));
104 property<T>& set_coerced(
const T& value)
112 const T get(
void)
const
120 if (_coerced_value.get() == NULL
123 "uninitialized coerced value for manually coerced attribute");
124 return get_value_ref(_coerced_value);
128 const T get_desired(
void)
const
130 if (_value.get() == NULL)
132 "Cannot get_desired() on an uninitialized (empty) property");
134 return get_value_ref(_value);
137 bool empty(
void)
const
139 return !bool(_publisher) and _value.get() == NULL;
143 static T DEFAULT_COERCER(
const T& value)
148 static void init_or_set_value(std::unique_ptr<T>& scoped_value,
const T& init_val)
150 if (scoped_value.get() == NULL) {
151 scoped_value.reset(
new T(init_val));
153 *scoped_value = init_val;
157 static const T& get_value_ref(
const std::unique_ptr<T>& scoped_value)
159 if (scoped_value.get() == NULL)
161 return *scoped_value.get();
165 std::vector<typename property<T>::subscriber_type> _desired_subscribers;
166 std::vector<typename property<T>::subscriber_type> _coerced_subscribers;
169 std::unique_ptr<T> _value;
170 std::unique_ptr<T> _coerced_value;
184 typename std::shared_ptr<
property<T> >(
new property_impl<T>(coerce_mode)),
185 std::type_index(
typeid(T)));
186 return this->access<T>(path);
192 return *std::static_pointer_cast<property<T> >(
193 this->_access_with_type_check(path, std::type_index(
typeid(T))));
199 return std::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:181
std::shared_ptr< property< T > > pop(const fs_path &path)
Pop a property off the tree, and returns the property.
Definition property_tree.ipp:197
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
Definition property_tree.hpp:70
std::function< T(void)> publisher_type
Definition property_tree.hpp:73
std::function< T(const T &)> coercer_type
Definition property_tree.hpp:74
std::function< void(const T &)> subscriber_type
Definition property_tree.hpp:72
Definition build_info.hpp:12
Definition exception.hpp:49
Definition property_tree.hpp:200
Definition exception.hpp:133