USRP Hardware Driver and USRP Manual  Version: 3.13.0.HEAD-0-gf114cfa0
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 //
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 
8 #ifndef INCLUDED_UHD_PROPERTY_TREE_HPP
9 #define INCLUDED_UHD_PROPERTY_TREE_HPP
10 
11 #include <uhd/config.hpp>
12 #include <boost/utility.hpp>
13 #include <boost/shared_ptr.hpp>
14 #include <boost/function.hpp>
15 #include <vector>
16 
17 namespace uhd{
18 
66 template <typename T> class property : boost::noncopyable{
67 public:
68  typedef boost::function<void(const T &)> subscriber_type;
69  typedef boost::function<T(void)> publisher_type;
70  typedef boost::function<T(const T &)> coercer_type;
71 
72  virtual ~property<T>(void) = 0;
73 
84  virtual property<T> &set_coercer(const coercer_type &coercer) = 0;
85 
96  virtual property<T> &set_publisher(const publisher_type &publisher) = 0;
97 
107  virtual property<T> &add_desired_subscriber(const subscriber_type &subscriber) = 0;
108 
118  virtual property<T> &add_coerced_subscriber(const subscriber_type &subscriber) = 0;
119 
126  virtual property<T> &update(void) = 0;
127 
140  virtual property<T> &set(const T &value) = 0;
141 
153  virtual property<T> &set_coerced(const T &value) = 0;
154 
163  virtual const T get(void) const = 0;
164 
171  virtual const T get_desired(void) const = 0;
172 
179  virtual bool empty(void) const = 0;
180 };
181 
182 template <typename T>
184  /* NOP */
185 }
186 
194 struct fs_path : std::string{
195  UHD_API fs_path(void);
196  UHD_API fs_path(const char *);
197  UHD_API fs_path(const std::string &);
198  UHD_API std::string leaf(void) const;
199  UHD_API fs_path branch_path(void) const;
200 };
201 
202 UHD_API fs_path operator/(const fs_path &, const fs_path &);
203 UHD_API fs_path operator/(const fs_path &, size_t);
204 
208 class UHD_API property_tree : boost::noncopyable{
209 public:
210  typedef boost::shared_ptr<property_tree> sptr;
211 
212  enum coerce_mode_t { AUTO_COERCE, MANUAL_COERCE };
213 
214  virtual ~property_tree(void) = 0;
215 
217  static sptr make(void);
218 
220  virtual sptr subtree(const fs_path &path) const = 0;
221 
223  virtual void remove(const fs_path &path) = 0;
224 
226  virtual bool exists(const fs_path &path) const = 0;
227 
229  virtual std::vector<std::string> list(const fs_path &path) const = 0;
230 
232  template <typename T> property<T> &create(
233  const fs_path &path,
234  coerce_mode_t coerce_mode = AUTO_COERCE);
235 
237  template <typename T> property<T> &access(const fs_path &path);
238 
239 private:
241  virtual void _create(const fs_path &path, const boost::shared_ptr<void> &prop) = 0;
242 
244  virtual boost::shared_ptr<void> &_access(const fs_path &path) const = 0;
245 
246 };
247 
248 } //namespace uhd
249 
250 #include <uhd/property_tree.ipp>
251 
252 #endif /* INCLUDED_UHD_PROPERTY_TREE_HPP */
boost::function< void(const T &)> subscriber_type
Definition: property_tree.hpp:68
virtual ~property(void)=0
Definition: property_tree.hpp:183
virtual property< T > & update(void)=0
Definition: property_tree.hpp:194
boost::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:210
virtual property< T > & add_coerced_subscriber(const subscriber_type &subscriber)=0
Definition: build_info.hpp:14
boost::function< T(const T &)> coercer_type
Definition: property_tree.hpp:70
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:69
#define UHD_API
Definition: config.h:63
coerce_mode_t
Definition: property_tree.hpp:212
Definition: property_tree.hpp:208
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:66
virtual property< T > & set_coercer(const coercer_type &coercer)=0