USRP Hardware Driver and USRP Manual  Version: 003.010.003.HEAD-0-gef157678
UHD and USRP Manual
property_tree.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2011,2014-2016 Ettus Research
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef INCLUDED_UHD_PROPERTY_TREE_HPP
19 #define INCLUDED_UHD_PROPERTY_TREE_HPP
20 
21 #include <uhd/config.hpp>
22 #include <boost/utility.hpp>
23 #include <boost/shared_ptr.hpp>
24 #include <boost/function.hpp>
25 #include <vector>
26 
27 namespace uhd{
28 
76 template <typename T> class property : boost::noncopyable{
77 public:
78  typedef boost::function<void(const T &)> subscriber_type;
79  typedef boost::function<T(void)> publisher_type;
80  typedef boost::function<T(const T &)> coercer_type;
81 
82  virtual ~property<T>(void) = 0;
83 
94  virtual property<T> &set_coercer(const coercer_type &coercer) = 0;
95 
106  virtual property<T> &set_publisher(const publisher_type &publisher) = 0;
107 
117  virtual property<T> &add_desired_subscriber(const subscriber_type &subscriber) = 0;
118 
128  virtual property<T> &add_coerced_subscriber(const subscriber_type &subscriber) = 0;
129 
136  virtual property<T> &update(void) = 0;
137 
150  virtual property<T> &set(const T &value) = 0;
151 
163  virtual property<T> &set_coerced(const T &value) = 0;
164 
173  virtual const T get(void) const = 0;
174 
181  virtual const T get_desired(void) const = 0;
182 
189  virtual bool empty(void) const = 0;
190 };
191 
192 template <typename T>
194  /* NOP */
195 }
196 
204 struct fs_path : std::string{
205  UHD_API fs_path(void);
206  UHD_API fs_path(const char *);
207  UHD_API fs_path(const std::string &);
208  UHD_API std::string leaf(void) const;
209  UHD_API fs_path branch_path(void) const;
210 };
211 
212 UHD_API fs_path operator/(const fs_path &, const fs_path &);
213 UHD_API fs_path operator/(const fs_path &, size_t);
214 
218 class UHD_API property_tree : boost::noncopyable{
219 public:
220  typedef boost::shared_ptr<property_tree> sptr;
221 
222  enum coerce_mode_t { AUTO_COERCE, MANUAL_COERCE };
223 
224  virtual ~property_tree(void) = 0;
225 
227  static sptr make(void);
228 
230  virtual sptr subtree(const fs_path &path) const = 0;
231 
233  virtual void remove(const fs_path &path) = 0;
234 
236  virtual bool exists(const fs_path &path) const = 0;
237 
239  virtual std::vector<std::string> list(const fs_path &path) const = 0;
240 
242  template <typename T> property<T> &create(
243  const fs_path &path,
244  coerce_mode_t coerce_mode = AUTO_COERCE);
245 
247  template <typename T> property<T> &access(const fs_path &path);
248 
249 private:
251  virtual void _create(const fs_path &path, const boost::shared_ptr<void> &prop) = 0;
252 
254  virtual boost::shared_ptr<void> &_access(const fs_path &path) const = 0;
255 
256 };
257 
258 } //namespace uhd
259 
260 #include <uhd/property_tree.ipp>
261 
262 #endif /* INCLUDED_UHD_PROPERTY_TREE_HPP */
boost::function< void(const T &)> subscriber_type
Definition: property_tree.hpp:78
virtual ~property(void)=0
Definition: property_tree.hpp:193
virtual property< T > & update(void)=0
Definition: property_tree.hpp:204
boost::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:220
virtual property< T > & add_coerced_subscriber(const subscriber_type &subscriber)=0
Definition: build_info.hpp:25
boost::function< T(const T &)> coercer_type
Definition: property_tree.hpp:80
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:79
#define UHD_API
Definition: config.h:73
coerce_mode_t
Definition: property_tree.hpp:222
Definition: property_tree.hpp:218
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:76
virtual property< T > & set_coercer(const coercer_type &coercer)=0