USRP Hardware Driver and USRP Manual  Version: 4.4.0.HEAD-0-g5fac246b
UHD and USRP Manual
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>
11 #include <vector>
12 
13 namespace uhd { namespace features {
14 
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>
31  {
32  auto p = get_feature_ptr(T::get_feature_id());
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
discoverable_feature.hpp
UHD_ASSERT_THROW
#define UHD_ASSERT_THROW(code)
Definition: exception.hpp:321
uhd::features::discoverable_feature_getter_iface
Definition: discoverable_feature_getter_iface.hpp:17
UHD_API
#define UHD_API
Definition: config.h:87
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::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
Definition: build_info.hpp:12
exception.hpp
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::sptr
std::shared_ptr< discoverable_feature > sptr
Definition: discoverable_feature.hpp:28