diff options
Diffstat (limited to 'boost/geometry/srs/projections/impl/pj_param.hpp')
-rw-r--r-- | boost/geometry/srs/projections/impl/pj_param.hpp | 219 |
1 files changed, 144 insertions, 75 deletions
diff --git a/boost/geometry/srs/projections/impl/pj_param.hpp b/boost/geometry/srs/projections/impl/pj_param.hpp index 4f33ad837f..7648055414 100644 --- a/boost/geometry/srs/projections/impl/pj_param.hpp +++ b/boost/geometry/srs/projections/impl/pj_param.hpp @@ -3,8 +3,8 @@ // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands. -// This file was modified by Oracle on 2017. -// Modifications copyright (c) 2017, Oracle and/or its affiliates. +// This file was modified by Oracle on 2017, 2018. +// Modifications copyright (c) 2017-2018, 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, @@ -43,15 +43,30 @@ #include <string> #include <vector> +#include <boost/geometry/srs/projections/exception.hpp> + #include <boost/geometry/srs/projections/impl/dms_parser.hpp> #include <boost/geometry/srs/projections/impl/projects.hpp> +#include <boost/mpl/assert.hpp> +#include <boost/type_traits/is_integral.hpp> + namespace boost { namespace geometry { namespace projections { namespace detail { +/* create pvalue list entry */ +template <typename T> +inline pvalue<T> pj_mkparam(std::string const& name, std::string const& value) +{ + pvalue<T> newitem; + newitem.param = name; + newitem.s = value; + //newitem.used = false; + return newitem; +} /* create pvalue list entry */ template <typename T> @@ -67,92 +82,146 @@ inline pvalue<T> pj_mkparam(std::string const& str) name.erase(loc); } + return pj_mkparam<T>(name, value); +} - pvalue<T> newitem; - newitem.param = name; - newitem.s = value; - newitem.used = 0; - newitem.i = atoi(value.c_str()); - newitem.f = atof(value.c_str()); - return newitem; +/* input exists */ +template <typename T> +inline typename std::vector<pvalue<T> >::const_iterator + pj_param_find(std::vector<pvalue<T> > const& pl, std::string const& name) +{ + typedef typename std::vector<pvalue<T> >::const_iterator iterator; + for (iterator it = pl.begin(); it != pl.end(); it++) + { + if (it->param == name) + { + //it->used = true; + return it; + } + // TODO: needed for pipeline + /*else if (it->param == "step") + { + return pl.end(); + }*/ + } + + return pl.end(); } -/************************************************************************/ -/* pj_param() */ -/* */ -/* Test for presence or get pvalue value. The first */ -/* character in `opt' is a pvalue type which can take the */ -/* values: */ -/* */ -/* `t' - test for presence, return TRUE/FALSE in pvalue.i */ -/* `i' - integer value returned in pvalue.i */ -/* `d' - simple valued real input returned in pvalue.f */ -/* `r' - degrees (DMS translation applied), returned as */ -/* radians in pvalue.f */ -/* `s' - string returned in pvalue.s */ -/* `b' - test for t/T/f/F, return in pvalue.i */ -/* */ -/************************************************************************/ +/* input exists */ +template <typename T> +inline bool pj_param_exists(std::vector<pvalue<T> > const& pl, std::string const& name) +{ + return pj_param_find(pl, name) != pl.end(); +} +/* integer input */ template <typename T> -inline pvalue<T> pj_param(std::vector<pvalue<T> > const& pl, std::string opt) +inline bool pj_param_i(std::vector<pvalue<T> > const& pl, std::string const& name, int & par) { - char type = opt[0]; - opt.erase(opt.begin()); + typename std::vector<pvalue<T> >::const_iterator it = pj_param_find(pl, name); + if (it != pl.end()) + { + par = geometry::str_cast<int>(it->s); + return true; + } + return false; +} - pvalue<T> value; +/* floating point input */ +template <typename T> +inline bool pj_param_f(std::vector<pvalue<T> > const& pl, std::string const& name, T & par) +{ + typename std::vector<pvalue<T> >::const_iterator it = pj_param_find(pl, name); + if (it != pl.end()) + { + par = geometry::str_cast<T>(it->s); + return true; + } + return false; +} - /* simple linear lookup */ - typedef typename std::vector<pvalue<T> >::const_iterator iterator; - for (iterator it = pl.begin(); it != pl.end(); it++) +/* radians input */ +template <typename T> +inline bool pj_param_r(std::vector<pvalue<T> > const& pl, std::string const& name, T & par) +{ + typename std::vector<pvalue<T> >::const_iterator it = pj_param_find(pl, name); + if (it != pl.end()) + { + dms_parser<T, true> parser; + par = parser.apply(it->s.c_str()).angle(); + return true; + } + return false; +} + +/* string input */ +template <typename T> +inline bool pj_param_s(std::vector<pvalue<T> > const& pl, std::string const& name, std::string & par) +{ + typename std::vector<pvalue<T> >::const_iterator it = pj_param_find(pl, name); + if (it != pl.end()) + { + par = it->s; + return true; + } + return false; +} + +/* bool input */ +template <typename T> +inline bool pj_get_param_b(std::vector<pvalue<T> > const& pl, std::string const& name) +{ + typename std::vector<pvalue<T> >::const_iterator it = pj_param_find(pl, name); + if (it != pl.end()) { - if (it->param == opt) + switch (it->s[0]) { - //it->used = 1; - switch (type) - { - case 't': - value.i = 1; - break; - case 'i': /* integer input */ - value.i = atoi(it->s.c_str()); - break; - case 'd': /* simple real input */ - value.f = atof(it->s.c_str()); - break; - case 'r': /* degrees input */ - { - dms_parser<T, true> parser; - value.f = parser.apply(it->s.c_str()).angle(); - } - break; - case 's': /* char string */ - value.s = it->s; - break; - case 'b': /* boolean */ - switch (it->s[0]) - { - case 'F': case 'f': - value.i = 0; - break; - case '\0': case 'T': case 't': - value.i = 1; - break; - default: - value.i = 0; - break; - } - break; - } - return value; + case '\0': case 'T': case 't': + return true; + case 'F': case 'f': + return false; + default: + BOOST_THROW_EXCEPTION( projection_exception(error_invalid_boolean_param) ); + return false; } + } + return false; +} - } +// NOTE: In the original code, in pl_ell_set.c there is a function pj_get_param +// which behavior is similar to pj_param but it doesn't set `user` member to TRUE +// while pj_param does in the original code. In Boost.Geometry this member is not used. +template <typename T> +inline int pj_get_param_i(std::vector<pvalue<T> > const& pl, std::string const& name) +{ + int res = 0; + pj_param_i(pl, name, res); + return res; +} - value.i = 0; - value.f = 0.0; - value.s = ""; - return value; +template <typename T> +inline T pj_get_param_f(std::vector<pvalue<T> > const& pl, std::string const& name) +{ + T res = 0; + pj_param_f(pl, name, res); + return res; +} + +template <typename T> +inline T pj_get_param_r(std::vector<pvalue<T> > const& pl, std::string const& name) +{ + T res = 0; + pj_param_r(pl, name, res); + return res; +} + +template <typename T> +inline std::string pj_get_param_s(std::vector<pvalue<T> > const& pl, std::string const& name) +{ + std::string res; + pj_param_s(pl, name, res); + return res; } } // namespace detail |