coordinate_cast.hpp 1.5 KB

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