summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-07-08 12:52:15 -0700
committerJosh Blum <josh@joshknows.com>2010-07-08 12:52:15 -0700
commitf6217746dce159085b9941a8fcc9f6407f7fdd5e (patch)
treec38e3a0e7343fdb33015db7d066a66805998510c /host
parentab617b492ed2dc47a814f8c01f60f7639ba633e7 (diff)
downloaduhd-f6217746dce159085b9941a8fcc9f6407f7fdd5e.tar.gz
uhd-f6217746dce159085b9941a8fcc9f6407f7fdd5e.tar.bz2
uhd-f6217746dce159085b9941a8fcc9f6407f7fdd5e.zip
uhd: moved assert implementation into ipp file, fixed potential bug with assert throw macro
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/utils/CMakeLists.txt1
-rw-r--r--host/include/uhd/utils/assert.hpp31
-rw-r--r--host/include/uhd/utils/assert.ipp52
3 files changed, 60 insertions, 24 deletions
diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt
index 36f86054a..d484788b2 100644
--- a/host/include/uhd/utils/CMakeLists.txt
+++ b/host/include/uhd/utils/CMakeLists.txt
@@ -18,6 +18,7 @@
INSTALL(FILES
algorithm.hpp
assert.hpp
+ assert.ipp
byteswap.hpp
byteswap.ipp
exception.hpp
diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp
index 2f0ed4ff1..7f7b71cfb 100644
--- a/host/include/uhd/utils/assert.hpp
+++ b/host/include/uhd/utils/assert.hpp
@@ -20,10 +20,6 @@
#include <uhd/config.hpp>
#include <uhd/utils/exception.hpp>
-#include <uhd/utils/algorithm.hpp>
-#include <boost/format.hpp>
-#include <boost/foreach.hpp>
-#include <boost/lexical_cast.hpp>
#include <stdexcept>
#include <string>
@@ -35,8 +31,9 @@ namespace uhd{
};
//! Throw an assert error with throw-site information
- #define UHD_ASSERT_THROW(_x) if (not (_x)) \
- throw uhd::assert_error(UHD_THROW_SITE_INFO("assertion failed: " + std::string(#_x)))
+ #define UHD_ASSERT_THROW(_x) if (not (_x)) throw uhd::assert_error( \
+ UHD_THROW_SITE_INFO("assertion failed: " + std::string(#_x)) \
+ ); else void(0)
/*!
* Check that an element is found in a container.
@@ -46,31 +43,17 @@ namespace uhd{
*
* \param range a list of possible settings
* \param value an element that may be in the list
- * \param what a description of what is being set
+ * \param what a description of what the value is
* \throw assertion_error when elem not in list
*/
template<typename T, typename Range> void assert_has(
const Range &range,
const T &value,
const std::string &what = "unknown"
- ){
- if (std::has(range, value)) return;
- std::string possible_values = "";
- size_t i = 0;
- BOOST_FOREACH(const T &v, range){
- if (i++ > 0) possible_values += ", ";
- possible_values += boost::lexical_cast<std::string>(v);
- }
- throw uhd::assert_error(str(boost::format(
- "assertion failed:\n"
- " %s is not a valid %s.\n"
- " possible values are: [%s].\n"
- )
- % boost::lexical_cast<std::string>(value)
- % what % possible_values
- ));
- }
+ );
}//namespace uhd
+#include <uhd/utils/assert.ipp>
+
#endif /* INCLUDED_UHD_UTILS_ASSERT_HPP */
diff --git a/host/include/uhd/utils/assert.ipp b/host/include/uhd/utils/assert.ipp
new file mode 100644
index 000000000..6a8b3e417
--- /dev/null
+++ b/host/include/uhd/utils/assert.ipp
@@ -0,0 +1,52 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+
+#ifndef INCLUDED_UHD_UTILS_ASSERT_IPP
+#define INCLUDED_UHD_UTILS_ASSERT_IPP
+
+#include <uhd/utils/algorithm.hpp>
+#include <boost/format.hpp>
+#include <boost/foreach.hpp>
+#include <boost/lexical_cast.hpp>
+
+namespace uhd{
+
+ template<typename T, typename Range> UHD_INLINE void assert_has(
+ const Range &range,
+ const T &value,
+ const std::string &what
+ ){
+ if (std::has(range, value)) return;
+ std::string possible_values = "";
+ size_t i = 0;
+ BOOST_FOREACH(const T &v, range){
+ if (i++ > 0) possible_values += ", ";
+ possible_values += boost::lexical_cast<std::string>(v);
+ }
+ throw uhd::assert_error(str(boost::format(
+ "assertion failed:\n"
+ " %s is not a valid %s.\n"
+ " possible values are: [%s].\n"
+ )
+ % boost::lexical_cast<std::string>(value)
+ % what % possible_values
+ ));
+ }
+
+}//namespace uhd
+
+#endif /* INCLUDED_UHD_UTILS_ASSERT_IPP */