~ubuntu-branches/ubuntu/wily/davix/wily

« back to all changes in this revision

Viewing changes to deps/boost_intern/boost/intrusive/detail/parent_from_member.hpp

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2015-07-31 13:17:55 UTC
  • mfrom: (5.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20150731131755-mizprbmn7ogv33te
Tags: 0.4.1-1
* Update to version 0.4.1
* Implement Multi-Arch support

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/////////////////////////////////////////////////////////////////////////////
2
 
//
3
 
// (C) Copyright Ion Gaztanaga  2007-2013
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
 
#ifndef BOOST_INTRUSIVE_DETAIL_PARENT_FROM_MEMBER_HPP
13
 
#define BOOST_INTRUSIVE_DETAIL_PARENT_FROM_MEMBER_HPP
14
 
 
15
 
#include <boost/intrusive/detail/config_begin.hpp>
16
 
#include <cstddef>
17
 
 
18
 
#if defined(BOOST_MSVC) || ((defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) && defined(BOOST_INTEL))
19
 
   #define BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER
20
 
   #include <boost/cstdint.hpp>
21
 
   #include <boost/static_assert.hpp>
22
 
#endif
23
 
 
24
 
namespace boost {
25
 
namespace intrusive {
26
 
namespace detail {
27
 
 
28
 
template<class Parent, class Member>
29
 
inline std::ptrdiff_t offset_from_pointer_to_member(const Member Parent::* ptr_to_member)
30
 
{
31
 
   //The implementation of a pointer to member is compiler dependent.
32
 
   #if defined(BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER)
33
 
 
34
 
   //MSVC compliant compilers use their the first 32 bits as offset (even in 64 bit mode)
35
 
   union caster_union
36
 
   {
37
 
      const Member Parent::* ptr_to_member;
38
 
      boost::int32_t offset;
39
 
   } caster;
40
 
 
41
 
   //MSVC ABI can use up to 3 int32 to represent pointer to member data
42
 
   //with virtual base classes, in those cases there is no simple to
43
 
   //obtain the address of the parent. So static assert to avoid runtime errors
44
 
   BOOST_STATIC_ASSERT( sizeof(caster) == sizeof(boost::int32_t) );
45
 
 
46
 
   caster.ptr_to_member = ptr_to_member;
47
 
   return std::ptrdiff_t(caster.offset);
48
 
   //Additional info on MSVC behaviour for the future. For 2/3 int ptr-to-member 
49
 
   //types dereference seems to be:
50
 
   //
51
 
   // vboffset = [compile_time_offset if 2-int ptr2memb] /
52
 
   //            [ptr2memb.i32[2] if 3-int ptr2memb].
53
 
   // vbtable = *(this + vboffset);
54
 
   // adj = vbtable[ptr2memb.i32[1]];
55
 
   // var = adj + (this + vboffset) + ptr2memb.i32[0];
56
 
   //
57
 
   //To reverse the operation we need to
58
 
   // - obtain vboffset (in 2-int ptr2memb implementation only)
59
 
   // - Go to Parent's vbtable and obtain adjustment at index ptr2memb.i32[1]
60
 
   // - parent = member - adj - vboffset - ptr2memb.i32[0]
61
 
   //
62
 
   //Even accessing to RTTI we might not be able to obtain this information
63
 
   //so anyone who thinks it's possible, please send a patch.
64
 
 
65
 
   //This works with gcc, msvc, ac++, ibmcpp
66
 
   #elif defined(__GNUC__)   || defined(__HP_aCC) || defined(BOOST_INTEL) || \
67
 
         defined(__IBMCPP__) || defined(__DECCXX)
68
 
   const Parent * const parent = 0;
69
 
   const char *const member = static_cast<const char*>(static_cast<const void*>(&(parent->*ptr_to_member)));
70
 
   return std::ptrdiff_t(member - static_cast<const char*>(static_cast<const void*>(parent)));
71
 
   #else
72
 
   //This is the traditional C-front approach: __MWERKS__, __DMC__, __SUNPRO_CC
73
 
   union caster_union
74
 
   {
75
 
      const Member Parent::* ptr_to_member;
76
 
      std::ptrdiff_t offset;
77
 
   } caster;
78
 
   caster.ptr_to_member = ptr_to_member;
79
 
   return caster.offset - 1;
80
 
   #endif
81
 
}
82
 
 
83
 
template<class Parent, class Member>
84
 
inline Parent *parent_from_member(Member *member, const Member Parent::* ptr_to_member)
85
 
{
86
 
   return static_cast<Parent*>
87
 
      (
88
 
         static_cast<void*>
89
 
         (
90
 
            static_cast<char*>(static_cast<void*>(member)) - offset_from_pointer_to_member(ptr_to_member)
91
 
         )
92
 
      );
93
 
}
94
 
 
95
 
template<class Parent, class Member>
96
 
inline const Parent *parent_from_member(const Member *member, const Member Parent::* ptr_to_member)
97
 
{
98
 
   return static_cast<const Parent*>
99
 
      (
100
 
         static_cast<const void*>
101
 
         (
102
 
            static_cast<const char*>(static_cast<const void*>(member)) - offset_from_pointer_to_member(ptr_to_member)
103
 
         )
104
 
      );
105
 
}
106
 
 
107
 
}  //namespace detail {
108
 
}  //namespace intrusive {
109
 
}  //namespace boost {
110
 
 
111
 
#ifdef BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER
112
 
#undef BOOST_INTRUSIVE_MSVC_ABI_PTR_TO_MEMBER
113
 
#endif
114
 
 
115
 
#include <boost/intrusive/detail/config_end.hpp>
116
 
 
117
 
#endif   //#ifndef BOOST_INTRUSIVE_DETAIL_PARENT_FROM_MEMBER_HPP