epoc32/include/stdapis/boost/lexical_cast.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/lexical_cast.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,252 @@
     1.4 +#ifndef BOOST_LEXICAL_CAST_INCLUDED
     1.5 +#define BOOST_LEXICAL_CAST_INCLUDED
     1.6 +
     1.7 +// Boost lexical_cast.hpp header  -------------------------------------------//
     1.8 +//
     1.9 +// See http://www.boost.org for most recent version including documentation.
    1.10 +// See end of this header for rights and permissions.
    1.11 +//
    1.12 +// what:  lexical_cast custom keyword cast
    1.13 +// who:   contributed by Kevlin Henney,
    1.14 +//        enhanced with contributions from Terje Slettebų,
    1.15 +//        with additional fixes and suggestions from Gennaro Prota,
    1.16 +//        Beman Dawes, Dave Abrahams, Daryle Walker, Peter Dimov,
    1.17 +//        and other Boosters
    1.18 +// when:  November 2000, March 2003, June 2005
    1.19 +
    1.20 +#include <cstddef>
    1.21 +#include <string>
    1.22 +#include <typeinfo>
    1.23 +#include <boost/config.hpp>
    1.24 +#include <boost/limits.hpp>
    1.25 +#include <boost/throw_exception.hpp>
    1.26 +#include <boost/type_traits/is_pointer.hpp>
    1.27 +
    1.28 +#ifdef BOOST_NO_STRINGSTREAM
    1.29 +#include <strstream>
    1.30 +#else
    1.31 +#include <sstream>
    1.32 +#endif
    1.33 +
    1.34 +#if defined(BOOST_NO_STRINGSTREAM) || \
    1.35 +    defined(BOOST_NO_STD_WSTRING) || \
    1.36 +    defined(BOOST_NO_STD_LOCALE) 
    1.37 +#define DISABLE_WIDE_CHAR_SUPPORT
    1.38 +#endif
    1.39 +
    1.40 +namespace boost
    1.41 +{
    1.42 +    // exception used to indicate runtime lexical_cast failure
    1.43 +    class bad_lexical_cast : public std::bad_cast
    1.44 +    {
    1.45 +    public:
    1.46 +        bad_lexical_cast() :
    1.47 +        source(&typeid(void)), target(&typeid(void))
    1.48 +        {
    1.49 +        }
    1.50 +        bad_lexical_cast(
    1.51 +            const std::type_info &source_type,
    1.52 +            const std::type_info &target_type) :
    1.53 +            source(&source_type), target(&target_type)
    1.54 +        {
    1.55 +        }
    1.56 +        const std::type_info &source_type() const
    1.57 +        {
    1.58 +            return *source;
    1.59 +        }
    1.60 +        const std::type_info &target_type() const
    1.61 +        {
    1.62 +            return *target;
    1.63 +        }
    1.64 +        virtual const char *what() const throw()
    1.65 +        {
    1.66 +            return "bad lexical cast: "
    1.67 +                   "source type value could not be interpreted as target";
    1.68 +        }
    1.69 +        virtual ~bad_lexical_cast() throw()
    1.70 +        {
    1.71 +        }
    1.72 +    private:
    1.73 +        const std::type_info *source;
    1.74 +        const std::type_info *target;
    1.75 +    };
    1.76 +
    1.77 +    namespace detail // selectors for choosing stream character type
    1.78 +    {
    1.79 +        template<typename Type>
    1.80 +        struct stream_char
    1.81 +        {
    1.82 +            typedef char type;
    1.83 +        };
    1.84 +
    1.85 +        #ifndef DISABLE_WIDE_CHAR_SUPPORT
    1.86 +#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
    1.87 +        template<>
    1.88 +        struct stream_char<wchar_t>
    1.89 +        {
    1.90 +            typedef wchar_t type;
    1.91 +        };
    1.92 +#endif
    1.93 +
    1.94 +        template<>
    1.95 +        struct stream_char<wchar_t *>
    1.96 +        {
    1.97 +            typedef wchar_t type;
    1.98 +        };
    1.99 +
   1.100 +        template<>
   1.101 +        struct stream_char<const wchar_t *>
   1.102 +        {
   1.103 +            typedef wchar_t type;
   1.104 +        };
   1.105 +
   1.106 +        template<>
   1.107 +        struct stream_char<std::wstring>
   1.108 +        {
   1.109 +            typedef wchar_t type;
   1.110 +        };
   1.111 +        #endif
   1.112 +
   1.113 +        template<typename TargetChar, typename SourceChar>
   1.114 +        struct widest_char
   1.115 +        {
   1.116 +            typedef TargetChar type;
   1.117 +        };
   1.118 +
   1.119 +        template<>
   1.120 +        struct widest_char<char, wchar_t>
   1.121 +        {
   1.122 +            typedef wchar_t type;
   1.123 +        };
   1.124 +    }
   1.125 +    
   1.126 +    namespace detail // stream wrapper for handling lexical conversions
   1.127 +    {
   1.128 +        template<typename Target, typename Source>
   1.129 +        class lexical_stream
   1.130 +        {
   1.131 +        private:
   1.132 +            typedef typename widest_char<
   1.133 +                typename stream_char<Target>::type,
   1.134 +                typename stream_char<Source>::type>::type char_type;
   1.135 +
   1.136 +        public:
   1.137 +            lexical_stream()
   1.138 +            {
   1.139 +                stream.unsetf(std::ios::skipws);
   1.140 +
   1.141 +                if(std::numeric_limits<Target>::is_specialized)
   1.142 +                    stream.precision(std::numeric_limits<Target>::digits10 + 1);
   1.143 +                else if(std::numeric_limits<Source>::is_specialized)
   1.144 +                    stream.precision(std::numeric_limits<Source>::digits10 + 1);
   1.145 +            }
   1.146 +            ~lexical_stream()
   1.147 +            {
   1.148 +                #if defined(BOOST_NO_STRINGSTREAM)
   1.149 +                stream.freeze(false);
   1.150 +                #endif
   1.151 +            }
   1.152 +            bool operator<<(const Source &input)
   1.153 +            {
   1.154 +                return !(stream << input).fail();
   1.155 +            }
   1.156 +            template<typename InputStreamable>
   1.157 +            bool operator>>(InputStreamable &output)
   1.158 +            {
   1.159 +                return !is_pointer<InputStreamable>::value &&
   1.160 +                       stream >> output &&
   1.161 +                       stream.get() ==
   1.162 +#if defined(__GNUC__) && (__GNUC__<3) && defined(BOOST_NO_STD_WSTRING)
   1.163 +// GCC 2.9x lacks std::char_traits<>::eof().
   1.164 +// We use BOOST_NO_STD_WSTRING to filter out STLport and libstdc++-v3
   1.165 +// configurations, which do provide std::char_traits<>::eof().
   1.166 +    
   1.167 +                           EOF;
   1.168 +#else
   1.169 +                           std::char_traits<char_type>::eof();
   1.170 +#endif
   1.171 +            }
   1.172 +            bool operator>>(std::string &output)
   1.173 +            {
   1.174 +                #if defined(BOOST_NO_STRINGSTREAM)
   1.175 +                stream << '\0';
   1.176 +                #endif
   1.177 +                output = stream.str();
   1.178 +                return true;
   1.179 +            }
   1.180 +            #ifndef DISABLE_WIDE_CHAR_SUPPORT
   1.181 +            bool operator>>(std::wstring &output)
   1.182 +            {
   1.183 +                output = stream.str();
   1.184 +                return true;
   1.185 +            }
   1.186 +            #endif
   1.187 +        private:
   1.188 +            #if defined(BOOST_NO_STRINGSTREAM)
   1.189 +            std::strstream stream;
   1.190 +            #elif defined(BOOST_NO_STD_LOCALE)
   1.191 +            std::stringstream stream;
   1.192 +            #else
   1.193 +            std::basic_stringstream<char_type> stream;
   1.194 +            #endif
   1.195 +        };
   1.196 +    }
   1.197 +
   1.198 +    #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
   1.199 +
   1.200 +    // call-by-const reference version
   1.201 +
   1.202 +    namespace detail
   1.203 +    {
   1.204 +        template<class T>
   1.205 +        struct array_to_pointer_decay
   1.206 +        {
   1.207 +            typedef T type;
   1.208 +        };
   1.209 +
   1.210 +        template<class T, std::size_t N>
   1.211 +        struct array_to_pointer_decay<T[N]>
   1.212 +        {
   1.213 +            typedef const T * type;
   1.214 +        };
   1.215 +    }
   1.216 +
   1.217 +    template<typename Target, typename Source>
   1.218 +    Target lexical_cast(const Source &arg)
   1.219 +    {
   1.220 +        typedef typename detail::array_to_pointer_decay<Source>::type NewSource;
   1.221 +
   1.222 +        detail::lexical_stream<Target, NewSource> interpreter;
   1.223 +        Target result;
   1.224 +
   1.225 +        if(!(interpreter << arg && interpreter >> result))
   1.226 +            throw_exception(bad_lexical_cast(typeid(NewSource), typeid(Target)));
   1.227 +        return result;
   1.228 +    }
   1.229 +
   1.230 +    #else
   1.231 +
   1.232 +    // call-by-value fallback version (deprecated)
   1.233 +
   1.234 +    template<typename Target, typename Source>
   1.235 +    Target lexical_cast(Source arg)
   1.236 +    {
   1.237 +        detail::lexical_stream<Target, Source> interpreter;
   1.238 +        Target result;
   1.239 +
   1.240 +        if(!(interpreter << arg && interpreter >> result))
   1.241 +            throw_exception(bad_lexical_cast(typeid(Source), typeid(Target)));
   1.242 +        return result;
   1.243 +    }
   1.244 +
   1.245 +    #endif
   1.246 +}
   1.247 +
   1.248 +// Copyright Kevlin Henney, 2000-2005. All rights reserved.
   1.249 +//
   1.250 +// Distributed under the Boost Software License, Version 1.0. (See
   1.251 +// accompanying file LICENSE_1_0.txt or copy at
   1.252 +// http://www.boost.org/LICENSE_1_0.txt)
   1.253 +
   1.254 +#undef DISABLE_WIDE_CHAR_SUPPORT
   1.255 +#endif