UHD 003.002.004

include/uhd/property_tree.hpp

Go to the documentation of this file.
00001 //
00002 // Copyright 2011 Ettus Research LLC
00003 //
00004 // This program is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #ifndef INCLUDED_UHD_PROPERTY_TREE_HPP
00019 #define INCLUDED_UHD_PROPERTY_TREE_HPP
00020 
00021 #include <uhd/config.hpp>
00022 #include <boost/utility.hpp>
00023 #include <boost/shared_ptr.hpp>
00024 #include <boost/function.hpp>
00025 #include <vector>
00026 
00027 namespace uhd{
00028 
00033 template <typename T> class property : boost::noncopyable{
00034 public:
00035     typedef boost::function<void(const T &)> subscriber_type;
00036     typedef boost::function<T(void)> publisher_type;
00037     typedef boost::function<T(const T &)> coercer_type;
00038 
00047     virtual property<T> &coerce(const coercer_type &coercer) = 0;
00048 
00058     virtual property<T> &publish(const publisher_type &publisher) = 0;
00059 
00067     virtual property<T> &subscribe(const subscriber_type &subscriber) = 0;
00068 
00073     virtual property<T> &update(void) = 0;
00074 
00082     virtual property<T> &set(const T &value) = 0;
00083 
00090     virtual T get(void) const = 0;
00091 
00097     virtual bool empty(void) const = 0;
00098 };
00099 
00107 struct fs_path : std::string{
00108     UHD_API fs_path(void);
00109     UHD_API fs_path(const char *);
00110     UHD_API fs_path(const std::string &);
00111     UHD_API std::string leaf(void) const;
00112     UHD_API fs_path branch_path(void) const;
00113 };
00114 
00115 UHD_API fs_path operator/(const fs_path &, const fs_path &);
00116 
00120 class UHD_API property_tree : boost::noncopyable{
00121 public:
00122     typedef boost::shared_ptr<property_tree> sptr;
00123 
00125     static sptr make(void);
00126 
00128     virtual sptr subtree(const fs_path &path) const = 0;
00129 
00131     virtual void remove(const fs_path &path) = 0;
00132 
00134     virtual bool exists(const fs_path &path) const = 0;
00135 
00137     virtual std::vector<std::string> list(const fs_path &path) const = 0;
00138 
00140     template <typename T> property<T> &create(const fs_path &path);
00141 
00143     template <typename T> property<T> &access(const fs_path &path);
00144 
00145 private:
00147     virtual void _create(const fs_path &path, const boost::shared_ptr<void> &prop) = 0;
00148 
00150     virtual boost::shared_ptr<void> &_access(const fs_path &path) const = 0;
00151 
00152 };
00153 
00154 } //namespace uhd
00155 
00156 #include <uhd/property_tree.ipp>
00157 
00158 #endif /* INCLUDED_UHD_PROPERTY_TREE_HPP */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines