USRP Hardware Driver and USRP Manual  Version: 3.14.0.HEAD-0-g6875d061
UHD and USRP Manual
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/function.hpp>
13 #include <boost/shared_ptr.hpp>
14 #include <boost/utility.hpp>
15 #include <vector>
16 
17 namespace uhd {
18 
66 template <typename T> class property : boost::noncopyable
67 {
68 public:
69  typedef boost::function<void(const T&)> subscriber_type;
70  typedef boost::function<T(void)> publisher_type;
71  typedef boost::function<T(const T&)> coercer_type;
72 
73  virtual ~property<T>(void) = 0;
74 
85  virtual property<T>& set_coercer(const coercer_type& coercer) = 0;
86 
97  virtual property<T>& set_publisher(const publisher_type& publisher) = 0;
98 
108  virtual property<T>& add_desired_subscriber(const subscriber_type& subscriber) = 0;
109 
119  virtual property<T>& add_coerced_subscriber(const subscriber_type& subscriber) = 0;
120 
127  virtual property<T>& update(void) = 0;
128 
141  virtual property<T>& set(const T& value) = 0;
142 
154  virtual property<T>& set_coerced(const T& value) = 0;
155 
164  virtual const T get(void) const = 0;
165 
172  virtual const T get_desired(void) const = 0;
173 
180  virtual bool empty(void) const = 0;
181 };
182 
183 template <typename T> property<T>::~property(void)
184 {
185  /* NOP */
186 }
187 
195 struct fs_path : std::string
196 {
197  UHD_API fs_path(void);
198  UHD_API fs_path(const char*);
199  UHD_API fs_path(const std::string&);
200  UHD_API std::string leaf(void) const;
201  UHD_API fs_path branch_path(void) const;
202 };
203 
204 UHD_API fs_path operator/(const fs_path&, const fs_path&);
205 UHD_API fs_path operator/(const fs_path&, size_t);
206 
210 class UHD_API property_tree : boost::noncopyable
211 {
212 public:
213  typedef boost::shared_ptr<property_tree> sptr;
214 
215  enum coerce_mode_t { AUTO_COERCE, MANUAL_COERCE };
216 
217  virtual ~property_tree(void) = 0;
218 
220  static sptr make(void);
221 
223  virtual sptr subtree(const fs_path& path) const = 0;
224 
226  virtual void remove(const fs_path& path) = 0;
227 
229  virtual bool exists(const fs_path& path) const = 0;
230 
232  virtual std::vector<std::string> list(const fs_path& path) const = 0;
233 
235  template <typename T>
236  property<T>& create(const fs_path& path, coerce_mode_t coerce_mode = AUTO_COERCE);
237 
239  template <typename T> property<T>& access(const fs_path& path);
240 
241 private:
243  virtual void _create(const fs_path& path, const boost::shared_ptr<void>& prop) = 0;
244 
246  virtual boost::shared_ptr<void>& _access(const fs_path& path) const = 0;
247 };
248 
249 } // namespace uhd
250 
251 #include <uhd/property_tree.ipp>
252 
253 #endif /* INCLUDED_UHD_PROPERTY_TREE_HPP */
virtual ~property(void)=0
Definition: property_tree.hpp:183
virtual property< T > & update(void)=0
Definition: property_tree.hpp:195
boost::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:213
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:71
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:70
#define UHD_API
Definition: config.h:68
coerce_mode_t
Definition: property_tree.hpp:215
Definition: property_tree.hpp:210
boost::function< void(const T &)> subscriber_type
Definition: property_tree.hpp:69
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