Chris@102: // Copyright Kevlin Henney, 2000-2005. Chris@102: // Copyright Alexander Nasonov, 2006-2010. Chris@102: // Copyright Antony Polukhin, 2011-2014. Chris@102: // Chris@102: // Distributed under the Boost Software License, Version 1.0. (See Chris@102: // accompanying file LICENSE_1_0.txt or copy at Chris@102: // http://www.boost.org/LICENSE_1_0.txt) Chris@102: // Chris@102: // what: lexical_cast custom keyword cast Chris@102: // who: contributed by Kevlin Henney, Chris@102: // enhanced with contributions from Terje Slettebo, Chris@102: // with additional fixes and suggestions from Gennaro Prota, Chris@102: // Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov, Chris@102: // Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann, Chris@102: // Cheng Yang, Matthew Bradbury, David W. Birdsall, Pavel Korzh and other Boosters Chris@102: // when: November 2000, March 2003, June 2005, June 2006, March 2011 - 2014 Chris@102: Chris@102: #ifndef BOOST_LEXICAL_CAST_BAD_LEXICAL_CAST_HPP Chris@102: #define BOOST_LEXICAL_CAST_BAD_LEXICAL_CAST_HPP Chris@102: Chris@102: #include Chris@102: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@102: # pragma once Chris@102: #endif Chris@102: Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: Chris@102: namespace boost Chris@102: { Chris@102: // exception used to indicate runtime lexical_cast failure Chris@102: class BOOST_SYMBOL_VISIBLE bad_lexical_cast : Chris@102: // workaround MSVC bug with std::bad_cast when _HAS_EXCEPTIONS == 0 Chris@102: #if defined(BOOST_MSVC) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS Chris@102: public std::exception Chris@102: #else Chris@102: public std::bad_cast Chris@102: #endif Chris@102: Chris@102: #if defined(__BORLANDC__) && BOOST_WORKAROUND( __BORLANDC__, < 0x560 ) Chris@102: // under bcc32 5.5.1 bad_cast doesn't derive from exception Chris@102: , public std::exception Chris@102: #endif Chris@102: Chris@102: { Chris@102: public: Chris@102: bad_lexical_cast() BOOST_NOEXCEPT Chris@102: #ifndef BOOST_NO_TYPEID Chris@102: : source(&typeid(void)), target(&typeid(void)) Chris@102: #endif Chris@102: {} Chris@102: Chris@102: virtual const char *what() const BOOST_NOEXCEPT_OR_NOTHROW { Chris@102: return "bad lexical cast: " Chris@102: "source type value could not be interpreted as target"; Chris@102: } Chris@102: Chris@102: virtual ~bad_lexical_cast() BOOST_NOEXCEPT_OR_NOTHROW Chris@102: {} Chris@102: Chris@102: #ifndef BOOST_NO_TYPEID Chris@102: bad_lexical_cast( Chris@102: const std::type_info &source_type_arg, Chris@102: const std::type_info &target_type_arg) BOOST_NOEXCEPT Chris@102: : source(&source_type_arg), target(&target_type_arg) Chris@102: {} Chris@102: Chris@102: const std::type_info &source_type() const BOOST_NOEXCEPT { Chris@102: return *source; Chris@102: } Chris@102: Chris@102: const std::type_info &target_type() const BOOST_NOEXCEPT { Chris@102: return *target; Chris@102: } Chris@102: Chris@102: private: Chris@102: const std::type_info *source; Chris@102: const std::type_info *target; Chris@102: #endif Chris@102: }; Chris@102: Chris@102: namespace conversion { namespace detail { Chris@102: #ifdef BOOST_NO_TYPEID Chris@102: template Chris@102: inline void throw_bad_cast() { Chris@102: boost::throw_exception(bad_lexical_cast()); Chris@102: } Chris@102: #else Chris@102: template Chris@102: inline void throw_bad_cast() { Chris@102: boost::throw_exception(bad_lexical_cast(typeid(S), typeid(T))); Chris@102: } Chris@102: #endif Chris@102: }} // namespace conversion::detail Chris@102: Chris@102: Chris@102: } // namespace boost Chris@102: Chris@102: #endif // BOOST_LEXICAL_CAST_BAD_LEXICAL_CAST_HPP Chris@102: