USRP Hardware Driver and USRP Manual  Version: 3.15.0.HEAD-0-gaea0e2de
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 #ifndef INCLUDED_UHD_PROPERTY_TREE_HPP
10 #define INCLUDED_UHD_PROPERTY_TREE_HPP
11 
12 #include <uhd/config.hpp>
14 #include <boost/function.hpp>
15 #include <boost/shared_ptr.hpp>
16 #include <boost/utility.hpp>
17 #include <vector>
18 
19 namespace uhd {
20 
68 template <typename T>
70 {
71 public:
72  typedef boost::function<void(const T&)> subscriber_type;
73  typedef boost::function<T(void)> publisher_type;
74  typedef boost::function<T(const T&)> coercer_type;
75 
76  virtual ~property<T>(void) = 0;
77 
88  virtual property<T>& set_coercer(const coercer_type& coercer) = 0;
89 
100  virtual property<T>& set_publisher(const publisher_type& publisher) = 0;
101 
111  virtual property<T>& add_desired_subscriber(const subscriber_type& subscriber) = 0;
112 
122  virtual property<T>& add_coerced_subscriber(const subscriber_type& subscriber) = 0;
123 
130  virtual property<T>& update(void) = 0;
131 
144  virtual property<T>& set(const T& value) = 0;
145 
157  virtual property<T>& set_coerced(const T& value) = 0;
158 
167  virtual const T get(void) const = 0;
168 
175  virtual const T get_desired(void) const = 0;
176 
183  virtual bool empty(void) const = 0;
184 };
185 
186 template <typename T>
188 {
189  /* NOP */
190 }
191 
199 struct fs_path : std::string
200 {
201  UHD_API fs_path(void);
202  UHD_API fs_path(const char*);
203  UHD_API fs_path(const std::string&);
204  UHD_API std::string leaf(void) const;
205  UHD_API fs_path branch_path(void) const;
206 };
207 
208 UHD_API fs_path operator/(const fs_path&, const fs_path&);
209 UHD_API fs_path operator/(const fs_path&, size_t);
210 
215 {
216 public:
217  typedef boost::shared_ptr<property_tree> sptr;
218 
219  enum coerce_mode_t { AUTO_COERCE, MANUAL_COERCE };
220 
221  virtual ~property_tree(void) = 0;
222 
224  static sptr make(void);
225 
227  virtual sptr subtree(const fs_path& path) const = 0;
228 
230  virtual void remove(const fs_path& path) = 0;
231 
233  virtual bool exists(const fs_path& path) const = 0;
234 
236  virtual std::vector<std::string> list(const fs_path& path) const = 0;
237 
239  template <typename T>
240  property<T>& create(const fs_path& path, coerce_mode_t coerce_mode = AUTO_COERCE);
241 
243  template <typename T>
244  property<T>& access(const fs_path& path);
245 
247  template <typename T>
248  boost::shared_ptr<property<T> > pop(const fs_path& path);
249 
250 private:
252  virtual boost::shared_ptr<void> _pop(const fs_path& path) = 0;
253 
255  virtual void _create(const fs_path& path, const boost::shared_ptr<void>& prop) = 0;
256 
258  virtual boost::shared_ptr<void>& _access(const fs_path& path) const = 0;
259 };
260 
261 } // namespace uhd
262 
263 #include <uhd/property_tree.ipp>
264 
265 #endif /* INCLUDED_UHD_PROPERTY_TREE_HPP */
virtual ~property(void)=0
Definition: property_tree.hpp:187
virtual property< T > & update(void)=0
Definition: property_tree.hpp:199
boost::noncopyable noncopyable
Definition: noncopyable.hpp:46
boost::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:217
virtual property< T > & add_coerced_subscriber(const subscriber_type &subscriber)=0
Definition: build_info.hpp:13
boost::function< T(const T &)> coercer_type
Definition: property_tree.hpp:74
virtual property< T > & set_publisher(const publisher_type &publisher)=0
virtual bool empty(void) const =0
virtual const T get_desired(void) const =0
virtual property< T > & set_coerced(const T &value)=0
boost::function< T(void)> publisher_type
Definition: property_tree.hpp:73
#define UHD_API
Definition: config.h:68
coerce_mode_t
Definition: property_tree.hpp:219
Definition: property_tree.hpp:214
boost::function< void(const T &)> subscriber_type
Definition: property_tree.hpp:72
virtual property< T > & add_desired_subscriber(const subscriber_type &subscriber)=0
UHD_API fs_path operator/(const fs_path &, const fs_path &)
Definition: property_tree.hpp:69
virtual property< T > & set_coercer(const coercer_type &coercer)=0