| USRP Hardware Driver and USRP Manual Version: 4.8.0.makepkg-0-g308126a4 UHD and USRP Manual |

Loading...
Searching...
No Matches
discoverable_feature_getter_iface.hpp
Go to the documentation of this file.
1//
2// Copyright 2020 Ettus Research, a National Instruments Brand
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5//
6
7#pragma once
8
9#include <uhd/exception.hpp>
10#include <uhd/features/discoverable_feature.hpp>
11#include <vector>
12
13 namespace uhd { namespace features {
14
17 class UHD_API discoverable_feature_getter_iface
18{
19 public:
20 virtual ~discoverable_feature_getter_iface() = default;
21
23 //
24 // Note that if the given feature type does not exist, this function will
25 // assert. The user should first check that the feature exists via the
26 // has_feature method.
27 // Usage:
28 // auto feature_ref = radio.get_feature<desired_feature_class>();
29 template <typename T>
30 T& get_feature()
31 {
32 auto p = get_feature_ptr(T::get_feature_id());
33 UHD_ASSERT_THROW(p);
34 auto typed_p = dynamic_cast<T*>(p.get());
35 UHD_ASSERT_THROW(typed_p);
36 return *typed_p;
37 }
38
40 //
41 // This function should be used to gate functionality before calling
42 // get_feature().
43 template <typename T>
44 bool has_feature()
45 {
46 return bool(get_feature_ptr(T::get_feature_id()));
47 }
48
50 //
51 // Returns a vector (in no particular order) of the features that this
52 // device supports.
53 virtual std::vector<std::string> enumerate_features() = 0;
54
55 private:
57 //
58 // If the feature does not exist on the device, returns a null pointer.
59 virtual discoverable_feature::sptr get_feature_ptr(
60 discoverable_feature::feature_id_t feature_id) = 0;
61};
62
63}} // 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:322
uhd::features
Definition adc_self_calibration_iface.hpp:16
uhd
Definition build_info.hpp:12