1/////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Ion Gaztanaga 2014-2014
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/intrusive for documentation.
10//
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP
14#define BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP
15
16#ifndef BOOST_CONFIG_HPP
17# include <boost/config.hpp>
18#endif
19
20#if defined(BOOST_HAS_PRAGMA_ONCE)
21# pragma once
22#endif
23
24#include <boost/intrusive/pointer_traits.hpp>
25#include <boost/intrusive/detail/to_raw_pointer.hpp>
26
27namespace boost {
28namespace intrusive {
29namespace detail {
30
31// trivial header node holder
32template < typename NodeTraits >
33struct default_header_holder : public NodeTraits::node
34{
35 typedef NodeTraits node_traits;
36 typedef typename node_traits::node node;
37 typedef typename node_traits::node_ptr node_ptr;
38 typedef typename node_traits::const_node_ptr const_node_ptr;
39
40 default_header_holder() : node() {}
41
42 const_node_ptr get_node() const
43 { return pointer_traits< const_node_ptr >::pointer_to(*static_cast< const node* >(this)); }
44
45 node_ptr get_node()
46 { return pointer_traits< node_ptr >::pointer_to(*static_cast< node* >(this)); }
47
48 // (unsafe) downcast used to implement container-from-iterator
49 static default_header_holder* get_holder(const node_ptr &p)
50 { return static_cast< default_header_holder* >(boost::intrusive::detail::to_raw_pointer(p)); }
51};
52
53// type function producing the header node holder
54template < typename Value_Traits, typename HeaderHolder >
55struct get_header_holder_type
56{
57 typedef HeaderHolder type;
58};
59template < typename Value_Traits >
60struct get_header_holder_type< Value_Traits, void >
61{
62 typedef default_header_holder< typename Value_Traits::node_traits > type;
63};
64
65} //namespace detail
66} //namespace intrusive
67} //namespace boost
68
69#endif //BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP
70