base_static.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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, 2019.
  4. // Modifications copyright (c) 2017-2019, 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/assert.hpp>
  17. #include <boost/geometry/core/tags.hpp>
  18. #include <boost/geometry/srs/projections/impl/pj_fwd.hpp>
  19. #include <boost/geometry/srs/projections/impl/pj_inv.hpp>
  20. #include <boost/mpl/assert.hpp>
  21. namespace boost { namespace geometry { namespace projections
  22. {
  23. #ifndef DOXYGEN_NO_DETAIL
  24. namespace detail
  25. {
  26. template <typename Prj, typename CSTag, typename SP, typename CT, typename P>
  27. struct static_projection_type
  28. {
  29. BOOST_MPL_ASSERT_MSG((false),
  30. NOT_IMPLEMENTED_FOR_THIS_PROJECTION_OR_CSTAG,
  31. (Prj, CSTag));
  32. };
  33. #define BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(PROJ, P_SPHXXX) \
  34. template <typename SP, typename CT, typename P> \
  35. struct static_projection_type<PROJ, srs_sphere_tag, SP, CT, P> \
  36. { \
  37. typedef projections::detail::static_wrapper_f<P_SPHXXX<CT, P>, P> type; \
  38. }; \
  39. template <typename SP, typename CT, typename P> \
  40. struct static_projection_type<PROJ, srs_spheroid_tag, SP, CT, P> \
  41. { \
  42. typedef projections::detail::static_wrapper_f<P_SPHXXX<CT, P>, P> type; \
  43. }; \
  44. #define BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(PROJ, P_SPHXXX) \
  45. template <typename SP, typename CT, typename P> \
  46. struct static_projection_type<PROJ, srs_sphere_tag, SP, CT, P> \
  47. { \
  48. typedef projections::detail::static_wrapper_fi<P_SPHXXX<CT, P>, P> type; \
  49. }; \
  50. template <typename SP, typename CT, typename P> \
  51. struct static_projection_type<PROJ, srs_spheroid_tag, SP, CT, P> \
  52. { \
  53. typedef projections::detail::static_wrapper_fi<P_SPHXXX<CT, P>, P> type; \
  54. }; \
  55. #define BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI2(PROJ, P_SPHERE, P_SPHEROID) \
  56. template <typename SP, typename CT, typename P> \
  57. struct static_projection_type<PROJ, srs_sphere_tag, SP, CT, P> \
  58. { \
  59. typedef projections::detail::static_wrapper_fi<P_SPHERE<CT, P>, P> type; \
  60. }; \
  61. template <typename SP, typename CT, typename P> \
  62. struct static_projection_type<PROJ, srs_spheroid_tag, SP, CT, P> \
  63. { \
  64. typedef projections::detail::static_wrapper_fi<P_SPHEROID<CT, P>, P> type; \
  65. }; \
  66. template <typename P>
  67. struct static_wrapper_b
  68. {
  69. inline explicit static_wrapper_b(P const& par)
  70. : m_par(par)
  71. {}
  72. std::string name() const { return m_par.id.name; }
  73. P const& params() const { return m_par; }
  74. P& mutable_params() { return m_par; }
  75. protected:
  76. P m_par;
  77. };
  78. // Forward
  79. template <typename Prj, typename P>
  80. struct static_wrapper_f
  81. : public static_wrapper_b<P>
  82. , public Prj
  83. {
  84. public:
  85. template <typename Params>
  86. inline static_wrapper_f(Params const& params, P const& par)
  87. : static_wrapper_b<P>(par)
  88. , Prj(params, this->m_par) // prj can modify parameters
  89. {}
  90. template <typename LL, typename XY>
  91. inline bool forward(LL const& lp, XY& xy) const
  92. {
  93. try
  94. {
  95. pj_fwd(*this, this->m_par, lp, xy);
  96. return true;
  97. }
  98. catch (...)
  99. {
  100. return false;
  101. }
  102. }
  103. template <typename XY, typename LL>
  104. inline bool inverse(XY const&, LL&) const
  105. {
  106. BOOST_MPL_ASSERT_MSG((false),
  107. PROJECTION_IS_NOT_INVERTABLE,
  108. (Prj));
  109. return false;
  110. }
  111. };
  112. // Forward/inverse
  113. template <typename Prj, typename P>
  114. struct static_wrapper_fi
  115. : public static_wrapper_f<Prj, P>
  116. {
  117. public:
  118. template <typename Params>
  119. inline static_wrapper_fi(Params const& params, P const& par)
  120. : static_wrapper_f<Prj, P>(params, par)
  121. {}
  122. template <typename XY, typename LL>
  123. inline bool inverse(XY const& xy, LL& lp) const
  124. {
  125. try
  126. {
  127. pj_inv(*this, this->m_par, xy, lp);
  128. return true;
  129. }
  130. catch (...)
  131. {
  132. return false;
  133. }
  134. }
  135. };
  136. } // namespace detail
  137. #endif // DOXYGEN_NO_DETAIL
  138. }}} // namespace boost::geometry::projections
  139. #endif // BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_STATIC_HPP