From d6cb55ef08f51c9ebef57e5bbcb95b03a65972a9 Mon Sep 17 00:00:00 2001 From: Lane Kolbly Date: Mon, 22 Jun 2020 18:06:38 -0500 Subject: uhd: Create discoverable feature registry implementation Classes which want to implement discoverable_feature can simply inherit from this registry and get access to an ergonomic map-backed registry of features. --- .../features/discoverable_feature_registry.hpp | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 host/lib/include/uhdlib/features/discoverable_feature_registry.hpp (limited to 'host/lib/include') diff --git a/host/lib/include/uhdlib/features/discoverable_feature_registry.hpp b/host/lib/include/uhdlib/features/discoverable_feature_registry.hpp new file mode 100644 index 000000000..f27f1a4f1 --- /dev/null +++ b/host/lib/include/uhdlib/features/discoverable_feature_registry.hpp @@ -0,0 +1,42 @@ +// +// Copyright 2020 Ettus Research, a National Instruments Brand +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace uhd { namespace features { + +/*! Map-based registry to implement discoverable_feature_getter_iface + */ +class discoverable_feature_registry : public virtual discoverable_feature_getter_iface +{ +public: + virtual ~discoverable_feature_registry() = default; + + std::vector enumerate_features() override; + + template + void register_feature(std::shared_ptr feature) + { + if (!_features.emplace(T::get_feature_id(), feature).second) { + UHD_ASSERT_THROW(false); + } + } + +private: + discoverable_feature::sptr get_feature_ptr( + discoverable_feature::feature_id_t feature_id) override; + + std::map _features; +}; + +}} // namespace uhd::features -- cgit v1.2.3