]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/geometry/srs/projections/proj4.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / geometry / srs / projections / proj4.hpp
CommitLineData
11fdf7f2
TL
1// Boost.Geometry
2
92f5a8d4
TL
3// Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
4
5// Copyright (c) 2017-2018, Oracle and/or its affiliates.
11fdf7f2
TL
6// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7
8// Use, modification and distribution is subject to the Boost Software License,
9// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10// http://www.boost.org/LICENSE_1_0.txt)
11
12#ifndef BOOST_GEOMETRY_SRS_PROJECTIONS_PROJ4_HPP
13#define BOOST_GEOMETRY_SRS_PROJECTIONS_PROJ4_HPP
14
15
16#include <string>
92f5a8d4 17#include <vector>
11fdf7f2 18
92f5a8d4 19#include <boost/algorithm/string/trim.hpp>
11fdf7f2
TL
20
21
92f5a8d4
TL
22namespace boost { namespace geometry
23{
24
25namespace srs
11fdf7f2
TL
26{
27
28
29struct dynamic {};
30
31
32struct proj4
33{
34 explicit proj4(const char* s)
92f5a8d4 35 : m_str(s)
11fdf7f2
TL
36 {}
37
38 explicit proj4(std::string const& s)
92f5a8d4 39 : m_str(s)
11fdf7f2
TL
40 {}
41
92f5a8d4
TL
42 std::string const& str() const
43 {
44 return m_str;
45 }
46
47private:
48 std::string m_str;
11fdf7f2
TL
49};
50
51
92f5a8d4 52namespace detail
11fdf7f2 53{
11fdf7f2 54
92f5a8d4
TL
55struct proj4_parameter
56{
57 proj4_parameter() {}
58 proj4_parameter(std::string const& n, std::string const& v) : name(n), value(v) {}
59 std::string name;
60 std::string value;
11fdf7f2
TL
61};
62
92f5a8d4
TL
63struct proj4_parameters
64 : std::vector<proj4_parameter>
65{
66 // Initially implemented as part of pj_init_plus() and pj_init()
67 proj4_parameters(std::string const& proj4_str)
68 {
69 const char* sep = " +";
70
71 /* split into arguments based on '+' and trim white space */
72
73 // boost::split splits on one character, here it should be on " +", so implementation below
74 // todo: put in different routine or sort out
75 std::string def = boost::trim_copy(proj4_str);
76 boost::trim_left_if(def, boost::is_any_of(sep));
77
78 std::string::size_type loc = def.find(sep);
79 while (loc != std::string::npos)
80 {
81 std::string par = def.substr(0, loc);
82 boost::trim(par);
83 if (! par.empty())
84 {
85 this->add(par);
86 }
87
88 def.erase(0, loc);
89 boost::trim_left_if(def, boost::is_any_of(sep));
90 loc = def.find(sep);
91 }
92
93 if (! def.empty())
94 {
95 this->add(def);
96 }
97 }
98
99 void add(std::string const& str)
100 {
101 std::string name = str;
102 std::string value;
103 boost::trim_left_if(name, boost::is_any_of("+"));
104 std::string::size_type loc = name.find("=");
105 if (loc != std::string::npos)
106 {
107 value = name.substr(loc + 1);
108 name.erase(loc);
109 }
110
111 this->add(name, value);
112 }
113
114 void add(std::string const& name, std::string const& value)
115 {
116 this->push_back(proj4_parameter(name, value));
117 }
118};
11fdf7f2 119
92f5a8d4 120}
11fdf7f2
TL
121
122
92f5a8d4 123} // namespace srs
11fdf7f2 124
11fdf7f2 125
92f5a8d4 126}} // namespace boost::geometry
11fdf7f2 127
11fdf7f2
TL
128
129#endif // BOOST_GEOMETRY_SRS_PROJECTIONS_PROJ4_HPP