coordinate_cast.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. See also "define_pi" where the same issue is solved
  24. */
  25. template <typename CoordinateType>
  26. struct coordinate_cast
  27. {
  28. static inline CoordinateType apply(std::string const& source)
  29. {
  30. #if defined(BOOST_GEOMETRY_NO_LEXICAL_CAST)
  31. return atof(source.c_str());
  32. #else
  33. return boost::lexical_cast<CoordinateType>(source);
  34. #endif
  35. }
  36. };
  37. } // namespace detail
  38. #endif
  39. }} // namespace boost::geometry
  40. #endif // BOOST_GEOMETRY_UTIL_COORDINATE_CAST_HPP