USRP Hardware Driver and USRP Manual  Version: 3.11.0.HEAD-0-gdca39145
UHD and USRP Manual
property_tree.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2011,2014-2016 Ettus Research
3 //
4 // SPDX-License-Identifier: GPL-3.0
5 //
6 
7 #ifndef INCLUDED_UHD_PROPERTY_TREE_HPP
8 #define INCLUDED_UHD_PROPERTY_TREE_HPP
9 
10 #include <uhd/config.hpp>
11 #include <boost/utility.hpp>
12 #include <boost/shared_ptr.hpp>
13 #include <boost/function.hpp>
14 #include <vector>
15 
16 namespace uhd{
17 
65 template <typename T> class property : boost::noncopyable{
66 public:
67  typedef boost::function<void(const T &)> subscriber_type;
68  typedef boost::function<T(void)> publisher_type;
69  typedef boost::function<T(const T &)> coercer_type;
70 
71  virtual ~property<T>(void) = 0;
72 
83  virtual property<T> &set_coercer(const coercer_type &coercer) = 0;
84 
95  virtual property<T> &set_publisher(const publisher_type &publisher) = 0;
96 
106  virtual property<T> &add_desired_subscriber(const subscriber_type &subscriber) = 0;
107 
117  virtual property<T> &add_coerced_subscriber(const subscriber_type &subscriber) = 0;
118 
125  virtual property<T> &update(void) = 0;
126 
139  virtual property<T> &set(const T &value) = 0;
140 
152  virtual property<T> &set_coerced(const T &value) = 0;
153 
162  virtual const T get(void) const = 0;
163 
170  virtual const T get_desired(void) const = 0;
171 
178  virtual bool empty(void) const = 0;
179 };
180 
181 template <typename T>
183  /* NOP */
184 }
185 
193 struct fs_path : std::string{
194  UHD_API fs_path(void);
195  UHD_API fs_path(const char *);
196  UHD_API fs_path(const std::string &);
197  UHD_API std::string leaf(void) const;
198  UHD_API fs_path branch_path(void) const;
199 };
200 
201 UHD_API fs_path operator/(const fs_path &, const fs_path &);
202 UHD_API fs_path operator/(const fs_path &, size_t);
203 
207 class UHD_API property_tree : boost::noncopyable{
208 public:
209  typedef boost::shared_ptr<property_tree> sptr;
210 
211  enum coerce_mode_t { AUTO_COERCE, MANUAL_COERCE };
212 
213  virtual ~property_tree(void) = 0;
214 
216  static sptr make(void);
217 
219  virtual sptr subtree(const fs_path &path) const = 0;
220 
222  virtual void remove(const fs_path &path) = 0;
223 
225  virtual bool exists(const fs_path &path) const = 0;
226 
228  virtual std::vector<std::string> list(const fs_path &path) const = 0;
229 
231  template <typename T> property<T> &create(
232  const fs_path &path,
233  coerce_mode_t coerce_mode = AUTO_COERCE);
234 
236  template <typename T> property<T> &access(const fs_path &path);
237 
238 private:
240  virtual void _create(const fs_path &path, const boost::shared_ptr<void> &prop) = 0;
241 
243  virtual boost::shared_ptr<void> &_access(const fs_path &path) const = 0;
244 
245 };
246 
247 } //namespace uhd
248 
249 #include <uhd/property_tree.ipp>
250 
251 #endif /* INCLUDED_UHD_PROPERTY_TREE_HPP */
boost::function< void(const T &)> subscriber_type
Definition: property_tree.hpp:67
virtual ~property(void)=0
Definition: property_tree.hpp:182
virtual property< T > & update(void)=0
Definition: property_tree.hpp:193
boost::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:209
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:69
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:68
#define UHD_API
Definition: config.h:62
coerce_mode_t
Definition: property_tree.hpp:211
Definition: property_tree.hpp:207
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:65
virtual property< T > & set_coercer(const coercer_type &coercer)=0