shared_grids_boost.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Boost.Geometry
  2. // Copyright (c) 2018-2019, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Use, modification and distribution is subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #ifndef BOOST_GEOMETRY_SRS_SHARED_GRIDS_BOOST_HPP
  8. #define BOOST_GEOMETRY_SRS_SHARED_GRIDS_BOOST_HPP
  9. #include <boost/geometry/srs/projections/grids.hpp>
  10. #include <boost/thread.hpp>
  11. namespace boost { namespace geometry
  12. {
  13. namespace srs
  14. {
  15. class shared_grids_boost
  16. {
  17. public:
  18. std::size_t size() const
  19. {
  20. boost::shared_lock<boost::shared_mutex> lock(mutex);
  21. return gridinfo.size();
  22. }
  23. bool empty() const
  24. {
  25. boost::shared_lock<boost::shared_mutex> lock(mutex);
  26. return gridinfo.empty();
  27. }
  28. typedef projections::detail::shared_grids_tag tag;
  29. struct read_locked
  30. {
  31. read_locked(shared_grids_boost & g)
  32. : gridinfo(g.gridinfo)
  33. , lock(g.mutex)
  34. {}
  35. // should be const&
  36. projections::detail::pj_gridinfo & gridinfo;
  37. private:
  38. boost::shared_lock<boost::shared_mutex> lock;
  39. };
  40. struct write_locked
  41. {
  42. write_locked(shared_grids_boost & g)
  43. : gridinfo(g.gridinfo)
  44. , lock(g.mutex)
  45. {}
  46. projections::detail::pj_gridinfo & gridinfo;
  47. private:
  48. boost::unique_lock<boost::shared_mutex> lock;
  49. };
  50. private:
  51. projections::detail::pj_gridinfo gridinfo;
  52. mutable boost::shared_mutex mutex;
  53. };
  54. } // namespace srs
  55. }} // namespace boost::geometry
  56. #endif // BOOST_GEOMETRY_SRS_SHARED_GRIDS_BOOST_HPP