uhd: Remove usage of boost::optional

- boost::optional is replaced by std::optional
- In public APIs, boost::optional is still usable, but it is declared
  deprecated. That means this is no API break (but it is an ABI break).
- Within the library portion (host/lib/**) there is no more usage of
  boost::optional. Some backward-compatibility code (in actions.cpp and
  ctrlport_endpoint.cpp) was moved out to the header.

Note: The most difficult replacement was that for
parse_log_level_from_string(), where boost::optional is the return
value. To retain API compatibility, we had to create a helper function.
This commit is contained in:
Martin Braun 2026-03-24 20:30:44 +01:00 committed by mkoop-ni
parent 34bf82ad2b
commit 3eb6fe492a
33 changed files with 281 additions and 148 deletions

View File

@ -1,6 +1,11 @@
Change Log for Releases
==============================
## 004.next
* API Changes:
- All usage of boost::optional within the library is removed. Public APIs
that used boost::optional are retained, but flagged deprecated.
## 004.010.000.000
* Highlights / Main Changes
- Support for USRP X420

View File

@ -14,6 +14,7 @@
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <string>
namespace uhd { namespace usrp { namespace cal {
@ -69,7 +70,36 @@ public:
const double min_power,
const double max_power,
const double freq,
const boost::optional<int> temperature = boost::none) = 0;
const std::optional<int> temperature = {}) = 0;
// Helper to resolve between the two optional methods
void add_power_table(const std::map<double, double>& gain_power_map,
const double min_power,
const double max_power,
const double freq,
const int temperature)
{
add_power_table(gain_power_map,
min_power,
max_power,
freq,
std::make_optional<int>(temperature));
}
[[deprecated("Prefer std::optional over boost::optional.")]] void add_power_table(
const std::map<double, double>& gain_power_map,
const double min_power,
const double max_power,
const double freq,
const boost::optional<int> temperature)
{
add_power_table(gain_power_map,
min_power,
max_power,
freq,
bool(temperature) ? std::make_optional<int>(*temperature) : std::nullopt);
}
/*! Clear all stored values
*
@ -106,8 +136,21 @@ public:
/*! Return the min and max power available for this frequency
*/
virtual uhd::meta_range_t get_power_limits(const double freq,
const boost::optional<int> temperature = boost::none) const = 0;
virtual uhd::meta_range_t get_power_limits(
const double freq, const std::optional<int> temperature = {}) const = 0;
// Helper to resolve between the two optional methods
uhd::meta_range_t get_power_limits(const double freq, const int temperature) const
{
return get_power_limits(freq, std::make_optional<int>(temperature));
}
[[deprecated("Prefer std::optional over boost::optional.")]] uhd::meta_range_t
get_power_limits(const double freq, const boost::optional<int> temperature) const
{
return get_power_limits(freq,
bool(temperature) ? std::make_optional<int>(*temperature) : std::nullopt);
}
/*! Returns the power at a gain value.
*
@ -122,7 +165,22 @@ public:
*/
virtual double get_power(const double gain,
const double freq,
const boost::optional<int> temperature = boost::none) const = 0;
const std::optional<int> temperature = {}) const = 0;
double get_power(const double gain, const double freq, const int temperature) const
{
return get_power(gain, freq, std::make_optional<int>(temperature));
}
[[deprecated("Prefer std::optional over boost::optional.")]] double get_power(
const double gain,
const double freq,
const boost::optional<int> temperature) const
{
return get_power(gain,
freq,
bool(temperature) ? std::make_optional<int>(*temperature) : std::nullopt);
}
/*! Look up a gain value from a power value.
*
@ -141,7 +199,23 @@ public:
*/
virtual double get_gain(const double power_dbm,
const double freq,
const boost::optional<int> temperature = boost::none) const = 0;
const std::optional<int> temperature = {}) const = 0;
double get_gain(
const double power_dbm, const double freq, const int temperature) const
{
return get_gain(power_dbm, freq, std::make_optional<int>(temperature));
}
[[deprecated("Prefer std::optional over boost::optional.")]] double get_gain(
const double power_dbm,
const double freq,
const boost::optional<int> temperature) const
{
return get_gain(power_dbm,
freq,
bool(temperature) ? std::make_optional<int>(*temperature) : std::nullopt);
}
//! Factory for new cal data sets
static sptr make(

View File

@ -107,12 +107,19 @@ public:
//
// Required to avoid ambiguity between boost and std versions when using
// timestamp directly.
static sptr make(uhd::async_metadata_t::event_code_t event_code, uint64_t tsf);
static sptr make(uhd::async_metadata_t::event_code_t event_code, uint64_t tsf)
{
return make(event_code, std::make_optional<uint64_t>(tsf));
}
//! Factory function (legacy, to support boost::optional)
[[deprecated("Prefer std::optional over boost::optional.")]] static sptr make(
uhd::async_metadata_t::event_code_t event_code,
const boost::optional<uint64_t>& tsf);
const boost::optional<uint64_t>& tsf)
{
return make(
event_code, bool(tsf) ? std::make_optional<uint64_t>(*tsf) : std::nullopt);
}
protected:
tx_event_action_info(uhd::async_metadata_t::event_code_t event_code,

View File

@ -71,7 +71,21 @@ public:
*/
virtual double set_freq(const double freq,
const size_t chan,
const boost::optional<uhd::time_spec_t> time = boost::none) = 0;
const std::optional<uhd::time_spec_t> time = {}) = 0;
double set_freq(const double freq, const size_t chan, const uhd::time_spec_t time)
{
return set_freq(freq, chan, std::make_optional(time));
}
[[deprecated("Prefer std::optional over boost::optional.")]] double set_freq(
const double freq,
const size_t chan,
const boost::optional<uhd::time_spec_t> time)
{
return set_freq(
freq, chan, bool(time) ? std::make_optional(*time) : std::nullopt);
}
/*! Return the current DDS frequency
*

View File

@ -11,6 +11,7 @@
#include <uhd/types/ranges.hpp>
#include <uhd/types/time_spec.hpp>
#include <boost/optional.hpp>
#include <optional>
namespace uhd { namespace rfnoc {
@ -70,7 +71,21 @@ public:
*/
virtual double set_freq(const double freq,
const size_t chan,
const boost::optional<uhd::time_spec_t> time = boost::none) = 0;
const std::optional<uhd::time_spec_t> time = {}) = 0;
double set_freq(const double freq, const size_t chan, const uhd::time_spec_t time)
{
return set_freq(freq, chan, std::make_optional(time));
}
[[deprecated("Prefer std::optional over boost::optional.")]] virtual double set_freq(
const double freq,
const size_t chan,
const boost::optional<uhd::time_spec_t> time)
{
return set_freq(
freq, chan, bool(time) ? std::make_optional(*time) : std::nullopt);
}
/*! Return the current DDS frequency
*

View File

@ -116,11 +116,6 @@ public:
// nop
}
void register_async_msg_handler(async_msg_callback_legacy_t /*callback_f*/) override
{
// nop
}
void set_policy(const std::string& name, const uhd::device_addr_t& args) override
{
UHD_LOG_INFO("MOCK_REG_IFACE",

View File

@ -357,8 +357,20 @@ public:
*
* \param callback_f The function to call when an asynchronous message is received.
*/
[[deprecated("Prefer std::optional over boost::optional.")]] virtual void
register_async_msg_handler(async_msg_callback_legacy_t callback_f) = 0;
[[deprecated("Prefer std::optional over boost::optional.")]] void
register_async_msg_handler(async_msg_callback_legacy_t callback_f)
{
auto wrapper_f = [callback_f](uint32_t addr,
const std::vector<uint32_t>& data,
std::optional<uint64_t> timestamp) {
boost::optional<uint64_t> legacy_timestamp;
if (timestamp.has_value()) {
legacy_timestamp = timestamp.value();
}
callback_f(addr, data, legacy_timestamp);
};
register_async_msg_handler(wrapper_f);
}
/*! Set a policy that governs the operational parameters of this register bus.
* Policies can be used to make tradeoffs between performance, resilience, latency,

View File

@ -11,23 +11,22 @@
#include <uhd/rfnoc/defaults.hpp>
#include <uhd/rfnoc/graph_edge.hpp>
#include <uhd/rfnoc_graph.hpp>
#include <boost/none.hpp>
#include <boost/optional.hpp>
#include <optional>
#include <vector>
namespace uhd { namespace rfnoc {
//! Tuple that stores a block ID, as well as an optional port number
using block_port_def = std::tuple<std::string, boost::optional<size_t>>;
using block_port_def = std::tuple<std::string, std::optional<size_t>>;
// TODO: Get rid of magic strings
/*! List of blocks that can terminate chains. Note that some blocks only terminate at
* some of their ports, so we can optionally include a port number.
*/
static const std::vector<block_port_def> TERMINATOR_BLOCKS{
block_port_def{NODE_ID_SEP, boost::none},
block_port_def{"Radio", boost::none},
block_port_def{NODE_ID_SEP, std::nullopt},
block_port_def{"Radio", std::nullopt},
block_port_def{"NullSrcSink", 0}};
/*!

View File

@ -8,10 +8,13 @@
#pragma once
#include <uhd/config.hpp>
#include <type_traits>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/none.hpp>
#include <boost/optional.hpp>
#include <iomanip>
#include <iostream>
#include <optional>
#include <ostream>
#include <sstream>
#include <string>
@ -123,12 +126,34 @@ enum severity_level {
off = 6, /**< logging is turned off */
};
namespace detail {
/*! Parses a `severity_level` from a string. If a value could not be parsed,
* returns none.
* Note: All of this is necessary to retain backward-compatibility with
* boost::optional. When we deprecate boost::optional from the API
* entirely, this can be removed.
*/
boost::optional<uhd::log::severity_level> UHD_API parse_log_level_from_string(
UHD_API std::optional<uhd::log::severity_level> parse_log_level_from_string_impl(
const std::string& log_level_str);
} // namespace detail
template <typename T = boost::optional<uhd::log::severity_level>,
std::enable_if_t<
std::is_same_v<T,
boost::optional<uhd::log::
severity_level>> || std::is_same_v<T, std::optional<uhd::log::severity_level>>,
int> = 0>
T parse_log_level_from_string(const std::string& log_level_str)
{
if constexpr (std::is_same_v<T, boost::optional<uhd::log::severity_level>>) {
const auto level = detail::parse_log_level_from_string_impl(log_level_str);
return bool(level) ? boost::make_optional(*level) : boost::none;
} else {
return detail::parse_log_level_from_string_impl(log_level_str);
}
}
/*! Logging info structure
*
* Information needed to create a log entry is fully contained in the

View File

@ -16,6 +16,7 @@
#include <cstring>
#include <functional>
#include <memory>
#include <optional>
#include <vector>
namespace uhd {
@ -25,7 +26,8 @@ public:
typedef std::shared_ptr<msg_task> sptr;
typedef std::vector<uint8_t> msg_payload_t;
typedef std::pair<uint32_t, msg_payload_t> msg_type_t;
typedef std::function<boost::optional<msg_type_t>(void)> task_fcn_type;
typedef std::function<std::optional<msg_type_t>(void)> task_fcn_type;
typedef std::function<boost::optional<msg_type_t>(void)> task_fcn_type_legacy;
/*
* During shutdown message queues for radio control cores might not be available
@ -63,5 +65,17 @@ public:
* \return a new task object
*/
static sptr make(const task_fcn_type& task_fcn);
/*! Backward-compatible version to retain boost::optional compatibility.
*/
[[deprecated("Prefer std::optional over boost::optional.")]] static sptr make(
const task_fcn_type_legacy& task_fcn)
{
return make([task_fcn]() -> std::optional<msg_type_t> {
auto task_result = task_fcn();
return bool(task_result) ? std::make_optional<msg_type_t>(*task_result)
: std::nullopt;
});
}
};
} // namespace uhd

View File

@ -126,31 +126,40 @@ void export_cal(py::module& m)
return container::make<pwr_cal>(pybytes_to_vector(data));
}))
.def("add_power_table",
&pwr_cal::add_power_table,
static_cast<void (pwr_cal::*)(const std::map<double, double>&,
const double,
const double,
const double,
const std::optional<int>)>(&pwr_cal::add_power_table),
py::arg("gain_power_map"),
py::arg("min_power"),
py::arg("max_power"),
py::arg("freq"),
py::arg("temperature") = boost::optional<int>())
py::arg("temperature") = std::optional<int>())
.def("clear", &pwr_cal::clear)
.def("set_temperature", &pwr_cal::set_temperature)
.def("get_temperature", &pwr_cal::get_temperature)
.def("set_ref_gain", &pwr_cal::set_ref_gain)
.def("get_ref_gain", &pwr_cal::get_ref_gain)
.def("get_power_limits",
&pwr_cal::get_power_limits,
static_cast<uhd::meta_range_t (pwr_cal::*)(const double,
const std::optional<int>) const>(&pwr_cal::get_power_limits),
py::arg("freq"),
py::arg("temperature") = boost::optional<int>())
py::arg("temperature") = std::optional<int>())
.def("get_power",
&pwr_cal::get_power,
static_cast<double (pwr_cal::*)(
const double, const double, const std::optional<int>) const>(
&pwr_cal::get_power),
py::arg("gain"),
py::arg("freq"),
py::arg("temperature") = boost::optional<int>())
py::arg("temperature") = std::optional<int>())
.def("get_gain",
&pwr_cal::get_gain,
static_cast<double (pwr_cal::*)(
const double, const double, const std::optional<int>) const>(
&pwr_cal::get_gain),
py::arg("power_dbm"),
py::arg("freq"),
py::arg("temperature") = boost::optional<int>());
py::arg("temperature") = std::optional<int>());
py::class_<zbx_tx_dsa_cal, container, zbx_tx_dsa_cal::sptr>(m, "zbx_tx_dsa_cal")
.def(py::init([](const std::string& name,

View File

@ -77,7 +77,7 @@ public:
const double min_power,
const double max_power,
const double freq,
const boost::optional<int> temperature = boost::none) override
const std::optional<int> temperature) override
{
if (min_power > max_power) {
throw uhd::runtime_error(
@ -86,7 +86,7 @@ public:
+ std::to_string(min_power) + " dBm, "
+ std::to_string(max_power) + " dBm)"));
}
const int temp = bool(temperature) ? temperature.get() : _default_temp;
const int temp = temperature.value_or(_default_temp);
_data[temp][static_cast<uint64_t>(freq)] = {
gain_power_map, reverse_map(gain_power_map), min_power, max_power};
}
@ -96,7 +96,7 @@ public:
// a struct).
double get_power(const double gain,
const double freq,
const boost::optional<int> temperature = boost::none) const override
const std::optional<int> temperature = {}) const override
{
UHD_ASSERT_THROW(!_data.empty());
const uint64_t freqi = static_cast<uint64_t>(freq);
@ -156,8 +156,8 @@ public:
return _ref_gain;
}
uhd::meta_range_t get_power_limits(const double freq,
const boost::optional<int> temperature = boost::none) const override
uhd::meta_range_t get_power_limits(
const double freq, const std::optional<int> temperature = {}) const override
{
const auto table = at_nearest(_get_table(temperature), uint64_t(freq));
return uhd::meta_range_t(table.min_power, table.max_power);
@ -165,7 +165,7 @@ public:
double get_gain(const double power_dbm,
const double freq,
const boost::optional<int> temperature = boost::none) const override
const std::optional<int> temperature = {}) const override
{
UHD_ASSERT_THROW(!_data.empty());
const uint64_t freqi = static_cast<uint64_t>(freq);
@ -314,8 +314,6 @@ private:
// We map the gain to power, and power to gain, in different data structures.
// This is suboptimal w.r.t. memory usage (it duplicates the keys/values),
// but helps us with the algorithms above.
// This could also be solved with a Boost.Bimap, but it doesn't seem worth
// the additional dependency.
struct pwr_cal_table
{
std::map<double, double> g2p; //!< Maps gain to power
@ -326,10 +324,9 @@ private:
using freq_table_map = std::map<uint64_t /* freq */, pwr_cal_table>;
freq_table_map _get_table(const boost::optional<int> temperature) const
freq_table_map _get_table(const std::optional<int> temperature) const
{
const int temp = bool(temperature) ? temperature.get() : _default_temp;
return at_nearest(_data, temp);
return at_nearest(_data, temperature.value_or(_default_temp));
}
std::string _name;

View File

@ -9,10 +9,10 @@
#include <uhdlib/rfnoc/rfnoc_common.hpp>
#include <boost/format.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/optional.hpp>
#include <list>
#include <map>
#include <memory>
#include <optional>
namespace uhd { namespace rfnoc { namespace detail {
@ -52,8 +52,8 @@ struct topo_node_t
topo_node_t(device_id_t device_id_,
node_type type_,
sep_inst_t inst_,
uint32_t extended_info_ = 0,
const boost::optional<sep_id_t> epid_ = boost::none)
uint32_t extended_info_ = 0,
const std::optional<sep_id_t> epid_ = {})
: device_id(device_id_)
, type(type_)
, inst(inst_)
@ -62,8 +62,8 @@ struct topo_node_t
{
}
topo_node_t(const sep_addr_t& sep_addr,
const bool is_local_ = false,
const boost::optional<sep_id_t> epid_ = boost::none)
const bool is_local_ = false,
const std::optional<sep_id_t> epid_ = {})
: device_id(sep_addr.first)
, type(node_type::STRM_EP)
, inst(sep_addr.second)
@ -89,7 +89,7 @@ struct topo_node_t
//! If applicable, the endpoint ID of this node. This is only set if
// type == node_type::STRM_EP or node_type::VIRTUAL.
boost::optional<sep_id_t> epid;
std::optional<sep_id_t> epid;
//! True if this is a stream endpoint (type == node_type::STRM_EP) and the
// endpoint is local, i.e. based within the UHD session.

View File

@ -78,7 +78,7 @@ struct io_service_args_t
* struct above is returned.
*
* \param args The dictionary from which to read the I/O service args
* \param defaults Default values (not including boost::optional values)
* \param defaults Default values (not including optional values)
* \return The I/O service args read
*/
io_service_args_t read_io_service_args(

View File

@ -94,20 +94,6 @@ tx_event_action_info::sptr tx_event_action_info::make(
return std::make_shared<tx_event_action_info_make_shared>(event_code, tsf);
}
tx_event_action_info::sptr tx_event_action_info::make(
uhd::async_metadata_t::event_code_t event_code, uint64_t tsf)
{
return tx_event_action_info::make(event_code, std::optional<uint64_t>{tsf});
}
tx_event_action_info::sptr tx_event_action_info::make(
uhd::async_metadata_t::event_code_t event_code, const boost::optional<uint64_t>& tsf)
{
return tx_event_action_info::make(event_code,
bool(tsf) ? std::optional<uint64_t>(*tsf) : std::optional<uint64_t>{});
}
/*** Tune Request Metadata Action Info *************************************************/
tune_request_action_info::tune_request_action_info(
const uhd::tune_request_t tune_request_)

View File

@ -11,7 +11,6 @@
#include <uhdlib/rfnoc/ctrlport_endpoint.hpp>
#include <condition_variable>
#include <boost/format.hpp>
#include <boost/optional.hpp>
#include <algorithm>
#include <chrono>
#include <deque>
@ -227,18 +226,6 @@ public:
_handle_async_msg = callback_f;
}
// Backward-compatible, legacy version
void register_async_msg_handler(async_msg_callback_legacy_t callback_f) override
{
std::unique_lock<std::mutex> lock(_mutex);
_handle_async_msg = [callback_f](uint32_t addr,
const std::vector<uint32_t>& data,
std::optional<uint64_t> timestamp) {
return callback_f(
addr, data, bool(timestamp) ? *timestamp : boost::optional<uint64_t>{});
};
}
void set_policy(const std::string& name, const uhd::device_addr_t& args) override
{
std::unique_lock<std::mutex> lock(_mutex);

View File

@ -110,12 +110,12 @@ public:
double set_freq(const double freq,
const size_t chan,
const boost::optional<uhd::time_spec_t> time) override
const std::optional<uhd::time_spec_t> time) override
{
// Store the current command time so we can restore it later
auto prev_cmd_time = get_command_time(chan);
if (time) {
set_command_time(time.get(), chan);
set_command_time(*time, chan);
}
// This will trigger property propagation:
set_property<double>("freq", freq, chan);
@ -487,7 +487,7 @@ private:
if (src.type == res_source_info::INPUT_EDGE) {
auto set_dsp_freq = [this, chan](
double freq) { set_freq(freq, chan, boost::none); };
double freq) { set_freq(freq, chan, std::nullopt); };
double clipped_requested_freq = tune_range.clip(tune_request.target_freq);
tune_request_action->tune_result.target_dsp_freq = std::abs(

View File

@ -17,10 +17,12 @@ void export_ddc_block_control(py::module& m)
m, "ddc_block_control")
.def(py::init(&block_controller_factory<ddc_block_control>::make_from))
.def("set_freq",
&ddc_block_control::set_freq,
static_cast<double (ddc_block_control::*)(
const double, const size_t, const std::optional<uhd::time_spec_t>)>(
&ddc_block_control::set_freq),
py::arg("freq"),
py::arg("chan"),
py::arg("time") = boost::optional<uhd::time_spec_t>())
py::arg("time") = std::optional<uhd::time_spec_t>())
.def("get_freq", &ddc_block_control::get_freq)
.def("get_frequency_range", &ddc_block_control::get_frequency_range)
.def("get_input_rate", &ddc_block_control::get_input_rate)

View File

@ -109,12 +109,12 @@ public:
double set_freq(const double freq,
const size_t chan,
const boost::optional<uhd::time_spec_t> time) override
const std::optional<uhd::time_spec_t> time) override
{
// Store the current command time so we can restore it later
auto prev_cmd_time = get_command_time(chan);
if (time) {
set_command_time(time.get(), chan);
set_command_time(*time, chan);
}
// This will trigger property propagation:
set_property<double>("freq", freq, chan);
@ -479,7 +479,7 @@ private:
if (src.type == res_source_info::OUTPUT_EDGE) {
auto set_dsp_freq = [this, chan](
double freq) { set_freq(freq, chan, boost::none); };
double freq) { set_freq(freq, chan, std::nullopt); };
double clipped_requested_freq = tune_range.clip(tune_request.target_freq);
tune_request_action->tune_result.target_dsp_freq = std::abs(

View File

@ -17,10 +17,12 @@ void export_duc_block_control(py::module& m)
m, "duc_block_control")
.def(py::init(&block_controller_factory<duc_block_control>::make_from))
.def("set_freq",
&duc_block_control::set_freq,
static_cast<double (duc_block_control::*)(
const double, const size_t, const std::optional<uhd::time_spec_t>)>(
&duc_block_control::set_freq),
py::arg("freq"),
py::arg("chan"),
py::arg("time") = boost::optional<uhd::time_spec_t>())
py::arg("time") = std::optional<uhd::time_spec_t>())
.def("get_freq", &duc_block_control::get_freq)
.def("get_frequency_range", &duc_block_control::get_frequency_range)
.def("get_input_rate", &duc_block_control::get_input_rate)

View File

@ -460,7 +460,7 @@ private:
const auto route_to_sep = _mgmt_portal->get_route(src_addr);
auto route_it = route_to_sep.begin();
UHD_ASSERT_THROW(!!route_it->node.epid);
const sep_id_t src_epid = route_it->node.epid.get();
const sep_id_t src_epid = route_it->node.epid.value();
route_it++;
UHD_ASSERT_THROW(route_it->node.type == topo_node_t::node_type::XPORT);
auto ta_node = route_it->node;
@ -525,7 +525,7 @@ private:
dst_epid);
UHD_LOG_DEBUG(LOG_ID,
"Adding virtual endpoint: " << virtual_ep.to_string() << " (EPID: "
<< virtual_ep.epid.get() << ")");
<< virtual_ep.epid.value() << ")");
detail::topo_edge_t virtual_edge;
virtual_edge.type = detail::topo_edge_t::edge_type::ETHERNET;
_tgraph->add_edge(ta_node, virtual_ep, virtual_edge);

View File

@ -68,11 +68,6 @@ public:
UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!");
}
void register_async_msg_handler(async_msg_callback_legacy_t) override
{
UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!");
}
void register_async_msg_validator(async_msg_validator_t) override
{
UHD_LOG_ERROR("REGS", "Attempting to use invalidated register interface!");

View File

@ -21,6 +21,7 @@
#include <uhdlib/usrp/common/io_service_mgr.hpp>
#include <uhdlib/utils/narrow.hpp>
#include <memory>
#include <optional>
using namespace uhd;
using namespace uhd::rfnoc;
@ -170,7 +171,7 @@ public:
if (!src_static_edge_o) {
return false;
}
graph_edge_t src_static_edge = src_static_edge_o.get();
graph_edge_t src_static_edge = src_static_edge_o.value();
// Now see if it's already connected to the destination
if (src_static_edge.dst_blockid == dst_blk.to_string()
@ -198,7 +199,7 @@ public:
if (!dst_static_edge_o) {
return false;
}
graph_edge_t dst_static_edge = dst_static_edge_o.get();
graph_edge_t dst_static_edge = dst_static_edge_o.value();
// If they're not statically connected, the source *must* be connected
// to an SEP, or this route is impossible
@ -950,11 +951,11 @@ private:
dst_sep_addr, src_sep_addr, false, 0.1, 0.0, false);
UHD_LOGGER_DEBUG(LOG_ID)
<< boost::format(
"Data stream between EPID %d and EPID %d established "
"where downstream buffer can hold %lu bytes and %u packets")
% std::get<0>(strm_info).first % std::get<0>(strm_info).second
% std::get<1>(strm_info).bytes % std::get<1>(strm_info).packets;
<< "Data stream between EPID " << std::get<0>(strm_info).first
<< " and EPID " << std::get<0>(strm_info).second
<< " established where downstream buffer can hold "
<< std::get<1>(strm_info).bytes << " bytes and "
<< std::get<1>(strm_info).packets << " packets";
}
return route_info.edge_type;
@ -1003,11 +1004,11 @@ private:
* \throws uhd::assertion_error if the edge can't be found. So be careful!
*/
template <typename UnaryPredicate>
boost::optional<graph_edge_t> _get_static_edge(UnaryPredicate&& pred)
std::optional<graph_edge_t> _get_static_edge(UnaryPredicate&& pred)
{
auto edge_it = std::find_if(_static_edges.cbegin(), _static_edges.cend(), pred);
if (edge_it == _static_edges.cend()) {
return boost::none;
return std::nullopt;
}
return *edge_it;
}
@ -1015,7 +1016,7 @@ private:
/*! Make sure an optional edge info is valid, or throw.
*/
graph_edge_t _assert_edge(
boost::optional<graph_edge_t> edge_o, const std::string& blk_info)
std::optional<graph_edge_t> edge_o, const std::string& blk_info)
{
if (!bool(edge_o)) {
const std::string err_msg = std::string("Cannot connect block ") + blk_info
@ -1023,7 +1024,7 @@ private:
UHD_LOG_ERROR(LOG_ID, err_msg);
throw uhd::routing_error(err_msg);
}
return edge_o.get();
return edge_o.value();
}
/**************************************************************************

View File

@ -20,7 +20,6 @@
#include <uhd/utils/paths.hpp>
#include <uhd/utils/safe_call.hpp>
#include <uhd/utils/static.hpp>
#include <boost/filesystem.hpp>
#include <boost/format.hpp>
#include <boost/functional/hash.hpp>
#include <chrono>

View File

@ -36,9 +36,9 @@
#include <uhdlib/usrp/cores/user_settings_core_3000.hpp>
#include <uhdlib/usrp/gps_ctrl.hpp>
#include <unordered_map>
#include <boost/optional.hpp>
#include <memory>
#include <mutex>
#include <optional>
static const uint8_t B200_FW_COMPAT_NUM_MAJOR = 8;
static const uint8_t B200_FW_COMPAT_NUM_MINOR = 0;
@ -171,7 +171,7 @@ private:
b200_uart::sptr gpsdo_uart;
};
std::shared_ptr<AsyncTaskData> _async_task_data;
boost::optional<uhd::msg_task::msg_type_t> handle_async_task(
std::optional<uhd::msg_task::msg_type_t> handle_async_task(
uhd::transport::zero_copy_if::sptr, std::shared_ptr<AsyncTaskData>);
void register_loopback_self_test(uhd::wb_iface::sptr iface);

View File

@ -325,12 +325,12 @@ bool b200_impl::recv_async_msg(async_metadata_t& async_metadata, double timeout)
* a dump_queue implemented in msg_task. A radio_ctrl_core can search for missing messages
* there.
*/
boost::optional<uhd::msg_task::msg_type_t> b200_impl::handle_async_task(
std::optional<uhd::msg_task::msg_type_t> b200_impl::handle_async_task(
uhd::transport::zero_copy_if::sptr xport, std::shared_ptr<AsyncTaskData> data)
{
managed_recv_buffer::sptr buff = xport->get_recv_buff();
if (not buff or buff->size() < 8)
return boost::none;
return std::nullopt;
const uint32_t sid = uhd::wtohx(buff->cast<const uint32_t*>()[1]);
switch (sid) {
@ -395,7 +395,7 @@ boost::optional<uhd::msg_task::msg_type_t> b200_impl::handle_async_task(
default:
UHD_LOGGER_ERROR("B200") << "Got a ctrl packet with unknown SID " << sid;
}
return boost::none;
return std::nullopt;
}
/***********************************************************************

View File

@ -259,7 +259,7 @@ device_addrs_t mpmd_find(const device_addr_t& hint_)
<< "check devices for reachability");
if (check_reachability) {
std::vector<std::future<boost::optional<device_addr_t>>> reachability_tasks;
std::vector<std::future<std::optional<device_addr_t>>> reachability_tasks;
for (const auto& mpm_dev : bcast_mpm_devs) {
if (mpm_dev.get(RPC_VERSION_KEY, DEFAULT_RPC_VERSION) == RPC_VERSION) {
reachability_tasks.emplace_back(
@ -267,8 +267,8 @@ device_addrs_t mpmd_find(const device_addr_t& hint_)
return mpmd_mboard_impl::is_device_reachable(mpm_dev);
}));
} else {
reachability_tasks.emplace_back(std::async(std::launch::async,
[]() { return boost::optional<device_addr_t>{}; }));
reachability_tasks.emplace_back(std::async(
std::launch::async, []() { return std::optional<device_addr_t>{}; }));
}
}
// Variable i is used to index reachability_tasks as well as bcast_mpm_devs (both
@ -276,7 +276,7 @@ device_addrs_t mpmd_find(const device_addr_t& hint_)
for (size_t i = 0; i < reachability_tasks.size(); ++i) {
const auto reachable_device_addr = reachability_tasks[i].get();
if (bool(reachable_device_addr)) {
filtered_mpm_devs.push_back(reachable_device_addr.get());
filtered_mpm_devs.push_back(reachable_device_addr.value());
} else if (find_all) {
filtered_mpm_devs.emplace_back(
flag_dev_as_unreachable(bcast_mpm_devs[i]));

View File

@ -21,12 +21,12 @@
#include <boost/algorithm/string.hpp>
#include <boost/archive/iterators/binary_from_base64.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/optional.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <cctype>
#include <filesystem>
#include <fstream>
#include <iterator>
#include <optional>
#include <string>
#include <vector>
@ -105,7 +105,7 @@ uhd::usrp::component_file_t generate_component(const std::string& id,
return component_file;
}
boost::optional<std::vector<uint8_t>> parse_dts_from_lvbitx(
std::optional<std::vector<uint8_t>> parse_dts_from_lvbitx(
const boost::property_tree::ptree& pt)
{
std::string dts;
@ -115,7 +115,7 @@ boost::optional<std::vector<uint8_t>> parse_dts_from_lvbitx(
} catch (boost::property_tree::ptree_error&) {
UHD_LOG_WARNING(
"MPMD IMAGE LOADER", "Could not find DTS in .lvbitx file, not including it");
return boost::none;
return std::nullopt;
}
if (dts.size() % 2 != 0) {
@ -239,7 +239,7 @@ static uhd::usrp::component_files_t lvbitx_to_component_files(
const auto maybe_dts = parse_dts_from_lvbitx(pt);
if (maybe_dts) {
const auto dts = maybe_dts.get();
const auto dts = maybe_dts.value();
uhd::dict<std::string, std::string> dts_metadata;
dts_metadata.set("filename", "usrp_x410_fpga_LV.dts");

View File

@ -16,9 +16,9 @@
#include <uhdlib/rfnoc/rfnoc_device.hpp>
#include <uhdlib/usrp/common/mpmd_mb_controller.hpp>
#include <uhdlib/utils/rpc.hpp>
#include <boost/optional.hpp>
#include <map>
#include <memory>
#include <optional>
/*************************************************************************
* RPC timeout constants for MPMD
@ -67,7 +67,7 @@ public:
*
* \param device_addr Device args. Must contain an mgmt_addr.
*/
static boost::optional<device_addr_t> is_device_reachable(
static std::optional<device_addr_t> is_device_reachable(
const device_addr_t& device_addr);
/*** Structors ***********************************************************/

View File

@ -12,6 +12,7 @@
#include <uhd/utils/safe_call.hpp>
#include <chrono>
#include <memory>
#include <optional>
#include <thread>
namespace {
@ -174,7 +175,7 @@ using namespace uhd::mpmd;
/******************************************************************************
* Static Helpers
*****************************************************************************/
boost::optional<device_addr_t> mpmd_mboard_impl::is_device_reachable(
std::optional<device_addr_t> mpmd_mboard_impl::is_device_reachable(
const device_addr_t& device_addr)
{
UHD_LOG_TRACE(
@ -191,18 +192,18 @@ boost::optional<device_addr_t> mpmd_mboard_impl::is_device_reachable(
rpcc->request<dev_info>(MPMD_SHORT_RPC_TIMEOUT, "get_device_info");
} catch (const uhd::runtime_error& e) {
UHD_LOG_DEBUG("MPMD", e.what());
return boost::optional<device_addr_t>();
return std::nullopt;
} catch (...) {
UHD_LOG_DEBUG("MPMD",
"Unexpected exception when trying to query device info. Flagging "
"device as unreachable.");
return boost::optional<device_addr_t>();
return std::nullopt;
}
// 2) Check for local device
if (device_info_dict.count("connection")
and device_info_dict.at("connection") == "local") {
UHD_LOG_TRACE("MPMD", "Device is local, flagging as reachable.");
return boost::optional<device_addr_t>(device_addr);
return std::make_optional<device_addr_t>(device_addr);
}
// 3) Check for network-reachable device
// Note: This makes the assumption that devices will always allow RPC
@ -244,7 +245,7 @@ boost::optional<device_addr_t> mpmd_mboard_impl::is_device_reachable(
}
device_addr_t device_addr_copy = device_addr;
device_addr_copy["addr"] = chdr_addr;
return boost::optional<device_addr_t>(device_addr_copy);
return std::make_optional<device_addr_t>(device_addr_copy);
} catch (...) {
UHD_LOG_DEBUG(
"MPMD", "Failed to reach device on network addr " << chdr_addr << ".");
@ -259,12 +260,12 @@ boost::optional<device_addr_t> mpmd_mboard_impl::is_device_reachable(
// via Virtual NIC packet fowarding.
device_addr_t device_addr_copy = device_addr;
device_addr_copy["addr"] = rpc_addr;
return boost::optional<device_addr_t>(device_addr_copy);
return std::make_optional<device_addr_t>(device_addr_copy);
}
// If everything fails, we probably can't talk to this chap.
UHD_LOG_TRACE(
"MPMD", "All reachability checks failed -- assuming device is not reachable.");
return boost::optional<device_addr_t>();
return std::nullopt;
}
/*****************************************************************************

View File

@ -25,7 +25,7 @@ bool check_terminator_block(const block_id_t blk_id, const size_t port)
for (auto term_block : TERMINATOR_BLOCKS) {
auto optional_port = std::get<1>(term_block);
if (blk_id_str == std::get<0>(term_block)
&& (!optional_port || port == optional_port.get())) {
&& (!optional_port || port == *optional_port)) {
return true;
}
}

View File

@ -6,6 +6,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
#include <uhd/config.hpp>
#include <uhd/transport/bounded_buffer.hpp>
#include <uhd/utils/log.hpp>
#include <uhd/utils/log_add.hpp>
@ -105,7 +106,7 @@ inline std::string path_to_filename(std::string path)
namespace uhd { namespace log {
boost::optional<uhd::log::severity_level> parse_log_level_from_string(
std::optional<uhd::log::severity_level> detail::parse_log_level_from_string_impl(
const std::string& log_level_str)
{
if (std::isdigit(log_level_str[0])) {
@ -115,7 +116,7 @@ boost::optional<uhd::log::severity_level> parse_log_level_from_string(
return log_level_num;
} else {
std::cerr << "[LOG] Failed to set log level to: " << log_level_str;
return boost::none;
return std::nullopt;
}
}
@ -127,7 +128,7 @@ boost::optional<uhd::log::severity_level> parse_log_level_from_string(
if_loglevel_equal(error);
if_loglevel_equal(fatal);
if_loglevel_equal(off);
return boost::none;
return std::nullopt;
}
}} // namespace uhd::log
@ -229,8 +230,7 @@ public:
{
// allow override from macro definition
#ifdef UHD_LOG_MIN_LEVEL
this->global_level =
_get_log_level(BOOST_STRINGIZE(UHD_LOG_MIN_LEVEL), this->global_level);
this->global_level = _get_log_level(STR(UHD_LOG_MIN_LEVEL), this->global_level);
#endif
// allow override from environment variables
const char* log_level_env = std::getenv("UHD_LOG_LEVEL");
@ -442,13 +442,9 @@ private:
uhd::log::severity_level _get_log_level(
const std::string& log_level_str, const uhd::log::severity_level& previous_level)
{
boost::optional<uhd::log::severity_level> parsed_level =
uhd::log::parse_log_level_from_string(log_level_str);
if (parsed_level) {
return *parsed_level;
} else {
return previous_level;
}
const auto parsed_level = uhd::log::parse_log_level_from_string<
std::optional<uhd::log::severity_level>>(log_level_str);
return parsed_level.value_or(previous_level);
}
void _setup_console_logging()
@ -456,8 +452,7 @@ private:
#ifndef UHD_LOG_CONSOLE_DISABLE
uhd::log::severity_level console_level = uhd::log::trace;
# ifdef UHD_LOG_CONSOLE_LEVEL
console_level =
_get_log_level(BOOST_STRINGIZE(UHD_LOG_CONSOLE_LEVEL), console_level);
console_level = _get_log_level(STR(UHD_LOG_CONSOLE_LEVEL), console_level);
# endif
const char* log_console_level_env = std::getenv("UHD_LOG_CONSOLE_LEVEL");
if (log_console_level_env != NULL && log_console_level_env[0] != '\0') {
@ -472,10 +467,10 @@ private:
uhd::log::severity_level file_level = uhd::log::trace;
std::string log_file_target;
#if defined(UHD_LOG_FILE_LEVEL)
file_level = _get_log_level(BOOST_STRINGIZE(UHD_LOG_FILE_LEVEL), file_level);
file_level = _get_log_level(STR(UHD_LOG_FILE_LEVEL), file_level);
#endif
#if defined(UHD_LOG_FILE)
log_file_target = BOOST_STRINGIZE(UHD_LOG_FILE);
log_file_target = STR(UHD_LOG_FILE);
#endif
const char* log_file_level_env = std::getenv("UHD_LOG_FILE_LEVEL");
if (log_file_level_env != NULL && log_file_level_env[0] != '\0') {

View File

@ -11,7 +11,6 @@
#include <uhd/utils/tasks.hpp>
#include <uhd/utils/thread.hpp>
#include <condition_variable>
#include <boost/optional.hpp>
#include <atomic>
#include <exception>
#include <functional>
@ -130,15 +129,15 @@ private:
try {
while (_running) {
boost::optional<msg_type_t> buff = task_fcn();
if (buff != boost::none) {
auto buff = task_fcn();
if (bool(buff)) {
/*
* If a message gets stranded it is returned by task_fcn and then
* pushed to the dump_queue. This way ctrl_cores can check dump_queue
* for missing messages.
*/
std::lock_guard<std::mutex> lock(_mutex);
_dump_queue.push_back(buff.get());
_dump_queue.push_back(*buff);
}
}
} catch (const std::exception& e) {