diff options
author | Martin Braun <martin.braun@ettus.com> | 2021-11-08 11:41:11 +0100 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-11-12 12:11:33 -0800 |
commit | bccc2b49ab25551c6fc104a0b69f69121b76031d (patch) | |
tree | 1337f6e7cc528421ff28025605b548900d78f5e9 | |
parent | 1d7cba5c6ce0cfa7545053fe213e2f1a268ae5bc (diff) | |
download | uhd-bccc2b49ab25551c6fc104a0b69f69121b76031d.tar.gz uhd-bccc2b49ab25551c6fc104a0b69f69121b76031d.tar.bz2 uhd-bccc2b49ab25551c6fc104a0b69f69121b76031d.zip |
rfnoc: Make chdr_w_to_bits() C++11-compatible
This allows consumers of UHD compiling with C++11 to include this file
(which is now included via noc_block_base) by turning a switch statement
into a functionally equivalent (albeit less readable) nested ternary
statement.
-rw-r--r-- | host/include/uhd/rfnoc/rfnoc_types.hpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/host/include/uhd/rfnoc/rfnoc_types.hpp b/host/include/uhd/rfnoc/rfnoc_types.hpp index 606850a27..123bf82f1 100644 --- a/host/include/uhd/rfnoc/rfnoc_types.hpp +++ b/host/include/uhd/rfnoc/rfnoc_types.hpp @@ -20,6 +20,13 @@ enum chdr_w_t { CHDR_W_64 = 0, CHDR_W_128 = 1, CHDR_W_256 = 2, CHDR_W_512 = 3 }; //! Conversion from chdr_w_t to a number of bits constexpr size_t chdr_w_to_bits(chdr_w_t chdr_w) { + // clang-format off + // This switch statement is what this function is doing, but it requires all + // consumers of this file to use C++14, which we currently enforce. We + // therefore keep this switch statement for reference, and for future + // improvements of this code, but what we feed the compiler is the nested + // ternary statement below. + /* switch (chdr_w) { case CHDR_W_64: return 64; @@ -32,6 +39,14 @@ constexpr size_t chdr_w_to_bits(chdr_w_t chdr_w) default: return 0; } + */ + return + chdr_w == CHDR_W_64 ? 64 : + chdr_w == CHDR_W_128 ? 128 : + chdr_w == CHDR_W_256 ? 256 : + chdr_w == CHDR_W_512 ? 512 : + /* default */ 0 ; + // clang-format on } //! Stream Endpoint ID Type |