Loading...
Searching...
No Matches
discoverable_feature_getter_iface.hpp
Go to the documentation of this file.
//
// Copyright 2020 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#pragma once
#include <uhd/exception.hpp>
#include <uhd/features/discoverable_feature.hpp>
#include <vector>
namespace uhd { namespace features {
class UHD_API discoverable_feature_getter_iface
{
public:
virtual ~discoverable_feature_getter_iface() = default;
//
// Note that if the given feature type does not exist, this function will
// assert. The user should first check that the feature exists via the
// has_feature method.
// Usage:
// auto feature_ref = radio.get_feature<desired_feature_class>();
template <typename T>
T& get_feature()
{
auto p = get_feature_ptr(T::get_feature_id());
UHD_ASSERT_THROW(p);
auto typed_p = dynamic_cast<T*>(p.get());
UHD_ASSERT_THROW(typed_p);
return *typed_p;
}
//
// This function should be used to gate functionality before calling
// get_feature().
template <typename T>
bool has_feature()
{
return bool(get_feature_ptr(T::get_feature_id()));
}
//
// Returns a vector (in no particular order) of the features that this
// device supports.
virtual std::vector<std::string> enumerate_features() = 0;
private:
//
// If the feature does not exist on the device, returns a null pointer.
virtual discoverable_feature::sptr get_feature_ptr(
discoverable_feature::feature_id_t feature_id) = 0;
};
}} // namespace uhd::features
uhd::features::discoverable_feature_getter_iface
Definition discoverable_feature_getter_iface.hpp:18
uhd::features::discoverable_feature_getter_iface::enumerate_features
virtual std::vector< std::string > enumerate_features()=0
Enumerate all discoverable features present on the device.
uhd::features::discoverable_feature_getter_iface::get_feature
T & get_feature()
Retrieves a feature of the specified type.
Definition discoverable_feature_getter_iface.hpp:30
uhd::features::discoverable_feature_getter_iface::~discoverable_feature_getter_iface
virtual ~discoverable_feature_getter_iface()=default
uhd::features::discoverable_feature_getter_iface::has_feature
bool has_feature()
Determines whether a given feature exists.
Definition discoverable_feature_getter_iface.hpp:44
uhd::features::discoverable_feature::feature_id_t
feature_id_t
An enum of all features supported by the driver. When creating a new.
Definition discoverable_feature.hpp:32
uhd::features::discoverable_feature::sptr
std::shared_ptr< discoverable_feature > sptr
Definition discoverable_feature.hpp:28
UHD_API
#define UHD_API
Definition config.h:87
discoverable_feature.hpp
exception.hpp
UHD_ASSERT_THROW
#define UHD_ASSERT_THROW(code)
Definition exception.hpp:321
uhd::features
Definition adc_self_calibration_iface.hpp:16
uhd
Definition build_info.hpp:12