Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:40

0001 // Boost.Geometry
0002 
0003 // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
0004 
0005 // Copyright (c) 2017-2018, Oracle and/or its affiliates.
0006 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0007 
0008 // Use, modification and distribution is subject to the Boost Software License,
0009 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0010 // http://www.boost.org/LICENSE_1_0.txt)
0011 
0012 #ifndef BOOST_GEOMETRY_SRS_PROJECTIONS_PROJ4_HPP
0013 #define BOOST_GEOMETRY_SRS_PROJECTIONS_PROJ4_HPP
0014 
0015 
0016 #include <string>
0017 #include <vector>
0018 
0019 #include <boost/algorithm/string/trim.hpp>
0020 
0021 
0022 namespace boost { namespace geometry
0023 {
0024 
0025 namespace srs
0026 {
0027 
0028 
0029 struct dynamic {};
0030 
0031 
0032 struct proj4
0033 {
0034     explicit proj4(const char* s)
0035         : m_str(s)
0036     {}
0037 
0038     explicit proj4(std::string const& s)
0039         : m_str(s)
0040     {}
0041 
0042     std::string const& str() const
0043     {
0044         return m_str;
0045     }
0046 
0047 private:
0048     std::string m_str;
0049 };
0050 
0051 
0052 namespace detail
0053 {
0054 
0055 struct proj4_parameter
0056 {
0057     proj4_parameter() {}
0058     proj4_parameter(std::string const& n, std::string const& v) : name(n), value(v) {}
0059     std::string name;
0060     std::string value;
0061 };
0062 
0063 struct proj4_parameters
0064     : std::vector<proj4_parameter>
0065 {
0066     // Initially implemented as part of pj_init_plus() and pj_init()
0067     proj4_parameters(std::string const& proj4_str)
0068     {
0069         const char* sep = " +";
0070 
0071         /* split into arguments based on '+' and trim white space */
0072 
0073         // boost::split splits on one character, here it should be on " +", so implementation below
0074         // todo: put in different routine or sort out
0075         std::string def = boost::trim_copy(proj4_str);
0076         boost::trim_left_if(def, boost::is_any_of(sep));
0077 
0078         std::string::size_type loc = def.find(sep);
0079         while (loc != std::string::npos)
0080         {
0081             std::string par = def.substr(0, loc);
0082             boost::trim(par);
0083             if (! par.empty())
0084             {
0085                 this->add(par);
0086             }
0087 
0088             def.erase(0, loc);
0089             boost::trim_left_if(def, boost::is_any_of(sep));
0090             loc = def.find(sep);
0091         }
0092 
0093         if (! def.empty())
0094         {
0095             this->add(def);
0096         }
0097     }
0098 
0099     void add(std::string const& str)
0100     {
0101         std::string name = str;
0102         std::string value;
0103         boost::trim_left_if(name, boost::is_any_of("+"));
0104         std::string::size_type loc = name.find("=");
0105         if (loc != std::string::npos)
0106         {
0107             value = name.substr(loc + 1);
0108             name.erase(loc);
0109         }
0110 
0111         this->add(name, value);
0112     }
0113 
0114     void add(std::string const& name, std::string const& value)
0115     {
0116         this->push_back(proj4_parameter(name, value));
0117     }
0118 };
0119 
0120 }
0121 
0122 
0123 } // namespace srs
0124 
0125 
0126 }} // namespace boost::geometry
0127 
0128 
0129 #endif // BOOST_GEOMETRY_SRS_PROJECTIONS_PROJ4_HPP