Loading...
Searching...
No Matches
property_tree.hpp
Go to the documentation of this file.
//
// Copyright 2011,2014-2016 Ettus Research
// Copyright 2018 Ettus Research, a National Instruments Company
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#pragma once
#include <uhd/config.hpp>
#include <uhd/utils/noncopyable.hpp>
#include <cstddef>
#include <functional>
#include <memory>
#include <string>
#include <vector>
namespace uhd {
class UHD_API property_iface
{
public:
virtual ~property_iface() = default;
};
template <typename T>
class UHD_API_HEADER property : uhd::noncopyable, public property_iface
{
public:
typedef std::function<void(const T&)> subscriber_type;
typedef std::function<T(void)> publisher_type;
typedef std::function<T(const T&)> coercer_type;
virtual ~property(void) = 0;
virtual property<T>& set_coercer(const coercer_type& coercer) = 0;
virtual property<T>& set_publisher(const publisher_type& publisher) = 0;
virtual property<T>& add_desired_subscriber(const subscriber_type& subscriber) = 0;
virtual property<T>& add_coerced_subscriber(const subscriber_type& subscriber) = 0;
virtual property<T>& update(void) = 0;
virtual property<T>& set(const T& value) = 0;
virtual property<T>& set_coerced(const T& value) = 0;
virtual const T get(void) const = 0;
virtual const T get_desired(void) const = 0;
virtual bool empty(void) const = 0;
};
template <typename T>
property<T>::~property(void)
{
/* NOP */
}
struct UHD_API_HEADER fs_path : std::string
{
UHD_API fs_path(void);
UHD_API fs_path(const char*);
UHD_API fs_path(const std::string&);
UHD_API std::string leaf(void) const;
UHD_API fs_path branch_path(void) const;
};
UHD_API fs_path operator/(const fs_path&, const fs_path&);
UHD_API fs_path operator/(const fs_path&, size_t);
class UHD_API property_tree : uhd::noncopyable
{
public:
typedef std::shared_ptr<property_tree> sptr;
enum coerce_mode_t { AUTO_COERCE, MANUAL_COERCE };
virtual ~property_tree(void) = 0;
static sptr make(void);
virtual sptr subtree(const fs_path& path) const = 0;
virtual void remove(const fs_path& path) = 0;
virtual bool exists(const fs_path& path) const = 0;
virtual std::vector<std::string> list(const fs_path& path) const = 0;
template <typename T>
property<T>& create(const fs_path& path, coerce_mode_t coerce_mode = AUTO_COERCE);
template <typename T>
property<T>& access(const fs_path& path);
template <typename T>
std::shared_ptr<property<T>> pop(const fs_path& path);
private:
virtual std::shared_ptr<property_iface> _pop(const fs_path& path) = 0;
virtual void _create(
const fs_path& path, const std::shared_ptr<property_iface>& prop) = 0;
virtual std::shared_ptr<property_iface>& _access(const fs_path& path) const = 0;
};
} // namespace uhd
#include <uhd/property_tree.ipp>
uhd::property_iface
Definition property_tree.hpp:26
uhd::property_iface::~property_iface
virtual ~property_iface()=default
uhd::property_tree
Definition property_tree.hpp:222
uhd::property_tree::create
property< T > & create(const fs_path &path, coerce_mode_t coerce_mode=AUTO_COERCE)
Create a new property entry in the tree.
Definition property_tree.ipp:180
uhd::property_tree::pop
std::shared_ptr< property< T > > pop(const fs_path &path)
Pop a property off the tree, and returns the property.
Definition property_tree.ipp:198
uhd::property_tree::sptr
std::shared_ptr< property_tree > sptr
Definition property_tree.hpp:224
uhd::property_tree::~property_tree
virtual ~property_tree(void)=0
uhd::property_tree::list
virtual std::vector< std::string > list(const fs_path &path) const =0
Get an iterable to all things in the given path.
uhd::property_tree::remove
virtual void remove(const fs_path &path)=0
Remove a property or directory (recursive).
uhd::property_tree::access
property< T > & access(const fs_path &path)
Get access to a property in the tree.
Definition property_tree.ipp:187
uhd::property_tree::subtree
virtual sptr subtree(const fs_path &path) const =0
Get a subtree with a new root starting at path.
uhd::property_tree::make
static sptr make(void)
Create a new + empty property tree.
uhd::property_tree::exists
virtual bool exists(const fs_path &path) const =0
True if the path exists in the tree.
uhd::property_tree::coerce_mode_t
coerce_mode_t
Definition property_tree.hpp:226
uhd::property_tree::AUTO_COERCE
@ AUTO_COERCE
Definition property_tree.hpp:226
uhd::property_tree::MANUAL_COERCE
@ MANUAL_COERCE
Definition property_tree.hpp:226
uhd::property
Definition property_tree.hpp:80
uhd::property::set_coerced
virtual property< T > & set_coerced(const T &value)=0
uhd::property::set_coercer
virtual property< T > & set_coercer(const coercer_type &coercer)=0
uhd::property::publisher_type
std::function< T(void)> publisher_type
Definition property_tree.hpp:83
uhd::property::get_desired
virtual const T get_desired(void) const =0
uhd::property::empty
virtual bool empty(void) const =0
uhd::property::add_coerced_subscriber
virtual property< T > & add_coerced_subscriber(const subscriber_type &subscriber)=0
uhd::property::~property
virtual ~property(void)=0
Definition property_tree.hpp:197
uhd::property::update
virtual property< T > & update(void)=0
uhd::property::coercer_type
std::function< T(const T &)> coercer_type
Definition property_tree.hpp:84
uhd::property::subscriber_type
std::function< void(const T &)> subscriber_type
Definition property_tree.hpp:82
uhd::property::add_desired_subscriber
virtual property< T > & add_desired_subscriber(const subscriber_type &subscriber)=0
uhd::property::set_publisher
virtual property< T > & set_publisher(const publisher_type &publisher)=0
uhd::property::set
virtual property< T > & set(const T &value)=0
uhd::property::get
virtual const T get(void) const =0
UHD_API_HEADER
#define UHD_API_HEADER
Definition config.h:88
UHD_API
#define UHD_API
Definition config.h:87
config.hpp
uhd
Definition build_info.hpp:12
uhd::noncopyable
boost::noncopyable noncopyable
Definition noncopyable.hpp:45
uhd::operator/
UHD_API fs_path operator/(const fs_path &, const fs_path &)
noncopyable.hpp
property_tree.ipp
uhd::fs_path
Definition property_tree.hpp:207
uhd::fs_path::fs_path
UHD_API fs_path(const char *)
uhd::fs_path::leaf
UHD_API std::string leaf(void) const
uhd::fs_path::branch_path
UHD_API fs_path branch_path(void) const
uhd::fs_path::fs_path
UHD_API fs_path(void)
uhd::fs_path::fs_path
UHD_API fs_path(const std::string &)