2 // This file is manually converted from PROJ4
4 // This file was modified by Oracle on 2018, 2019.
5 // Modifications copyright (c) 2018-2019, Oracle and/or its affiliates.
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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)
12 // This file is converted from PROJ4, http://trac.osgeo.org/proj
13 // PROJ4 is originally written by Gerald Evenden (then of the USGS)
14 // PROJ4 is maintained by Frank Warmerdam
15 // This file was converted to Geometry Library by Adam Wulkiewicz
17 // Original copyright notice:
18 // Author: Frank Warmerdam, warmerdam@pobox.com
20 // Copyright (c) 2000, Frank Warmerdam
22 // Permission is hereby granted, free of charge, to any person obtaining a
23 // copy of this software and associated documentation files (the "Software"),
24 // to deal in the Software without restriction, including without limitation
25 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
26 // and/or sell copies of the Software, and to permit persons to whom the
27 // Software is furnished to do so, subject to the following conditions:
29 // The above copyright notice and this permission notice shall be included
30 // in all copies or substantial portions of the Software.
32 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
33 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
35 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
37 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
38 // DEALINGS IN THE SOFTWARE.
40 #ifndef BOOST_GEOMETRY_SRS_PROJECTIONS_IMPL_PJ_GRIDLIST_SHARED_HPP
41 #define BOOST_GEOMETRY_SRS_PROJECTIONS_IMPL_PJ_GRIDLIST_SHARED_HPP
44 #include <boost/geometry/srs/projections/shared_grids.hpp>
45 #include <boost/geometry/srs/projections/impl/pj_gridinfo.hpp>
46 #include <boost/geometry/srs/projections/impl/pj_gridlist.hpp>
49 namespace boost { namespace geometry { namespace projections
56 /************************************************************************/
57 /* pj_gridlist_merge_grid() */
59 /* Find/load the named gridfile and merge it into the */
60 /* last_nadgrids_list. */
61 /************************************************************************/
63 // Generic stream policy and shared grids
64 template <typename StreamPolicy>
65 inline bool pj_gridlist_merge_gridfile(std::string const& gridname,
66 StreamPolicy const& stream_policy,
68 std::vector<std::size_t> & gridindexes)
70 // Try to find in the existing list of loaded grids. Add all
71 // matching grids as with NTv2 we can get many grids from one
72 // file (one shared gridname).
74 boost::shared_lock<boost::shared_mutex> lock(grids.mutex);
76 if (pj_gridlist_find_all(gridname, grids.gridinfo, gridindexes))
80 // Try to load the named grid.
81 typename StreamPolicy::stream_type is;
82 stream_policy.open(is, gridname);
84 pj_gridinfo new_grids;
86 if (! pj_gridinfo_init(gridname, is, new_grids))
91 // Add the grid now that it is loaded.
93 std::size_t orig_size = 0;
94 std::size_t new_size = 0;
97 boost::unique_lock<boost::shared_mutex> lock(grids.mutex);
99 // Try to find in the existing list of loaded grids again
100 // in case other thread already added it.
101 if (pj_gridlist_find_all(gridname, grids.gridinfo, gridindexes))
104 orig_size = grids.gridinfo.size();
105 new_size = orig_size + new_grids.size();
107 grids.gridinfo.resize(new_size);
108 for (std::size_t i = 0 ; i < new_grids.size() ; ++ i)
109 new_grids[i].swap(grids.gridinfo[i + orig_size]);
112 pj_gridlist_add_seq_inc(gridindexes, orig_size, new_size);
118 } // namespace detail
120 }}} // namespace boost::geometry::projections
122 #endif // BOOST_GEOMETRY_SRS_PROJECTIONS_IMPL_PJ_GRIDLIST_SHARED_HPP