Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / geometry / srs / projections / impl / base_dynamic.hpp
index 5eeba47..05a103e 100644 (file)
@@ -2,8 +2,8 @@
 
 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
 
-// This file was modified by Oracle on 2017, 2018.
-// Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
+// This file was modified by Oracle on 2017, 2018, 2019.
+// Modifications copyright (c) 2017-2019, Oracle and/or its affiliates.
 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
 
 // Use, modification and distribution is subject to the Boost Software License,
@@ -33,16 +33,28 @@ namespace detail
     \tparam P parameters type
 */
 template <typename CT, typename P>
-class base_v
+class dynamic_wrapper_b
 {
 public :
+    dynamic_wrapper_b(P const& par)
+        : m_par(par)
+    {}
+
+    virtual ~dynamic_wrapper_b() {}
+
+    /// Forward projection using lon / lat and x / y separately
+    virtual void fwd(P const& par, CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const = 0;
+
+    /// Inverse projection using x / y and lon / lat
+    virtual void inv(P const& par, CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const = 0;
+
     /// Forward projection, from Latitude-Longitude to Cartesian
     template <typename LL, typename XY>
     inline bool forward(LL const& lp, XY& xy) const
     {
         try
         {
-            pj_fwd(*this, this->params(), lp, xy);
+            pj_fwd(*this, m_par, lp, xy);
             return true;
         }
         catch (...)
@@ -57,7 +69,7 @@ public :
     {
         try
         {
-            pj_inv(*this, this->params(), xy, lp);
+            pj_inv(*this, m_par, xy, lp);
             return true;
         }
         catch (projection_not_invertible_exception &)
@@ -70,87 +82,74 @@ public :
         }
     }
 
-    /// Forward projection using lon / lat and x / y separately
-    virtual void fwd(CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const = 0;
-
-    /// Inverse projection using x / y and lon / lat
-    virtual void inv(CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const = 0;
-
     /// Returns name of projection
-    virtual std::string name() const = 0;
+    std::string name() const { return m_par.id.name; }
 
     /// Returns parameters of projection
-    virtual P const& params() const = 0;
+    P const& params() const { return m_par; }
 
     /// Returns mutable parameters of projection
-    virtual P& mutable_params() = 0;
+    P& mutable_params() { return m_par; }
 
-    virtual ~base_v() {}
+protected:
+    P m_par;
 };
 
-// Base-virtual-forward
+// Forward
 template <typename Prj, typename CT, typename P>
-class base_v_f : public base_v<CT, P>
+class dynamic_wrapper_f
+    : public dynamic_wrapper_b<CT, P>
+    , protected Prj
 {
-public:
-    explicit base_v_f(P const& p)
-        : m_proj(p)
-    {}
+    typedef dynamic_wrapper_b<CT, P> base_t;
 
-    template <typename P1, typename P2>
-    base_v_f(P1 const& p1, P2 const& p2)
-        : m_proj(p1, p2)
+public:
+    template <typename Params>
+    dynamic_wrapper_f(Params const& params, P const& par)
+        : base_t(par)
+        , Prj(params, this->m_par) // prj can modify parameters
     {}
 
-    template <typename P1, typename P2, typename P3>
-    base_v_f(P1 const& p1, P2 const& p2, P3 const& p3)
-        : m_proj(p1, p2, p3)
+    template <typename Params, typename P3>
+    dynamic_wrapper_f(Params const& params, P const& par, P3 const& p3)
+        : base_t(par)
+        , Prj(params, this->m_par, p3) // prj can modify parameters
     {}
 
-    virtual void fwd(CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const
+    virtual void fwd(P const& par, CT const& lp_lon, CT const& lp_lat, CT& xy_x, CT& xy_y) const
     {
-        m_proj.fwd(lp_lon, lp_lat, xy_x, xy_y);
+        prj().fwd(par, lp_lon, lp_lat, xy_x, xy_y);
     }
 
-    virtual void inv(CT const& , CT const& , CT& , CT& ) const
+    virtual void inv(P const& , CT const& , CT const& , CT& , CT& ) const
     {
-        BOOST_THROW_EXCEPTION(projection_not_invertible_exception(params().id.name));
+        BOOST_THROW_EXCEPTION(projection_not_invertible_exception(this->name()));
     }
 
-    virtual std::string name() const { return m_proj.name(); }
-
-    virtual P const& params() const { return m_proj.params(); }
-
-    virtual P& mutable_params() { return m_proj.mutable_params(); }
-
 protected:
-    Prj m_proj;
+    Prj const& prj() const { return *this; }
 };
 
-// Base-virtual-forward/inverse
+// Forward/inverse
 template <typename Prj, typename CT, typename P>
-class base_v_fi : public base_v_f<Prj, CT, P>
+class dynamic_wrapper_fi : public dynamic_wrapper_f<Prj, CT, P>
 {
-    typedef base_v_f<Prj, CT, P> base_t;
+    typedef dynamic_wrapper_f<Prj, CT, P> base_t;
 
 public:
-    explicit base_v_fi(P const& p)
-        : base_t(p)
+    template <typename Params>
+    dynamic_wrapper_fi(Params const& params, P const& par)
+        : base_t(params, par)
     {}
 
-    template <typename P1, typename P2>
-    base_v_fi(P1 const& p1, P2 const& p2)
-        : base_t(p1, p2)
+    template <typename Params, typename P3>
+    dynamic_wrapper_fi(Params const& params, P const& par, P3 const& p3)
+        : base_t(params, par, p3)
     {}
-
-    template <typename P1, typename P2, typename P3>
-    base_v_fi(P1 const& p1, P2 const& p2, P3 const& p3)
-        : base_t(p1, p2, p3)
-    {}
-
-    virtual void inv(CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const
+    
+    virtual void inv(P const& par, CT const& xy_x, CT const& xy_y, CT& lp_lon, CT& lp_lat) const
     {
-        this->m_proj.inv(xy_x, xy_y, lp_lon, lp_lat);
+        this->prj().inv(par, xy_x, xy_y, lp_lon, lp_lat);
     }
 };