From 16f08844d7b6ccbdcfdf17963b88cadb7525ddc6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 24 Feb 2011 14:54:24 -0800 Subject: uhd: renamed the assert header to assert has only the assert has implementation is in this header uhd assert throw moved to the exception header updated code base includes to match --- host/include/uhd/exception.hpp | 9 ++++++ host/include/uhd/utils/CMakeLists.txt | 4 +-- host/include/uhd/utils/assert.hpp | 53 ----------------------------------- host/include/uhd/utils/assert.ipp | 52 ---------------------------------- host/include/uhd/utils/assert_has.hpp | 47 +++++++++++++++++++++++++++++++ host/include/uhd/utils/assert_has.ipp | 53 +++++++++++++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 107 deletions(-) delete mode 100644 host/include/uhd/utils/assert.hpp delete mode 100644 host/include/uhd/utils/assert.ipp create mode 100644 host/include/uhd/utils/assert_has.hpp create mode 100644 host/include/uhd/utils/assert_has.ipp (limited to 'host/include') diff --git a/host/include/uhd/exception.hpp b/host/include/uhd/exception.hpp index 71836e22e..9acc768ed 100644 --- a/host/include/uhd/exception.hpp +++ b/host/include/uhd/exception.hpp @@ -114,6 +114,15 @@ namespace uhd{ #define UHD_THROW_INVALID_CODE_PATH() \ throw uhd::system_error(UHD_THROW_SITE_INFO("invalid code path")) + /*! + * Assert the result of the code evaluation. + * If the code evaluates to false, throw an assertion error. + * \param code the code that resolved to a boolean + */ + #define UHD_ASSERT_THROW(code) if (not (code)) \ + throw uhd::assertion_error(UHD_THROW_SITE_INFO(#code)); \ + else void(0) + } //namespace uhd #endif /* INCLUDED_UHD_UTILS_EXCEPTION_HPP */ diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt index b638431d3..4ed7ca460 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -17,8 +17,8 @@ INSTALL(FILES algorithm.hpp - assert.hpp - assert.ipp + assert_has.hpp + assert_has.ipp byteswap.hpp byteswap.ipp gain_group.hpp diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp deleted file mode 100644 index 1be4237d6..000000000 --- a/host/include/uhd/utils/assert.hpp +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright 2010-2011 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 . -// - -#ifndef INCLUDED_UHD_UTILS_ASSERT_HPP -#define INCLUDED_UHD_UTILS_ASSERT_HPP - -#include -#include -#include - -namespace uhd{ - - //! Throw an assert error with throw-site information - #define UHD_ASSERT_THROW(_x) if (not (_x)) throw uhd::assertion_error( \ - UHD_THROW_SITE_INFO("assertion failed: " + std::string(#_x)) \ - ); else void(0) - - /*! - * Check that an element is found in a container. - * If not, throw a meaningful assertion error. - * The "what" in the error will show what is - * being set and a list of known good values. - * - * \param range a list of possible settings - * \param value an element that may be in the list - * \param what a description of what the value is - * \throw assertion_error when elem not in list - */ - template void assert_has( - const Range &range, - const T &value, - const std::string &what = "unknown" - ); - -}//namespace uhd - -#include - -#endif /* INCLUDED_UHD_UTILS_ASSERT_HPP */ diff --git a/host/include/uhd/utils/assert.ipp b/host/include/uhd/utils/assert.ipp deleted file mode 100644 index 4374fff67..000000000 --- a/host/include/uhd/utils/assert.ipp +++ /dev/null @@ -1,52 +0,0 @@ -// -// Copyright 2010-2011 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 . -// - -#ifndef INCLUDED_UHD_UTILS_ASSERT_IPP -#define INCLUDED_UHD_UTILS_ASSERT_IPP - -#include -#include -#include -#include - -namespace uhd{ - - template 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(v); - } - throw uhd::assertion_error(str(boost::format( - "assertion failed:\n" - " %s is not a valid %s.\n" - " possible values are: [%s].\n" - ) - % boost::lexical_cast(value) - % what % possible_values - )); - } - -}//namespace uhd - -#endif /* INCLUDED_UHD_UTILS_ASSERT_IPP */ diff --git a/host/include/uhd/utils/assert_has.hpp b/host/include/uhd/utils/assert_has.hpp new file mode 100644 index 000000000..eae7652ad --- /dev/null +++ b/host/include/uhd/utils/assert_has.hpp @@ -0,0 +1,47 @@ +// +// Copyright 2010-2011 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 . +// + +#ifndef INCLUDED_UHD_UTILS_ASSERT_HAS_HPP +#define INCLUDED_UHD_UTILS_ASSERT_HAS_HPP + +#include +#include + +namespace uhd{ + + /*! + * Check that an element is found in a container. + * If not, throw a meaningful assertion error. + * The "what" in the error will show what is + * being set and a list of known good values. + * + * \param range a list of possible settings + * \param value an element that may be in the list + * \param what a description of what the value is + * \throw assertion_error when elem not in list + */ + template void assert_has( + const Range &range, + const T &value, + const std::string &what = "unknown" + ); + +}//namespace uhd + +#include + +#endif /* INCLUDED_UHD_UTILS_ASSERT_HAS_HPP */ diff --git a/host/include/uhd/utils/assert_has.ipp b/host/include/uhd/utils/assert_has.ipp new file mode 100644 index 000000000..a46d172f4 --- /dev/null +++ b/host/include/uhd/utils/assert_has.ipp @@ -0,0 +1,53 @@ +// +// Copyright 2010-2011 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 . +// + +#ifndef INCLUDED_UHD_UTILS_ASSERT_HAS_IPP +#define INCLUDED_UHD_UTILS_ASSERT_HAS_IPP + +#include +#include +#include +#include +#include + +namespace uhd{ + + template 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(v); + } + throw uhd::assertion_error(str(boost::format( + "assertion failed:\n" + " %s is not a valid %s.\n" + " possible values are: [%s].\n" + ) + % boost::lexical_cast(value) + % what % possible_values + )); + } + +}//namespace uhd + +#endif /* INCLUDED_UHD_UTILS_ASSERT_HAS_IPP */ -- cgit v1.2.3