summaryrefslogtreecommitdiff
path: root/boost/interprocess/offset_ptr.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/interprocess/offset_ptr.hpp')
-rw-r--r--boost/interprocess/offset_ptr.hpp473
1 files changed, 348 insertions, 125 deletions
diff --git a/boost/interprocess/offset_ptr.hpp b/boost/interprocess/offset_ptr.hpp
index ac8da2c292..5f523ce521 100644
--- a/boost/interprocess/offset_ptr.hpp
+++ b/boost/interprocess/offset_ptr.hpp
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Ion Gaztanaga 2005-2011. Distributed under the Boost
+// (C) Copyright Ion Gaztanaga 2005-2014. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
@@ -11,7 +11,7 @@
#ifndef BOOST_INTERPROCESS_OFFSET_PTR_HPP
#define BOOST_INTERPROCESS_OFFSET_PTR_HPP
-#if (defined _MSC_VER) && (_MSC_VER >= 1200)
+#if defined(_MSC_VER)
# pragma once
#endif
@@ -26,6 +26,7 @@
#include <ostream>
#include <istream>
#include <iterator>
+#include <iostream>
#include <boost/aligned_storage.hpp>
#include <boost/type_traits/alignment_of.hpp>
@@ -35,6 +36,8 @@
namespace boost {
+#if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
+
//Predeclarations
template <class T>
struct has_trivial_constructor;
@@ -42,22 +45,209 @@ struct has_trivial_constructor;
template <class T>
struct has_trivial_destructor;
+#endif //#if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
+
namespace interprocess {
+#if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
+namespace ipcdetail {
+
+ template<class OffsetType, std::size_t OffsetAlignment>
+ union offset_ptr_internal
+ {
+ explicit offset_ptr_internal(OffsetType off)
+ : m_offset(off)
+ {}
+ OffsetType m_offset; //Distance between this object and pointee address
+ typename ::boost::aligned_storage
+ < sizeof(OffsetType)
+ , (OffsetAlignment == offset_type_alignment) ?
+ ::boost::alignment_of<OffsetType>::value : OffsetAlignment
+ >::type alignment_helper;
+ };
+
+ //Note: using the address of a local variable to point to another address
+ //is not standard conforming and this can be optimized-away by the compiler.
+ //Non-inlining is a method to remain illegal but correct
+
+ //Undef BOOST_INTERPROCESS_OFFSET_PTR_INLINE_XXX if your compiler can inline
+ //this code without breaking the library
+
+ ////////////////////////////////////////////////////////////////////////
+ //
+ // offset_ptr_to_raw_pointer
+ //
+ ////////////////////////////////////////////////////////////////////////
+ #define BOOST_INTERPROCESS_OFFSET_PTR_INLINE_TO_PTR
+ #if defined(_MSC_VER) && (_MSC_VER >= 1800) && (defined(_M_AMD64) || defined(_M_X64))
+ //Visual 2013 x64 optimizes more than we desire, so disable branchless option
+ #else
+ #define BOOST_INTERPROCESS_OFFSET_PTR_BRANCHLESS_TO_PTR
+ #endif
+ template<int Dummy>
+ #ifndef BOOST_INTERPROCESS_OFFSET_PTR_INLINE_TO_PTR
+ BOOST_INTERPROCESS_NEVER_INLINE
+ #elif defined(NDEBUG)
+ inline
+ #endif
+ void * offset_ptr_to_raw_pointer(const volatile void *this_ptr, std::size_t offset)
+ {
+ typedef pointer_size_t_caster<void*> caster_t;
+ #ifndef BOOST_INTERPROCESS_OFFSET_PTR_BRANCHLESS_TO_PTR
+ if(offset == 1){
+ return 0;
+ }
+ else{
+ const caster_t caster((void*)this_ptr);
+ return caster_t(caster.size() + offset).pointer();
+ }
+ #else
+ const caster_t caster((void*)this_ptr);
+ std::size_t target_offset = caster.size() + offset;
+ std::size_t mask = -std::size_t(offset != 1);
+ target_offset &= mask;
+ return caster_t(target_offset).pointer();
+ #endif
+ }
+
+ #ifdef BOOST_INTERPROCESS_OFFSET_PTR_INLINE_TO_PTR
+ #undef BOOST_INTERPROCESS_OFFSET_PTR_INLINE_TO_PTR
+ #endif
+ #ifdef BOOST_INTERPROCESS_OFFSET_PTR_BRANCHLESS_TO_PTR
+ #undef BOOST_INTERPROCESS_OFFSET_PTR_BRANCHLESS_TO_PTR
+ #endif
+
+ ////////////////////////////////////////////////////////////////////////
+ //
+ // offset_ptr_to_offset
+ //
+ ////////////////////////////////////////////////////////////////////////
+ #define BOOST_INTERPROCESS_OFFSET_PTR_INLINE_TO_OFF
+ //Branchless seems slower in x86
+ #define BOOST_INTERPROCESS_OFFSET_PTR_BRANCHLESS_TO_OFF
+
+ template<int Dummy>
+ #ifndef BOOST_INTERPROCESS_OFFSET_PTR_INLINE_TO_OFF
+ BOOST_INTERPROCESS_NEVER_INLINE
+ #elif defined(NDEBUG)
+ inline
+ #endif
+ std::size_t offset_ptr_to_offset(const volatile void *ptr, const volatile void *this_ptr)
+ {
+ typedef pointer_size_t_caster<void*> caster_t;
+ #ifndef BOOST_INTERPROCESS_OFFSET_PTR_BRANCHLESS_TO_OFF
+ //offset == 1 && ptr != 0 is not legal for this pointer
+ if(!ptr){
+ return 1;
+ }
+ else{
+ const caster_t this_caster((void*)this_ptr);
+ const caster_t ptr_caster((void*)ptr);
+ std::size_t offset = ptr_caster.size() - this_caster.size();
+ BOOST_ASSERT(offset != 1);
+ return offset;
+ }
+ #else
+ const caster_t this_caster((void*)this_ptr);
+ const caster_t ptr_caster((void*)ptr);
+ //std::size_t other = -std::size_t(ptr != 0);
+ //std::size_t offset = (ptr_caster.size() - this_caster.size()) & other;
+ //return offset + !other;
+ //
+ std::size_t offset = (ptr_caster.size() - this_caster.size() - 1) & -std::size_t(ptr != 0);
+ return ++offset;
+ #endif
+ }
+
+ #ifdef BOOST_INTERPROCESS_OFFSET_PTR_INLINE_TO_OFF
+ #undef BOOST_INTERPROCESS_OFFSET_PTR_INLINE_TO_OFF
+ #endif
+ #ifdef BOOST_INTERPROCESS_OFFSET_PTR_BRANCHLESS_TO_OFF
+ #undef BOOST_INTERPROCESS_OFFSET_PTR_BRANCHLESS_TO_OFF
+ #endif
+
+ ////////////////////////////////////////////////////////////////////////
+ //
+ // offset_ptr_to_offset_from_other
+ //
+ ////////////////////////////////////////////////////////////////////////
+ #define BOOST_INTERPROCESS_OFFSET_PTR_INLINE_TO_OFF_FROM_OTHER
+ //Branchless seems slower in x86
+ #define BOOST_INTERPROCESS_OFFSET_PTR_BRANCHLESS_TO_OFF_FROM_OTHER
+
+ template<int Dummy>
+ #ifndef BOOST_INTERPROCESS_OFFSET_PTR_INLINE_TO_OFF_FROM_OTHER
+ BOOST_INTERPROCESS_NEVER_INLINE
+ #elif defined(NDEBUG)
+ inline
+ #endif
+ std::size_t offset_ptr_to_offset_from_other
+ (const volatile void *this_ptr, const volatile void *other_ptr, std::size_t other_offset)
+ {
+ typedef pointer_size_t_caster<void*> caster_t;
+ #ifndef BOOST_INTERPROCESS_OFFSET_PTR_BRANCHLESS_TO_OFF_FROM_OTHER
+ if(other_offset == 1){
+ return 1;
+ }
+ else{
+ const caster_t this_caster((void*)this_ptr);
+ const caster_t other_caster((void*)other_ptr);
+ std::size_t offset = other_caster.size() - this_caster.size() + other_offset;
+ BOOST_ASSERT(offset != 1);
+ return offset;
+ }
+ #else
+ const caster_t this_caster((void*)this_ptr);
+ const caster_t other_caster((void*)other_ptr);
+ return ((other_caster.size() - this_caster.size()) & -std::size_t(other_offset != 1)) + other_offset;
+ #endif
+ }
+
+ #ifdef BOOST_INTERPROCESS_OFFSET_PTR_INLINE_TO_OFF_FROM_OTHER
+ #undef BOOST_INTERPROCESS_OFFSET_PTR_INLINE_TO_OFF_FROM_OTHER
+ #endif
+ #ifdef BOOST_INTERPROCESS_OFFSET_PTR_BRANCHLESS_TO_OFF_FROM_OTHER
+ #undef BOOST_INTERPROCESS_OFFSET_PTR_BRANCHLESS_TO_OFF_FROM_OTHER
+ #endif
+
+ ////////////////////////////////////////////////////////////////////////
+ //
+ // Let's assume cast to void and cv cast don't change any target address
+ //
+ ////////////////////////////////////////////////////////////////////////
+ template<class From, class To>
+ struct offset_ptr_maintains_address
+ {
+ static const bool value = ipcdetail::is_cv_same<From, To>::value
+ || ipcdetail::is_cv_same<void, To>::value;
+ };
+
+} //namespace ipcdetail {
+#endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
+
//!A smart pointer that stores the offset between between the pointer and the
//!the object it points. This allows offset allows special properties, since
//!the pointer is independent from the address address of the pointee, if the
//!pointer and the pointee are still separated by the same offset. This feature
//!converts offset_ptr in a smart pointer that can be placed in shared memory and
//!memory mapped files mapped in different addresses in every process.
+//!
+//! \tparam PointedType The type of the pointee.
+//! \tparam DifferenceType A signed integer type that can represent the arithmetic operations on the pointer
+//! \tparam OffsetType An unsigned integer type that can represent the
+//! distance between two pointers reinterpret_cast-ed as unsigned integers. In general this type
+//! should be at least of the same size of std::uintptr_t. In some systems it's possible to communicate
+//! between 32 and 64 bit processes using 64 bit offsets.
+//! \tparam OffsetAlignment Alignment of the OffsetType stored inside. In some systems might be necessary
+//! to align it to 64 bits in order to communicate 32 and 64 bit processes using 64 bit offsets.
template <class PointedType, class DifferenceType, class OffsetType, std::size_t OffsetAlignment>
class offset_ptr
{
- /// @cond
+ #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
typedef offset_ptr<PointedType, DifferenceType, OffsetType, OffsetAlignment> self_t;
void unspecified_bool_type_func() const {}
typedef void (self_t::*unspecified_bool_type)() const;
- /// @endcond
+ #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
public:
typedef PointedType element_type;
@@ -74,69 +264,111 @@ class offset_ptr
public: //Public Functions
+ //!Default constructor (null pointer).
+ //!Never throws.
+ offset_ptr()
+ : internal(1)
+ {}
+
//!Constructor from raw pointer (allows "0" pointer conversion).
//!Never throws.
- offset_ptr(pointer ptr = 0) { this->set_offset(ptr); }
+ offset_ptr(pointer ptr)
+ : internal(static_cast<OffsetType>(ipcdetail::offset_ptr_to_offset<0>(ptr, this)))
+ {}
//!Constructor from other pointer.
//!Never throws.
template <class T>
offset_ptr( T *ptr
, typename ipcdetail::enable_if< ipcdetail::is_convertible<T*, PointedType*> >::type * = 0)
- { this->set_offset(static_cast<PointedType*>(ptr)); }
+ : internal(static_cast<OffsetType>
+ (ipcdetail::offset_ptr_to_offset<0>(static_cast<PointedType*>(ptr), this)))
+ {}
//!Constructor from other offset_ptr
//!Never throws.
offset_ptr(const offset_ptr& ptr)
- { this->set_offset(ptr.get()); }
+ : internal(static_cast<OffsetType>
+ (ipcdetail::offset_ptr_to_offset_from_other<0>(this, &ptr, ptr.internal.m_offset)))
+ {}
//!Constructor from other offset_ptr. If pointers of pointee types are
//!convertible, offset_ptrs will be convertibles. Never throws.
- template<class T2, class P2, class O2, std::size_t A2>
- offset_ptr( const offset_ptr<T2, P2, O2, A2> &ptr
- , typename ipcdetail::enable_if< ipcdetail::is_convertible<T2*, PointedType*> >::type * = 0)
- { this->set_offset(static_cast<PointedType*>(ptr.get())); }
+ template<class T2>
+ offset_ptr( const offset_ptr<T2, DifferenceType, OffsetType, OffsetAlignment> &ptr
+ #ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
+ , typename ipcdetail::enable_if_c< ipcdetail::is_convertible<T2*, PointedType*>::value
+ && ipcdetail::offset_ptr_maintains_address<T2, PointedType>::value
+ >::type * = 0
+ #endif
+ )
+ : internal(static_cast<OffsetType>
+ (ipcdetail::offset_ptr_to_offset_from_other<0>(this, &ptr, ptr.get_offset())))
+ {}
+
+ #ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
+
+ //!Constructor from other offset_ptr. If pointers of pointee types are
+ //!convertible, offset_ptrs will be convertibles. Never throws.
+ template<class T2>
+ offset_ptr( const offset_ptr<T2, DifferenceType, OffsetType, OffsetAlignment> &ptr
+ , typename ipcdetail::enable_if_c< ipcdetail::is_convertible<T2*, PointedType*>::value
+ && !ipcdetail::offset_ptr_maintains_address<T2, PointedType>::value
+ >::type * = 0)
+ : internal(static_cast<OffsetType>
+ (ipcdetail::offset_ptr_to_offset<0>(static_cast<PointedType*>(ptr.get()), this)))
+ {}
+
+ #endif
//!Emulates static_cast operator.
//!Never throws.
template<class T2, class P2, class O2, std::size_t A2>
offset_ptr(const offset_ptr<T2, P2, O2, A2> & r, ipcdetail::static_cast_tag)
- { this->set_offset(static_cast<PointedType*>(r.get())); }
+ : internal(static_cast<OffsetType>
+ (ipcdetail::offset_ptr_to_offset<0>(static_cast<PointedType*>(r.get()), this)))
+ {}
//!Emulates const_cast operator.
//!Never throws.
template<class T2, class P2, class O2, std::size_t A2>
offset_ptr(const offset_ptr<T2, P2, O2, A2> & r, ipcdetail::const_cast_tag)
- { this->set_offset(const_cast<PointedType*>(r.get())); }
+ : internal(static_cast<OffsetType>
+ (ipcdetail::offset_ptr_to_offset<0>(const_cast<PointedType*>(r.get()), this)))
+ {}
//!Emulates dynamic_cast operator.
//!Never throws.
template<class T2, class P2, class O2, std::size_t A2>
offset_ptr(const offset_ptr<T2, P2, O2, A2> & r, ipcdetail::dynamic_cast_tag)
- { this->set_offset(dynamic_cast<PointedType*>(r.get())); }
+ : internal(static_cast<OffsetType>
+ (ipcdetail::offset_ptr_to_offset<0>(dynamic_cast<PointedType*>(r.get()), this)))
+ {}
//!Emulates reinterpret_cast operator.
//!Never throws.
template<class T2, class P2, class O2, std::size_t A2>
offset_ptr(const offset_ptr<T2, P2, O2, A2> & r, ipcdetail::reinterpret_cast_tag)
- { this->set_offset(reinterpret_cast<PointedType*>(r.get())); }
+ : internal(static_cast<OffsetType>
+ (ipcdetail::offset_ptr_to_offset<0>(reinterpret_cast<PointedType*>(r.get()), this)))
+ {}
//!Obtains raw pointer from offset.
//!Never throws.
- pointer get()const
- { return this->to_raw_pointer(); }
+ pointer get() const
+ { return (pointer)ipcdetail::offset_ptr_to_raw_pointer<0>(this, this->internal.m_offset); }
offset_type get_offset() const
- { return internal.m_offset; }
+ { return this->internal.m_offset; }
//!Pointer-like -> operator. It can return 0 pointer.
//!Never throws.
- pointer operator->() const
+ pointer operator->() const
{ return this->get(); }
//!Dereferencing operator, if it is a null offset_ptr behavior
//! is undefined. Never throws.
- reference operator* () const
+ reference operator* () const
{
pointer p = this->get();
reference r = *p;
@@ -145,26 +377,56 @@ class offset_ptr
//!Indexing operator.
//!Never throws.
- template<class T>
- reference operator[](T idx) const
+ reference operator[](difference_type idx) const
{ return this->get()[idx]; }
//!Assignment from pointer (saves extra conversion).
//!Never throws.
offset_ptr& operator= (pointer from)
- { this->set_offset(from); return *this; }
+ {
+ this->internal.m_offset =
+ static_cast<OffsetType>(ipcdetail::offset_ptr_to_offset<0>(from, this));
+ return *this;
+ }
//!Assignment from other offset_ptr.
//!Never throws.
- offset_ptr& operator= (const offset_ptr & pt)
- { pointer p(pt.get()); (void)p; this->set_offset(p); return *this; }
+ offset_ptr& operator= (const offset_ptr & ptr)
+ {
+ this->internal.m_offset =
+ static_cast<OffsetType>(ipcdetail::offset_ptr_to_offset_from_other<0>(this, &ptr, ptr.internal.m_offset));
+ return *this;
+ }
//!Assignment from related offset_ptr. If pointers of pointee types
//! are assignable, offset_ptrs will be assignable. Never throws.
- template<class T2, class P2, class O2, std::size_t A2>
- typename ipcdetail::enable_if<ipcdetail::is_convertible<T2*, PointedType*>, offset_ptr&>::type
- operator= (const offset_ptr<T2, P2, O2, A2> & ptr)
- { this->set_offset(static_cast<PointedType*>(ptr.get())); return *this; }
+ template<class T2>
+ #ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
+ typename ipcdetail::enable_if_c< ipcdetail::is_convertible<T2*, PointedType*>::value
+ && ipcdetail::offset_ptr_maintains_address<T2, PointedType>::value
+ , offset_ptr&>::type
+ #else
+ offset_ptr&
+ #endif
+ operator= (const offset_ptr<T2, DifferenceType, OffsetType, OffsetAlignment> &ptr)
+ {
+ this->internal.m_offset =
+ static_cast<OffsetType>(ipcdetail::offset_ptr_to_offset_from_other<0>(this, &ptr, ptr.get_offset()));
+ return *this;
+ }
+
+ #ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
+ template<class T2>
+ typename ipcdetail::enable_if_c<ipcdetail::is_convertible<T2*, PointedType*>::value
+ && !ipcdetail::offset_ptr_maintains_address<T2, PointedType>::value
+ , offset_ptr&>::type
+ operator= (const offset_ptr<T2, DifferenceType, OffsetType, OffsetAlignment> &ptr)
+ {
+ this->internal.m_offset =
+ static_cast<OffsetType>(ipcdetail::offset_ptr_to_offset<0>(static_cast<PointedType*>(ptr.get()), this));
+ return *this;
+ }
+ #endif
//!offset_ptr += difference_type.
//!Never throws.
@@ -173,8 +435,7 @@ class offset_ptr
//!offset_ptr -= difference_type.
//!Never throws.
- template<class T>
- offset_ptr &operator-= (T offset)
+ offset_ptr &operator-= (difference_type offset)
{ this->dec_offset(offset * sizeof (PointedType)); return *this; }
//!++offset_ptr.
@@ -185,7 +446,11 @@ class offset_ptr
//!offset_ptr++.
//!Never throws.
offset_ptr operator++ (int)
- { offset_ptr temp(*this); ++*this; return temp; }
+ {
+ offset_ptr tmp(*this);
+ this->inc_offset(sizeof (PointedType));
+ return tmp;
+ }
//!--offset_ptr.
//!Never throws.
@@ -195,17 +460,21 @@ class offset_ptr
//!offset_ptr--.
//!Never throws.
offset_ptr operator-- (int)
- { offset_ptr temp(*this); --*this; return temp; }
+ {
+ offset_ptr tmp(*this);
+ this->dec_offset(sizeof (PointedType));
+ return tmp;
+ }
//!safe bool conversion operator.
//!Never throws.
- operator unspecified_bool_type() const
- { return this->get()? &self_t::unspecified_bool_type_func : 0; }
+ operator unspecified_bool_type() const
+ { return this->internal.m_offset != 1? &self_t::unspecified_bool_type_func : 0; }
//!Not operator. Not needed in theory, but improves portability.
//!Never throws
bool operator! () const
- { return this->get() == 0; }
+ { return this->internal.m_offset == 1; }
//!Compatibility with pointer_traits
//!
@@ -220,23 +489,23 @@ class offset_ptr
//!difference_type + offset_ptr
//!operation
- friend offset_ptr operator+(difference_type diff, const offset_ptr& right)
- { offset_ptr tmp(right); tmp += diff; return tmp; }
+ friend offset_ptr operator+(difference_type diff, offset_ptr right)
+ { right += diff; return right; }
//!offset_ptr + difference_type
//!operation
- friend offset_ptr operator+(const offset_ptr& left, difference_type diff)
- { offset_ptr tmp(left); tmp += diff; return tmp; }
+ friend offset_ptr operator+(offset_ptr left, difference_type diff)
+ { left += diff; return left; }
//!offset_ptr - diff
//!operation
- friend offset_ptr operator-(const offset_ptr &left, difference_type diff)
- { offset_ptr tmp(left); tmp -= diff; return tmp; }
+ friend offset_ptr operator-(offset_ptr left, difference_type diff)
+ { left -= diff; return left; }
//!offset_ptr - diff
//!operation
- friend offset_ptr operator-(difference_type diff, const offset_ptr &right)
- { offset_ptr tmp(right); tmp -= diff; return tmp; }
+ friend offset_ptr operator-(difference_type diff, offset_ptr right)
+ { right -= diff; return right; }
//!offset_ptr - offset_ptr
//!operation
@@ -308,65 +577,15 @@ class offset_ptr
}
private:
- /// @cond
-
- //Note: using the address of a local variable to point to another address
- //is not standard conforming and this can be optimized-away by the compiler.
- //Non-inlining is a method to remain illegal and correct
- #if defined(_MSC_VER)
- __declspec(noinline) //this workaround is needed for MSVC compilers
- #elif defined (__GNUC__)//this workaround is needed for GCC
- __attribute__((__noinline__))
- #endif
- void set_offset(const PointedType *ptr)
- {
- #if defined (__GNUC__)
- //asm(""); //Prevents the function to be optimized-away (provokes an special "side-effect")
- #endif
- //offset == 1 && ptr != 0 is not legal for this pointer
- if(!ptr){
- internal.m_offset = 1;
- }
- else{
- internal.m_offset = (OffsetType)((const char*)ptr - (const char*)(this));
- BOOST_ASSERT(internal.m_offset != 1);
- }
- }
-
- #if defined(_MSC_VER) && (_MSC_VER >= 1400)
- __declspec(noinline)
- #elif defined (__GNUC__)
- __attribute__((__noinline__))
- #endif
- PointedType * to_raw_pointer() const
- {
- #if defined (__GNUC__)
- //asm(""); //Prevents the function to be optimized-away (provokes an special "side-effect")
- #endif
- return static_cast<PointedType *>(
- static_cast<void*>(
- (internal.m_offset == 1) ?
- 0 :
- (const_cast<char*>(reinterpret_cast<const char*>(this)) + internal.m_offset)
- )
- );
- }
-
+ #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
void inc_offset(DifferenceType bytes)
{ internal.m_offset += bytes; }
void dec_offset(DifferenceType bytes)
{ internal.m_offset -= bytes; }
- union internal_type{
- OffsetType m_offset; //Distance between this object and pointee address
- typename ::boost::aligned_storage
- < sizeof(OffsetType)
- , (OffsetAlignment == offset_type_alignment) ?
- ::boost::alignment_of<OffsetType>::value : OffsetAlignment
- >::type alignment_helper;
- } internal;
- /// @endcond
+ ipcdetail::offset_ptr_internal<OffsetType, OffsetAlignment> internal;
+ #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
};
//!operator<<
@@ -387,41 +606,41 @@ inline std::basic_istream<E, T> & operator>>
template<class T1, class P1, class O1, std::size_t A1, class T2, class P2, class O2, std::size_t A2>
inline boost::interprocess::offset_ptr<T1, P1, O1, A1>
static_pointer_cast(const boost::interprocess::offset_ptr<T2, P2, O2, A2> & r)
-{
+{
return boost::interprocess::offset_ptr<T1, P1, O1, A1>
- (r, boost::interprocess::ipcdetail::static_cast_tag());
+ (r, boost::interprocess::ipcdetail::static_cast_tag());
}
//!Simulation of const_cast between pointers. Never throws.
template<class T1, class P1, class O1, std::size_t A1, class T2, class P2, class O2, std::size_t A2>
inline boost::interprocess::offset_ptr<T1, P1, O1, A1>
const_pointer_cast(const boost::interprocess::offset_ptr<T2, P2, O2, A2> & r)
-{
+{
return boost::interprocess::offset_ptr<T1, P1, O1, A1>
- (r, boost::interprocess::ipcdetail::const_cast_tag());
+ (r, boost::interprocess::ipcdetail::const_cast_tag());
}
//!Simulation of dynamic_cast between pointers. Never throws.
template<class T1, class P1, class O1, std::size_t A1, class T2, class P2, class O2, std::size_t A2>
inline boost::interprocess::offset_ptr<T1, P1, O1, A1>
dynamic_pointer_cast(const boost::interprocess::offset_ptr<T2, P2, O2, A2> & r)
-{
+{
return boost::interprocess::offset_ptr<T1, P1, O1, A1>
- (r, boost::interprocess::ipcdetail::dynamic_cast_tag());
+ (r, boost::interprocess::ipcdetail::dynamic_cast_tag());
}
//!Simulation of reinterpret_cast between pointers. Never throws.
template<class T1, class P1, class O1, std::size_t A1, class T2, class P2, class O2, std::size_t A2>
inline boost::interprocess::offset_ptr<T1, P1, O1, A1>
reinterpret_pointer_cast(const boost::interprocess::offset_ptr<T2, P2, O2, A2> & r)
-{
+{
return boost::interprocess::offset_ptr<T1, P1, O1, A1>
- (r, boost::interprocess::ipcdetail::reinterpret_cast_tag());
+ (r, boost::interprocess::ipcdetail::reinterpret_cast_tag());
}
} //namespace interprocess {
-/// @cond
+#if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
//!has_trivial_constructor<> == true_type specialization for optimizations
template <class T, class P, class O, std::size_t A>
@@ -437,22 +656,22 @@ struct has_trivial_destructor< boost::interprocess::offset_ptr<T, P, O, A> >
static const bool value = true;
};
-//#if !defined(_MSC_VER) || (_MSC_VER >= 1400)
+
namespace interprocess {
-//#endif
+
//!to_raw_pointer() enables boost::mem_fn to recognize offset_ptr.
//!Never throws.
template <class T, class P, class O, std::size_t A>
inline T * to_raw_pointer(boost::interprocess::offset_ptr<T, P, O, A> const & p)
-{ return p.get(); }
-//#if !defined(_MSC_VER) || (_MSC_VER >= 1400)
+{ return ipcdetail::to_raw_pointer(p); }
+
} //namespace interprocess
-//#endif
-/// @endcond
+
+#endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
} //namespace boost {
-/// @cond
+#if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
namespace boost{
@@ -479,28 +698,34 @@ struct pointer_plus_bits;
template<class T, class P, class O, std::size_t A, std::size_t NumBits>
struct pointer_plus_bits<boost::interprocess::offset_ptr<T, P, O, A>, NumBits>
{
- typedef boost::interprocess::offset_ptr<T, P, O, A> pointer;
+ typedef boost::interprocess::offset_ptr<T, P, O, A> pointer;
+ typedef ::boost::interprocess::pointer_size_t_caster<T*> caster_t;
//Bits are stored in the lower bits of the pointer except the LSB,
//because this bit is used to represent the null pointer.
- static const std::size_t Mask = ((std::size_t(1) << NumBits)-1)<<1u;
+ static const std::size_t Mask = ((std::size_t(1) << NumBits) - 1) << 1u;
static pointer get_pointer(const pointer &n)
- { return reinterpret_cast<T*>(std::size_t(n.get()) & ~std::size_t(Mask)); }
+ {
+ caster_t caster(n.get());
+ return pointer(caster_t(caster.size() & ~Mask).pointer());
+ }
- static void set_pointer(pointer &n, pointer p)
+ static void set_pointer(pointer &n, const pointer &p)
{
- std::size_t pint = std::size_t(p.get());
- BOOST_ASSERT(0 == (std::size_t(pint) & Mask));
- n = reinterpret_cast<T*>(pint | (std::size_t(n.get()) & std::size_t(Mask)));
+ caster_t n_caster(n.get());
+ caster_t p_caster(p.get());
+ BOOST_ASSERT(0 == (p_caster.size() & Mask));
+ n = caster_t(p_caster.size() | (n_caster.size() & Mask)).pointer();
}
static std::size_t get_bits(const pointer &n)
- { return(std::size_t(n.get()) & std::size_t(Mask)) >> 1u; }
+ { return (caster_t(n.get()).size() & Mask) >> 1u; }
static void set_bits(pointer &n, std::size_t b)
{
BOOST_ASSERT(b < (std::size_t(1) << NumBits));
- n = reinterpret_cast<T*>(std::size_t(get_pointer(n).get()) | (b << 1u));
+ caster_t n_caster(n.get());
+ n = caster_t((n_caster.size() & ~Mask) | (b << 1u)).pointer();
}
};
@@ -510,8 +735,6 @@ struct pointer_plus_bits<boost::interprocess::offset_ptr<T, P, O, A>, NumBits>
template<class T, class U>
struct pointer_to_other;
-
-
//Backwards compatibility with pointer_to_other
template <class PointedType, class DifferenceType, class OffsetType, std::size_t OffsetAlignment, class U>
struct pointer_to_other
@@ -521,7 +744,7 @@ struct pointer_to_other
};
} //namespace boost{
-/// @endcond
+#endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
#include <boost/interprocess/detail/config_end.hpp>