base_static.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2017, 2018.
  4. // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_STATIC_HPP
  10. #define BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_STATIC_HPP
  11. #if defined(_MSC_VER)
  12. // For CRTP, *this is acceptable in constructor -> turn warning off
  13. #pragma warning( disable : 4355 )
  14. #endif // defined(_MSC_VER)
  15. #include <string>
  16. #include <boost/geometry/core/tags.hpp>
  17. #include <boost/geometry/srs/projections/impl/pj_fwd.hpp>
  18. #include <boost/geometry/srs/projections/impl/pj_inv.hpp>
  19. #include <boost/mpl/assert.hpp>
  20. namespace boost { namespace geometry { namespace projections
  21. {
  22. #ifndef DOXYGEN_NO_DETAIL
  23. namespace detail
  24. {
  25. template <typename Prj, typename CSTag, typename SP, typename CT, typename P>
  26. struct static_projection_type
  27. {
  28. BOOST_MPL_ASSERT_MSG((false),
  29. NOT_IMPLEMENTED_FOR_THIS_PROJECTION_OR_CSTAG,
  30. (Prj, CSTag));
  31. };
  32. #define BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION(PROJ, P_SPHERE, P_SPHEROID) \
  33. template <typename SP, typename CT, typename P> \
  34. struct static_projection_type<PROJ, srs_sphere_tag, SP, CT, P> \
  35. { \
  36. typedef P_SPHERE<CT, P> type; \
  37. }; \
  38. template <typename SP, typename CT, typename P> \
  39. struct static_projection_type<PROJ, srs_spheroid_tag, SP, CT, P> \
  40. { \
  41. typedef P_SPHEROID<CT, P> type; \
  42. }; \
  43. // Base-template-forward
  44. template <typename Prj, typename CT, typename P>
  45. struct base_t_f
  46. {
  47. public:
  48. inline base_t_f(Prj const& prj, P const& params)
  49. : m_par(params), m_prj(prj)
  50. {}
  51. inline P const& params() const { return m_par; }
  52. inline P& mutable_params() { return m_par; }
  53. template <typename LL, typename XY>
  54. inline bool forward(LL const& lp, XY& xy) const
  55. {
  56. try
  57. {
  58. pj_fwd(m_prj, m_par, lp, xy);
  59. return true;
  60. }
  61. catch(...)
  62. {
  63. return false;
  64. }
  65. }
  66. template <typename XY, typename LL>
  67. inline bool inverse(XY const& , LL& ) const
  68. {
  69. BOOST_MPL_ASSERT_MSG((false),
  70. PROJECTION_IS_NOT_INVERTABLE,
  71. (Prj));
  72. return false;
  73. }
  74. inline std::string name() const
  75. {
  76. return this->m_par.id.name;
  77. }
  78. protected:
  79. P m_par;
  80. const Prj& m_prj;
  81. };
  82. // Base-template-forward/inverse
  83. template <typename Prj, typename CT, typename P>
  84. struct base_t_fi : public base_t_f<Prj, CT, P>
  85. {
  86. public :
  87. inline base_t_fi(Prj const& prj, P const& params)
  88. : base_t_f<Prj, CT, P>(prj, params)
  89. {}
  90. template <typename XY, typename LL>
  91. inline bool inverse(XY const& xy, LL& lp) const
  92. {
  93. try
  94. {
  95. pj_inv(this->m_prj, this->m_par, xy, lp);
  96. return true;
  97. }
  98. catch(...)
  99. {
  100. return false;
  101. }
  102. }
  103. };
  104. } // namespace detail
  105. #endif // DOXYGEN_NO_DETAIL
  106. }}} // namespace boost::geometry::projections
  107. #endif // BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_STATIC_HPP