[PATCH] hackrf: replace boost::assign with C++11

argilo at gmail.com argilo at gmail.com
Fri Jan 31 04:22:03 UTC 2020


From: Clayton Smith <argilo at gmail.com>

Since GNU Radio is gradually replacing Boost with C++11, it seemed worth
doing that for the HackRF blocks I was working on. This change removes
all usage of boost::assign.
---
 lib/hackrf/hackrf_common.cc   | 54 +++++++++++++++--------------------
 lib/hackrf/hackrf_common.h    |  1 +
 lib/hackrf/hackrf_sink_c.cc   | 11 +------
 lib/hackrf/hackrf_source_c.cc | 11 +------
 4 files changed, 26 insertions(+), 51 deletions(-)

diff --git a/lib/hackrf/hackrf_common.cc b/lib/hackrf/hackrf_common.cc
index 0a20f2ec9c..a6de22aab6 100644
--- a/lib/hackrf/hackrf_common.cc
+++ b/lib/hackrf/hackrf_common.cc
@@ -21,14 +21,10 @@
 #include "config.h"
 #endif
 
-#include <boost/assign.hpp>
-
 #include "hackrf_common.h"
 
 #include "arg_helpers.h"
 
-using namespace boost::assign;
-
 int hackrf_common::_usage = 0;
 std::mutex hackrf_common::_usage_mutex;
 
@@ -213,11 +209,11 @@ osmosdr::meta_range_t hackrf_common::get_sample_rates()
    * the user is allowed to request arbitrary (fractional) rates within these
    * boundaries. */
 
-  range += osmosdr::range_t( 8e6 );
-  range += osmosdr::range_t( 10e6 );
-  range += osmosdr::range_t( 12.5e6 );
-  range += osmosdr::range_t( 16e6 );
-  range += osmosdr::range_t( 20e6 ); /* confirmed to work on fast machines */
+  range.push_back(osmosdr::range_t( 8e6 ));
+  range.push_back(osmosdr::range_t( 10e6 ));
+  range.push_back(osmosdr::range_t( 12.5e6 ));
+  range.push_back(osmosdr::range_t( 16e6 ));
+  range.push_back(osmosdr::range_t( 20e6 )); /* confirmed to work on fast machines */
 
   return range;
 }
@@ -246,7 +242,7 @@ osmosdr::freq_range_t hackrf_common::get_freq_range( size_t chan )
 {
   osmosdr::freq_range_t range;
 
-  range += osmosdr::range_t( _sample_rate / 2, 7250e6 - _sample_rate / 2 );
+  range.push_back(osmosdr::range_t( _sample_rate / 2, 7250e6 - _sample_rate / 2 ));
 
   return range;
 }
@@ -325,11 +321,7 @@ double hackrf_common::get_gain( size_t chan )
 
 std::vector< std::string > hackrf_common::get_antennas( size_t chan )
 {
-  std::vector< std::string > antennas;
-
-  antennas += get_antenna( chan );
-
-  return antennas;
+  return { get_antenna( chan ) };
 }
 
 std::string hackrf_common::set_antenna( const std::string & antenna, size_t chan )
@@ -375,22 +367,22 @@ osmosdr::freq_range_t hackrf_common::get_bandwidth_range( size_t chan )
 
   // TODO: read out from libhackrf when an API is available
 
-  bandwidths += osmosdr::range_t( 1750000 );
-  bandwidths += osmosdr::range_t( 2500000 );
-  bandwidths += osmosdr::range_t( 3500000 );
-  bandwidths += osmosdr::range_t( 5000000 );
-  bandwidths += osmosdr::range_t( 5500000 );
-  bandwidths += osmosdr::range_t( 6000000 );
-  bandwidths += osmosdr::range_t( 7000000 );
-  bandwidths += osmosdr::range_t( 8000000 );
-  bandwidths += osmosdr::range_t( 9000000 );
-  bandwidths += osmosdr::range_t( 10000000 );
-  bandwidths += osmosdr::range_t( 12000000 );
-  bandwidths += osmosdr::range_t( 14000000 );
-  bandwidths += osmosdr::range_t( 15000000 );
-  bandwidths += osmosdr::range_t( 20000000 );
-  bandwidths += osmosdr::range_t( 24000000 );
-  bandwidths += osmosdr::range_t( 28000000 );
+  bandwidths.push_back(osmosdr::range_t( 1750000 ));
+  bandwidths.push_back(osmosdr::range_t( 2500000 ));
+  bandwidths.push_back(osmosdr::range_t( 3500000 ));
+  bandwidths.push_back(osmosdr::range_t( 5000000 ));
+  bandwidths.push_back(osmosdr::range_t( 5500000 ));
+  bandwidths.push_back(osmosdr::range_t( 6000000 ));
+  bandwidths.push_back(osmosdr::range_t( 7000000 ));
+  bandwidths.push_back(osmosdr::range_t( 8000000 ));
+  bandwidths.push_back(osmosdr::range_t( 9000000 ));
+  bandwidths.push_back(osmosdr::range_t( 10000000 ));
+  bandwidths.push_back(osmosdr::range_t( 12000000 ));
+  bandwidths.push_back(osmosdr::range_t( 14000000 ));
+  bandwidths.push_back(osmosdr::range_t( 15000000 ));
+  bandwidths.push_back(osmosdr::range_t( 20000000 ));
+  bandwidths.push_back(osmosdr::range_t( 24000000 ));
+  bandwidths.push_back(osmosdr::range_t( 28000000 ));
 
   return bandwidths;
 }
diff --git a/lib/hackrf/hackrf_common.h b/lib/hackrf/hackrf_common.h
index 02eabd2f0c..ea093b9680 100644
--- a/lib/hackrf/hackrf_common.h
+++ b/lib/hackrf/hackrf_common.h
@@ -20,6 +20,7 @@
 #ifndef INCLUDED_HACKRF_COMMON_H
 #define INCLUDED_HACKRF_COMMON_H
 
+#include <map>
 #include <memory>
 #include <mutex>
 #include <string>
diff --git a/lib/hackrf/hackrf_sink_c.cc b/lib/hackrf/hackrf_sink_c.cc
index f003b89ce3..7271109b15 100644
--- a/lib/hackrf/hackrf_sink_c.cc
+++ b/lib/hackrf/hackrf_sink_c.cc
@@ -38,16 +38,12 @@
 #include <emmintrin.h>
 #endif
 
-#include <boost/assign.hpp>
-
 #include <gnuradio/io_signature.h>
 
 #include "hackrf_sink_c.h"
 
 #include "arg_helpers.h"
 
-using namespace boost::assign;
-
 static inline bool cb_init(circular_buffer_t *cb, size_t capacity, size_t sz)
 {
   cb->buffer = malloc(capacity * sz);
@@ -449,12 +445,7 @@ double hackrf_sink_c::get_freq_corr( size_t chan )
 
 std::vector<std::string> hackrf_sink_c::get_gain_names( size_t chan )
 {
-  std::vector< std::string > names;
-
-  names += "RF";
-  names += "IF";
-
-  return names;
+  return { "RF", "IF" };
 }
 
 osmosdr::gain_range_t hackrf_sink_c::get_gain_range( size_t chan )
diff --git a/lib/hackrf/hackrf_source_c.cc b/lib/hackrf/hackrf_source_c.cc
index 51a6580eca..eea5caafda 100644
--- a/lib/hackrf/hackrf_source_c.cc
+++ b/lib/hackrf/hackrf_source_c.cc
@@ -31,7 +31,6 @@
 #include <stdexcept>
 #include <iostream>
 
-#include <boost/assign.hpp>
 #include <boost/detail/endian.hpp>
 
 #include <gnuradio/io_signature.h>
@@ -40,8 +39,6 @@
 
 #include "arg_helpers.h"
 
-using namespace boost::assign;
-
 hackrf_source_c_sptr make_hackrf_source_c (const std::string & args)
 {
   return gnuradio::get_initial_sptr(new hackrf_source_c (args));
@@ -306,13 +303,7 @@ double hackrf_source_c::get_freq_corr( size_t chan )
 
 std::vector<std::string> hackrf_source_c::get_gain_names( size_t chan )
 {
-  std::vector< std::string > names;
-
-  names += "RF";
-  names += "IF";
-  names += "BB";
-
-  return names;
+  return { "RF", "IF", "BB" };
 }
 
 osmosdr::gain_range_t hackrf_source_c::get_gain_range( size_t chan )
-- 
2.17.1



More information about the osmocom-sdr mailing list