mirror of
https://github.com/boostorg/conversion.git
synced 2025-08-03 14:34:33 +02:00
Merged from trunk
[SVN r18237]
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <boost/limits.hpp>
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/throw_exception.hpp>
|
||||||
#include <boost/type_traits/is_pointer.hpp>
|
#include <boost/type_traits/is_pointer.hpp>
|
||||||
|
|
||||||
#ifdef BOOST_NO_STRINGSTREAM
|
#ifdef BOOST_NO_STRINGSTREAM
|
||||||
@@ -29,51 +30,47 @@
|
|||||||
#if defined(BOOST_NO_STRINGSTREAM) || \
|
#if defined(BOOST_NO_STRINGSTREAM) || \
|
||||||
defined(BOOST_NO_STD_WSTRING) || \
|
defined(BOOST_NO_STD_WSTRING) || \
|
||||||
defined(BOOST_NO_STD_LOCALE) || \
|
defined(BOOST_NO_STD_LOCALE) || \
|
||||||
defined(BOOST_NO_CWCHAR) || \
|
defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
||||||
defined(BOOST_MSVC) && (BOOST_MSVC <= 1200)
|
|
||||||
#define DISABLE_WIDE_CHAR_SUPPORT
|
#define DISABLE_WIDE_CHAR_SUPPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BOOST_NO_INTRINSIC_WCHAR_T
|
|
||||||
#include <cwchar>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
// exception used to indicate runtime lexical_cast failure
|
// exception used to indicate runtime lexical_cast failure
|
||||||
class bad_lexical_cast : public std::bad_cast
|
class bad_lexical_cast : public std::bad_cast
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
bad_lexical_cast() :
|
||||||
|
source(&typeid(void)), target(&typeid(void))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
bad_lexical_cast(
|
||||||
|
const std::type_info &s,
|
||||||
|
const std::type_info &t) :
|
||||||
|
source(&s), target(&t)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
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()
|
virtual ~bad_lexical_cast() throw()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
const std::type_info *source;
|
||||||
|
const std::type_info *target;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail // actual underlying concrete exception type
|
|
||||||
{
|
|
||||||
template<typename Target, typename Source>
|
|
||||||
class no_lexical_conversion : public bad_lexical_cast
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
no_lexical_conversion()
|
|
||||||
: description(
|
|
||||||
std::string() + "bad lexical cast: " +
|
|
||||||
"source type value could not be interpreted as target, Target=" +
|
|
||||||
typeid(Target).name() + ", Source=" + typeid(Source).name())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
virtual ~no_lexical_conversion() throw()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
virtual const char *what() const throw()
|
|
||||||
{
|
|
||||||
return description.c_str();
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
const std::string description; // static initialization fails on MSVC6
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace detail // selectors for choosing stream character type
|
namespace detail // selectors for choosing stream character type
|
||||||
{
|
{
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
@@ -144,7 +141,7 @@ namespace boost
|
|||||||
}
|
}
|
||||||
bool operator<<(const Source &input)
|
bool operator<<(const Source &input)
|
||||||
{
|
{
|
||||||
return stream << input;
|
return !(stream << input).fail();
|
||||||
}
|
}
|
||||||
template<typename InputStreamable>
|
template<typename InputStreamable>
|
||||||
bool operator>>(InputStreamable &output)
|
bool operator>>(InputStreamable &output)
|
||||||
@@ -190,7 +187,7 @@ namespace boost
|
|||||||
Target result;
|
Target result;
|
||||||
|
|
||||||
if(!(interpreter << arg && interpreter >> result))
|
if(!(interpreter << arg && interpreter >> result))
|
||||||
throw detail::no_lexical_conversion<Target, Source>();
|
throw_exception(detail::no_lexical_conversion<Target, Source>());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,3 +202,4 @@ namespace boost
|
|||||||
|
|
||||||
#undef DISABLE_WIDE_CHAR_SUPPORT
|
#undef DISABLE_WIDE_CHAR_SUPPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user