Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73421 - in sandbox/mmap/boost/mmap: . mappble_objects mappble_objects/file mappble_objects/nt_file mappble_objects/nt_shared_memory mappble_objects/posix_file mappble_objects/posix_shared_memory mappble_objects/shared_memory mappble_objects/win32_file mappble_objects/win32_shared_memory mappble_objects/xsi_shared_memory
From: dsaritz_at_[hidden]
Date: 2011-07-28 19:49:17


Author: psiha
Date: 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
New Revision: 73421
URL: http://svn.boost.org/trac/boost/changeset/73421

Log:
Major refactoring: split the monolithic memory_mapping module into many smaller parts and created an appropriate directory structure.
Added:
   sandbox/mmap/boost/mmap/mappble_objects/ (props changed)
   sandbox/mmap/boost/mmap/mappble_objects/file/ (props changed)
   sandbox/mmap/boost/mmap/mappble_objects/file/flags.hpp (contents, props changed)
   sandbox/mmap/boost/mmap/mappble_objects/file/handle.hpp (contents, props changed)
   sandbox/mmap/boost/mmap/mappble_objects/nt_file/ (props changed)
   sandbox/mmap/boost/mmap/mappble_objects/nt_shared_memory/ (props changed)
   sandbox/mmap/boost/mmap/mappble_objects/posix_file/ (props changed)
   sandbox/mmap/boost/mmap/mappble_objects/posix_file/flags.hpp (contents, props changed)
   sandbox/mmap/boost/mmap/mappble_objects/posix_file/flags.inl (contents, props changed)
   sandbox/mmap/boost/mmap/mappble_objects/posix_file/handle.hpp (contents, props changed)
   sandbox/mmap/boost/mmap/mappble_objects/posix_file/handle.inl (contents, props changed)
   sandbox/mmap/boost/mmap/mappble_objects/posix_shared_memory/ (props changed)
   sandbox/mmap/boost/mmap/mappble_objects/shared_memory/ (props changed)
   sandbox/mmap/boost/mmap/mappble_objects/win32_file/ (props changed)
   sandbox/mmap/boost/mmap/mappble_objects/win32_file/flags.hpp (contents, props changed)
   sandbox/mmap/boost/mmap/mappble_objects/win32_file/flags.inl (contents, props changed)
   sandbox/mmap/boost/mmap/mappble_objects/win32_file/handle.hpp (contents, props changed)
   sandbox/mmap/boost/mmap/mappble_objects/win32_file/handle.inl (contents, props changed)
   sandbox/mmap/boost/mmap/mappble_objects/win32_shared_memory/ (props changed)
   sandbox/mmap/boost/mmap/mappble_objects/xsi_shared_memory/ (props changed)
   sandbox/mmap/boost/mmap/mapped_view.hpp
      - copied, changed from r73413, /sandbox/mmap/boost/mmap/memory_mapping.hpp
   sandbox/mmap/boost/mmap/mapped_view.inl
      - copied, changed from r73413, /sandbox/mmap/boost/mmap/memory_mapping.inl
Removed:
   sandbox/mmap/boost/mmap/memory_mapping.hpp
   sandbox/mmap/boost/mmap/memory_mapping.inl
Text files modified:
   sandbox/mmap/boost/mmap/mapped_view.hpp | 159 ++---------------------------
   sandbox/mmap/boost/mmap/mapped_view.inl | 217 +--------------------------------------
   2 files changed, 21 insertions(+), 355 deletions(-)

Added: sandbox/mmap/boost/mmap/mappble_objects/file/flags.hpp
==============================================================================
--- (empty file)
+++ sandbox/mmap/boost/mmap/mappble_objects/file/flags.hpp 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
@@ -0,0 +1,26 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file flags.hpp
+/// ---------------
+///
+/// Copyright (c) Domagoj Saric 2010.-2011.
+///
+/// Use, modification and distribution is subject to 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)
+///
+/// For more information, see http://www.boost.org
+///
+////////////////////////////////////////////////////////////////////////////////
+//------------------------------------------------------------------------------
+#ifndef flags_hpp__BFFC0541_21AC_4A80_A9EE_E0450B6D4D8A
+#define flags_hpp__BFFC0541_21AC_4A80_A9EE_E0450B6D4D8A
+#pragma once
+//------------------------------------------------------------------------------
+#ifdef _WIN32
+#include "../win32_file/flags.hpp"
+#else
+#include "../posix_file/flags.hpp"
+#endif
+//------------------------------------------------------------------------------
+#endif // flags_hpp

Added: sandbox/mmap/boost/mmap/mappble_objects/file/handle.hpp
==============================================================================
--- (empty file)
+++ sandbox/mmap/boost/mmap/mappble_objects/file/handle.hpp 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
@@ -0,0 +1,50 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file handle.hpp
+/// ----------------
+///
+/// Copyright (c) Domagoj Saric 2010.-2011.
+///
+/// Use, modification and distribution is subject to 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)
+///
+/// For more information, see http://www.boost.org
+///
+////////////////////////////////////////////////////////////////////////////////
+//------------------------------------------------------------------------------
+#ifndef handle_hpp__D3705ED0_EC0D_4747_A789_1EE17252B6E2
+#define handle_hpp__D3705ED0_EC0D_4747_A789_1EE17252B6E2
+#pragma once
+//------------------------------------------------------------------------------
+#ifdef _WIN32
+#include "../win32_file/handle.hpp"
+#else
+#include "../posix_file/handle.hpp"
+#endif
+//------------------------------------------------------------------------------
+namespace boost
+{
+//------------------------------------------------------------------------------
+namespace mmap
+{
+//------------------------------------------------------------------------------
+namespace guard
+{
+//------------------------------------------------------------------------------
+
+#ifdef _WIN32
+ typedef windows_handle native_handle;
+#else
+ typedef posix_handle native_handle;
+#endif // _WIN32
+typedef native_handle::handle_t native_handle_t;
+
+//------------------------------------------------------------------------------
+} // namespace guard
+//------------------------------------------------------------------------------
+} // namespace mmap
+//------------------------------------------------------------------------------
+} // namespace boost
+//------------------------------------------------------------------------------
+#endif // handle_hpp

Added: sandbox/mmap/boost/mmap/mappble_objects/posix_file/flags.hpp
==============================================================================
--- (empty file)
+++ sandbox/mmap/boost/mmap/mappble_objects/posix_file/flags.hpp 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
@@ -0,0 +1,118 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file flags.hpp
+/// ---------------
+///
+/// Copyright (c) Domagoj Saric 2010.-2011.
+///
+/// Use, modification and distribution is subject to 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)
+///
+/// For more information, see http://www.boost.org
+///
+////////////////////////////////////////////////////////////////////////////////
+//------------------------------------------------------------------------------
+
+#ifndef flags_hpp__0F422517_D9AA_4E3F_B3E4_B139021D068E
+#define flags_hpp__0F422517_D9AA_4E3F_B3E4_B139021D068E
+#pragma once
+//------------------------------------------------------------------------------
+#include "boost/assert.hpp"
+#include "boost/noncopyable.hpp"
+
+#include "fcntl.h"
+//------------------------------------------------------------------------------
+namespace boost
+{
+//------------------------------------------------------------------------------
+namespace mmap
+{
+//------------------------------------------------------------------------------
+
+// Implementation note:
+// Using structs with public members and factory functions to enable (almost)
+// zero-overhead 'link-time' conversion to native flag formats and to allow the
+// user to modify the created flags or create fully custom ones so that specific
+// platform-dependent use-cases, not otherwise covered through the generic
+// interface, can also be covered.
+// (10.10.2010.) (Domagoj Saric)
+
+struct posix_file_flags
+{
+ struct handle_access_rights
+ {
+ static unsigned int const read ;
+ static unsigned int const write ;
+ static unsigned int const execute;
+ };
+
+ struct share_mode
+ {
+ static unsigned int const none ;
+ static unsigned int const read ;
+ static unsigned int const write ;
+ static unsigned int const remove;
+ };
+
+ struct open_policy
+ {
+ enum value_type
+ {
+ create_new = O_CREAT | O_EXCL ,
+ create_new_or_truncate_existing = O_CREAT | O_TRUNC,
+ open_existing = 0 ,
+ open_or_create = O_CREAT ,
+ open_and_truncate_existing = O_TRUNC
+ };
+ };
+ typedef open_policy::value_type open_policy_t;
+
+ struct system_hints
+ {
+ static unsigned int const random_access ;
+ static unsigned int const sequential_access;
+ static unsigned int const non_cached ;
+ static unsigned int const delete_on_close ;
+ static unsigned int const temporary ;
+ };
+
+ struct on_construction_rights
+ {
+ static unsigned int const read ;
+ static unsigned int const write ;
+ static unsigned int const execute;
+ };
+
+ static posix_file_flags create
+ (
+ unsigned int handle_access_flags ,
+ unsigned int share_mode ,
+ open_policy_t ,
+ unsigned int system_hints ,
+ unsigned int on_construction_rights
+ );
+
+ static posix_file_flags create_for_opening_existing_files
+ (
+ unsigned int handle_access_flags,
+ unsigned int share_mode ,
+ bool truncate ,
+ unsigned int system_hints
+ );
+
+ int oflag;
+ int pmode;
+};
+
+//------------------------------------------------------------------------------
+} // namespace mmap
+//------------------------------------------------------------------------------
+} // namespace boost
+//------------------------------------------------------------------------------
+
+#undef BOOST_MMAP_IMPL_FILE
+#define BOOST_MMAP_IMPL_FILE "flags.inl"
+#include "../../detail/include_impl_file.hpp"
+
+#endif // flags_hpp

Added: sandbox/mmap/boost/mmap/mappble_objects/posix_file/flags.inl
==============================================================================
--- (empty file)
+++ sandbox/mmap/boost/mmap/mappble_objects/posix_file/flags.inl 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
@@ -0,0 +1,99 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file flags.inl
+/// ---------------
+///
+/// Copyright (c) Domagoj Saric 2010.-2011.
+///
+/// Use, modification and distribution is subject to 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)
+///
+/// For more information, see http://www.boost.org
+///
+////////////////////////////////////////////////////////////////////////////////
+//------------------------------------------------------------------------------
+#include "flags.hpp"
+
+#include "../../detail/impl_inline.hpp"
+
+#include "boost/assert.hpp"
+
+#ifdef _WIN32
+ #define BOOST_AUX_IO_WIN32_OR_POSIX( win32, posix ) win32
+ #pragma warning ( disable : 4996 ) // "The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name."
+ #include "io.h"
+ #include "sys/stat.h"
+#else
+ #define BOOST_AUX_IO_WIN32_OR_POSIX( win32, posix ) posix
+ #include "sys/mman.h" // mmap, munmap.
+ #include "sys/stat.h"
+ #include "sys/types.h" // struct stat.
+ #include "unistd.h" // sysconf.
+#endif // _WIN32
+#include "errno.h"
+#include "fcntl.h"
+
+#ifndef _WIN32
+ #ifdef __APPLE__
+ #define BOOST_AUX_MMAP_POSIX_OR_OSX( posix, osx ) osx
+ #else
+ #define BOOST_AUX_MMAP_POSIX_OR_OSX( posix, osx ) posix
+ #endif
+#endif
+//------------------------------------------------------------------------------
+namespace boost
+{
+//------------------------------------------------------------------------------
+namespace mmap
+{
+//------------------------------------------------------------------------------
+
+unsigned int const posix_file_flags::handle_access_rights::read = O_RDONLY;
+unsigned int const posix_file_flags::handle_access_rights::write = O_WRONLY;
+unsigned int const posix_file_flags::handle_access_rights::execute = O_RDONLY;
+
+unsigned int const posix_file_flags::share_mode::none = 0;
+unsigned int const posix_file_flags::share_mode::read = 0;
+unsigned int const posix_file_flags::share_mode::write = 0;
+unsigned int const posix_file_flags::share_mode::remove = 0;
+
+unsigned int const posix_file_flags::system_hints::random_access = BOOST_AUX_IO_WIN32_OR_POSIX( O_RANDOM , 0 );
+unsigned int const posix_file_flags::system_hints::sequential_access = BOOST_AUX_IO_WIN32_OR_POSIX( O_SEQUENTIAL , 0 );
+// http://stackoverflow.com/questions/2299402/how-does-one-do-raw-io-on-mac-os-x-ie-equivalent-to-linuxs-o-direct-flag
+unsigned int const posix_file_flags::system_hints::non_cached = BOOST_AUX_IO_WIN32_OR_POSIX( 0 , BOOST_AUX_MMAP_POSIX_OR_OSX( O_DIRECT, 0 ) );
+unsigned int const posix_file_flags::system_hints::delete_on_close = BOOST_AUX_IO_WIN32_OR_POSIX( O_TEMPORARY , 0 );
+unsigned int const posix_file_flags::system_hints::temporary = BOOST_AUX_IO_WIN32_OR_POSIX( _O_SHORT_LIVED, 0 );
+
+unsigned int const posix_file_flags::on_construction_rights::read = BOOST_AUX_IO_WIN32_OR_POSIX( _S_IREAD , S_IRUSR );
+unsigned int const posix_file_flags::on_construction_rights::write = BOOST_AUX_IO_WIN32_OR_POSIX( _S_IWRITE, S_IWUSR );
+unsigned int const posix_file_flags::on_construction_rights::execute = BOOST_AUX_IO_WIN32_OR_POSIX( _S_IEXEC , S_IXUSR );
+
+BOOST_IMPL_INLINE
+posix_file_flags posix_file_flags::create
+(
+ unsigned int const handle_access_flags ,
+ unsigned int const /*share_mode*/ ,
+ open_policy_t const open_flags ,
+ unsigned int const system_hints ,
+ unsigned int const on_construction_rights
+)
+{
+ posix_file_flags const flags =
+ {
+ ( ( handle_access_flags == ( O_RDONLY | O_WRONLY ) ) ? O_RDWR : handle_access_flags )
+ |
+ open_flags
+ |
+ system_hints, // oflag
+ on_construction_rights // pmode
+ };
+
+ return flags;
+}
+
+//------------------------------------------------------------------------------
+} // mmap
+//------------------------------------------------------------------------------
+} // boost
+//------------------------------------------------------------------------------

Added: sandbox/mmap/boost/mmap/mappble_objects/posix_file/handle.hpp
==============================================================================
--- (empty file)
+++ sandbox/mmap/boost/mmap/mappble_objects/posix_file/handle.hpp 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
@@ -0,0 +1,91 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file handle.hpp
+/// ----------------
+///
+/// Copyright (c) Domagoj Saric 2010.-2011.
+///
+/// Use, modification and distribution is subject to 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)
+///
+/// For more information, see http://www.boost.org
+///
+////////////////////////////////////////////////////////////////////////////////
+//------------------------------------------------------------------------------
+#ifndef handle_hpp__63113526_C3F1_46DC_850E_D8D8C62031DB
+#define handle_hpp__63113526_C3F1_46DC_850E_D8D8C62031DB
+#pragma once
+//------------------------------------------------------------------------------
+#ifdef BOOST_MSVC
+ #include "../win32_file/handle.hpp"
+#endif
+
+#include "boost/assert.hpp"
+#include "boost/noncopyable.hpp"
+//------------------------------------------------------------------------------
+namespace boost
+{
+//------------------------------------------------------------------------------
+namespace mmap
+{
+//------------------------------------------------------------------------------
+
+struct posix_file_flags;
+
+namespace guard
+{
+//------------------------------------------------------------------------------
+
+class posix_handle
+#ifdef BOOST_MSVC
+ : noncopyable
+#endif // BOOST_MSVC
+{
+public:
+ typedef int handle_t;
+
+ explicit posix_handle( handle_t );
+ #ifndef BOOST_MSVC
+ posix_handle( posix_handle const & );
+ #endif // BOOST_MSVC
+
+ #ifdef BOOST_MSVC
+ explicit posix_handle( windows_handle::handle_t );
+ #endif // _WIN32
+
+ ~posix_handle();
+
+ handle_t const & handle() const { return handle_; }
+
+private:
+ handle_t const handle_;
+};
+
+
+#ifdef _WIN32
+ typedef windows_handle native_handle;
+#else
+ typedef posix_handle native_handle;
+#endif // _WIN32
+typedef native_handle::handle_t native_handle_t;
+
+//------------------------------------------------------------------------------
+} // namespace guard
+
+guard::native_handle create_file( char const * file_name, guard::native_handle::flags const & );
+guard::native_handle create_file( char const * file_name, guard::native_handle::flags const &, unsigned int desired_size );
+
+bool set_file_size( guard::native_handle_t, std::size_t desired_size );
+std::size_t get_file_size( guard::native_handle_t );
+
+//------------------------------------------------------------------------------
+} // namespace mmap
+//------------------------------------------------------------------------------
+} // namespace boost
+//------------------------------------------------------------------------------
+
+#define BOOST_MMAP_IMPL_FILE "handle.inl"
+#include "../../detail/include_impl_file.hpp"
+
+#endif // handle_hpp

Added: sandbox/mmap/boost/mmap/mappble_objects/posix_file/handle.inl
==============================================================================
--- (empty file)
+++ sandbox/mmap/boost/mmap/mappble_objects/posix_file/handle.inl 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
@@ -0,0 +1,128 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file handle.inl
+/// ----------------
+///
+/// Copyright (c) Domagoj Saric 2010.-2011.
+///
+/// Use, modification and distribution is subject to 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)
+///
+/// For more information, see http://www.boost.org
+///
+////////////////////////////////////////////////////////////////////////////////
+//------------------------------------------------------------------------------
+#include "handle.hpp"
+
+#include "flags.hpp"
+#include "../../detail/impl_inline.hpp"
+
+#include "boost/assert.hpp"
+
+#ifdef BOOST_MSVC
+ #pragma warning ( disable : 4996 ) // "The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name."
+ #include "io.h"
+#else
+ #include "sys/mman.h" // mmap, munmap.
+ #include "sys/stat.h"
+ #include "sys/types.h" // struct stat.
+ #include "unistd.h" // sysconf.
+#endif // BOOST_MSVC
+#include "errno.h"
+#include "fcntl.h"
+
+#ifndef _WIN32
+ #ifdef __APPLE__
+ #define BOOST_AUX_MMAP_POSIX_OR_OSX( posix, osx ) osx
+ #else
+ #define BOOST_AUX_MMAP_POSIX_OR_OSX( posix, osx ) posix
+ #endif
+#endif
+
+//------------------------------------------------------------------------------
+namespace boost
+{
+//------------------------------------------------------------------------------
+namespace mmap
+{
+//------------------------------------------------------------------------------
+namespace guard
+{
+
+BOOST_IMPL_INLINE
+posix_handle::posix_handle( handle_t const handle )
+ :
+ handle_( handle )
+{}
+
+#ifdef BOOST_MSVC
+BOOST_IMPL_INLINE
+posix_handle::posix_handle( windows_handle::handle_t const native_handle )
+ :
+ handle_( ::_open_osfhandle( reinterpret_cast<intptr_t>( native_handle ), _O_APPEND ) )
+{
+ if ( handle_ == -1 )
+ {
+ BOOST_VERIFY
+ (
+ ( ::CloseHandle( native_handle ) != false ) ||
+ ( native_handle == 0 || native_handle == INVALID_HANDLE_VALUE )
+ );
+ }
+}
+#endif // BOOST_MSVC
+
+BOOST_IMPL_INLINE
+posix_handle::~posix_handle()
+{
+ BOOST_VERIFY
+ (
+ ( ::close( handle() ) == 0 ) ||
+ (
+ ( handle() == -1 ) &&
+ ( errno == EBADF )
+ )
+ );
+}
+
+//------------------------------------------------------------------------------
+} // guard
+
+
+BOOST_IMPL_INLINE
+guard::posix_handle create_file( char const * const file_name, posix_file_flags const & flags )
+{
+ BOOST_ASSERT( file_name );
+
+ int const current_mask( ::umask( 0 ) );
+ int const file_handle ( ::open( file_name, flags.oflag, flags.pmode ) );
+ //...zzz...investigate posix_fadvise, posix_madvise, fcntl for the system hints...
+ BOOST_VERIFY( ::umask( current_mask ) == 0 );
+
+ return guard::posix_handle( file_handle );
+}
+
+
+#ifndef BOOST_MSVC
+BOOST_IMPL_INLINE
+bool set_file_size( guard::posix_handle::handle_t const file_handle, std::size_t const desired_size )
+{
+ return ::ftruncate( file_handle, desired_size ) != -1;
+}
+#endif // BOOST_MSVC
+
+
+BOOST_IMPL_INLINE
+std::size_t get_file_size( guard::posix_handle::handle_t const file_handle )
+{
+ struct stat file_info;
+ BOOST_VERIFY( ::fstat( file_handle, &file_info ) == 0 );
+ return file_info.st_size;
+}
+
+//------------------------------------------------------------------------------
+} // mmap
+//------------------------------------------------------------------------------
+} // boost
+//------------------------------------------------------------------------------

Added: sandbox/mmap/boost/mmap/mappble_objects/win32_file/flags.hpp
==============================================================================
--- (empty file)
+++ sandbox/mmap/boost/mmap/mappble_objects/win32_file/flags.hpp 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
@@ -0,0 +1,117 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file flags.hpp
+/// ---------------
+///
+/// Copyright (c) Domagoj Saric 2010.-2011.
+///
+/// Use, modification and distribution is subject to 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)
+///
+/// For more information, see http://www.boost.org
+///
+////////////////////////////////////////////////////////////////////////////////
+//------------------------------------------------------------------------------
+#ifndef flags_hpp__77AE8A6F_0E93_433B_A1F2_531BBBB353FC
+#define flags_hpp__77AE8A6F_0E93_433B_A1F2_531BBBB353FC
+#pragma once
+//------------------------------------------------------------------------------
+#include "boost/assert.hpp"
+#include "boost/noncopyable.hpp"
+//------------------------------------------------------------------------------
+namespace boost
+{
+//------------------------------------------------------------------------------
+namespace mmap
+{
+//------------------------------------------------------------------------------
+
+// Implementation note:
+// Using structs with public members and factory functions to enable (almost)
+// zero-overhead 'link-time' conversion to native flag formats and to allow the
+// user to modify the created flags or create fully custom ones so that specific
+// platform-dependent use-cases, not otherwise covered through the generic
+// interface, can also be covered.
+// (10.10.2010.) (Domagoj Saric)
+
+struct win32_file_flags
+{
+ struct handle_access_rights
+ {
+ static unsigned int const read ;
+ static unsigned int const write ;
+ static unsigned int const execute;
+ };
+
+ struct share_mode
+ {
+ static unsigned int const none ;
+ static unsigned int const read ;
+ static unsigned int const write ;
+ static unsigned int const remove;
+ };
+
+ struct open_policy
+ {
+ enum value_type
+ {
+ create_new = 1,
+ create_new_or_truncate_existing = 2,
+ open_existing = 3,
+ open_or_create = 4,
+ open_and_truncate_existing = 5
+ };
+ };
+ typedef open_policy::value_type open_policy_t;
+
+ struct system_hints
+ {
+ static unsigned int const random_access ;
+ static unsigned int const sequential_access;
+ static unsigned int const non_cached ;
+ static unsigned int const delete_on_close ;
+ static unsigned int const temporary ;
+ };
+
+ struct on_construction_rights
+ {
+ static unsigned int const read ;
+ static unsigned int const write ;
+ static unsigned int const execute;
+ };
+
+ static win32_file_flags create
+ (
+ unsigned int handle_access_flags ,
+ unsigned int share_mode ,
+ open_policy_t ,
+ unsigned int system_hints ,
+ unsigned int on_construction_rights
+ );
+
+ static win32_file_flags create_for_opening_existing_files
+ (
+ unsigned int handle_access_flags,
+ unsigned int share_mode ,
+ bool truncate ,
+ unsigned int system_hints
+ );
+
+ unsigned long desired_access ;
+ unsigned long share_mode ;
+ unsigned long creation_disposition;
+ unsigned long flags_and_attributes;
+};
+
+//------------------------------------------------------------------------------
+} // namespace mmap
+//------------------------------------------------------------------------------
+} // namespace boost
+//------------------------------------------------------------------------------
+
+#undef BOOST_MMAP_IMPL_FILE
+#define BOOST_MMAP_IMPL_FILE "flags.inl"
+#include "../../detail/include_impl_file.hpp"
+
+#endif // flags_hpp

Added: sandbox/mmap/boost/mmap/mappble_objects/win32_file/flags.inl
==============================================================================
--- (empty file)
+++ sandbox/mmap/boost/mmap/mappble_objects/win32_file/flags.inl 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
@@ -0,0 +1,101 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file flags.inl
+/// ---------------
+///
+/// Copyright (c) Domagoj Saric 2010.-2011.
+///
+/// Use, modification and distribution is subject to 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)
+///
+/// For more information, see http://www.boost.org
+///
+////////////////////////////////////////////////////////////////////////////////
+//------------------------------------------------------------------------------
+#include "flags.hpp"
+
+#include "../../detail/impl_inline.hpp"
+
+#include "boost/assert.hpp"
+
+#ifndef WIN32_LEAN_AND_MEAN
+ #define WIN32_LEAN_AND_MEAN
+#endif // WIN32_LEAN_AND_MEAN
+#include "windows.h"
+//------------------------------------------------------------------------------
+namespace boost
+{
+//------------------------------------------------------------------------------
+namespace mmap
+{
+//------------------------------------------------------------------------------
+
+unsigned int const win32_file_flags::handle_access_rights::read = GENERIC_READ ;
+unsigned int const win32_file_flags::handle_access_rights::write = GENERIC_WRITE ;
+unsigned int const win32_file_flags::handle_access_rights::execute = GENERIC_EXECUTE;
+
+unsigned int const win32_file_flags::share_mode::none = 0 ;
+unsigned int const win32_file_flags::share_mode::read = FILE_SHARE_READ ;
+unsigned int const win32_file_flags::share_mode::write = FILE_SHARE_WRITE ;
+unsigned int const win32_file_flags::share_mode::remove = FILE_SHARE_DELETE;
+
+unsigned int const win32_file_flags::system_hints::random_access = FILE_FLAG_RANDOM_ACCESS ;
+unsigned int const win32_file_flags::system_hints::sequential_access = FILE_FLAG_SEQUENTIAL_SCAN ;
+unsigned int const win32_file_flags::system_hints::non_cached = FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH;
+unsigned int const win32_file_flags::system_hints::delete_on_close = FILE_FLAG_DELETE_ON_CLOSE ;
+unsigned int const win32_file_flags::system_hints::temporary = FILE_ATTRIBUTE_TEMPORARY ;
+
+unsigned int const win32_file_flags::on_construction_rights::read = FILE_ATTRIBUTE_READONLY;
+unsigned int const win32_file_flags::on_construction_rights::write = FILE_ATTRIBUTE_NORMAL ;
+unsigned int const win32_file_flags::on_construction_rights::execute = FILE_ATTRIBUTE_NORMAL ;
+
+BOOST_IMPL_INLINE
+win32_file_flags win32_file_flags::create
+(
+ unsigned int const handle_access_flags ,
+ unsigned int const share_mode ,
+ open_policy_t const open_flags ,
+ unsigned int const system_hints ,
+ unsigned int const on_construction_rights
+)
+{
+ win32_file_flags const flags =
+ {
+ handle_access_flags, // desired_access
+ share_mode, // share_mode
+ open_flags, // creation_disposition
+ system_hints
+ |
+ (
+ ( on_construction_rights & FILE_ATTRIBUTE_NORMAL )
+ ? ( on_construction_rights & ~FILE_ATTRIBUTE_READONLY )
+ : on_construction_rights
+ ) // flags_and_attributes
+ };
+
+ return flags;
+}
+
+
+BOOST_IMPL_INLINE
+win32_file_flags win32_file_flags::create_for_opening_existing_files( unsigned int const handle_access_flags, unsigned int const share_mode , bool const truncate, unsigned int const system_hints )
+{
+ return create
+ (
+ handle_access_flags,
+ share_mode,
+ truncate
+ ? open_policy::open_and_truncate_existing
+ : open_policy::open_existing,
+ system_hints,
+ 0
+ );
+}
+
+
+//------------------------------------------------------------------------------
+} // mmap
+//------------------------------------------------------------------------------
+} // boost
+//------------------------------------------------------------------------------

Added: sandbox/mmap/boost/mmap/mappble_objects/win32_file/handle.hpp
==============================================================================
--- (empty file)
+++ sandbox/mmap/boost/mmap/mappble_objects/win32_file/handle.hpp 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
@@ -0,0 +1,77 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file handle.hpp
+/// ----------------
+///
+/// Copyright (c) Domagoj Saric 2010.-2011.
+///
+/// Use, modification and distribution is subject to 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)
+///
+/// For more information, see http://www.boost.org
+///
+////////////////////////////////////////////////////////////////////////////////
+//------------------------------------------------------------------------------
+#ifndef handle_hpp__1CEA6D65_D5C0_474E_833D_2CE927A1C74D
+#define handle_hpp__1CEA6D65_D5C0_474E_833D_2CE927A1C74D
+#pragma once
+//------------------------------------------------------------------------------
+#include "boost/assert.hpp"
+#include "boost/noncopyable.hpp"
+//------------------------------------------------------------------------------
+namespace boost
+{
+//------------------------------------------------------------------------------
+namespace mmap
+{
+//------------------------------------------------------------------------------
+
+struct win32_file_flags;
+
+namespace guard
+{
+//------------------------------------------------------------------------------
+
+class windows_handle : noncopyable
+{
+public:
+ typedef void * handle_t;
+
+ typedef win32_file_flags flags;
+
+ explicit windows_handle( handle_t );
+ ~windows_handle();
+
+ handle_t const & handle() const { return handle_; }
+
+private:
+ handle_t const handle_;
+};
+
+#ifdef _WIN32
+ typedef windows_handle native_handle;
+#else
+ typedef posix_handle native_handle;
+#endif // _WIN32
+typedef native_handle::handle_t native_handle_t;
+
+//------------------------------------------------------------------------------
+} // namespace guard
+
+guard::native_handle create_file( char const * file_name, guard::native_handle::flags const & );
+guard::native_handle create_file( char const * file_name, guard::native_handle::flags const &, unsigned int desired_size );
+
+bool set_file_size( guard::native_handle_t, std::size_t desired_size );
+std::size_t get_file_size( guard::native_handle_t );
+
+//------------------------------------------------------------------------------
+} // namespace mmap
+//------------------------------------------------------------------------------
+} // namespace boost
+//------------------------------------------------------------------------------
+
+#define BOOST_MMAP_IMPL_FILE "handle.inl"
+#include "../../detail/include_impl_file.hpp"
+
+#endif // handle_hpp

Added: sandbox/mmap/boost/mmap/mappble_objects/win32_file/handle.inl
==============================================================================
--- (empty file)
+++ sandbox/mmap/boost/mmap/mappble_objects/win32_file/handle.inl 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
@@ -0,0 +1,105 @@
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file handle.inl
+/// ----------------
+///
+/// Copyright (c) Domagoj Saric 2010.-2011.
+///
+/// Use, modification and distribution is subject to 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)
+///
+/// For more information, see http://www.boost.org
+///
+////////////////////////////////////////////////////////////////////////////////
+//------------------------------------------------------------------------------
+#include "handle.hpp"
+
+#include "flags.hpp"
+#include "../../detail/impl_inline.hpp"
+
+#include "boost/assert.hpp"
+
+#ifndef WIN32_LEAN_AND_MEAN
+ #define WIN32_LEAN_AND_MEAN
+#endif // WIN32_LEAN_AND_MEAN
+#include "windows.h"
+//------------------------------------------------------------------------------
+namespace boost
+{
+//------------------------------------------------------------------------------
+namespace mmap
+{
+//------------------------------------------------------------------------------
+namespace guard
+{
+
+BOOST_IMPL_INLINE
+windows_handle::windows_handle( handle_t const handle )
+ :
+ handle_( handle )
+{}
+
+BOOST_IMPL_INLINE
+windows_handle::~windows_handle()
+{
+ BOOST_VERIFY
+ (
+ ( ::CloseHandle( handle_ ) != false ) ||
+ ( handle_ == 0 || handle_ == INVALID_HANDLE_VALUE )
+ );
+}
+
+//------------------------------------------------------------------------------
+} // guard
+
+
+BOOST_IMPL_INLINE
+guard::native_handle create_file( char const * const file_name, guard::native_handle::flags const & flags )
+{
+ BOOST_ASSERT( file_name );
+
+ HANDLE const file_handle
+ (
+ ::CreateFileA
+ (
+ file_name, flags.desired_access, flags.share_mode, 0, flags.creation_disposition, flags.flags_and_attributes, 0
+ )
+ );
+ BOOST_ASSERT( ( file_handle == INVALID_HANDLE_VALUE ) || ( ::GetLastError() == NO_ERROR ) || ( ::GetLastError() == ERROR_ALREADY_EXISTS ) );
+
+ return guard::native_handle( file_handle );
+}
+
+
+BOOST_IMPL_INLINE
+bool set_file_size( guard::native_handle_t const file_handle, std::size_t const desired_size )
+{
+ // It is 'OK' to send null/invalid handles to Windows functions (they will
+ // simply fail), this simplifies error handling (it is enough to go through
+ // all the logic, inspect the final result and then throw on error).
+ DWORD const new_size( ::SetFilePointer( file_handle, desired_size, 0, FILE_BEGIN ) );
+ BOOST_ASSERT( ( new_size == desired_size ) || ( file_handle == INVALID_HANDLE_VALUE ) );
+ ignore_unused_variable_warning( new_size );
+
+ BOOL const success( ::SetEndOfFile( file_handle ) );
+
+ BOOST_VERIFY( ( ::SetFilePointer( file_handle, 0, 0, FILE_BEGIN ) == 0 ) || ( file_handle == INVALID_HANDLE_VALUE ) );
+
+ return success != false;
+}
+
+
+BOOST_IMPL_INLINE
+std::size_t get_file_size( guard::native_handle_t const file_handle )
+{
+ DWORD const file_size( ::GetFileSize( file_handle, 0 ) );
+ BOOST_ASSERT( ( file_size != INVALID_FILE_SIZE ) || ( file_handle == INVALID_HANDLE_VALUE ) || ( ::GetLastError() == NO_ERROR ) );
+ return file_size;
+}
+
+//------------------------------------------------------------------------------
+} // mmap
+//------------------------------------------------------------------------------
+} // boost
+//------------------------------------------------------------------------------

Copied: sandbox/mmap/boost/mmap/mapped_view.hpp (from r73413, /sandbox/mmap/boost/mmap/memory_mapping.hpp)
==============================================================================
--- /sandbox/mmap/boost/mmap/memory_mapping.hpp (original)
+++ sandbox/mmap/boost/mmap/mapped_view.hpp 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
@@ -1,7 +1,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 ///
-/// \file memory_mapping.hpp
-/// ------------------------
+/// \file mapped_view.hpp
+/// ---------------------
 ///
 /// Copyright (c) Domagoj Saric 2010.-2011.
 ///
@@ -13,10 +13,13 @@
 ///
 ////////////////////////////////////////////////////////////////////////////////
 //------------------------------------------------------------------------------
-#ifndef memory_mapping_hpp__D9C84FF5_E506_4ECB_9778_61E036048D28
-#define memory_mapping_hpp__D9C84FF5_E506_4ECB_9778_61E036048D28
+#ifndef mapped_view_hpp__D9C84FF5_E506_4ECB_9778_61E036048D28
+#define mapped_view_hpp__D9C84FF5_E506_4ECB_9778_61E036048D28
 #pragma once
 //------------------------------------------------------------------------------
+#include "mappble_objects/posix_file/handle.hpp"
+#include "mappble_objects/win32_file/handle.hpp"
+
 #include "boost/assert.hpp"
 #include "boost/noncopyable.hpp"
 #include "boost/range/iterator_range.hpp"
@@ -46,80 +49,6 @@
 // interface, can also be covered.
 // (10.10.2010.) (Domagoj Saric)
 
-struct file_flags
-{
- struct handle_access_rights
- {
- static unsigned int const read ;
- static unsigned int const write ;
- static unsigned int const execute;
- };
-
- struct share_mode
- {
- static unsigned int const none ;
- static unsigned int const read ;
- static unsigned int const write ;
- static unsigned int const remove;
- };
-
- struct open_policy
- {
- enum value_type
- {
- create_new = BOOST_AUX_IO_WIN32_OR_POSIX( 1, O_CREAT | O_EXCL ),
- create_new_or_truncate_existing = BOOST_AUX_IO_WIN32_OR_POSIX( 2, O_CREAT | O_TRUNC ),
- open_existing = BOOST_AUX_IO_WIN32_OR_POSIX( 3, 0 ),
- open_or_create = BOOST_AUX_IO_WIN32_OR_POSIX( 4, O_CREAT ),
- open_and_truncate_existing = BOOST_AUX_IO_WIN32_OR_POSIX( 5, O_TRUNC )
- };
- };
- typedef open_policy::value_type open_policy_t;
-
- struct system_hints
- {
- static unsigned int const random_access ;
- static unsigned int const sequential_access;
- static unsigned int const non_cached ;
- static unsigned int const delete_on_close ;
- static unsigned int const temporary ;
- };
-
- struct on_construction_rights
- {
- static unsigned int const read ;
- static unsigned int const write ;
- static unsigned int const execute;
- };
-
- static file_flags create
- (
- unsigned int handle_access_flags ,
- unsigned int share_mode ,
- open_policy_t ,
- unsigned int system_hints ,
- unsigned int on_construction_rights
- );
-
- static file_flags create_for_opening_existing_files
- (
- unsigned int handle_access_flags,
- unsigned int share_mode ,
- bool truncate ,
- unsigned int system_hints
- );
-
-#ifdef _WIN32
- unsigned long desired_access ;
- unsigned long share_mode ;
- unsigned long creation_disposition;
- unsigned long flags_and_attributes;
-#else
- int oflag;
- int pmode;
-#endif // _WIN32
-};
-
 struct mapping_flags
 {
     struct handle_access_rights
@@ -170,69 +99,6 @@
 typedef mapped_view_reference<unsigned char > basic_mapped_view_ref;
 typedef mapped_view_reference<unsigned char const> basic_mapped_read_only_view_ref;
 
-namespace guard
-{
-//------------------------------------------------------------------------------
-
-#ifdef _WIN32
-class windows_handle : noncopyable
-{
-public:
- typedef void * handle_t;
-
- explicit windows_handle( handle_t );
- ~windows_handle();
-
- handle_t const & handle() const { return handle_; }
-
-private:
- handle_t const handle_;
-};
-#endif // _WIN32
-
-class posix_handle
-#ifdef BOOST_MSVC
- : noncopyable
-#endif // BOOST_MSVC
-{
-public:
- typedef int handle_t;
-
- explicit posix_handle( handle_t );
- #ifndef BOOST_MSVC
- posix_handle( posix_handle const & );
- #endif // BOOST_MSVC
-
- #ifdef _WIN32
- explicit posix_handle( windows_handle::handle_t );
- #endif // _WIN32
-
- ~posix_handle();
-
- handle_t const & handle() const { return handle_; }
-
-private:
- handle_t const handle_;
-};
-
-
-#ifdef _WIN32
- typedef windows_handle native_handle;
-#else
- typedef posix_handle native_handle;
-#endif // _WIN32
-typedef native_handle::handle_t native_handle_t;
-
-//------------------------------------------------------------------------------
-} // namespace guard
-
-guard::native_handle create_file( char const * file_name, file_flags const & );
-guard::native_handle create_file( char const * file_name, file_flags const &, unsigned int desired_size );
-
-bool set_file_size( guard::native_handle_t, std::size_t desired_size );
-std::size_t get_file_size( guard::native_handle_t );
-
-
 namespace detail
 {
     template <typename Element>
@@ -335,7 +201,7 @@
 
     mapped_view_reference( iterator_range<Element const *> const & mapped_range ) : detail::mapped_view_base<Element const>( mapped_range ) {}
     mapped_view_reference( Element const * const p_begin, Element const * const p_end ) : detail::mapped_view_base<Element const>( p_begin, p_end ) {}
- mapped_view_reference( mapped_view_reference<Element> const & mutable_view ) : detail::mapped_view_base<Element const>( mutable_view ) {}
+ mapped_view_reference( mapped_view_reference<Element> const & mutable_view ) : detail::mapped_view_base<Element const>( mutable_view ) {}
 };
 
 
@@ -344,7 +210,7 @@
     // Implementation note:
     // These have to be defined after mapped_view_reference for eager
     // compilers (e.g. GCC and Clang).
- // (14.07.2011.) (Domagoj Saric)
+ // (14.07.2011.) (Domagoj Saric)
 
     template <typename Element>
     mapped_view_reference<unsigned char const>
@@ -440,16 +306,13 @@
     #endif // BOOST_MSVC
 };
 
-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
 //------------------------------------------------------------------------------
 } // namespace boost
 //------------------------------------------------------------------------------
 
-#define BOOST_MMAP_IMPL_FILE "memory_mapping.inl"
+#define BOOST_MMAP_IMPL_FILE "mapped_view.inl"
 #include "detail/include_impl_file.hpp"
 
-#endif // memory_mapping_hpp
+#endif // mapped_view_hpp

Copied: sandbox/mmap/boost/mmap/mapped_view.inl (from r73413, /sandbox/mmap/boost/mmap/memory_mapping.inl)
==============================================================================
--- /sandbox/mmap/boost/mmap/memory_mapping.inl (original)
+++ sandbox/mmap/boost/mmap/mapped_view.inl 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
@@ -1,7 +1,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 ///
-/// \file memory_mapping.inl
-/// ------------------------
+/// \file mapped_view.inl
+/// ---------------------
 ///
 /// Copyright (c) Domagoj Saric 2010.-2011.
 ///
@@ -13,7 +13,7 @@
 ///
 ////////////////////////////////////////////////////////////////////////////////
 //------------------------------------------------------------------------------
-#include "memory_mapping.hpp"
+#include "mapped_view.hpp"
 
 #include "detail/impl_inline.hpp"
 
@@ -51,206 +51,6 @@
 namespace mmap
 {
 //------------------------------------------------------------------------------
-namespace guard
-{
-
-#ifdef _WIN32
-
-BOOST_IMPL_INLINE
-windows_handle::windows_handle( handle_t const handle )
- :
- handle_( handle )
-{}
-
-BOOST_IMPL_INLINE
-windows_handle::~windows_handle()
-{
- BOOST_VERIFY
- (
- ( ::CloseHandle( handle_ ) != false ) ||
- ( handle_ == 0 || handle_ == INVALID_HANDLE_VALUE )
- );
-}
-
-#endif // _WIN32
-
-BOOST_IMPL_INLINE
-posix_handle::posix_handle( handle_t const handle )
- :
- handle_( handle )
-{}
-
-#ifdef _WIN32
-BOOST_IMPL_INLINE
-posix_handle::posix_handle( windows_handle::handle_t const native_handle )
- :
- handle_( ::_open_osfhandle( reinterpret_cast<intptr_t>( native_handle ), _O_APPEND ) )
-{
- if ( handle_ == -1 )
- {
- BOOST_VERIFY
- (
- ( ::CloseHandle( native_handle ) != false ) ||
- ( native_handle == 0 || native_handle == INVALID_HANDLE_VALUE )
- );
- }
-}
-#endif // _WIN32
-
-BOOST_IMPL_INLINE
-posix_handle::~posix_handle()
-{
- BOOST_VERIFY
- (
- ( ::close( handle() ) == 0 ) ||
- (
- ( handle() == -1 ) &&
- ( errno == EBADF )
- )
- );
-}
-
-//------------------------------------------------------------------------------
-} // guard
-
-
-BOOST_IMPL_INLINE
-guard::native_handle create_file( char const * const file_name, file_flags const & flags )
-{
- BOOST_ASSERT( file_name );
-
-#ifdef _WIN32
-
- HANDLE const file_handle
- (
- ::CreateFileA
- (
- file_name, flags.desired_access, flags.share_mode, 0, flags.creation_disposition, flags.flags_and_attributes, 0
- )
- );
- BOOST_ASSERT( ( file_handle == INVALID_HANDLE_VALUE ) || ( ::GetLastError() == NO_ERROR ) || ( ::GetLastError() == ERROR_ALREADY_EXISTS ) );
-
-#else
-
- mode_t const current_mask( ::umask( 0 ) );
- int const file_handle ( ::open( file_name, flags.oflag, flags.pmode ) );
- //...zzz...investigate posix_fadvise, posix_madvise, fcntl for the system hints...
- BOOST_VERIFY( ::umask( current_mask ) == 0 );
-
-#endif // _WIN32
-
- return guard::native_handle( file_handle );
-}
-
-
-BOOST_IMPL_INLINE
-bool set_file_size( guard::native_handle_t const file_handle, std::size_t const desired_size )
-{
-#ifdef _WIN32
- // It is 'OK' to send null/invalid handles to Windows functions (they will
- // simply fail), this simplifies error handling (it is enough to go through
- // all the logic, inspect the final result and then throw on error).
- DWORD const new_size( ::SetFilePointer( file_handle, desired_size, 0, FILE_BEGIN ) );
- BOOST_ASSERT( ( new_size == desired_size ) || ( file_handle == INVALID_HANDLE_VALUE ) );
- ignore_unused_variable_warning( new_size );
-
- BOOL const success( ::SetEndOfFile( file_handle ) );
-
- BOOST_VERIFY( ( ::SetFilePointer( file_handle, 0, 0, FILE_BEGIN ) == 0 ) || ( file_handle == INVALID_HANDLE_VALUE ) );
-
- return success != false;
-#else
- return ::ftruncate( file_handle, desired_size ) != -1;
-#endif // _WIN32
-}
-
-
-BOOST_IMPL_INLINE
-std::size_t get_file_size( guard::native_handle_t const file_handle )
-{
-#ifdef _WIN32
- DWORD const file_size( ::GetFileSize( file_handle, 0 ) );
- BOOST_ASSERT( ( file_size != INVALID_FILE_SIZE ) || ( file_handle == INVALID_HANDLE_VALUE ) || ( ::GetLastError() == NO_ERROR ) );
- return file_size;
-#else
- struct stat file_info;
- BOOST_VERIFY( ::fstat( file_handle, &file_info ) == 0 );
- return file_info.st_size;
-#endif // _WIN32
-}
-
-
-unsigned int const file_flags::handle_access_rights::read = BOOST_AUX_IO_WIN32_OR_POSIX( GENERIC_READ , O_RDONLY );
-unsigned int const file_flags::handle_access_rights::write = BOOST_AUX_IO_WIN32_OR_POSIX( GENERIC_WRITE , O_WRONLY );
-unsigned int const file_flags::handle_access_rights::execute = BOOST_AUX_IO_WIN32_OR_POSIX( GENERIC_EXECUTE, O_RDONLY );
-
-unsigned int const file_flags::share_mode::none = BOOST_AUX_IO_WIN32_OR_POSIX( 0 , 0 );
-unsigned int const file_flags::share_mode::read = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_SHARE_READ , 0 );
-unsigned int const file_flags::share_mode::write = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_SHARE_WRITE , 0 );
-unsigned int const file_flags::share_mode::remove = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_SHARE_DELETE, 0 );
-
-unsigned int const file_flags::system_hints::random_access = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_RANDOM_ACCESS , /*O_RANDOM*/0 );//...zzz...msvc specific flags...fix this...
-unsigned int const file_flags::system_hints::sequential_access = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_SEQUENTIAL_SCAN , /*O_SEQUENTIAL*/0 );
-unsigned int const file_flags::system_hints::non_cached = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, /*O_DIRECT*/0 );
-unsigned int const file_flags::system_hints::delete_on_close = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_DELETE_ON_CLOSE , /*O_TEMPORARY*/0 );
-unsigned int const file_flags::system_hints::temporary = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_TEMPORARY , /*O_SHORT_LIVED*/0 );
-
-unsigned int const file_flags::on_construction_rights::read = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_READONLY, S_IRUSR );
-unsigned int const file_flags::on_construction_rights::write = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_NORMAL , S_IWUSR );
-unsigned int const file_flags::on_construction_rights::execute = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_NORMAL , S_IXUSR );
-
-BOOST_IMPL_INLINE
-file_flags file_flags::create
-(
- unsigned int const handle_access_flags ,
- unsigned int const share_mode ,
- open_policy_t const open_flags ,
- unsigned int const system_hints ,
- unsigned int const on_construction_rights
-)
-{
- file_flags const flags =
- {
- #ifdef _WIN32
- handle_access_flags, // desired_access
- share_mode, // share_mode
- open_flags, // creation_disposition
- system_hints
- |
- (
- ( on_construction_rights & FILE_ATTRIBUTE_NORMAL )
- ? ( on_construction_rights & ~FILE_ATTRIBUTE_READONLY )
- : on_construction_rights
- ) // flags_and_attributes
- #else // POSIX
- ( ( handle_access_flags == ( O_RDONLY | O_WRONLY ) ) ? O_RDWR : handle_access_flags )
- |
- open_flags
- |
- system_hints, // oflag
- on_construction_rights // pmode
- #endif // OS impl
- };
-
- return flags;
-}
-
-
-BOOST_IMPL_INLINE
-file_flags file_flags::create_for_opening_existing_files( unsigned int const handle_access_flags, unsigned int const share_mode , bool const truncate, unsigned int const system_hints )
-{
- return create
- (
- handle_access_flags,
- share_mode,
- truncate
- ? open_policy::open_and_truncate_existing
- : open_policy::open_existing,
- system_hints,
- 0
- );
-}
-
 
 unsigned int const mapping_flags::handle_access_rights::read = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_MAP_READ , PROT_READ );
 unsigned int const mapping_flags::handle_access_rights::write = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_MAP_WRITE , PROT_WRITE );
@@ -269,9 +69,9 @@
 BOOST_IMPL_INLINE
 mapping_flags mapping_flags::create
 (
- unsigned int handle_access_flags,
- unsigned int share_mode ,
- unsigned int system_hints
+ unsigned int const handle_access_flags,
+ unsigned int const share_mode ,
+ unsigned int const system_hints
 )
 {
     mapping_flags flags;
@@ -400,6 +200,7 @@
 BOOST_IMPL_INLINE
 basic_mapped_view_ref map_file( char const * const file_name, std::size_t desired_size )
 {
+ typedef guard::native_handle::flags file_flags;
     guard::native_handle const file_handle
     (
         create_file
@@ -439,6 +240,7 @@
 BOOST_IMPL_INLINE
 basic_mapped_read_only_view_ref map_read_only_file( char const * const file_name )
 {
+ typedef guard::native_handle::flags file_flags;
     guard::native_handle const file_handle
     (
         create_file
@@ -459,7 +261,8 @@
         file_handle.handle(),
         // Implementation note:
         // Windows APIs interpret zero as 'whole file' but we still need to
- // query the file size in order to be able properly set the end pointer.
+ // query the file size in order to be able to properly set the end
+ // pointer.
         // (13.07.2011.) (Domagoj Saric)
         get_file_size( file_handle.handle() )
     );

Deleted: sandbox/mmap/boost/mmap/memory_mapping.hpp
==============================================================================
--- sandbox/mmap/boost/mmap/memory_mapping.hpp 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
+++ (empty file)
@@ -1,455 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////
-///
-/// \file memory_mapping.hpp
-/// ------------------------
-///
-/// Copyright (c) Domagoj Saric 2010.-2011.
-///
-/// Use, modification and distribution is subject to 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)
-///
-/// For more information, see http://www.boost.org
-///
-////////////////////////////////////////////////////////////////////////////////
-//------------------------------------------------------------------------------
-#ifndef memory_mapping_hpp__D9C84FF5_E506_4ECB_9778_61E036048D28
-#define memory_mapping_hpp__D9C84FF5_E506_4ECB_9778_61E036048D28
-#pragma once
-//------------------------------------------------------------------------------
-#include "boost/assert.hpp"
-#include "boost/noncopyable.hpp"
-#include "boost/range/iterator_range.hpp"
-
-#ifndef _WIN32
- #include "fcntl.h"
-#endif // _WIN32
-
-#ifdef _WIN32
- #define BOOST_AUX_IO_WIN32_OR_POSIX( win32, posix ) win32
-#else
- #define BOOST_AUX_IO_WIN32_OR_POSIX( win32, posix ) posix
-#endif
-//------------------------------------------------------------------------------
-namespace boost
-{
-//------------------------------------------------------------------------------
-namespace mmap
-{
-//------------------------------------------------------------------------------
-
-// Implementation note:
-// Using structs with public members and factory functions to enable (almost)
-// zero-overhead 'link-time' conversion to native flag formats and to allow the
-// user to modify the created flags or create fully custom ones so that specific
-// platform-dependent use-cases, not otherwise covered through the generic
-// interface, can also be covered.
-// (10.10.2010.) (Domagoj Saric)
-
-struct file_flags
-{
- struct handle_access_rights
- {
- static unsigned int const read ;
- static unsigned int const write ;
- static unsigned int const execute;
- };
-
- struct share_mode
- {
- static unsigned int const none ;
- static unsigned int const read ;
- static unsigned int const write ;
- static unsigned int const remove;
- };
-
- struct open_policy
- {
- enum value_type
- {
- create_new = BOOST_AUX_IO_WIN32_OR_POSIX( 1, O_CREAT | O_EXCL ),
- create_new_or_truncate_existing = BOOST_AUX_IO_WIN32_OR_POSIX( 2, O_CREAT | O_TRUNC ),
- open_existing = BOOST_AUX_IO_WIN32_OR_POSIX( 3, 0 ),
- open_or_create = BOOST_AUX_IO_WIN32_OR_POSIX( 4, O_CREAT ),
- open_and_truncate_existing = BOOST_AUX_IO_WIN32_OR_POSIX( 5, O_TRUNC )
- };
- };
- typedef open_policy::value_type open_policy_t;
-
- struct system_hints
- {
- static unsigned int const random_access ;
- static unsigned int const sequential_access;
- static unsigned int const non_cached ;
- static unsigned int const delete_on_close ;
- static unsigned int const temporary ;
- };
-
- struct on_construction_rights
- {
- static unsigned int const read ;
- static unsigned int const write ;
- static unsigned int const execute;
- };
-
- static file_flags create
- (
- unsigned int handle_access_flags ,
- unsigned int share_mode ,
- open_policy_t ,
- unsigned int system_hints ,
- unsigned int on_construction_rights
- );
-
- static file_flags create_for_opening_existing_files
- (
- unsigned int handle_access_flags,
- unsigned int share_mode ,
- bool truncate ,
- unsigned int system_hints
- );
-
-#ifdef _WIN32
- unsigned long desired_access ;
- unsigned long share_mode ;
- unsigned long creation_disposition;
- unsigned long flags_and_attributes;
-#else
- int oflag;
- int pmode;
-#endif // _WIN32
-};
-
-struct mapping_flags
-{
- struct handle_access_rights
- {
- static unsigned int const read ;
- static unsigned int const write ;
- static unsigned int const execute;
- };
-
- struct share_mode
- {
- static unsigned int const shared;
- static unsigned int const hidden;
- };
-
- struct system_hint
- {
- static unsigned int const strict_target_address ;
- static unsigned int const lock_to_ram ;
- static unsigned int const reserve_page_file_space;
- static unsigned int const precommit ;
- static unsigned int const uninitialized ;
- };
-
- static mapping_flags create
- (
- unsigned int handle_access_rights,
- unsigned int share_mode ,
- unsigned int system_hints
- );
-
-#ifdef _WIN32
- unsigned int create_mapping_flags;
- unsigned int map_view_flags;
-#else
- int protection;
- int flags ;
-#endif // _WIN32
-};
-
-
-typedef iterator_range<unsigned char *> basic_memory_range_t;
-typedef iterator_range<unsigned char const *> basic_read_only_memory_range_t;
-
-template <typename Element>
-class mapped_view_reference;
-
-typedef mapped_view_reference<unsigned char > basic_mapped_view_ref;
-typedef mapped_view_reference<unsigned char const> basic_mapped_read_only_view_ref;
-
-namespace guard
-{
-//------------------------------------------------------------------------------
-
-#ifdef _WIN32
-class windows_handle : noncopyable
-{
-public:
- typedef void * handle_t;
-
- explicit windows_handle( handle_t );
- ~windows_handle();
-
- handle_t const & handle() const { return handle_; }
-
-private:
- handle_t const handle_;
-};
-#endif // _WIN32
-
-class posix_handle
-#ifdef BOOST_MSVC
- : noncopyable
-#endif // BOOST_MSVC
-{
-public:
- typedef int handle_t;
-
- explicit posix_handle( handle_t );
- #ifndef BOOST_MSVC
- posix_handle( posix_handle const & );
- #endif // BOOST_MSVC
-
- #ifdef _WIN32
- explicit posix_handle( windows_handle::handle_t );
- #endif // _WIN32
-
- ~posix_handle();
-
- handle_t const & handle() const { return handle_; }
-
-private:
- handle_t const handle_;
-};
-
-
-#ifdef _WIN32
- typedef windows_handle native_handle;
-#else
- typedef posix_handle native_handle;
-#endif // _WIN32
-typedef native_handle::handle_t native_handle_t;
-
-//------------------------------------------------------------------------------
-} // namespace guard
-
-guard::native_handle create_file( char const * file_name, file_flags const & );
-guard::native_handle create_file( char const * file_name, file_flags const &, unsigned int desired_size );
-
-bool set_file_size( guard::native_handle_t, std::size_t desired_size );
-std::size_t get_file_size( guard::native_handle_t );
-
-
-namespace detail
-{
- template <typename Element>
- class mapped_view_base : public iterator_range<Element *>
- {
- 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<unsigned char const>
- #ifdef BOOST_MSVC
- const &
- #endif
- make_basic_view( mapped_view_base<Element> const & );
-
- static mapped_view_reference<Element>
- #ifdef BOOST_MSVC
- const &
- #endif
- make_typed_range( mapped_view_base<unsigned char> const & );
-
- private: // Hide mutable members
- void advance_begin();
- void advance_end ();
-
- void pop_front();
- void pop_back ();
- };
-
-
- template <typename Element>
- void mapped_view_base<Element>::unmap( mapped_view_base<Element> const & mapped_range )
- {
- mapped_view_base<unsigned char const>::unmap( make_basic_view( mapped_range ) );
- }
-
- template <>
- void mapped_view_base<unsigned char const>::unmap( mapped_view_base<unsigned char const> const & );
-} // namespace detail
-
-template <typename Element>
-class mapped_view_reference : public detail::mapped_view_base<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 () ) )
- );
- }
-
-public: // Factory methods.
- static mapped_view_reference map
- (
- guard::native_handle_t,
- mapping_flags const &,
- std::size_t desired_size = 0,
- std::size_t offset = 0
- );
-
-private:
- template <typename T> friend class detail::mapped_view_base;
-
- mapped_view_reference( iterator_range<Element *> const & mapped_range ) : detail::mapped_view_base<Element>( mapped_range ) {}
- mapped_view_reference( Element * const p_begin, Element * const p_end ) : detail::mapped_view_base<Element>( p_begin, p_end ) {}
-};
-
-template <typename Element>
-class mapped_view_reference<Element const> : public detail::mapped_view_base<Element const>
-{
-public:
- basic_memory_range_t basic_range() const
- {
- return basic_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 () ) )
- );
- }
-
-public: // Factory methods.
- static mapped_view_reference map
- (
- guard::native_handle_t object_handle,
- std::size_t desired_size = 0,
- std::size_t offset = 0,
- bool map_for_code_execution = false
- );
-
-private:
- template <typename T> friend class detail::mapped_view_base;
-
- mapped_view_reference( iterator_range<Element const *> const & mapped_range ) : detail::mapped_view_base<Element const>( mapped_range ) {}
- mapped_view_reference( Element const * const p_begin, Element const * const p_end ) : detail::mapped_view_base<Element const>( p_begin, p_end ) {}
- mapped_view_reference( mapped_view_reference<Element> const & mutable_view ) : detail::mapped_view_base<Element const>( mutable_view ) {}
-};
-
-
-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>
- mapped_view_reference<unsigned char const>
- #ifdef BOOST_MSVC
- const &
- #endif
- mapped_view_base<Element>::make_basic_view( mapped_view_base<Element> const & range )
- {
- return
- #ifdef BOOST_MSVC
- reinterpret_cast<mapped_view_reference<unsigned char const> const &>( range );
- #else // compiler might care about strict aliasing rules
- mapped_view_reference<unsigned char const>
- (
- static_cast<unsigned char const *>( static_cast<void const *>( range.begin() ) ),
- static_cast<unsigned char const *>( static_cast<void const *>( range.end () ) )
- );
- #endif // compiler
- }
-
-
- template <typename Element>
- mapped_view_reference<Element>
- #ifdef BOOST_MSVC
- const &
- #endif
- mapped_view_base<Element>::make_typed_range( mapped_view_base<unsigned char> const & range )
- {
- 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> const &>( range );
- #else // compiler might care about strict aliasing rules
- mapped_view_reference<unsigned char const>
- (
- 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<guard::posix_handle::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<guard::windows_handle::handle_t > : mpl::true_ {};
-#endif // _WIN32
-
-
-template <>
-mapped_view_reference<unsigned char> mapped_view_reference<unsigned char>::map
-(
- guard::native_handle_t,
- mapping_flags const &,
- std::size_t desired_size,
- std::size_t offset
-);
-
-template <>
-mapped_view_reference<unsigned char const> mapped_view_reference<unsigned char const>::map
-(
- guard::native_handle_t object_handle,
- std::size_t desired_size,
- std::size_t offset,
- bool map_for_code_execution
-);
-
-
-template <typename Element>
-class mapped_view
- :
- public mapped_view_reference<Element>
- #ifdef BOOST_MSVC
- ,private noncopyable
- #endif // BOOST_MSVC
-{
-public:
- mapped_view( mapped_view_reference<Element> const range ) : mapped_view_reference<Element>( range ) {}
- ~mapped_view<Element>() { boost::mapped_view_reference<Element>::unmap( *this ); }
-
- #ifndef BOOST_MSVC
- mapped_view( mapped_view const & ); // noncopyable
- #endif // BOOST_MSVC
-};
-
-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
-//------------------------------------------------------------------------------
-} // namespace boost
-//------------------------------------------------------------------------------
-
-#define BOOST_MMAP_IMPL_FILE "memory_mapping.inl"
-#include "detail/include_impl_file.hpp"
-
-#endif // memory_mapping_hpp

Deleted: sandbox/mmap/boost/mmap/memory_mapping.inl
==============================================================================
--- sandbox/mmap/boost/mmap/memory_mapping.inl 2011-07-28 19:49:15 EDT (Thu, 28 Jul 2011)
+++ (empty file)
@@ -1,473 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////
-///
-/// \file memory_mapping.inl
-/// ------------------------
-///
-/// Copyright (c) Domagoj Saric 2010.-2011.
-///
-/// Use, modification and distribution is subject to 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)
-///
-/// For more information, see http://www.boost.org
-///
-////////////////////////////////////////////////////////////////////////////////
-//------------------------------------------------------------------------------
-#include "memory_mapping.hpp"
-
-#include "detail/impl_inline.hpp"
-
-#include "boost/assert.hpp"
-
-#ifdef _WIN32
- #ifndef WIN32_LEAN_AND_MEAN
- #define WIN32_LEAN_AND_MEAN
- #endif // WIN32_LEAN_AND_MEAN
- #include "windows.h"
-
- #pragma warning ( disable : 4996 ) // "The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name."
- #include "io.h"
-#else
- #include "sys/mman.h" // mmap, munmap.
- #include "sys/stat.h"
- #include "sys/types.h" // struct stat.
- #include "unistd.h" // sysconf.
-#endif // _WIN32
-#include "errno.h"
-#include "fcntl.h"
-
-#ifndef _WIN32
- #ifdef __APPLE__
- #define BOOST_AUX_MMAP_POSIX_OR_OSX( posix, osx ) osx
- #else
- #define BOOST_AUX_MMAP_POSIX_OR_OSX( posix, osx ) posix
- #endif
-#endif
-
-//------------------------------------------------------------------------------
-namespace boost
-{
-//------------------------------------------------------------------------------
-namespace mmap
-{
-//------------------------------------------------------------------------------
-namespace guard
-{
-
-#ifdef _WIN32
-
-BOOST_IMPL_INLINE
-windows_handle::windows_handle( handle_t const handle )
- :
- handle_( handle )
-{}
-
-BOOST_IMPL_INLINE
-windows_handle::~windows_handle()
-{
- BOOST_VERIFY
- (
- ( ::CloseHandle( handle_ ) != false ) ||
- ( handle_ == 0 || handle_ == INVALID_HANDLE_VALUE )
- );
-}
-
-#endif // _WIN32
-
-BOOST_IMPL_INLINE
-posix_handle::posix_handle( handle_t const handle )
- :
- handle_( handle )
-{}
-
-#ifdef _WIN32
-BOOST_IMPL_INLINE
-posix_handle::posix_handle( windows_handle::handle_t const native_handle )
- :
- handle_( ::_open_osfhandle( reinterpret_cast<intptr_t>( native_handle ), _O_APPEND ) )
-{
- if ( handle_ == -1 )
- {
- BOOST_VERIFY
- (
- ( ::CloseHandle( native_handle ) != false ) ||
- ( native_handle == 0 || native_handle == INVALID_HANDLE_VALUE )
- );
- }
-}
-#endif // _WIN32
-
-BOOST_IMPL_INLINE
-posix_handle::~posix_handle()
-{
- BOOST_VERIFY
- (
- ( ::close( handle() ) == 0 ) ||
- (
- ( handle() == -1 ) &&
- ( errno == EBADF )
- )
- );
-}
-
-//------------------------------------------------------------------------------
-} // guard
-
-
-BOOST_IMPL_INLINE
-guard::native_handle create_file( char const * const file_name, file_flags const & flags )
-{
- BOOST_ASSERT( file_name );
-
-#ifdef _WIN32
-
- HANDLE const file_handle
- (
- ::CreateFileA
- (
- file_name, flags.desired_access, flags.share_mode, 0, flags.creation_disposition, flags.flags_and_attributes, 0
- )
- );
- BOOST_ASSERT( ( file_handle == INVALID_HANDLE_VALUE ) || ( ::GetLastError() == NO_ERROR ) || ( ::GetLastError() == ERROR_ALREADY_EXISTS ) );
-
-#else
-
- mode_t const current_mask( ::umask( 0 ) );
- int const file_handle ( ::open( file_name, flags.oflag, flags.pmode ) );
- //...zzz...investigate posix_fadvise, posix_madvise, fcntl for the system hints...
- BOOST_VERIFY( ::umask( current_mask ) == 0 );
-
-#endif // _WIN32
-
- return guard::native_handle( file_handle );
-}
-
-
-BOOST_IMPL_INLINE
-bool set_file_size( guard::native_handle_t const file_handle, std::size_t const desired_size )
-{
-#ifdef _WIN32
- // It is 'OK' to send null/invalid handles to Windows functions (they will
- // simply fail), this simplifies error handling (it is enough to go through
- // all the logic, inspect the final result and then throw on error).
- DWORD const new_size( ::SetFilePointer( file_handle, desired_size, 0, FILE_BEGIN ) );
- BOOST_ASSERT( ( new_size == desired_size ) || ( file_handle == INVALID_HANDLE_VALUE ) );
- ignore_unused_variable_warning( new_size );
-
- BOOL const success( ::SetEndOfFile( file_handle ) );
-
- BOOST_VERIFY( ( ::SetFilePointer( file_handle, 0, 0, FILE_BEGIN ) == 0 ) || ( file_handle == INVALID_HANDLE_VALUE ) );
-
- return success != false;
-#else
- return ::ftruncate( file_handle, desired_size ) != -1;
-#endif // _WIN32
-}
-
-
-BOOST_IMPL_INLINE
-std::size_t get_file_size( guard::native_handle_t const file_handle )
-{
-#ifdef _WIN32
- DWORD const file_size( ::GetFileSize( file_handle, 0 ) );
- BOOST_ASSERT( ( file_size != INVALID_FILE_SIZE ) || ( file_handle == INVALID_HANDLE_VALUE ) || ( ::GetLastError() == NO_ERROR ) );
- return file_size;
-#else
- struct stat file_info;
- BOOST_VERIFY( ::fstat( file_handle, &file_info ) == 0 );
- return file_info.st_size;
-#endif // _WIN32
-}
-
-
-unsigned int const file_flags::handle_access_rights::read = BOOST_AUX_IO_WIN32_OR_POSIX( GENERIC_READ , O_RDONLY );
-unsigned int const file_flags::handle_access_rights::write = BOOST_AUX_IO_WIN32_OR_POSIX( GENERIC_WRITE , O_WRONLY );
-unsigned int const file_flags::handle_access_rights::execute = BOOST_AUX_IO_WIN32_OR_POSIX( GENERIC_EXECUTE, O_RDONLY );
-
-unsigned int const file_flags::share_mode::none = BOOST_AUX_IO_WIN32_OR_POSIX( 0 , 0 );
-unsigned int const file_flags::share_mode::read = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_SHARE_READ , 0 );
-unsigned int const file_flags::share_mode::write = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_SHARE_WRITE , 0 );
-unsigned int const file_flags::share_mode::remove = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_SHARE_DELETE, 0 );
-
-unsigned int const file_flags::system_hints::random_access = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_RANDOM_ACCESS , /*O_RANDOM*/0 );//...zzz...msvc specific flags...fix this...
-unsigned int const file_flags::system_hints::sequential_access = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_SEQUENTIAL_SCAN , /*O_SEQUENTIAL*/0 );
-unsigned int const file_flags::system_hints::non_cached = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, /*O_DIRECT*/0 );
-unsigned int const file_flags::system_hints::delete_on_close = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_FLAG_DELETE_ON_CLOSE , /*O_TEMPORARY*/0 );
-unsigned int const file_flags::system_hints::temporary = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_TEMPORARY , /*O_SHORT_LIVED*/0 );
-
-unsigned int const file_flags::on_construction_rights::read = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_READONLY, S_IRUSR );
-unsigned int const file_flags::on_construction_rights::write = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_NORMAL , S_IWUSR );
-unsigned int const file_flags::on_construction_rights::execute = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_ATTRIBUTE_NORMAL , S_IXUSR );
-
-BOOST_IMPL_INLINE
-file_flags file_flags::create
-(
- unsigned int const handle_access_flags ,
- unsigned int const share_mode ,
- open_policy_t const open_flags ,
- unsigned int const system_hints ,
- unsigned int const on_construction_rights
-)
-{
- file_flags const flags =
- {
- #ifdef _WIN32
- handle_access_flags, // desired_access
- share_mode, // share_mode
- open_flags, // creation_disposition
- system_hints
- |
- (
- ( on_construction_rights & FILE_ATTRIBUTE_NORMAL )
- ? ( on_construction_rights & ~FILE_ATTRIBUTE_READONLY )
- : on_construction_rights
- ) // flags_and_attributes
- #else // POSIX
- ( ( handle_access_flags == ( O_RDONLY | O_WRONLY ) ) ? O_RDWR : handle_access_flags )
- |
- open_flags
- |
- system_hints, // oflag
- on_construction_rights // pmode
- #endif // OS impl
- };
-
- return flags;
-}
-
-
-BOOST_IMPL_INLINE
-file_flags file_flags::create_for_opening_existing_files( unsigned int const handle_access_flags, unsigned int const share_mode , bool const truncate, unsigned int const system_hints )
-{
- return create
- (
- handle_access_flags,
- share_mode,
- truncate
- ? open_policy::open_and_truncate_existing
- : open_policy::open_existing,
- system_hints,
- 0
- );
-}
-
-
-unsigned int const mapping_flags::handle_access_rights::read = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_MAP_READ , PROT_READ );
-unsigned int const mapping_flags::handle_access_rights::write = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_MAP_WRITE , PROT_WRITE );
-unsigned int const mapping_flags::handle_access_rights::execute = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_MAP_EXECUTE, PROT_EXEC );
-
-unsigned int const mapping_flags::share_mode::shared = BOOST_AUX_IO_WIN32_OR_POSIX( 0, MAP_SHARED );
-unsigned int const mapping_flags::share_mode::hidden = BOOST_AUX_IO_WIN32_OR_POSIX( FILE_MAP_COPY, MAP_PRIVATE );
-
-unsigned int const mapping_flags::system_hint::strict_target_address = BOOST_AUX_IO_WIN32_OR_POSIX( 0, MAP_FIXED );
-unsigned int const mapping_flags::system_hint::lock_to_ram = BOOST_AUX_IO_WIN32_OR_POSIX( SEC_COMMIT , BOOST_AUX_MMAP_POSIX_OR_OSX( MAP_LOCKED, 0 ) );
-unsigned int const mapping_flags::system_hint::reserve_page_file_space = BOOST_AUX_IO_WIN32_OR_POSIX( SEC_RESERVE, /*khm#1*/MAP_NORESERVE );
-unsigned int const mapping_flags::system_hint::precommit = BOOST_AUX_IO_WIN32_OR_POSIX( SEC_COMMIT , BOOST_AUX_MMAP_POSIX_OR_OSX( MAP_POPULATE, 0 ) );
-unsigned int const mapping_flags::system_hint::uninitialized = BOOST_AUX_IO_WIN32_OR_POSIX( 0, BOOST_AUX_MMAP_POSIX_OR_OSX( MAP_UNINITIALIZED, 0 ) );
-
-
-BOOST_IMPL_INLINE
-mapping_flags mapping_flags::create
-(
- unsigned int handle_access_flags,
- unsigned int share_mode ,
- unsigned int system_hints
-)
-{
- mapping_flags flags;
-#ifdef _WIN32
- flags.create_mapping_flags = ( handle_access_flags & handle_access_rights::execute ) ? PAGE_EXECUTE : PAGE_NOACCESS;
- if ( share_mode == share_mode::hidden ) // WRITECOPY
- flags.create_mapping_flags *= 8;
- else
- if ( handle_access_flags & handle_access_rights::write )
- flags.create_mapping_flags *= 4;
- else
- {
- BOOST_ASSERT( handle_access_flags & handle_access_rights::read );
- flags.create_mapping_flags *= 2;
- }
-
- flags.create_mapping_flags |= system_hints;
-
- flags.map_view_flags = handle_access_flags;
-#else
- flags.protection = handle_access_flags;
- flags.flags = share_mode | system_hints;
- if ( ( system_hints & system_hint::reserve_page_file_space ) ) /*khm#1*/
- flags.flags &= ~MAP_NORESERVE;
- else
- flags.flags |= MAP_NORESERVE;
-#endif // _WIN32
-
- return flags;
-}
-
-
-template <> BOOST_IMPL_INLINE
-mapped_view_reference<unsigned char> mapped_view_reference<unsigned char>::map
-(
- guard::native_handle_t const object_handle,
- mapping_flags const & flags,
- std::size_t const desired_size,
- std::size_t const offset
-)
-{
- typedef mapped_view_reference<unsigned char>::iterator iterator_t;
-
-#ifdef _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)
-
- ULARGE_INTEGER large_integer;
-
- // CreateFileMapping accepts INVALID_HANDLE_VALUE as valid input but only if
- // the size parameter is not null.
- large_integer.QuadPart = desired_size;
- guard::windows_handle const mapping
- (
- ::CreateFileMapping( object_handle, 0, flags.create_mapping_flags, large_integer.HighPart, large_integer.LowPart, 0 )
- );
- BOOST_ASSERT
- (
- !mapping.handle() || ( object_handle == INVALID_HANDLE_VALUE ) || ( desired_size != 0 )
- );
-
- large_integer.QuadPart = offset;
- iterator_t const view_start( static_cast<iterator_t>( ::MapViewOfFile( mapping.handle(), flags.map_view_flags, large_integer.HighPart, large_integer.LowPart, desired_size ) ) );
- return mapped_view_reference<unsigned char>
- (
- view_start,
- ( view_start && ( object_handle != INVALID_HANDLE_VALUE ) )
- ? view_start + desired_size
- : view_start
- );
-
-#else // POSIX
-
- iterator_t const view_start( static_cast<iterator_t>( ::mmap( 0, desired_size, flags.protection, flags.flags, object_handle, 0 ) ) );
- return mapped_view_reference<unsigned char>
- (
- view_start,
- ( view_start != MAP_FAILED )
- ? view_start + desired_size
- : view_start
- );
-
-#endif // OS API
-}
-
-
-template <> BOOST_IMPL_INLINE
-void detail::mapped_view_base<unsigned char const>::unmap( detail::mapped_view_base<unsigned char const> const & mapped_range )
-{
-#ifdef _WIN32
- BOOST_VERIFY( ::UnmapViewOfFile( mapped_range.begin() ) || mapped_range.empty() );
-#else
- BOOST_VERIFY( ( ::munmap ( const_cast<unsigned char *>( mapped_range.begin() ), mapped_range.size() ) == 0 ) || mapped_range.empty() );
-#endif // _WIN32
-}
-
-
-template <> BOOST_IMPL_INLINE
-mapped_view_reference<unsigned char const> mapped_view_reference<unsigned char const>::map
-(
- guard::native_handle_t const object_handle,
- std::size_t const desired_size,
- std::size_t const offset,
- bool const map_for_code_execution
-)
-{
- return mapped_view_reference<unsigned char>::map
- (
- object_handle,
- mapping_flags::create
- (
- mapping_flags::handle_access_rights::read | ( map_for_code_execution ? mapping_flags::handle_access_rights::execute : 0 ),
- mapping_flags::share_mode::shared,
- mapping_flags::system_hint::uninitialized
- ),
- desired_size,
- offset
- );
-}
-
-
-BOOST_IMPL_INLINE
-basic_mapped_view_ref map_file( char const * const file_name, std::size_t desired_size )
-{
- guard::native_handle const file_handle
- (
- create_file
- (
- file_name,
- file_flags::create
- (
- file_flags::handle_access_rights::read | file_flags::handle_access_rights::write,
- file_flags::share_mode ::read,
- file_flags::open_policy::open_or_create,
- file_flags::system_hints ::sequential_access,
- file_flags::on_construction_rights::read | file_flags::on_construction_rights::write
- )
- )
- );
-
- if ( desired_size )
- set_file_size( file_handle.handle(), desired_size );
- else
- desired_size = get_file_size( file_handle.handle() );
-
- return basic_mapped_view_ref::map
- (
- file_handle.handle(),
- mapping_flags::create
- (
- mapping_flags::handle_access_rights::read | mapping_flags::handle_access_rights::write,
- mapping_flags::share_mode::shared,
- mapping_flags::system_hint::uninitialized
- ),
- desired_size,
- 0
- );
-}
-
-
-BOOST_IMPL_INLINE
-basic_mapped_read_only_view_ref map_read_only_file( char const * const file_name )
-{
- guard::native_handle const file_handle
- (
- create_file
- (
- file_name,
- file_flags::create_for_opening_existing_files
- (
- file_flags::handle_access_rights::read,
- file_flags::share_mode ::read | file_flags::share_mode::write,
- false,
- file_flags::system_hints ::sequential_access
- )
- )
- );
-
- return basic_mapped_read_only_view_ref::map
- (
- file_handle.handle(),
- // Implementation note:
- // Windows APIs interpret zero as 'whole file' but we still need to
- // query the file size in order to be able properly set the end pointer.
- // (13.07.2011.) (Domagoj Saric)
- get_file_size( file_handle.handle() )
- );
-}
-
-
-//------------------------------------------------------------------------------
-} // mmap
-//------------------------------------------------------------------------------
-} // boost
-//------------------------------------------------------------------------------


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