From 6652eb4a033b38bd952563f3544eb11e98f27327 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 31 Jan 2018 20:20:14 +0100 Subject: uhd: Move internal headers to uhdlib/ To avoid the proliferation of additional include directories and multiple ways of including project-local headers, we now default to moving all headers that are used across UHD into the uhdlib/ subdirectory. Some #include statements were also reordered as they were modified for closer compliance with the coding guidelines. Internal cpp source files should now include files like this: #include Reviewed-by: Ashish Chaudhari --- host/lib/include/uhdlib/rfnoc/utils.hpp | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 host/lib/include/uhdlib/rfnoc/utils.hpp (limited to 'host/lib/include/uhdlib/rfnoc/utils.hpp') diff --git a/host/lib/include/uhdlib/rfnoc/utils.hpp b/host/lib/include/uhdlib/rfnoc/utils.hpp new file mode 100644 index 000000000..28c69987f --- /dev/null +++ b/host/lib/include/uhdlib/rfnoc/utils.hpp @@ -0,0 +1,67 @@ +// +// Copyright 2014 Ettus Research LLC +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#ifndef INCLUDED_LIBUHD_RFNOC_UTILS_HPP +#define INCLUDED_LIBUHD_RFNOC_UTILS_HPP + +#include +#include +#include + +namespace uhd { namespace rfnoc { namespace utils { + + /*! If \p suggested_port equals ANY_PORT, return the first available + * port number on \p nodes. Otherwise, return \p suggested_port. + * + * If \p allowed_ports is given, another condition is that the port + * number must be listed in here. + * If \p allowed_ports is not specified or empty, the assumption is + * that all ports are valid. + * + * On failure, ANY_PORT is returned. + */ + static size_t node_map_find_first_free( + node_ctrl_base::node_map_t nodes, + const size_t suggested_port, + const std::set allowed_ports=std::set() + ) { + size_t port = suggested_port; + if (port == ANY_PORT) { + if (allowed_ports.empty()) { + port = 0; + while (nodes.count(port) and (port != ANY_PORT)) { + port++; + } + } else { + for(const size_t allowed_port: allowed_ports) { + if (not nodes.count(port)) { + return allowed_port; + } + return ANY_PORT; + } + } + } else { + if (not (allowed_ports.empty() or allowed_ports.count(port))) { + return ANY_PORT; + } + } + return port; + } + + template + static std::set str_list_to_set(const std::vector &list) { + std::set return_set; + for(const std::string &S: list) { + return_set.insert(boost::lexical_cast(S)); + } + return return_set; + } + +}}}; /* namespace uhd::rfnoc::utils */ + +#endif /* INCLUDED_LIBUHD_RFNOC_UTILS_HPP */ +// vim: sw=4 et: -- cgit v1.2.3