USRP Hardware Driver and USRP Manual  Version: 4.6.0.0-7-gece7c4811
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 {
26 public:
27  virtual ~property_iface() = default;
28 };
29 
77 template <typename T>
79 {
80 public:
81  typedef std::function<void(const T&)> subscriber_type;
82  typedef std::function<T(void)> publisher_type;
83  typedef std::function<T(const T&)> coercer_type;
84 
85  virtual ~property(void) = 0;
86 
97  virtual property<T>& set_coercer(const coercer_type& coercer) = 0;
98 
109  virtual property<T>& set_publisher(const publisher_type& publisher) = 0;
110 
120  virtual property<T>& add_desired_subscriber(const subscriber_type& subscriber) = 0;
121 
131  virtual property<T>& add_coerced_subscriber(const subscriber_type& subscriber) = 0;
132 
139  virtual property<T>& update(void) = 0;
140 
153  virtual property<T>& set(const T& value) = 0;
154 
166  virtual property<T>& set_coerced(const T& value) = 0;
167 
176  virtual const T get(void) const = 0;
177 
184  virtual const T get_desired(void) const = 0;
185 
192  virtual bool empty(void) const = 0;
193 };
194 
195 template <typename T>
197 {
198  /* NOP */
199 }
200 
205 struct UHD_API_HEADER fs_path : std::string
206 {
207  UHD_API fs_path(void);
208  UHD_API fs_path(const char*);
209  UHD_API fs_path(const std::string&);
210  UHD_API std::string leaf(void) const;
211  UHD_API fs_path branch_path(void) const;
212 };
213 
214 UHD_API fs_path operator/(const fs_path&, const fs_path&);
215 UHD_API fs_path operator/(const fs_path&, size_t);
216 
221 {
222 public:
223  typedef std::shared_ptr<property_tree> sptr;
224 
225  enum coerce_mode_t { AUTO_COERCE, MANUAL_COERCE };
226 
227  virtual ~property_tree(void) = 0;
228 
230  static sptr make(void);
231 
233  virtual sptr subtree(const fs_path& path) const = 0;
234 
236  virtual void remove(const fs_path& path) = 0;
237 
239  virtual bool exists(const fs_path& path) const = 0;
240 
242  virtual std::vector<std::string> list(const fs_path& path) const = 0;
243 
245  template <typename T>
246  property<T>& create(const fs_path& path, coerce_mode_t coerce_mode = AUTO_COERCE);
247 
249  template <typename T>
250  property<T>& access(const fs_path& path);
251 
253  template <typename T>
254  std::shared_ptr<property<T>> pop(const fs_path& path);
255 
256 private:
258  virtual std::shared_ptr<property_iface> _pop(const fs_path& path) = 0;
259 
261  virtual void _create(
262  const fs_path& path, const std::shared_ptr<property_iface>& prop) = 0;
263 
265  virtual std::shared_ptr<property_iface>& _access(const fs_path& path) const = 0;
266 };
267 
268 } // namespace uhd
269 
270 #include <uhd/property_tree.ipp>
virtual ~property(void)=0
Definition: property_tree.hpp:196
std::function< T(const T &)> coercer_type
Definition: property_tree.hpp:83
Definition: property_tree.hpp:205
boost::noncopyable noncopyable
Definition: noncopyable.hpp:45
#define UHD_API_HEADER
Definition: config.h:88
std::function< void(const T &)> subscriber_type
Definition: property_tree.hpp:81
Definition: build_info.hpp:12
#define UHD_API
Definition: config.h:87
coerce_mode_t
Definition: property_tree.hpp:225
Definition: property_tree.hpp:220
UHD_API fs_path operator/(const fs_path &, const fs_path &)
Definition: property_tree.hpp:78
Definition: property_tree.hpp:24
std::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:223
std::function< T(void)> publisher_type
Definition: property_tree.hpp:82