X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=boost%2Fboost%2Flexical_cast.hpp;h=926b95e43034febdf49f2258f647b962202f5553;hb=b01a9dc187d9cd396a57463ad27511379dcdc9cd;hp=83464af870c2f2b746986ed4896b5e2715ac423b;hpb=59b6a4701a8d2b5155af08cf758b4ca120201282;p=lyx.git diff --git a/boost/boost/lexical_cast.hpp b/boost/boost/lexical_cast.hpp index 83464af870..926b95e430 100644 --- a/boost/boost/lexical_cast.hpp +++ b/boost/boost/lexical_cast.hpp @@ -1,31 +1,38 @@ -// boost lexical_cast.hpp header -------------------------------------------// - -// See http://www.boost.org for most recent version including documentation. - #ifndef BOOST_LEXICAL_CAST_INCLUDED #define BOOST_LEXICAL_CAST_INCLUDED +// Boost lexical_cast.hpp header -------------------------------------------// +// +// See http://www.boost.org for most recent version including documentation. +// See end of this header for rights and permissions. +// // what: lexical_cast custom keyword cast -// who: contributed by Kevlin Henney, with alternative naming, behaviors -// and fixes contributed by Dave Abrahams, Daryle Walker and other -// Boosters on the list -// when: November 2000 -// where: tested with MSVC 6.0, BCC 5.5, and g++ 2.91 +// who: contributed by Kevlin Henney, +// enhanced with contributions from Terje Slettebø, +// with additional fixes and suggestions from Gennaro Prota, +// Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov, +// and other Boosters +// when: November 2000, March 2003, June 2005 +#include +#include +#include #include +#include +#include +#include -// Some sstream implementations are broken for the purposes of lexical cast. -# if defined(BOOST_NO_STRINGSTREAM) -# define BOOST_LEXICAL_CAST_USE_STRSTREAM -# endif - -#ifdef BOOST_LEXICAL_CAST_USE_STRSTREAM -# include +#ifdef BOOST_NO_STRINGSTREAM +#include #else -# include +#include #endif -#include +#if defined(BOOST_NO_STRINGSTREAM) || \ + defined(BOOST_NO_STD_WSTRING) || \ + defined(BOOST_NO_STD_LOCALE) +#define DISABLE_WIDE_CHAR_SUPPORT +#endif namespace boost { @@ -33,44 +40,213 @@ namespace boost class bad_lexical_cast : public std::bad_cast { public: - // constructors, destructors, and assignment operator defaulted - - // function inlined for brevity and consistency with rest of library - virtual const char * what() const throw() + bad_lexical_cast() : + source(&typeid(void)), target(&typeid(void)) + { + } + bad_lexical_cast( + const std::type_info &source_type, + const std::type_info &target_type) : + source(&source_type), target(&target_type) + { + } + const std::type_info &source_type() const + { + return *source; + } + const std::type_info &target_type() const + { + return *target; + } + virtual const char *what() const throw() { return "bad lexical cast: " "source type value could not be interpreted as target"; } + virtual ~bad_lexical_cast() throw() + { + } + private: + const std::type_info *source; + const std::type_info *target; }; + namespace detail // selectors for choosing stream character type + { + template + struct stream_char + { + typedef char type; + }; + + #ifndef DISABLE_WIDE_CHAR_SUPPORT +#if !defined(BOOST_NO_INTRINSIC_WCHAR_T) + template<> + struct stream_char + { + typedef wchar_t type; + }; +#endif + + template<> + struct stream_char + { + typedef wchar_t type; + }; + + template<> + struct stream_char + { + typedef wchar_t type; + }; + + template<> + struct stream_char + { + typedef wchar_t type; + }; + #endif + + template + struct widest_char + { + typedef TargetChar type; + }; + + template<> + struct widest_char + { + typedef wchar_t type; + }; + } + + namespace detail // stream wrapper for handling lexical conversions + { + template + class lexical_stream + { + private: + typedef typename widest_char< + typename stream_char::type, + typename stream_char::type>::type char_type; + + public: + lexical_stream() + { + stream.unsetf(std::ios::skipws); + + if(std::numeric_limits::is_specialized) + stream.precision(std::numeric_limits::digits10 + 1); + else if(std::numeric_limits::is_specialized) + stream.precision(std::numeric_limits::digits10 + 1); + } + ~lexical_stream() + { + #if defined(BOOST_NO_STRINGSTREAM) + stream.freeze(false); + #endif + } + bool operator<<(const Source &input) + { + return !(stream << input).fail(); + } + template + bool operator>>(InputStreamable &output) + { + return !is_pointer::value && + stream >> output && + stream.get() == +#if defined(__GNUC__) && (__GNUC__<3) && defined(BOOST_NO_STD_WSTRING) +// GCC 2.9x lacks std::char_traits<>::eof(). +// We use BOOST_NO_STD_WSTRING to filter out STLport and libstdc++-v3 +// configurations, which do provide std::char_traits<>::eof(). + + EOF; +#else + std::char_traits::eof(); +#endif + } + bool operator>>(std::string &output) + { + #if defined(BOOST_NO_STRINGSTREAM) + stream << '\0'; + #endif + output = stream.str(); + return true; + } + #ifndef DISABLE_WIDE_CHAR_SUPPORT + bool operator>>(std::wstring &output) + { + output = stream.str(); + return true; + } + #endif + private: + #if defined(BOOST_NO_STRINGSTREAM) + std::strstream stream; + #elif defined(BOOST_NO_STD_LOCALE) + std::stringstream stream; + #else + std::basic_stringstream stream; + #endif + }; + } + + #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + + // call-by-const reference version + + namespace detail + { + template + struct array_to_pointer_decay + { + typedef T type; + }; + + template + struct array_to_pointer_decay + { + typedef const T * type; + }; + } + template - Target lexical_cast(Source arg) + Target lexical_cast(const Source &arg) { -# ifdef BOOST_LEXICAL_CAST_USE_STRSTREAM - std::strstream interpreter; // for out-of-the-box g++ 2.95.2 -# else - std::stringstream interpreter; -# endif + typedef typename detail::array_to_pointer_decay::type NewSource; + + detail::lexical_stream interpreter; Target result; - if(!(interpreter << arg) || !(interpreter >> result) || - !(interpreter >> std::ws).eof()) - throw bad_lexical_cast(); + if(!(interpreter << arg && interpreter >> result)) + throw_exception(bad_lexical_cast(typeid(NewSource), typeid(Target))); + return result; + } + + #else + + // call-by-value fallback version (deprecated) + + template + Target lexical_cast(Source arg) + { + detail::lexical_stream interpreter; + Target result; + if(!(interpreter << arg && interpreter >> result)) + throw_exception(bad_lexical_cast(typeid(Source), typeid(Target))); return result; } + + #endif } -// Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved. -// -// Permission to use, copy, modify, and distribute this software for any -// purpose is hereby granted without fee, provided that this copyright and -// permissions notice appear in all copies and derivatives. +// Copyright Kevlin Henney, 2000-2005. All rights reserved. // -// This software is provided "as is" without express or implied warranty. - -#ifdef BOOST_LEXICAL_CAST_USE_STRSTREAM -# undef BOOST_LEXICAL_CAST_USE_STRSTREAM -#endif +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +#undef DISABLE_WIDE_CHAR_SUPPORT #endif