USRP Hardware Driver and USRP Manual Version: 4.1.0.1
UHD and USRP Manual
property_tree.hpp
Go to the documentation of this file.
1//
2// Copyright 2011,2014-2016 Ettus Research
3// Copyright 2018 Ettus Research, a National Instruments Company
4// Copyright 2019 Ettus Research, a National Instruments Brand
5//
6// SPDX-License-Identifier: GPL-3.0-or-later
7//
8
9#pragma once
10
11#include <uhd/config.hpp>
13#include <functional>
14#include <memory>
15#include <string>
16#include <vector>
17
18namespace uhd {
19
67template <typename T>
69{
70public:
71 typedef std::function<void(const T&)> subscriber_type;
72 typedef std::function<T(void)> publisher_type;
73 typedef std::function<T(const T&)> coercer_type;
74
75 virtual ~property<T>(void) = 0;
76
87 virtual property<T>& set_coercer(const coercer_type& coercer) = 0;
88
99 virtual property<T>& set_publisher(const publisher_type& publisher) = 0;
100
110 virtual property<T>& add_desired_subscriber(const subscriber_type& subscriber) = 0;
111
121 virtual property<T>& add_coerced_subscriber(const subscriber_type& subscriber) = 0;
122
129 virtual property<T>& update(void) = 0;
130
143 virtual property<T>& set(const T& value) = 0;
144
156 virtual property<T>& set_coerced(const T& value) = 0;
157
166 virtual const T get(void) const = 0;
167
174 virtual const T get_desired(void) const = 0;
175
182 virtual bool empty(void) const = 0;
183};
184
185template <typename T>
187{
188 /* NOP */
189}
190
198struct fs_path : std::string
199{
201 UHD_API fs_path(const char*);
202 UHD_API fs_path(const std::string&);
203 UHD_API std::string leaf(void) const;
205};
206
209
214{
215public:
216 typedef std::shared_ptr<property_tree> sptr;
217
218 enum coerce_mode_t { AUTO_COERCE, MANUAL_COERCE };
219
220 virtual ~property_tree(void) = 0;
221
223 static sptr make(void);
224
226 virtual sptr subtree(const fs_path& path) const = 0;
227
229 virtual void remove(const fs_path& path) = 0;
230
232 virtual bool exists(const fs_path& path) const = 0;
233
235 virtual std::vector<std::string> list(const fs_path& path) const = 0;
236
238 template <typename T>
239 property<T>& create(const fs_path& path, coerce_mode_t coerce_mode = AUTO_COERCE);
240
242 template <typename T>
243 property<T>& access(const fs_path& path);
244
246 template <typename T>
247 std::shared_ptr<property<T>> pop(const fs_path& path);
248
249private:
251 virtual std::shared_ptr<void> _pop(const fs_path& path) = 0;
252
254 virtual void _create(const fs_path& path,
255 const std::shared_ptr<void>& prop) = 0;
256
258 virtual std::shared_ptr<void>& _access(const fs_path& path) const = 0;
259};
260
261} // namespace uhd
262
263#include <uhd/property_tree.ipp>
Definition: property_tree.hpp:214
std::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:216
virtual ~property_tree(void)=0
virtual std::vector< std::string > list(const fs_path &path) const =0
Get an iterable to all things in the given path.
virtual void remove(const fs_path &path)=0
Remove a property or directory (recursive)
virtual sptr subtree(const fs_path &path) const =0
Get a subtree with a new root starting at path.
static sptr make(void)
Create a new + empty property tree.
virtual bool exists(const fs_path &path) const =0
True if the path exists in the tree.
coerce_mode_t
Definition: property_tree.hpp:218
@ AUTO_COERCE
Definition: property_tree.hpp:218
Definition: property_tree.hpp:69
virtual property< T > & set_coerced(const T &value)=0
virtual property< T > & set_coercer(const coercer_type &coercer)=0
std::function< T(void)> publisher_type
Definition: property_tree.hpp:72
virtual const T get_desired(void) const =0
virtual bool empty(void) const =0
virtual property< T > & add_coerced_subscriber(const subscriber_type &subscriber)=0
virtual ~property(void)=0
Definition: property_tree.hpp:186
virtual property< T > & update(void)=0
std::function< T(const T &)> coercer_type
Definition: property_tree.hpp:73
std::function< void(const T &)> subscriber_type
Definition: property_tree.hpp:71
virtual property< T > & add_desired_subscriber(const subscriber_type &subscriber)=0
virtual property< T > & set_publisher(const publisher_type &publisher)=0
virtual property< T > & set(const T &value)=0
virtual const T get(void) const =0
#define UHD_API
Definition: config.h:70
Definition: build_info.hpp:12
boost::noncopyable noncopyable
Definition: noncopyable.hpp:45
UHD_API fs_path operator/(const fs_path &, const fs_path &)
Definition: property_tree.hpp:199
UHD_API fs_path(const char *)
UHD_API std::string leaf(void) const
UHD_API fs_path branch_path(void) const
UHD_API fs_path(void)
UHD_API fs_path(const std::string &)