Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/intrusive/pointer_plus_bits.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
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 | |
13 #ifndef BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP | |
14 #define BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP | |
15 | |
16 #include <boost/intrusive/detail/mpl.hpp> //ls_zeros | |
17 #include <boost/intrusive/detail/assert.hpp> //BOOST_INTRUSIVE_INVARIANT_ASSERT | |
18 | |
19 namespace boost { | |
20 namespace intrusive { | |
21 | |
22 //!This trait class is used to know if a pointer | |
23 //!can embed extra bits of information if | |
24 //!it's going to be used to point to objects | |
25 //!with an alignment of "Alignment" bytes. | |
26 template<class VoidPointer, std::size_t Alignment> | |
27 struct max_pointer_plus_bits | |
28 { | |
29 static const std::size_t value = 0; | |
30 }; | |
31 | |
32 //!This is a specialization for raw pointers. | |
33 //!Raw pointers can embed extra bits in the lower bits | |
34 //!if the alignment is multiple of 2pow(NumBits). | |
35 template<std::size_t Alignment> | |
36 struct max_pointer_plus_bits<void*, Alignment> | |
37 { | |
38 static const std::size_t value = detail::ls_zeros<Alignment>::value; | |
39 }; | |
40 | |
41 //!This is class that is supposed to have static methods | |
42 //!to embed extra bits of information in a pointer. | |
43 //!This is a declaration and there is no default implementation, | |
44 //!because operations to embed the bits change with every pointer type. | |
45 //! | |
46 //!An implementation that detects that a pointer type whose | |
47 //!has_pointer_plus_bits<>::value is non-zero can make use of these | |
48 //!operations to embed the bits in the pointer. | |
49 template<class Pointer, std::size_t NumBits> | |
50 struct pointer_plus_bits | |
51 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED | |
52 {} | |
53 #endif | |
54 ; | |
55 | |
56 //!This is the specialization to embed extra bits of information | |
57 //!in a raw pointer. The extra bits are stored in the lower bits of the pointer. | |
58 template<class T, std::size_t NumBits> | |
59 struct pointer_plus_bits<T*, NumBits> | |
60 { | |
61 static const std::size_t Mask = ((std::size_t(1u) << NumBits) - 1); | |
62 typedef T* pointer; | |
63 | |
64 static pointer get_pointer(pointer n) | |
65 { return pointer(std::size_t(n) & ~Mask); } | |
66 | |
67 static void set_pointer(pointer &n, pointer p) | |
68 { | |
69 BOOST_INTRUSIVE_INVARIANT_ASSERT(0 == (std::size_t(p) & Mask)); | |
70 n = pointer(std::size_t(p) | (std::size_t(n) & Mask)); | |
71 } | |
72 | |
73 static std::size_t get_bits(pointer n) | |
74 { return (std::size_t(n) & Mask); } | |
75 | |
76 static void set_bits(pointer &n, std::size_t c) | |
77 { | |
78 BOOST_INTRUSIVE_INVARIANT_ASSERT(c <= Mask); | |
79 n = pointer(std::size_t(get_pointer(n)) | c); | |
80 } | |
81 }; | |
82 | |
83 } //namespace intrusive | |
84 } //namespace boost | |
85 | |
86 #endif //BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP |