Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74138 - in sandbox/mmap/boost/mmap: . mappble_objects/file
From: dsaritz_at_[hidden]
Date: 2011-08-29 12:11:23


Author: psiha
Date: 2011-08-29 12:11:22 EDT (Mon, 29 Aug 2011)
New Revision: 74138
URL: http://svn.boost.org/trac/boost/changeset/74138

Log:
Extracted the map_file() and map_read_only_file() utility functions into a separate module.
Added:
   sandbox/mmap/boost/mmap/mappble_objects/file/utility.hpp
      - copied, changed from r74131, /sandbox/mmap/boost/mmap/mapped_view.hpp
   sandbox/mmap/boost/mmap/mappble_objects/file/utility.inl
      - copied, changed from r74128, /sandbox/mmap/boost/mmap/mapped_view.inl
Text files modified:
   sandbox/mmap/boost/mmap/mappble_objects/file/utility.hpp | 208 +--------------------------------------
   sandbox/mmap/boost/mmap/mappble_objects/file/utility.inl | 14 +-
   sandbox/mmap/boost/mmap/mapped_view.hpp | 3
   sandbox/mmap/boost/mmap/mapped_view.inl | 83 ---------------
   4 files changed, 17 insertions(+), 291 deletions(-)

Copied: sandbox/mmap/boost/mmap/mappble_objects/file/utility.hpp (from r74131, /sandbox/mmap/boost/mmap/mapped_view.hpp)
==============================================================================
--- /sandbox/mmap/boost/mmap/mapped_view.hpp (original)
+++ sandbox/mmap/boost/mmap/mappble_objects/file/utility.hpp 2011-08-29 12:11:22 EDT (Mon, 29 Aug 2011)
@@ -1,7 +1,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 ///
-/// \file mapped_view.hpp
-/// ---------------------
+/// \file utility.hpp
+/// -----------------
 ///
 /// Copyright (c) Domagoj Saric 2010.-2011.
 ///
@@ -13,18 +13,13 @@
 ///
 ////////////////////////////////////////////////////////////////////////////////
 //------------------------------------------------------------------------------
-#ifndef mapped_view_hpp__D9C84FF5_E506_4ECB_9778_61E036048D28
-#define mapped_view_hpp__D9C84FF5_E506_4ECB_9778_61E036048D28
+#ifndef utility_hpp__3713A8AF_A516_4A23_BE6A_2BB79EBF7B5F
+#define utility_hpp__3713A8AF_A516_4A23_BE6A_2BB79EBF7B5F
 #pragma once
 //------------------------------------------------------------------------------
-#include "detail/impl_selection.hpp"
-#include "handles/handle.hpp"
-#include "mapping/mapping.hpp"
+#include "../../mapped_view.hpp"
 
-#include "boost/assert.hpp"
-#include "boost/cstdint.hpp"
-#include "boost/noncopyable.hpp"
-#include "boost/range/iterator_range_core.hpp"
+#include <cstddef>
 //------------------------------------------------------------------------------
 namespace boost
 {
@@ -33,191 +28,6 @@
 {
 //------------------------------------------------------------------------------
 
-typedef iterator_range<char *> basic_memory_range_t;
-typedef iterator_range<char const *> basic_read_only_memory_range_t;
-
-template <typename Element, typename Impl = BOOST_MMAP_IMPL()>
-class mapped_view_reference;
-
-typedef mapped_view_reference<char > basic_mapped_view_ref;
-typedef mapped_view_reference<char const> basic_mapped_read_only_view_ref;
-
-namespace detail
-{
- template <typename Element, typename Impl>
- struct mapper
- {
- public:
- 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<char, Impl>::map( source_mapping, offset, desired_size ) );
- }
-
- static void unmap( mapped_view_reference<Element, Impl> const & view )
- {
- mapper<char, Impl>::unmap( make_basic_view( view ) );
- }
-
- private:
- static mapped_view_reference<char, Impl>
- #ifdef BOOST_MSVC
- const &
- #endif
- make_basic_view( mapped_view_reference<Element, Impl> const & );
-
- static mapped_view_reference<Element, Impl>
- #ifdef BOOST_MSVC
- const &
- #endif
- make_typed_view( mapped_view_reference<char, Impl> const & );
- };
-
- template <typename Impl>
- struct mapper<char, Impl>
- {
- static mapped_view_reference<char, Impl> map
- (
- mapping<Impl> const & source_mapping,
- boost::uint64_t offset ,
- std ::size_t desired_size
- );
-
- static void unmap( mapped_view_reference<char, Impl> const & );
- };
-} // namespace detail
-
-template <typename Impl> struct mapping;
-
-template <typename Element, typename Impl>
-class mapped_view_reference : public iterator_range<Element *>
-{
-public:
- typedef iterator_range<Element *> memory_range_t;
-
-public: // Factory methods.
- static mapped_view_reference map
- (
- mapping<Impl> const & source_mapping,
- boost::uint64_t offset = 0,
- std ::size_t desired_size = 0
- )
- {
- 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 );
- }
-
- 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 ();
-
- void pop_front();
- void pop_back ();
-};
-
-
-namespace detail
-{
- // Implementation note:
- // These have to be defined after mapped_view_reference for eager
- // compilers (e.g. GCC and Clang).
- // (14.07.2011.) (Domagoj Saric)
-
- template <typename Element, typename Impl>
- mapped_view_reference<char, Impl>
- #ifdef BOOST_MSVC
- const &
- #endif
- mapper<Element, Impl>::make_basic_view( mapped_view_reference<Element, Impl> const & range )
- {
- return
- #ifdef BOOST_MSVC
- reinterpret_cast<mapped_view_reference<char, Impl> const &>( range );
- #else // compiler might care about strict aliasing rules
- mapped_view_reference<char, Impl>
- (
- static_cast<char *>( const_cast<void *>( static_cast<void const *>( range.begin() ) ) ),
- static_cast<char *>( const_cast<void *>( static_cast<void const *>( range.end () ) ) )
- );
- #endif // compiler
- }
-
-
- template <typename Element, typename Impl>
- mapped_view_reference<Element, Impl>
- #ifdef BOOST_MSVC
- const &
- #endif
- mapper<Element, Impl>::make_typed_view( mapped_view_reference<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 );
- return
- #ifdef BOOST_MSVC
- reinterpret_cast<mapped_view_reference<Element, Impl> const &>( range );
- #else // compiler might care about strict aliasing rules
- mapped_view_reference<Element, Impl>
- (
- static_cast<Element *>( static_cast<void *>( range.begin() ) ),
- static_cast<Element *>( static_cast<void *>( range.end () ) )
- );
- #endif // compiler
- }
-} // namespace detail
-
-
-template <typename Handle>
-struct is_mappable : mpl::false_ {};
-
-template <> struct is_mappable<char *> : mpl::true_ {};
-template <> struct is_mappable<char const *> : mpl::true_ {};
-template <> struct is_mappable<FILE *> : mpl::true_ {};
-template <> struct is_mappable<handle<posix>::native_handle_t > : mpl::true_ {};
-#ifdef _WIN32
-template <> struct is_mappable<wchar_t *> : mpl::true_ {};
-template <> struct is_mappable<wchar_t const *> : mpl::true_ {};
-template <> struct is_mappable<handle<win32>::native_handle_t > : mpl::true_ {};
-#endif // _WIN32
-
-
-template <typename Element, typename Impl = BOOST_MMAP_IMPL()>
-class mapped_view
- :
- public mapped_view_reference<Element, Impl>
- #ifdef BOOST_MSVC
- ,private noncopyable
- #endif // BOOST_MSVC
-{
-public:
- mapped_view( mapped_view_reference<Element, Impl> const range ) : mapped_view_reference<Element, Impl>( range ) {}
- ~mapped_view() { mapped_view_reference<Element, Impl>::unmap( *this ); }
-
- #ifndef BOOST_MSVC
- mapped_view( mapped_view const & ); // noncopyable
- #endif // BOOST_MSVC
-};
-
-typedef mapped_view<char> basic_mapped_view;
-
 basic_mapped_view_ref map_file ( char const * file_name, std::size_t desired_size );
 basic_mapped_read_only_view_ref map_read_only_file( char const * file_name );
 
@@ -228,7 +38,7 @@
 //------------------------------------------------------------------------------
 
 #ifdef BOOST_MMAP_HEADER_ONLY
- #include "mapped_view.inl"
-#endif
+ #include "utility.inl"
+#endif // BOOST_MMAP_HEADER_ONLY
 
-#endif // mapped_view_hpp
+#endif // utility_hpp

Copied: sandbox/mmap/boost/mmap/mappble_objects/file/utility.inl (from r74128, /sandbox/mmap/boost/mmap/mapped_view.inl)
==============================================================================
--- /sandbox/mmap/boost/mmap/mapped_view.inl (original)
+++ sandbox/mmap/boost/mmap/mappble_objects/file/utility.inl 2011-08-29 12:11:22 EDT (Mon, 29 Aug 2011)
@@ -13,13 +13,12 @@
 ///
 ////////////////////////////////////////////////////////////////////////////////
 //------------------------------------------------------------------------------
-#include "mapped_view.hpp"
+#include "utility.hpp"
 
-#include "detail/impl_inline.hpp"
-#include "implementations.hpp"
-#include "mappble_objects/file/file.hpp"
+#include "file.hpp"
 
-#include "boost/assert.hpp"
+#include "../../detail/impl_inline.hpp"
+#include "../../detail/impl_selection.hpp"
 //------------------------------------------------------------------------------
 namespace boost
 {
@@ -105,9 +104,12 @@
     );
 }
 
-
 //------------------------------------------------------------------------------
 } // mmap
 //------------------------------------------------------------------------------
 } // boost
 //------------------------------------------------------------------------------
+
+#ifndef BOOST_MMAP_HEADER_ONLY
+ #include "file.inl"
+#endif // BOOST_MMAP_HEADER_ONLY

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 12:11:22 EDT (Mon, 29 Aug 2011)
@@ -218,9 +218,6 @@
 
 typedef mapped_view<char> basic_mapped_view;
 
-basic_mapped_view_ref map_file ( char const * file_name, std::size_t desired_size );
-basic_mapped_read_only_view_ref map_read_only_file( char const * file_name );
-
 //------------------------------------------------------------------------------
 } // namespace mmap
 //------------------------------------------------------------------------------

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 12:11:22 EDT (Mon, 29 Aug 2011)
@@ -14,12 +14,6 @@
 ////////////////////////////////////////////////////////////////////////////////
 //------------------------------------------------------------------------------
 #include "mapped_view.hpp"
-
-#include "detail/impl_inline.hpp"
-#include "implementations.hpp"
-#include "mappble_objects/file/file.hpp"
-
-#include "boost/assert.hpp"
 //------------------------------------------------------------------------------
 namespace boost
 {
@@ -28,83 +22,6 @@
 {
 //------------------------------------------------------------------------------
 
-BOOST_IMPL_INLINE
-basic_mapped_view_ref map_file( char const * const file_name, std::size_t desired_size )
-{
- typedef file_open_flags<BOOST_MMAP_IMPL()> open_flags;
- file_handle<BOOST_MMAP_IMPL()> const file_handle
- (
- create_file
- (
- file_name,
- open_flags::create
- (
- open_flags::handle_access_rights ::read | open_flags::handle_access_rights::write,
- open_flags::open_policy ::open_or_create,
- open_flags::system_hints ::sequential_access,
- open_flags::on_construction_rights::read | open_flags::on_construction_rights::write
- )
- )
- );
-
- if ( desired_size )
- set_size( file_handle.get(), desired_size );
- else
- desired_size = get_size( file_handle.get() );
-
- typedef file_mapping_flags<BOOST_MMAP_IMPL()> mapping_flags;
- return basic_mapped_view_ref::map
- (
- create_mapping
- (
- file_handle,
- mapping_flags::create
- (
- mapping_flags::handle_access_rights::read | mapping_flags::handle_access_rights::write,
- mapping_flags::share_mode ::shared
- )
- ),
- 0,
- desired_size
- );
-}
-
-
-BOOST_IMPL_INLINE
-basic_mapped_read_only_view_ref map_read_only_file( char const * const file_name )
-{
- typedef file_open_flags<BOOST_MMAP_IMPL()> open_flags;
- file_handle<BOOST_MMAP_IMPL()> const file_handle
- (
- create_file
- (
- file_name,
- open_flags::create_for_opening_existing_files
- (
- open_flags::handle_access_rights::read,
- false,
- open_flags::system_hints ::sequential_access
- )
- )
- );
-
- typedef file_mapping_flags<BOOST_MMAP_IMPL()> mapping_flags;
- return basic_mapped_read_only_view_ref::map
- (
- create_mapping
- (
- file_handle,
- mapping_flags::create
- (
- mapping_flags::handle_access_rights::read,
- mapping_flags::share_mode ::shared
- )
- ),
- 0,
- get_size( file_handle.get() )
- );
-}
-
 
 //------------------------------------------------------------------------------
 } // 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