USRP Hardware Driver and USRP Manual  Version: 4.4.0.HEAD-0-g5fac246b
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 
18 namespace uhd {
19 
25 public:
26  virtual ~property_iface() = default;
27 };
28 
76 template <typename T>
78 {
79 public:
80  typedef std::function<void(const T&)> subscriber_type;
81  typedef std::function<T(void)> publisher_type;
82  typedef std::function<T(const T&)> coercer_type;
83 
84  virtual ~property(void) = 0;
85 
96  virtual property<T>& set_coercer(const coercer_type& coercer) = 0;
97 
108  virtual property<T>& set_publisher(const publisher_type& publisher) = 0;
109 
119  virtual property<T>& add_desired_subscriber(const subscriber_type& subscriber) = 0;
120 
130  virtual property<T>& add_coerced_subscriber(const subscriber_type& subscriber) = 0;
131 
138  virtual property<T>& update(void) = 0;
139 
152  virtual property<T>& set(const T& value) = 0;
153 
165  virtual property<T>& set_coerced(const T& value) = 0;
166 
175  virtual const T get(void) const = 0;
176 
183  virtual const T get_desired(void) const = 0;
184 
191  virtual bool empty(void) const = 0;
192 };
193 
194 template <typename T>
196 {
197  /* NOP */
198 }
199 
204 struct UHD_API_HEADER fs_path : std::string
205 {
206  UHD_API fs_path(void);
207  UHD_API fs_path(const char*);
208  UHD_API fs_path(const std::string&);
209  UHD_API std::string leaf(void) const;
210  UHD_API fs_path branch_path(void) const;
211 };
212 
213 UHD_API fs_path operator/(const fs_path&, const fs_path&);
214 UHD_API fs_path operator/(const fs_path&, size_t);
215 
220 {
221 public:
222  typedef std::shared_ptr<property_tree> sptr;
223 
224  enum coerce_mode_t { AUTO_COERCE, MANUAL_COERCE };
225 
226  virtual ~property_tree(void) = 0;
227 
229  static sptr make(void);
230 
232  virtual sptr subtree(const fs_path& path) const = 0;
233 
235  virtual void remove(const fs_path& path) = 0;
236 
238  virtual bool exists(const fs_path& path) const = 0;
239 
241  virtual std::vector<std::string> list(const fs_path& path) const = 0;
242 
244  template <typename T>
245  property<T>& create(const fs_path& path, coerce_mode_t coerce_mode = AUTO_COERCE);
246 
248  template <typename T>
249  property<T>& access(const fs_path& path);
250 
252  template <typename T>
253  std::shared_ptr<property<T>> pop(const fs_path& path);
254 
255 private:
257  virtual std::shared_ptr<property_iface> _pop(const fs_path& path) = 0;
258 
260  virtual void _create(const fs_path& path,
261  const std::shared_ptr<property_iface>& prop) = 0;
262 
264  virtual std::shared_ptr<property_iface>& _access(const fs_path& path) const = 0;
265 };
266 
267 } // namespace uhd
268 
269 #include <uhd/property_tree.ipp>
uhd::property_iface
Definition: property_tree.hpp:24
config.hpp
uhd::property::coercer_type
std::function< T(const T &)> coercer_type
Definition: property_tree.hpp:82
property_tree.ipp
UHD_API
#define UHD_API
Definition: config.h:87
uhd::property::publisher_type
std::function< T(void)> publisher_type
Definition: property_tree.hpp:81
uhd::property_tree::sptr
std::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:222
noncopyable.hpp
uhd::operator/
UHD_API fs_path operator/(const fs_path &, const fs_path &)
uhd::property_tree::coerce_mode_t
coerce_mode_t
Definition: property_tree.hpp:224
uhd
Definition: build_info.hpp:12
uhd::fs_path
Definition: property_tree.hpp:204
uhd::property
Definition: property_tree.hpp:77
uhd::property_tree
Definition: property_tree.hpp:219
uhd::property::subscriber_type
std::function< void(const T &)> subscriber_type
Definition: property_tree.hpp:80
uhd::property::~property
virtual ~property(void)=0
Definition: property_tree.hpp:195
uhd::noncopyable
boost::noncopyable noncopyable
Definition: noncopyable.hpp:45
UHD_API_HEADER
#define UHD_API_HEADER
Definition: config.h:88