Boost-Geometry-Utils

 view release on metacpan or  search on metacpan

src/boost/lexical_cast.hpp  view on Meta::CPAN


                if ( exp_pow_of_10 ) {
                    /* Overflows are checked lower */
                    if ( exp_has_minus ) {
                        pow_of_10 -= exp_pow_of_10;
                    } else {
                        pow_of_10 += exp_pow_of_10;
                    }
                }
            }

            /* We need a more accurate algorithm... We can not use current algorithm
             * with long doubles (and with doubles if sizeof(double)==sizeof(long double)).
             */
            long double result = std::pow(10.0L, pow_of_10) * mantissa;
            value = static_cast<T>( has_minus ? (boost::math::changesign)(result) : result);

            if ( (boost::math::isinf)(value) || (boost::math::isnan)(value) ) return false;

            return true;
        }
    }

    namespace detail // stl_buf_unlocker
    {
        template< class BufferType, class CharT >
        class stl_buf_unlocker: public BufferType{
        public:
            typedef BufferType base_class;
#ifndef BOOST_NO_USING_TEMPLATE
            using base_class::pptr;
            using base_class::pbase;
            using base_class::setg;
            using base_class::setp;
#else
            CharT* pptr() const { return base_class::pptr(); }
            CharT* pbase() const { return base_class::pbase(); }
            void setg(CharT* gbeg, CharT* gnext, CharT* gend){ return base_class::setg(gbeg, gnext, gend); }
            void setp(CharT* pbeg, CharT* pend) { return setp(pbeg, pend); }
#endif
        };
    }

    namespace detail
    {
        struct do_not_construct_out_stream_t{};
    }

    namespace detail // optimized stream wrapper
    {
        // String representation of Source has an upper limit.
        template< class CharT // a result of widest_char transformation
                , class Traits // usually char_traits<CharT>
                , bool RequiresStringbuffer
                >
        class lexical_stream_limited_src
        {

#if defined(BOOST_NO_STRINGSTREAM)
            typedef std::ostrstream                         out_stream_t;
            typedef stl_buf_unlocker<std::strstreambuf, char>  unlocked_but_t;
#elif defined(BOOST_NO_STD_LOCALE)
            typedef std::ostringstream                      out_stream_t;
            typedef stl_buf_unlocker<std::stringbuf, char>  unlocked_but_t;
#else
            typedef std::basic_ostringstream<CharT, Traits>       out_stream_t;
            typedef stl_buf_unlocker<std::basic_stringbuf<CharT, Traits>, CharT> unlocked_but_t;
#endif
            typedef BOOST_DEDUCED_TYPENAME boost::mpl::if_c<
                RequiresStringbuffer,
                out_stream_t,
                do_not_construct_out_stream_t
            >::type deduced_out_stream_t;

            // A string representation of Source is written to [start, finish).
            CharT* start;
            CharT* finish;
            deduced_out_stream_t out_stream;

        public:
            lexical_stream_limited_src(CharT* sta, CharT* fin)
              : start(sta)
              , finish(fin)
            {}

        private:
            // Undefined:
            lexical_stream_limited_src(lexical_stream_limited_src const&);
            void operator=(lexical_stream_limited_src const&);

/************************************ HELPER FUNCTIONS FOR OPERATORS << ( ... ) ********************************/
            bool shl_char(CharT ch) BOOST_NOEXCEPT
            {
                Traits::assign(*start, ch);
                finish = start + 1;
                return true;
            }

#ifndef BOOST_LCAST_NO_WCHAR_T
            template <class T>
            bool shl_char(T ch)
            {
                BOOST_STATIC_ASSERT_MSG(( sizeof(T) <= sizeof(CharT)) ,
                    "boost::lexical_cast does not support narrowing of char types."
                    "Use boost::locale instead" );
#ifndef BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
                std::locale loc;
                CharT const w = BOOST_USE_FACET(std::ctype<CharT>, loc).widen(ch);
#else
                CharT const w = static_cast<CharT>(ch);
#endif
                Traits::assign(*start, w);
                finish = start + 1;
                return true;
            }
#endif

            bool shl_char_array(CharT const* str) BOOST_NOEXCEPT
            {
                start = const_cast<CharT*>(str);
                finish = start + Traits::length(str);
                return true;
            }

            template <class T>
            bool shl_char_array(T const* str)
            {
                BOOST_STATIC_ASSERT_MSG(( sizeof(T) <= sizeof(CharT)),
                    "boost::lexical_cast does not support narrowing of char types."
                    "Use boost::locale instead" );
                return shl_input_streamable(str);
            }
            
            bool shl_char_array_limited(CharT const* str, std::size_t max_size) BOOST_NOEXCEPT
            {
                start = const_cast<CharT*>(str);
                finish = std::find(start, start + max_size, Traits::to_char_type(0));
                return true;
            }

            template<typename InputStreamable>
            bool shl_input_streamable(InputStreamable& input)
            {
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
                // If you have compilation error at this point, than your STL library
                // does not support such conversions. Try updating it.
                BOOST_STATIC_ASSERT((boost::is_same<char, CharT>::value));
#endif
                bool const result = !(out_stream << input).fail();
                const unlocked_but_t* const p
                        = static_cast<unlocked_but_t*>(out_stream.rdbuf()) ;
                start = p->pbase();
                finish = p->pptr();
                return result;
            }

            template <class T>
            inline bool shl_signed(T n)
            {
                start = lcast_put_unsigned<Traits>(lcast_to_unsigned(n), finish);
                if(n < 0)
                {
                    --start;
                    CharT const minus = lcast_char_constants<CharT>::minus;
                    Traits::assign(*start, minus);
                }
                return true;
            }

            template <class T, class SomeCharT>
            bool shl_real_type(const T& val, SomeCharT* begin, SomeCharT*& end)
            {
                if (put_inf_nan(begin, end, val)) return true;
                lcast_set_precision(out_stream, &val);
                return shl_input_streamable(val);
            }

            static bool shl_real_type(float val, char* begin, char*& end)
            {   using namespace std;
                if (put_inf_nan(begin, end, val)) return true;
                const double val_as_double = val;
                end = begin + 
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
                    sprintf_s(begin, end-begin,
#else
                    sprintf(begin, 
#endif
                    "%.*g", static_cast<int>(boost::detail::lcast_get_precision<float>()), val_as_double);
                return end > begin;
            }

            static bool shl_real_type(double val, char* begin, char*& end)
            {   using namespace std;
                if (put_inf_nan(begin, end, val)) return true;
                end = begin + 
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
                    sprintf_s(begin, end-begin,
#else
                    sprintf(begin, 
#endif
                    "%.*g", static_cast<int>(boost::detail::lcast_get_precision<double>()), val);
                return end > begin;
            }

#ifndef __MINGW32__
            static bool shl_real_type(long double val, char* begin, char*& end)
            {   using namespace std;
                if (put_inf_nan(begin, end, val)) return true;
                end = begin + 
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__SGI_STL_PORT) && !defined(_STLPORT_VERSION)
                    sprintf_s(begin, end-begin,

src/boost/lexical_cast.hpp  view on Meta::CPAN

                return succeed;
            }

            template <typename Type>
            bool shr_signed(Type& output)
            {
                if (start == finish) return false;
                CharT const minus = lcast_char_constants<CharT>::minus;
                CharT const plus = lcast_char_constants<CharT>::plus;
                typedef BOOST_DEDUCED_TYPENAME make_unsigned<Type>::type utype;
                utype out_tmp =0;
                bool has_minus = false;

                /* We won`t use `start' any more, so no need in decrementing it after */
                if ( Traits::eq(minus,*start) )
                {
                    ++start;
                    has_minus = true;
                } else if ( Traits::eq(plus, *start) )
                {
                    ++start;
                }

                bool succeed = lcast_ret_unsigned<Traits>(out_tmp, start, finish);
                if (has_minus) {
                    utype const comp_val = (static_cast<utype>(1) << std::numeric_limits<Type>::digits);
                    succeed = succeed && out_tmp<=comp_val;
                    output = static_cast<Type>(0u - out_tmp);
                } else {
                    utype const comp_val = static_cast<utype>((std::numeric_limits<Type>::max)());
                    succeed = succeed && out_tmp<=comp_val;
                    output = out_tmp;
                }
                return succeed;
            }

            template<typename InputStreamable>
            bool shr_using_base_class(InputStreamable& output)
            {
#if (defined _MSC_VER)
# pragma warning( push )
  // conditional expression is constant
# pragma warning( disable : 4127 )
#endif
                if(is_pointer<InputStreamable>::value)
                    return false;

#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
                // If you have compilation error at this point, than your STL library
                // unsupports such conversions. Try updating it.
                BOOST_STATIC_ASSERT((boost::is_same<char, CharT>::value));
#endif

#if defined(BOOST_NO_STRINGSTREAM)
                std::istrstream stream(start, finish - start);
#elif defined(BOOST_NO_STD_LOCALE)
                std::istringstream stream;
#else
                std::basic_istringstream<CharT, Traits> stream;
#endif
                static_cast<unlocked_but_t*>(stream.rdbuf())
                        ->setg(start, start, finish);

                stream.unsetf(std::ios::skipws);
                lcast_set_precision(stream, static_cast<InputStreamable*>(0));
#if (defined _MSC_VER)
# pragma warning( pop )
#endif
                return 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
                Traits::eof();
#endif
            }

            template<class T>
            inline bool shr_xchar(T& output)
            {
                BOOST_STATIC_ASSERT_MSG(( sizeof(CharT) == sizeof(T) ),
                    "boost::lexical_cast does not support narrowing of character types."
                    "Use boost::locale instead" );
                bool const ok = (finish - start == 1);
                if (ok) {
                    CharT out;
                    Traits::assign(out, *start);
                    output = static_cast<T>(out);
                }
                return ok;
            }

/************************************ OPERATORS >> ( ... ) ********************************/
            public:
            bool operator>>(unsigned short& output)             { return shr_unsigned(output); }
            bool operator>>(unsigned int& output)               { return shr_unsigned(output); }
            bool operator>>(unsigned long int& output)          { return shr_unsigned(output); }
            bool operator>>(short& output)                      { return shr_signed(output); }
            bool operator>>(int& output)                        { return shr_signed(output); }
            bool operator>>(long int& output)                   { return shr_signed(output); }
#if defined(BOOST_HAS_LONG_LONG)
            bool operator>>(boost::ulong_long_type& output)     { return shr_unsigned(output); }
            bool operator>>(boost::long_long_type& output)      { return shr_signed(output); }
#elif defined(BOOST_HAS_MS_INT64)
            bool operator>>(unsigned __int64& output)           { return shr_unsigned(output); }
            bool operator>>(__int64& output)                    { return shr_signed(output); }
#endif
            bool operator>>(char& output)                       { return shr_xchar(output); }
            bool operator>>(unsigned char& output)              { return shr_xchar(output); }
            bool operator>>(signed char& output)                { return shr_xchar(output); }
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
            bool operator>>(wchar_t& output)                    { return shr_xchar(output); }
#endif
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
            bool operator>>(char16_t& output)                   { return shr_xchar(output); }
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)



( run in 4.120 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )