annotate DEPENDENCIES/generic/include/boost/intrusive/pointer_plus_bits.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 /////////////////////////////////////////////////////////////////////////////
Chris@16 2 //
Chris@16 3 // (C) Copyright Ion Gaztanaga 2007-2013
Chris@16 4 //
Chris@16 5 // Distributed under the Boost Software License, Version 1.0.
Chris@16 6 // (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 7 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8 //
Chris@16 9 // See http://www.boost.org/libs/intrusive for documentation.
Chris@16 10 //
Chris@16 11 /////////////////////////////////////////////////////////////////////////////
Chris@16 12
Chris@16 13 #ifndef BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP
Chris@16 14 #define BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP
Chris@16 15
Chris@101 16 #include <boost/intrusive/detail/config_begin.hpp>
Chris@101 17 #include <boost/intrusive/intrusive_fwd.hpp>
Chris@16 18 #include <boost/intrusive/detail/mpl.hpp> //ls_zeros
Chris@16 19 #include <boost/intrusive/detail/assert.hpp> //BOOST_INTRUSIVE_INVARIANT_ASSERT
Chris@16 20
Chris@101 21 #if defined(BOOST_HAS_PRAGMA_ONCE)
Chris@101 22 # pragma once
Chris@101 23 #endif
Chris@101 24
Chris@16 25 namespace boost {
Chris@16 26 namespace intrusive {
Chris@16 27
Chris@16 28 //!This trait class is used to know if a pointer
Chris@16 29 //!can embed extra bits of information if
Chris@16 30 //!it's going to be used to point to objects
Chris@16 31 //!with an alignment of "Alignment" bytes.
Chris@16 32 template<class VoidPointer, std::size_t Alignment>
Chris@16 33 struct max_pointer_plus_bits
Chris@16 34 {
Chris@16 35 static const std::size_t value = 0;
Chris@16 36 };
Chris@16 37
Chris@16 38 //!This is a specialization for raw pointers.
Chris@16 39 //!Raw pointers can embed extra bits in the lower bits
Chris@16 40 //!if the alignment is multiple of 2pow(NumBits).
Chris@16 41 template<std::size_t Alignment>
Chris@16 42 struct max_pointer_plus_bits<void*, Alignment>
Chris@16 43 {
Chris@16 44 static const std::size_t value = detail::ls_zeros<Alignment>::value;
Chris@16 45 };
Chris@16 46
Chris@16 47 //!This is class that is supposed to have static methods
Chris@16 48 //!to embed extra bits of information in a pointer.
Chris@16 49 //!This is a declaration and there is no default implementation,
Chris@16 50 //!because operations to embed the bits change with every pointer type.
Chris@16 51 //!
Chris@16 52 //!An implementation that detects that a pointer type whose
Chris@16 53 //!has_pointer_plus_bits<>::value is non-zero can make use of these
Chris@16 54 //!operations to embed the bits in the pointer.
Chris@16 55 template<class Pointer, std::size_t NumBits>
Chris@16 56 struct pointer_plus_bits
Chris@16 57 #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
Chris@16 58 {}
Chris@16 59 #endif
Chris@16 60 ;
Chris@16 61
Chris@16 62 //!This is the specialization to embed extra bits of information
Chris@16 63 //!in a raw pointer. The extra bits are stored in the lower bits of the pointer.
Chris@16 64 template<class T, std::size_t NumBits>
Chris@16 65 struct pointer_plus_bits<T*, NumBits>
Chris@16 66 {
Chris@16 67 static const std::size_t Mask = ((std::size_t(1u) << NumBits) - 1);
Chris@16 68 typedef T* pointer;
Chris@16 69
Chris@16 70 static pointer get_pointer(pointer n)
Chris@16 71 { return pointer(std::size_t(n) & ~Mask); }
Chris@16 72
Chris@16 73 static void set_pointer(pointer &n, pointer p)
Chris@16 74 {
Chris@16 75 BOOST_INTRUSIVE_INVARIANT_ASSERT(0 == (std::size_t(p) & Mask));
Chris@16 76 n = pointer(std::size_t(p) | (std::size_t(n) & Mask));
Chris@16 77 }
Chris@16 78
Chris@16 79 static std::size_t get_bits(pointer n)
Chris@16 80 { return (std::size_t(n) & Mask); }
Chris@16 81
Chris@16 82 static void set_bits(pointer &n, std::size_t c)
Chris@16 83 {
Chris@16 84 BOOST_INTRUSIVE_INVARIANT_ASSERT(c <= Mask);
Chris@16 85 n = pointer(std::size_t(get_pointer(n)) | c);
Chris@16 86 }
Chris@16 87 };
Chris@16 88
Chris@16 89 } //namespace intrusive
Chris@16 90 } //namespace boost
Chris@16 91
Chris@101 92 #include <boost/intrusive/detail/config_end.hpp>
Chris@101 93
Chris@16 94 #endif //BOOST_INTRUSIVE_POINTER_PLUS_BITS_HPP