From 2a185eee04a4b7f7414392bd3cc10ad7db621014 Mon Sep 17 00:00:00 2001 From: michael-west Date: Fri, 21 Feb 2014 18:08:56 -0800 Subject: Addressed comments from code review. - Created macro for gain name error. - Fixed typos. --- host/lib/usrp/multi_usrp.cpp | 40 ++++++++++++++-------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) (limited to 'host') diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index 182e774fc..d8322a39f 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -35,14 +35,20 @@ using namespace uhd::usrp; const std::string multi_usrp::ALL_GAINS = ""; -UHD_INLINE std::string string_vector_to_string(std::vector values, std::string delimeter = std::string(" ")) +UHD_INLINE std::string string_vector_to_string(std::vector values, std::string delimiter = std::string(" ")) { std::string out = ""; for (std::vector::iterator iter = values.begin(); iter != values.end(); iter++) - out += delimeter + *iter; + { + out += (iter != values.begin() ? delimiter : "") + *iter; + } return out; } +#define THROW_GAIN_NAME_ERROR(name,chan,dir) throw uhd::exception::runtime_error( \ + (boost::format("%s: gain \"%s\" not found for channel %d.\nAvailable gains: %s\n") % \ + __FUNCTION__ % name % chan % string_vector_to_string(get_##dir##_gain_names(chan))).str()); + /*********************************************************************** * Helper methods **********************************************************************/ @@ -671,10 +677,7 @@ public: try { return rx_gain_group(chan)->set_value(gain, name); } catch (uhd::key_error &e) { - std::stringstream err; - err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << - "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; - throw uhd::exception::runtime_error(err.str()); + THROW_GAIN_NAME_ERROR(name,chan,rx); } } @@ -682,10 +685,7 @@ public: try { return rx_gain_group(chan)->get_value(name); } catch (uhd::key_error &e) { - std::stringstream err; - err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << - "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; - throw uhd::exception::runtime_error(err.str()); + THROW_GAIN_NAME_ERROR(name,chan,rx); } } @@ -693,10 +693,7 @@ public: try { return rx_gain_group(chan)->get_range(name); } catch (uhd::key_error &e) { - std::stringstream err; - err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << - "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; - throw uhd::exception::runtime_error(err.str()); + THROW_GAIN_NAME_ERROR(name,chan,rx); } } @@ -861,10 +858,7 @@ public: try { return tx_gain_group(chan)->set_value(gain, name); } catch (uhd::key_error &e) { - std::stringstream err; - err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << - "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; - throw uhd::exception::runtime_error(err.str()); + THROW_GAIN_NAME_ERROR(name,chan,tx); } } @@ -872,10 +866,7 @@ public: try { return tx_gain_group(chan)->get_value(name); } catch (uhd::key_error &e) { - std::stringstream err; - err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << - "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; - throw uhd::exception::runtime_error(err.str()); + THROW_GAIN_NAME_ERROR(name,chan,tx); } } @@ -883,10 +874,7 @@ public: try { return tx_gain_group(chan)->get_range(name); } catch (uhd::key_error &e) { - std::stringstream err; - err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << - "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; - throw uhd::exception::runtime_error(err.str()); + THROW_GAIN_NAME_ERROR(name,chan,tx); } } -- cgit v1.2.3