scoped_deallocator.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Boost.Geometry Index
  2. //
  3. // R-tree scoped deallocator
  4. //
  5. // Copyright (c) 2011-2018 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // This file was modified by Oracle on 2021.
  8. // Modifications copyright (c) 2021 Oracle and/or its affiliates.
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. //
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_SCOPED_DEALLOCATOR_HPP
  15. #define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_SCOPED_DEALLOCATOR_HPP
  16. #include <boost/container/allocator_traits.hpp>
  17. namespace boost { namespace geometry { namespace index {
  18. namespace detail { namespace rtree {
  19. template <typename Alloc>
  20. class scoped_deallocator
  21. {
  22. typedef boost::container::allocator_traits<Alloc> alloc_traits;
  23. scoped_deallocator(scoped_deallocator const&);
  24. scoped_deallocator & operator=(scoped_deallocator const&);
  25. public:
  26. typedef typename alloc_traits::pointer pointer;
  27. inline scoped_deallocator(pointer p, Alloc & a)
  28. : m_ptr(p), m_alloc(a)
  29. {}
  30. inline ~scoped_deallocator()
  31. {
  32. if ( m_ptr )
  33. {
  34. alloc_traits::deallocate(m_alloc, m_ptr, 1);
  35. }
  36. }
  37. inline void release()
  38. {
  39. m_ptr = 0;
  40. }
  41. private:
  42. pointer m_ptr;
  43. Alloc & m_alloc;
  44. };
  45. }} // namespace detail::rtree
  46. }}} // namespace boost::geometry::index
  47. #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_NODE_SCOPED_DEALLOCATOR_HPP