1 // Boost.Geometry (aka GGL, Generic Geometry Library) 2 3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. 4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. 5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. 6 7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library 8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. 9 10 // Use, modification and distribution is subject to the Boost Software License, 11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 12 // http://www.boost.org/LICENSE_1_0.txt) 13 14 #ifndef BOOST_GEOMETRY_UTIL_COORDINATE_CAST_HPP 15 #define BOOST_GEOMETRY_UTIL_COORDINATE_CAST_HPP 16 17 #include <cstdlib> 18 #include <string> 19 #include <boost/lexical_cast.hpp> 20 21 namespace boost { namespace geometry 22 { 23 24 #ifndef DOXYGEN_NO_DETAIL 25 namespace detail 26 { 27 28 /*! 29 \brief cast coordinates from a string to a coordinate type 30 \detail By default it uses lexical_cast. However, lexical_cast seems not to support 31 ttmath / partial specializations. Therefore this small utility is added. 32 See also "define_pi" where the same issue is solved 33 */ 34 template <typename CoordinateType> 35 struct coordinate_cast 36 { applyboost::geometry::detail::coordinate_cast37 static inline CoordinateType apply(std::string const& source) 38 { 39 #if defined(BOOST_GEOMETRY_NO_LEXICAL_CAST) 40 return atof(source.c_str()); 41 #else 42 return boost::lexical_cast<CoordinateType>(source); 43 #endif 44 } 45 }; 46 47 48 } // namespace detail 49 #endif 50 51 52 53 }} // namespace boost::geometry 54 55 #endif // BOOST_GEOMETRY_UTIL_COORDINATE_CAST_HPP 56