USRP Hardware Driver and USRP Manual  Version: 003.008.003-0-g6eacba0a
UHD and USRP Manual
property_tree.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2011,2014 Ettus Research LLC
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 
33 template <typename T> class property : boost::noncopyable{
34 public:
35  typedef boost::function<void(const T &)> subscriber_type;
36  typedef boost::function<T(void)> publisher_type;
37  typedef boost::function<T(const T &)> coercer_type;
38 
39  virtual ~property<T>(void) = 0;
40 
49  virtual property<T> &coerce(const coercer_type &coercer) = 0;
50 
60  virtual property<T> &publish(const publisher_type &publisher) = 0;
61 
69  virtual property<T> &subscribe(const subscriber_type &subscriber) = 0;
70 
75  virtual property<T> &update(void) = 0;
76 
84  virtual property<T> &set(const T &value) = 0;
85 
92  virtual T get(void) const = 0;
93 
99  virtual bool empty(void) const = 0;
100 };
101 
102 template <typename T>
104  /* NOP */
105 }
106 
114 struct fs_path : std::string{
115  UHD_API fs_path(void);
116  UHD_API fs_path(const char *);
117  UHD_API fs_path(const std::string &);
118  UHD_API std::string leaf(void) const;
119  UHD_API fs_path branch_path(void) const;
120 };
121 
122 UHD_API fs_path operator/(const fs_path &, const fs_path &);
123 UHD_API fs_path operator/(const fs_path &, size_t);
124 
128 class UHD_API property_tree : boost::noncopyable{
129 public:
130  typedef boost::shared_ptr<property_tree> sptr;
131 
132  virtual ~property_tree(void) = 0;
133 
135  static sptr make(void);
136 
138  virtual sptr subtree(const fs_path &path) const = 0;
139 
141  virtual void remove(const fs_path &path) = 0;
142 
144  virtual bool exists(const fs_path &path) const = 0;
145 
147  virtual std::vector<std::string> list(const fs_path &path) const = 0;
148 
150  template <typename T> property<T> &create(const fs_path &path);
151 
153  template <typename T> property<T> &access(const fs_path &path);
154 
155 private:
157  virtual void _create(const fs_path &path, const boost::shared_ptr<void> &prop) = 0;
158 
160  virtual boost::shared_ptr<void> &_access(const fs_path &path) const = 0;
161 
162 };
163 
164 } //namespace uhd
165 
166 #include <uhd/property_tree.ipp>
167 
168 #endif /* INCLUDED_UHD_PROPERTY_TREE_HPP */
boost::function< void(const T &)> subscriber_type
Definition: property_tree.hpp:35
virtual ~property(void)=0
Definition: property_tree.hpp:103
virtual property< T > & update(void)=0
Definition: property_tree.hpp:114
boost::shared_ptr< property_tree > sptr
Definition: property_tree.hpp:130
virtual property< T > & publish(const publisher_type &publisher)=0
#define UHD_API
Definition: config.hpp:79
Definition: convert.hpp:28
boost::function< T(const T &)> coercer_type
Definition: property_tree.hpp:37
virtual bool empty(void) const =0
virtual property< T > & coerce(const coercer_type &coercer)=0
boost::function< T(void)> publisher_type
Definition: property_tree.hpp:36
virtual property< T > & subscribe(const subscriber_type &subscriber)=0
Definition: property_tree.hpp:128
UHD_API fs_path operator/(const fs_path &, const fs_path &)
Definition: property_tree.hpp:33