grids.hpp 2.7 KB

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