header_holder.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Copyright 2003-2008 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/multi_index for library home page.
  7. */
  8. #ifndef BOOST_MULTI_INDEX_DETAIL_HEADER_HOLDER_HPP
  9. #define BOOST_MULTI_INDEX_DETAIL_HEADER_HOLDER_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/noncopyable.hpp>
  14. namespace boost{
  15. namespace multi_index{
  16. namespace detail{
  17. /* A utility class used to hold a pointer to the header node.
  18. * The base from member idiom is used because index classes, which are
  19. * superclasses of multi_index_container, need this header in construction
  20. * time. The allocation is made by the allocator of the multi_index_container
  21. * class --hence, this allocator needs also be stored resorting
  22. * to the base from member trick.
  23. */
  24. template<typename NodeTypePtr,typename Final>
  25. struct header_holder:private noncopyable
  26. {
  27. header_holder():member(final().allocate_node()){}
  28. ~header_holder(){final().deallocate_node(&*member);}
  29. NodeTypePtr member;
  30. private:
  31. Final& final(){return *static_cast<Final*>(this);}
  32. };
  33. } /* namespace multi_index::detail */
  34. } /* namespace multi_index */
  35. } /* namespace boost */
  36. #endif