deleter.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2007-2012.
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/interprocess for documentation.
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. #ifndef BOOST_INTERPROCESS_DELETER_HPP
  13. #define BOOST_INTERPROCESS_DELETER_HPP
  14. #ifndef BOOST_CONFIG_HPP
  15. # include <boost/config.hpp>
  16. #endif
  17. #
  18. #if defined(BOOST_HAS_PRAGMA_ONCE)
  19. # pragma once
  20. #endif
  21. #include <boost/interprocess/detail/config_begin.hpp>
  22. #include <boost/interprocess/interprocess_fwd.hpp>
  23. #include <boost/interprocess/detail/utilities.hpp>
  24. #include <boost/intrusive/pointer_traits.hpp>
  25. //!\file
  26. //!Describes the functor to delete objects from the segment.
  27. namespace boost {
  28. namespace interprocess {
  29. //!A deleter that uses the segment manager's destroy_ptr
  30. //!function to destroy the passed pointer resource.
  31. //!
  32. //!This deleter is used
  33. template<class T, class SegmentManager>
  34. class deleter
  35. {
  36. public:
  37. typedef typename boost::intrusive::
  38. pointer_traits<typename SegmentManager::void_pointer>::template
  39. rebind_pointer<T>::type pointer;
  40. private:
  41. typedef typename boost::intrusive::
  42. pointer_traits<pointer>::template
  43. rebind_pointer<SegmentManager>::type segment_manager_pointer;
  44. segment_manager_pointer mp_mngr;
  45. public:
  46. deleter(segment_manager_pointer pmngr)
  47. : mp_mngr(pmngr)
  48. {}
  49. void operator()(const pointer &p)
  50. { mp_mngr->destroy_ptr(ipcdetail::to_raw_pointer(p)); }
  51. };
  52. } //namespace interprocess {
  53. } //namespace boost {
  54. #include <boost/interprocess/detail/config_end.hpp>
  55. #endif //#ifndef BOOST_INTERPROCESS_DELETER_HPP