Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / geometry / srs / projections / grids.hpp
1 // Boost.Geometry
2
3 // This file was modified by Oracle on 2018, 2019.
4 // Modifications copyright (c) 2018, 2019, Oracle and/or its affiliates.
5 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 #ifndef BOOST_GEOMETRY_SRS_PROJECTIONS_GRIDS_HPP
12 #define BOOST_GEOMETRY_SRS_PROJECTIONS_GRIDS_HPP
13
14
15 #include <boost/geometry/srs/projections/impl/pj_gridinfo.hpp>
16
17 #include <fstream>
18
19
20 namespace boost { namespace geometry
21 {
22
23
24 namespace projections { namespace detail
25 {
26
27
28 struct grids_tag {};
29 struct shared_grids_tag {};
30
31
32 }} // namespace projections::detail
33
34 namespace srs
35 {
36
37 class grids
38 {
39 public:
40     std::size_t size() const
41     {
42         return gridinfo.size();
43     }
44
45     bool empty() const
46     {
47         return gridinfo.empty();
48     }
49
50     typedef projections::detail::grids_tag tag;
51
52     projections::detail::pj_gridinfo gridinfo;
53 };
54
55 struct ifstream_policy
56 {
57     typedef std::ifstream stream_type;
58
59     static inline void open(stream_type & is, std::string const& gridname)
60     {
61         is.open(gridname.c_str(), std::ios::binary);
62     }
63 };
64
65 template
66 <
67     typename StreamPolicy = srs::ifstream_policy,
68     typename Grids = grids
69 >
70 struct grids_storage
71 {
72     typedef StreamPolicy stream_policy_type;
73     typedef Grids grids_type;
74
75     grids_storage()
76     {}
77
78     explicit grids_storage(stream_policy_type const& policy)
79         : stream_policy(policy)
80     {}
81
82     stream_policy_type stream_policy;
83     grids_type hgrids;
84 };
85
86
87 template <typename GridsStorage = grids_storage<> >
88 class projection_grids
89 {
90 public:
91     projection_grids(GridsStorage & storage)
92         : m_storage_ptr(boost::addressof(storage))
93     {}
94
95     typedef GridsStorage grids_storage_type;
96
97     GridsStorage & grids_storage() const
98     {
99         return *m_storage_ptr;
100     }
101
102 private:
103     GridsStorage * const m_storage_ptr;
104
105 public:
106     std::vector<std::size_t> hindexes;
107 };
108
109
110 template <typename GridsStorage = grids_storage<> >
111 struct transformation_grids
112 {
113     explicit transformation_grids(GridsStorage & storage)
114         : src_grids(storage)
115         , dst_grids(storage)
116     {}
117
118     projection_grids<GridsStorage> src_grids;
119     projection_grids<GridsStorage> dst_grids;
120 };
121
122
123 namespace detail
124 {
125
126 struct empty_grids_storage {};
127 struct empty_projection_grids {};
128
129 } // namespace detail
130
131
132 template <>
133 struct transformation_grids<detail::empty_grids_storage>
134 {
135     detail::empty_projection_grids src_grids;
136     detail::empty_projection_grids dst_grids;
137 };
138
139
140 }}} // namespace boost::geometry::srs
141
142
143 #endif // BOOST_GEOMETRY_SRS_PROJECTIONS_GRIDS_HPP