• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 
5 // This file was modified by Oracle on 2017, 2018, 2019.
6 // Modifications copyright (c) 2017-2019, Oracle and/or its affiliates.
7 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8 
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12 
13 #ifndef BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_STATIC_HPP
14 #define BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_STATIC_HPP
15 
16 #if defined(_MSC_VER)
17 // For CRTP, *this is acceptable in constructor -> turn warning off
18 #pragma warning( disable : 4355 )
19 #endif // defined(_MSC_VER)
20 
21 
22 #include <string>
23 
24 #include <boost/geometry/core/assert.hpp>
25 #include <boost/geometry/core/tags.hpp>
26 
27 #include <boost/geometry/srs/projections/impl/pj_fwd.hpp>
28 #include <boost/geometry/srs/projections/impl/pj_inv.hpp>
29 
30 #include <boost/mpl/assert.hpp>
31 
32 
33 namespace boost { namespace geometry { namespace projections
34 {
35 
36 
37 #ifndef DOXYGEN_NO_DETAIL
38 namespace detail
39 {
40 
41 template <typename Prj, typename CSTag, typename SP, typename CT, typename P>
42 struct static_projection_type
43 {
44     BOOST_MPL_ASSERT_MSG((false),
45         NOT_IMPLEMENTED_FOR_THIS_PROJECTION_OR_CSTAG,
46         (Prj, CSTag));
47 };
48 
49 #define BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_F(PROJ, P_SPHXXX) \
50 template <typename SP, typename CT, typename P> \
51 struct static_projection_type<PROJ, srs_sphere_tag, SP, CT, P> \
52 { \
53     typedef projections::detail::static_wrapper_f<P_SPHXXX<CT, P>, P> type; \
54 }; \
55 template <typename SP, typename CT, typename P> \
56 struct static_projection_type<PROJ, srs_spheroid_tag, SP, CT, P> \
57 { \
58     typedef projections::detail::static_wrapper_f<P_SPHXXX<CT, P>, P> type; \
59 }; \
60 
61 #define BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI(PROJ, P_SPHXXX) \
62 template <typename SP, typename CT, typename P> \
63 struct static_projection_type<PROJ, srs_sphere_tag, SP, CT, P> \
64 { \
65     typedef projections::detail::static_wrapper_fi<P_SPHXXX<CT, P>, P> type; \
66 }; \
67 template <typename SP, typename CT, typename P> \
68 struct static_projection_type<PROJ, srs_spheroid_tag, SP, CT, P> \
69 { \
70     typedef projections::detail::static_wrapper_fi<P_SPHXXX<CT, P>, P> type; \
71 }; \
72 
73 #define BOOST_GEOMETRY_PROJECTIONS_DETAIL_STATIC_PROJECTION_FI2(PROJ, P_SPHERE, P_SPHEROID) \
74 template <typename SP, typename CT, typename P> \
75 struct static_projection_type<PROJ, srs_sphere_tag, SP, CT, P> \
76 { \
77     typedef projections::detail::static_wrapper_fi<P_SPHERE<CT, P>, P> type; \
78 }; \
79 template <typename SP, typename CT, typename P> \
80 struct static_projection_type<PROJ, srs_spheroid_tag, SP, CT, P> \
81 { \
82     typedef projections::detail::static_wrapper_fi<P_SPHEROID<CT, P>, P> type; \
83 }; \
84 
85 template <typename P>
86 struct static_wrapper_b
87 {
static_wrapper_bboost::geometry::projections::detail::static_wrapper_b88     inline explicit static_wrapper_b(P const& par)
89         : m_par(par)
90     {}
91 
nameboost::geometry::projections::detail::static_wrapper_b92     std::string name() const { return m_par.id.name; }
93 
paramsboost::geometry::projections::detail::static_wrapper_b94     P const& params() const { return m_par; }
95 
mutable_paramsboost::geometry::projections::detail::static_wrapper_b96     P& mutable_params() { return m_par; }
97 
98 protected:
99     P m_par;
100 };
101 
102 // Forward
103 template <typename Prj, typename P>
104 struct static_wrapper_f
105     : public static_wrapper_b<P>
106     , public Prj
107 {
108 public:
109     template <typename Params>
static_wrapper_fboost::geometry::projections::detail::static_wrapper_f110     inline static_wrapper_f(Params const& params, P const& par)
111         : static_wrapper_b<P>(par)
112         , Prj(params, this->m_par) // prj can modify parameters
113     {}
114 
115     template <typename LL, typename XY>
forwardboost::geometry::projections::detail::static_wrapper_f116     inline bool forward(LL const& lp, XY& xy) const
117     {
118         try
119         {
120             pj_fwd(*this, this->m_par, lp, xy);
121             return true;
122         }
123         catch (...)
124         {
125             return false;
126         }
127     }
128 
129     template <typename XY, typename LL>
inverseboost::geometry::projections::detail::static_wrapper_f130     inline bool inverse(XY const&, LL&) const
131     {
132         BOOST_MPL_ASSERT_MSG((false),
133             PROJECTION_IS_NOT_INVERTABLE,
134             (Prj));
135         return false;
136     }
137 };
138 
139 // Forward/inverse
140 template <typename Prj, typename P>
141 struct static_wrapper_fi
142     : public static_wrapper_f<Prj, P>
143 {
144 public:
145     template <typename Params>
static_wrapper_fiboost::geometry::projections::detail::static_wrapper_fi146     inline static_wrapper_fi(Params const& params, P const& par)
147         : static_wrapper_f<Prj, P>(params, par)
148     {}
149 
150     template <typename XY, typename LL>
inverseboost::geometry::projections::detail::static_wrapper_fi151     inline bool inverse(XY const& xy, LL& lp) const
152     {
153         try
154         {
155             pj_inv(*this, this->m_par, xy, lp);
156             return true;
157         }
158         catch (...)
159         {
160             return false;
161         }
162     }
163 };
164 
165 } // namespace detail
166 #endif // DOXYGEN_NO_DETAIL
167 
168 
169 }}} // namespace boost::geometry::projections
170 
171 
172 #endif // BOOST_GEOMETRY_PROJECTIONS_IMPL_BASE_STATIC_HPP
173