Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:14

0001 // Copyright Kevlin Henney, 2000-2005.
0002 // Copyright Alexander Nasonov, 2006-2010.
0003 // Copyright Antony Polukhin, 2011-2023.
0004 //
0005 // Distributed under the Boost Software License, Version 1.0. (See
0006 // accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 // what:  lexical_cast custom keyword cast
0010 // who:   contributed by Kevlin Henney,
0011 //        enhanced with contributions from Terje Slettebo,
0012 //        with additional fixes and suggestions from Gennaro Prota,
0013 //        Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
0014 //        Alexander Nasonov, Antony Polukhin, Justin Viiret, Michael Hofmann,
0015 //        Cheng Yang, Matthew Bradbury, David W. Birdsall, Pavel Korzh and other Boosters
0016 // when:  November 2000, March 2003, June 2005, June 2006, March 2011 - 2014
0017 
0018 #ifndef BOOST_LEXICAL_CAST_BAD_LEXICAL_CAST_HPP
0019 #define BOOST_LEXICAL_CAST_BAD_LEXICAL_CAST_HPP
0020 
0021 #include <boost/config.hpp>
0022 #ifdef BOOST_HAS_PRAGMA_ONCE
0023 #   pragma once
0024 #endif
0025 
0026 #include <exception>
0027 #include <typeinfo>
0028 #include <boost/throw_exception.hpp>
0029 
0030 namespace boost
0031 {
0032     // exception used to indicate runtime lexical_cast failure
0033     class BOOST_SYMBOL_VISIBLE bad_lexical_cast :
0034     // workaround MSVC bug with std::bad_cast when _HAS_EXCEPTIONS == 0
0035 #if defined(BOOST_MSVC) && defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS
0036         public std::exception
0037 #else
0038         public std::bad_cast
0039 #endif
0040     {
0041     public:
0042         bad_lexical_cast() noexcept
0043 #ifndef BOOST_NO_TYPEID
0044            : source(&typeid(void)), target(&typeid(void))
0045 #endif
0046         {}
0047 
0048         const char *what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE {
0049             return "bad lexical cast: "
0050                    "source type value could not be interpreted as target";
0051         }
0052 
0053         bad_lexical_cast(const bad_lexical_cast&) = default;
0054         bad_lexical_cast& operator=(const bad_lexical_cast&) = default;
0055 
0056 #ifndef BOOST_NO_TYPEID
0057     private:
0058 #ifdef BOOST_NO_STD_TYPEINFO
0059         typedef ::type_info type_info_t;
0060 #else
0061         typedef ::std::type_info type_info_t;
0062 #endif
0063     public:
0064         bad_lexical_cast(
0065                 const type_info_t &source_type_arg,
0066                 const type_info_t &target_type_arg) noexcept
0067             : source(&source_type_arg), target(&target_type_arg)
0068         {}
0069 
0070         const type_info_t &source_type() const noexcept {
0071             return *source;
0072         }
0073 
0074         const type_info_t &target_type() const noexcept {
0075             return *target;
0076         }
0077 
0078     private:
0079         const type_info_t *source;
0080         const type_info_t *target;
0081 #endif
0082     };
0083 
0084     namespace conversion { namespace detail {
0085 #ifdef BOOST_NO_TYPEID
0086         template <class S, class T>
0087         inline void throw_bad_cast() {
0088             boost::throw_exception(bad_lexical_cast());
0089         }
0090 #else
0091         template <class S, class T>
0092         inline void throw_bad_cast() {
0093             boost::throw_exception(bad_lexical_cast(typeid(S), typeid(T)));
0094         }
0095 #endif
0096     }} // namespace conversion::detail
0097 
0098 } // namespace boost
0099 
0100 #endif // BOOST_LEXICAL_CAST_BAD_LEXICAL_CAST_HPP