From 20a524d1a00497bdffda0292143d92e4d98cfbe9 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 24 Feb 2011 14:18:52 -0800 Subject: uhd: moved exception to top level include --- host/include/uhd/CMakeLists.txt | 1 + host/include/uhd/exception.hpp | 119 ++++++++++++++++++++++++++++++++++ host/include/uhd/utils/CMakeLists.txt | 3 +- host/include/uhd/utils/assert.hpp | 3 +- host/include/uhd/utils/exception.hpp | 119 ---------------------------------- host/include/uhd/utils/props.hpp | 9 ++- host/lib/CMakeLists.txt | 1 + host/lib/convert/convert_impl.cpp | 2 +- host/lib/exception.cpp | 47 ++++++++++++++ host/lib/transport/usb_dummy_impl.cpp | 2 +- host/lib/types/sensors.cpp | 2 +- host/lib/usrp/usrp2/codec_ctrl.cpp | 2 +- host/lib/usrp/usrp2/codec_impl.cpp | 2 +- host/lib/usrp/usrp2/usrp2_iface.cpp | 2 +- host/lib/utils/CMakeLists.txt | 1 - host/lib/utils/exception.cpp | 47 -------------- host/tests/error_test.cpp | 2 +- 17 files changed, 181 insertions(+), 183 deletions(-) create mode 100644 host/include/uhd/exception.hpp delete mode 100644 host/include/uhd/utils/exception.hpp create mode 100644 host/lib/exception.cpp delete mode 100644 host/lib/utils/exception.cpp (limited to 'host') diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt index b7a22cf0b..db755511e 100644 --- a/host/include/uhd/CMakeLists.txt +++ b/host/include/uhd/CMakeLists.txt @@ -25,6 +25,7 @@ INSTALL(FILES config.hpp convert.hpp device.hpp + exception.hpp version.hpp wax.hpp DESTINATION ${INCLUDE_DIR}/uhd diff --git a/host/include/uhd/exception.hpp b/host/include/uhd/exception.hpp new file mode 100644 index 000000000..71836e22e --- /dev/null +++ b/host/include/uhd/exception.hpp @@ -0,0 +1,119 @@ +// +// 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_EXCEPTION_HPP +#define INCLUDED_UHD_UTILS_EXCEPTION_HPP + +#include +#include +#include +#include + +/*! + * Define common exceptions used throughout the code: + * + * - The python built-in exceptions were used as inspiration. + * - Exceptions inherit from std::exception to provide what(). + * - Exceptions inherit from uhd::exception to provide code(). + * + * The code() provides an error code which allows the application + * the option of printing a cryptic error message from the 1990s. + */ +namespace uhd{ + + struct UHD_API exception : std::runtime_error{ + exception(const std::string &what); + virtual unsigned code(void) const = 0; + }; + + struct UHD_API assertion_error : exception{ + assertion_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API lookup_error : exception{ + lookup_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API index_error : lookup_error{ + index_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API key_error : lookup_error{ + key_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API value_error : exception{ + value_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API runtime_error : exception{ + runtime_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API not_implemented_error : runtime_error{ + not_implemented_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API environment_error : exception{ + environment_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API io_error : environment_error{ + io_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API os_error : environment_error{ + os_error(const std::string &what); + virtual unsigned code(void) const; + }; + + struct UHD_API system_error : exception{ + system_error(const std::string &what); + virtual unsigned code(void) const; + }; + + /*! + * Create a formated string with throw-site information. + * Fills in the function name, file name, and line number. + * \param what the std::exeption message + * \return the formatted exception message + */ + #define UHD_THROW_SITE_INFO(what) std::string( \ + std::string(what) + "\n" + \ + " in " + std::string(BOOST_CURRENT_FUNCTION) + "\n" + \ + " at " + std::string(__FILE__) + ":" + BOOST_STRINGIZE(__LINE__) + "\n" \ + ) + + /*! + * Throws an invalid code path exception with throw-site information. + * Use this macro in places that code execution is not supposed to go. + */ + #define UHD_THROW_INVALID_CODE_PATH() \ + throw uhd::system_error(UHD_THROW_SITE_INFO("invalid code path")) + +} //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 b39b6083c..b638431d3 100644 --- a/host/include/uhd/utils/CMakeLists.txt +++ b/host/include/uhd/utils/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2010 Ettus Research LLC +# 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 @@ -21,7 +21,6 @@ INSTALL(FILES assert.ipp byteswap.hpp byteswap.ipp - exception.hpp gain_group.hpp images.hpp pimpl.hpp diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp index cd752c1c1..1be4237d6 100644 --- a/host/include/uhd/utils/assert.hpp +++ b/host/include/uhd/utils/assert.hpp @@ -19,8 +19,7 @@ #define INCLUDED_UHD_UTILS_ASSERT_HPP #include -#include -#include +#include #include namespace uhd{ diff --git a/host/include/uhd/utils/exception.hpp b/host/include/uhd/utils/exception.hpp deleted file mode 100644 index 71836e22e..000000000 --- a/host/include/uhd/utils/exception.hpp +++ /dev/null @@ -1,119 +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_EXCEPTION_HPP -#define INCLUDED_UHD_UTILS_EXCEPTION_HPP - -#include -#include -#include -#include - -/*! - * Define common exceptions used throughout the code: - * - * - The python built-in exceptions were used as inspiration. - * - Exceptions inherit from std::exception to provide what(). - * - Exceptions inherit from uhd::exception to provide code(). - * - * The code() provides an error code which allows the application - * the option of printing a cryptic error message from the 1990s. - */ -namespace uhd{ - - struct UHD_API exception : std::runtime_error{ - exception(const std::string &what); - virtual unsigned code(void) const = 0; - }; - - struct UHD_API assertion_error : exception{ - assertion_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API lookup_error : exception{ - lookup_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API index_error : lookup_error{ - index_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API key_error : lookup_error{ - key_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API value_error : exception{ - value_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API runtime_error : exception{ - runtime_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API not_implemented_error : runtime_error{ - not_implemented_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API environment_error : exception{ - environment_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API io_error : environment_error{ - io_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API os_error : environment_error{ - os_error(const std::string &what); - virtual unsigned code(void) const; - }; - - struct UHD_API system_error : exception{ - system_error(const std::string &what); - virtual unsigned code(void) const; - }; - - /*! - * Create a formated string with throw-site information. - * Fills in the function name, file name, and line number. - * \param what the std::exeption message - * \return the formatted exception message - */ - #define UHD_THROW_SITE_INFO(what) std::string( \ - std::string(what) + "\n" + \ - " in " + std::string(BOOST_CURRENT_FUNCTION) + "\n" + \ - " at " + std::string(__FILE__) + ":" + BOOST_STRINGIZE(__LINE__) + "\n" \ - ) - - /*! - * Throws an invalid code path exception with throw-site information. - * Use this macro in places that code execution is not supposed to go. - */ - #define UHD_THROW_INVALID_CODE_PATH() \ - throw uhd::system_error(UHD_THROW_SITE_INFO("invalid code path")) - -} //namespace uhd - -#endif /* INCLUDED_UHD_UTILS_EXCEPTION_HPP */ diff --git a/host/include/uhd/utils/props.hpp b/host/include/uhd/utils/props.hpp index fbca03019..81737423a 100644 --- a/host/include/uhd/utils/props.hpp +++ b/host/include/uhd/utils/props.hpp @@ -1,5 +1,5 @@ // -// Copyright 2010 Ettus Research LLC +// 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 @@ -20,8 +20,7 @@ #include #include -#include -#include +#include #include #include @@ -68,14 +67,14 @@ namespace uhd{ * Throw-site information will be included with this error. */ #define UHD_THROW_PROP_GET_ERROR() \ - throw std::runtime_error(UHD_THROW_SITE_INFO("cannot get this property")) + throw uhd::key_error(UHD_THROW_SITE_INFO("cannot get this property")) /*! * Throw when setting a not-implemented or read-only property. * Throw-site information will be included with this error. */ #define UHD_THROW_PROP_SET_ERROR() \ - throw std::runtime_error(UHD_THROW_SITE_INFO("cannot set this property")) + throw uhd::key_error(UHD_THROW_SITE_INFO("cannot set this property")) } //namespace uhd diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index c8a5dd51e..c2dbef89b 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -97,6 +97,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) LIBUHD_APPEND_SOURCES( ${CMAKE_CURRENT_BINARY_DIR}/constants.hpp ${CMAKE_CURRENT_SOURCE_DIR}/device.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/exception.cpp ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp ${CMAKE_CURRENT_SOURCE_DIR}/wax.cpp ) diff --git a/host/lib/convert/convert_impl.cpp b/host/lib/convert/convert_impl.cpp index 6a5a1465d..d43cecfec 100644 --- a/host/lib/convert/convert_impl.cpp +++ b/host/lib/convert/convert_impl.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include using namespace uhd; diff --git a/host/lib/exception.cpp b/host/lib/exception.cpp new file mode 100644 index 000000000..2299aa93f --- /dev/null +++ b/host/lib/exception.cpp @@ -0,0 +1,47 @@ +// +// Copyright 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 . +// + +#include +#include +#include + +using namespace uhd; + +static unsigned make_code(const std::string &name){ + boost::hash string_hash; + return unsigned(string_hash(name) & 0xfff); +}; + +exception::exception(const std::string &what): + std::runtime_error(what){/* NOP */} + +#define make_exception_impl(name, class, base) \ + class::class(const std::string &what): \ + base(str(boost::format("%s: %s") % name % what)){} \ + unsigned class::code(void) const{return make_code(#class);} + +make_exception_impl("AssertionError", assertion_error, exception) +make_exception_impl("LookupError", lookup_error, exception) +make_exception_impl("IndexError", index_error, lookup_error) +make_exception_impl("KeyError", key_error, lookup_error) +make_exception_impl("ValueError", value_error, exception) +make_exception_impl("RuntimeError", runtime_error, exception) +make_exception_impl("NotImplementedError", not_implemented_error, runtime_error) +make_exception_impl("EnvironmentError", environment_error, exception) +make_exception_impl("IOError", io_error, environment_error) +make_exception_impl("OSError", os_error, environment_error) +make_exception_impl("SystemError", system_error, exception) diff --git a/host/lib/transport/usb_dummy_impl.cpp b/host/lib/transport/usb_dummy_impl.cpp index 8a9772e7f..419a52279 100644 --- a/host/lib/transport/usb_dummy_impl.cpp +++ b/host/lib/transport/usb_dummy_impl.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include using namespace uhd; using namespace uhd::transport; diff --git a/host/lib/types/sensors.cpp b/host/lib/types/sensors.cpp index 5f7115d70..401c229a3 100644 --- a/host/lib/types/sensors.cpp +++ b/host/lib/types/sensors.cpp @@ -16,7 +16,7 @@ // #include -#include +#include #include #include diff --git a/host/lib/usrp/usrp2/codec_ctrl.cpp b/host/lib/usrp/usrp2/codec_ctrl.cpp index 890969b5a..0756c7971 100644 --- a/host/lib/usrp/usrp2/codec_ctrl.cpp +++ b/host/lib/usrp/usrp2/codec_ctrl.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include static const bool codec_ctrl_debug = false; diff --git a/host/lib/usrp/usrp2/codec_impl.cpp b/host/lib/usrp/usrp2/codec_impl.cpp index 09bec6db2..2135b155a 100644 --- a/host/lib/usrp/usrp2/codec_impl.cpp +++ b/host/lib/usrp/usrp2/codec_impl.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include using namespace uhd; using namespace uhd::usrp; diff --git a/host/lib/usrp/usrp2/usrp2_iface.cpp b/host/lib/usrp/usrp2/usrp2_iface.cpp index 4407a3011..6426ffd3e 100644 --- a/host/lib/usrp/usrp2/usrp2_iface.cpp +++ b/host/lib/usrp/usrp2/usrp2_iface.cpp @@ -17,7 +17,7 @@ #include "usrp2_regs.hpp" #include "usrp2_iface.hpp" -#include +#include #include #include #include diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt index 082553ff9..c0d99b37e 100644 --- a/host/lib/utils/CMakeLists.txt +++ b/host/lib/utils/CMakeLists.txt @@ -110,7 +110,6 @@ SET_SOURCE_FILES_PROPERTIES( # Append sources ######################################################################## LIBUHD_APPEND_SOURCES( - ${CMAKE_CURRENT_SOURCE_DIR}/exception.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gain_group.cpp ${CMAKE_CURRENT_SOURCE_DIR}/images.cpp ${CMAKE_CURRENT_SOURCE_DIR}/load_modules.cpp diff --git a/host/lib/utils/exception.cpp b/host/lib/utils/exception.cpp deleted file mode 100644 index e66addb0c..000000000 --- a/host/lib/utils/exception.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// -// Copyright 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 . -// - -#include -#include -#include - -using namespace uhd; - -static unsigned make_code(const std::string &name){ - boost::hash string_hash; - return unsigned(string_hash(name) & 0xfff); -}; - -exception::exception(const std::string &what): - std::runtime_error(what){/* NOP */} - -#define make_exception_impl(name, class, base) \ - class::class(const std::string &what): \ - base(str(boost::format("%s: %s") % name % what)){} \ - unsigned class::code(void) const{return make_code(#class);} - -make_exception_impl("AssertionError", assertion_error, exception) -make_exception_impl("LookupError", lookup_error, exception) -make_exception_impl("IndexError", index_error, lookup_error) -make_exception_impl("KeyError", key_error, lookup_error) -make_exception_impl("ValueError", value_error, exception) -make_exception_impl("RuntimeError", runtime_error, exception) -make_exception_impl("NotImplementedError", not_implemented_error, runtime_error) -make_exception_impl("EnvironmentError", environment_error, exception) -make_exception_impl("IOError", io_error, environment_error) -make_exception_impl("OSError", os_error, environment_error) -make_exception_impl("SystemError", system_error, exception) diff --git a/host/tests/error_test.cpp b/host/tests/error_test.cpp index 041e6b943..9254fbc85 100644 --- a/host/tests/error_test.cpp +++ b/host/tests/error_test.cpp @@ -16,7 +16,7 @@ // #include -#include +#include #include #include #include -- cgit v1.2.3