Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74128 - in sandbox/mmap/boost/mmap: . mapping/posix mapping/win32
From: dsaritz_at_[hidden]
Date: 2011-08-29 10:34:04


Author: psiha
Date: 2011-08-29 10:34:03 EDT (Mon, 29 Aug 2011)
New Revision: 74128
URL: http://svn.boost.org/trac/boost/changeset/74128

Log:
Simplified and cleaned up the mapped_view module:
 - removed the detail::mapped_view_base class template (merged it into the mapped_view_ref class template)
 - removed the mapped_view_ref<>::basic_range() utility member function
 - there was no longer need for the Element const mapped_view_ref<> partial specialization so it was also removed
 - added the small detail::mapper utility class template used for partial specializations of the basic map and unmap functions.

Fixed the POSIX implementation to pass the offset argument to mmap().
Text files modified:
   sandbox/mmap/boost/mmap/mapped_view.hpp | 145 ++++++++++++++++++---------------------
   sandbox/mmap/boost/mmap/mapped_view.inl | 8 +-
   sandbox/mmap/boost/mmap/mapping/posix/mapping.inl | 71 ++++++++++--------
   sandbox/mmap/boost/mmap/mapping/win32/mapping.inl | 82 +++++++++++-----------
   4 files changed, 150 insertions(+), 156 deletions(-)

Modified: sandbox/mmap/boost/mmap/mapped_view.hpp
==============================================================================
--- sandbox/mmap/boost/mmap/mapped_view.hpp (original)
+++ sandbox/mmap/boost/mmap/mapped_view.hpp 2011-08-29 10:34:03 EDT (Mon, 29 Aug 2011)
@@ -17,10 +17,12 @@
 #define mapped_view_hpp__D9C84FF5_E506_4ECB_9778_61E036048D28
 #pragma once
 //------------------------------------------------------------------------------
-#include "handles/handle.hpp"
 #include "detail/impl_selection.hpp"
+#include "handles/handle.hpp"
+#include "mapping/mapping.hpp"
 
 #include "boost/assert.hpp"
+#include "boost/cstdint.hpp"
 #include "boost/noncopyable.hpp"
 #include "boost/range/iterator_range_core.hpp"
 //------------------------------------------------------------------------------
@@ -43,60 +45,59 @@
 namespace detail
 {
     template <typename Element, typename Impl>
- class mapped_view_base : public iterator_range<Element *>
+ struct mapper
     {
     public:
- typedef iterator_range<Element *> memory_range_t;
-
- public: // Factory methods.
- static void unmap( mapped_view_base const & );
-
- protected:
- mapped_view_base( iterator_range<Element *> const & mapped_range ) : iterator_range<Element *>( mapped_range ) {}
- mapped_view_base( Element * const p_begin, Element * const p_end ) : iterator_range<Element *>( p_begin, p_end ) {}
+ static mapped_view_reference<Element, Impl> map
+ (
+ mapping<Impl> const & source_mapping,
+ boost::uint64_t offset ,
+ std ::size_t desired_size
+ )
+ {
+ return make_typed_view( mapper<unsigned char, Impl>::map( source_mapping, offset, desired_size ) );
+ }
+
+ static void unmap( mapped_view_reference<Element, Impl> const & view )
+ {
+ mapper<unsigned char, Impl>::unmap( make_basic_view( view ) );
+ }
 
- static mapped_view_reference<unsigned char const, Impl>
+ private:
+ static mapped_view_reference<unsigned char, Impl>
         #ifdef BOOST_MSVC
             const &
         #endif
- make_basic_view( mapped_view_base<Element, Impl> const & );
+ make_basic_view( mapped_view_reference<Element, Impl> const & );
 
         static mapped_view_reference<Element, Impl>
         #ifdef BOOST_MSVC
             const &
         #endif
- make_typed_range( mapped_view_base<unsigned char, Impl> const & );
-
- private: // Hide mutable members
- void advance_begin();
- void advance_end ();
-
- void pop_front();
- void pop_back ();
+ make_typed_view( mapped_view_reference<unsigned char, Impl> const & );
     };
 
-
- template <typename Element, typename Impl>
- void mapped_view_base<Element, Impl>::unmap( mapped_view_base<Element, Impl> const & mapped_range )
+ template <typename Impl>
+ struct mapper<unsigned char, Impl>
     {
- mapped_view_base<unsigned char const, Impl>::unmap( make_basic_view( mapped_range ) );
- }
+ static mapped_view_reference<unsigned char, Impl> map
+ (
+ mapping<Impl> const & source_mapping,
+ boost::uint64_t offset ,
+ std ::size_t desired_size
+ );
+
+ static void unmap( mapped_view_reference<unsigned char, Impl> const & );
+ };
 } // namespace detail
 
 template <typename Impl> struct mapping;
 
 template <typename Element, typename Impl>
-class mapped_view_reference : public detail::mapped_view_base<Element, Impl>
+class mapped_view_reference : public iterator_range<Element *>
 {
 public:
- basic_memory_range_t basic_range() const
- {
- return basic_memory_range_t
- (
- static_cast<unsigned char *>( static_cast<void *>( this->begin() ) ),
- static_cast<unsigned char *>( static_cast<void *>( this->end () ) )
- );
- }
+ typedef iterator_range<Element *> memory_range_t;
 
 public: // Factory methods.
     static mapped_view_reference map
@@ -104,26 +105,32 @@
         mapping<Impl> const & source_mapping,
         boost::uint64_t offset = 0,
         std ::size_t desired_size = 0
- );
-
-private:
- template <typename Element_, typename Impl_> friend class detail::mapped_view_base;
+ )
+ {
+ BOOST_ASSERT_MSG
+ (
+ !boost::is_const<Element>::value || source_mapping.is_read_only(),
+ "Use const element mapped view for read only mappings."
+ );
+ return detail::mapper<Element, Impl>::map( source_mapping, offset, desired_size );
+ }
 
- mapped_view_reference( iterator_range<Element *> const & mapped_range ) : detail::mapped_view_base<Element, Impl>( mapped_range ) {}
- mapped_view_reference( Element * const p_begin, Element * const p_end ) : detail::mapped_view_base<Element, Impl>( p_begin, p_end ) {}
-};
+ static void unmap( mapped_view_reference const & view )
+ {
+ detail::mapper<Element, Impl>::unmap( view );
+ }
 
+private: template <typename Element_, typename Impl_> friend struct detail::mapper;
+ mapped_view_reference( iterator_range<Element *> const & mapped_range ) : iterator_range<Element *>( mapped_range ) {}
+ mapped_view_reference( Element * const p_begin, Element * const p_end ) : iterator_range<Element *>( p_begin, p_end ) {}
+
+private: // Hide mutable members
+ void advance_begin();
+ void advance_end ();
 
-//...zzz...
-//template <typename Element, typename Impl>
-//basic_read_only_memory_range_t mapped_view_reference<Element const, Impl>::basic_range() const
-//{
-// return basic_read_only_memory_range_t
-// (
-// static_cast<unsigned char const *>( static_cast<void const *>( this->begin() ) ),
-// static_cast<unsigned char const *>( static_cast<void const *>( this->end () ) )
-// );
-//}
+ void pop_front();
+ void pop_back ();
+};
 
 
 namespace detail
@@ -134,20 +141,20 @@
     // (14.07.2011.) (Domagoj Saric)
 
     template <typename Element, typename Impl>
- mapped_view_reference<unsigned char const, Impl>
+ mapped_view_reference<unsigned char, Impl>
     #ifdef BOOST_MSVC
         const &
     #endif
- mapped_view_base<Element, Impl>::make_basic_view( mapped_view_base<Element, Impl> const & range )
+ mapper<Element, Impl>::make_basic_view( mapped_view_reference<Element, Impl> const & range )
     {
         return
         #ifdef BOOST_MSVC
- reinterpret_cast<mapped_view_reference<unsigned char const, Impl> const &>( range );
+ reinterpret_cast<mapped_view_reference<unsigned char, Impl> const &>( range );
         #else // compiler might care about strict aliasing rules
- mapped_view_reference<unsigned char const, Impl>
+ mapped_view_reference<unsigned char, Impl>
             (
- static_cast<unsigned char const *>( static_cast<void const *>( range.begin() ) ),
- static_cast<unsigned char const *>( static_cast<void const *>( range.end () ) )
+ static_cast<unsigned char *>( const_cast<void *>( static_cast<void const *>( range.begin() ) ) ),
+ static_cast<unsigned char *>( const_cast<void *>( static_cast<void const *>( range.end () ) ) )
             );
         #endif // compiler
     }
@@ -158,8 +165,9 @@
     #ifdef BOOST_MSVC
         const &
     #endif
- mapped_view_base<Element, Impl>::make_typed_range( mapped_view_base<unsigned char, Impl> const & range )
+ mapper<Element, Impl>::make_typed_view( mapped_view_reference<unsigned char, Impl> const & range )
     {
+ //...zzz...add proper error handling...
         BOOST_ASSERT( reinterpret_cast<std::size_t>( range.begin() ) % sizeof( Element ) == 0 );
         BOOST_ASSERT( reinterpret_cast<std::size_t>( range.end () ) % sizeof( Element ) == 0 );
         BOOST_ASSERT( range.size () % sizeof( Element ) == 0 );
@@ -190,27 +198,6 @@
 template <> struct is_mappable<handle<win32>::native_handle_t > : mpl::true_ {};
 #endif // _WIN32
 
-template <typename Element, typename Impl>
-mapped_view_reference<Element, Impl> mapped_view_reference<Element, Impl>::map
-(
- mapping<Impl> const & source_mapping,
- boost::uint64_t offset ,
- std ::size_t desired_size
-)
-{
- BOOST_ASSERT_MSG( !boost::is_const<Element>::value || source_mapping.is_read_only(), "Use const element mapped view for read only mappings." );
- return mapped_view_reference<unsigned char, Impl>::map( source_mapping, offset, desired_size );
-}
-
-//...zzz...
-//template <unsigned char, typename Impl>
-//static mapped_view_reference<unsigned char, Impl> mapped_view_reference<unsigned char, Impl>::map
-//(
-// mapping<Impl> const & source_mapping,
-// boost::uint64_t offset = 0,
-// std ::size_t desired_size = 0
-//);
-
 
 template <typename Element, typename Impl = BOOST_MMAP_IMPL()>
 class mapped_view

Modified: sandbox/mmap/boost/mmap/mapped_view.inl
==============================================================================
--- sandbox/mmap/boost/mmap/mapped_view.inl (original)
+++ sandbox/mmap/boost/mmap/mapped_view.inl 2011-08-29 10:34:03 EDT (Mon, 29 Aug 2011)
@@ -64,8 +64,8 @@
                 mapping_flags::share_mode ::shared
             )
         ),
- desired_size,
- 0
+ 0,
+ desired_size
     );
 }
 
@@ -100,8 +100,8 @@
                 mapping_flags::share_mode ::shared
             )
         ),
- get_size( file_handle.get() ),
- 0
+ 0,
+ get_size( file_handle.get() )
     );
 }
 

Modified: sandbox/mmap/boost/mmap/mapping/posix/mapping.inl
==============================================================================
--- sandbox/mmap/boost/mmap/mapping/posix/mapping.inl (original)
+++ sandbox/mmap/boost/mmap/mapping/posix/mapping.inl 2011-08-29 10:34:03 EDT (Mon, 29 Aug 2011)
@@ -24,45 +24,52 @@
 {
 //------------------------------------------------------------------------------
 
-template <> BOOST_IMPL_INLINE
-mapped_view_reference<unsigned char, posix> mapped_view_reference<unsigned char, posix>::map
-(
- mapping<posix> const & source_mapping,
- boost::uint64_t const offset ,
- std ::size_t const desired_size
-)
+template <>
+struct detail::mapper<unsigned char, posix>
 {
- iterator const view_start
+ static mapped_view_reference<unsigned char, posix> map
     (
- static_cast<iterator>
+ mapping<posix> const & source_mapping,
+ boost::uint64_t offset ,
+ std ::size_t desired_size
+ )
+ {
+ typedef mapped_view_reference<unsigned char, posix>::iterator iterator;
+
+ iterator const view_start
         (
- ::mmap
+ static_cast<iterator>
             (
- 0,
- desired_size,
- source_mapping.view_mapping_flags.protection,
- source_mapping.view_mapping_flags.flags,
- source_mapping,
- 0
+ ::mmap
+ (
+ 0,
+ desired_size,
+ source_mapping.view_mapping_flags.protection,
+ source_mapping.view_mapping_flags.flags,
+ source_mapping,
+ offset
+ )
             )
- )
- );
-
- return mapped_view_reference<unsigned char>
- (
- view_start,
- ( view_start != MAP_FAILED )
- ? view_start + desired_size
- : view_start
- );
-}
+ );
 
+ return mapped_view_reference<unsigned char>
+ (
+ view_start,
+ ( view_start != MAP_FAILED )
+ ? view_start + desired_size
+ : view_start
+ );
+ }
 
-template <> BOOST_IMPL_INLINE
-void detail::mapped_view_base<unsigned char const, posix>::unmap( detail::mapped_view_base<unsigned char const, posix> const & mapped_range )
-{
- BOOST_VERIFY( ( ::munmap( const_cast<unsigned char *>( mapped_range.begin() ), mapped_range.size() ) == 0 ) || mapped_range.empty() );
-}
+ static inline void unmap( mapped_view_reference<unsigned char, posix> const & view )
+ {
+ BOOST_VERIFY
+ (
+ ( ::munmap( view.begin(), view.size() ) == 0 ) ||
+ view.empty()
+ );
+ }
+};
 
 //------------------------------------------------------------------------------
 } // mmap

Modified: sandbox/mmap/boost/mmap/mapping/win32/mapping.inl
==============================================================================
--- sandbox/mmap/boost/mmap/mapping/win32/mapping.inl (original)
+++ sandbox/mmap/boost/mmap/mapping/win32/mapping.inl 2011-08-29 10:34:03 EDT (Mon, 29 Aug 2011)
@@ -25,55 +25,55 @@
 //------------------------------------------------------------------------------
 
 template <>
-BOOST_IMPL_INLINE
-mapped_view_reference<unsigned char, win32> mapped_view_reference<unsigned char, win32>::map
-(
- mapping<win32> const & source_mapping,
- boost::uint64_t const offset ,
- std ::size_t const desired_size
-)
+struct detail::mapper<unsigned char, win32>
 {
- // Implementation note:
- // Mapped views hold internal references to the following handles so we do
- // not need to hold/store them ourselves:
- // http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx
- // (26.03.2010.) (Domagoj Saric)
+ static mapped_view_reference<unsigned char, win32> map
+ (
+ mapping<win32> const & source_mapping,
+ boost::uint64_t offset ,
+ std ::size_t desired_size
+ )
+ {
+ // Implementation note:
+ // Mapped views hold internal references to the following handles so we do
+ // not need to hold/store them ourselves:
+ // http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx
+ // (26.03.2010.) (Domagoj Saric)
 
- typedef mapped_view_reference<unsigned char, win32>::iterator iterator_t;
+ typedef mapped_view_reference<unsigned char, win32>::iterator iterator;
 
- ULARGE_INTEGER large_integer;
- large_integer.QuadPart = offset;
+ ULARGE_INTEGER large_integer;
+ large_integer.QuadPart = offset;
 
- iterator_t const view_start
- (
- static_cast<iterator_t>
+ iterator const view_start
         (
- ::MapViewOfFile
+ static_cast<iterator>
             (
- source_mapping.get(),
- source_mapping.view_mapping_flags,
- large_integer.HighPart,
- large_integer.LowPart,
- desired_size
+ ::MapViewOfFile
+ (
+ source_mapping.get(),
+ source_mapping.view_mapping_flags,
+ large_integer.HighPart,
+ large_integer.LowPart,
+ desired_size
+ )
             )
- )
- );
-
- return mapped_view_reference<unsigned char>
- (
- view_start,
- view_start
- ? view_start + desired_size
- : view_start
- );
-}
+ );
 
-
-template <> BOOST_IMPL_INLINE
-void detail::mapped_view_base<unsigned char const, win32>::unmap( detail::mapped_view_base<unsigned char const, win32> const & mapped_range )
-{
- BOOST_VERIFY( ::UnmapViewOfFile( mapped_range.begin() ) || mapped_range.empty() );
-}
+ return mapped_view_reference<unsigned char>
+ (
+ view_start,
+ view_start
+ ? view_start + desired_size
+ : view_start
+ );
+ }
+
+ static void unmap( mapped_view_reference<unsigned char, win32> const & view )
+ {
+ BOOST_VERIFY( ::UnmapViewOfFile( view.begin() ) || view.empty() );
+ }
+};
 
 //------------------------------------------------------------------------------
 } // mmap


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk