shared_grids_boost.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/lock_types.hpp>
  11. #include <boost/thread/shared_mutex.hpp>
  12. namespace boost { namespace geometry
  13. {
  14. namespace srs
  15. {
  16. class shared_grids_boost
  17. {
  18. public:
  19. std::size_t size() const
  20. {
  21. boost::shared_lock<boost::shared_mutex> lock(mutex);
  22. return gridinfo.size();
  23. }
  24. bool empty() const
  25. {
  26. boost::shared_lock<boost::shared_mutex> lock(mutex);
  27. return gridinfo.empty();
  28. }
  29. typedef projections::detail::shared_grids_tag tag;
  30. struct read_locked
  31. {
  32. read_locked(shared_grids_boost & g)
  33. : gridinfo(g.gridinfo)
  34. , lock(g.mutex)
  35. {}
  36. // should be const&
  37. projections::detail::pj_gridinfo & gridinfo;
  38. private:
  39. boost::shared_lock<boost::shared_mutex> lock;
  40. };
  41. struct write_locked
  42. {
  43. write_locked(shared_grids_boost & g)
  44. : gridinfo(g.gridinfo)
  45. , lock(g.mutex)
  46. {}
  47. projections::detail::pj_gridinfo & gridinfo;
  48. private:
  49. boost::unique_lock<boost::shared_mutex> lock;
  50. };
  51. private:
  52. projections::detail::pj_gridinfo gridinfo;
  53. mutable boost::shared_mutex mutex;
  54. };
  55. } // namespace srs
  56. }} // namespace boost::geometry
  57. #endif // BOOST_GEOMETRY_SRS_SHARED_GRIDS_BOOST_HPP