|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r74062 - in sandbox/mmap/boost/mmap: . mappble_objects/file mappble_objects/file/posix mappble_objects/file/win32
From: dsaritz_at_[hidden]
Date: 2011-08-25 18:24:30
Author: psiha
Date: 2011-08-25 18:24:28 EDT (Thu, 25 Aug 2011)
New Revision: 74062
URL: http://svn.boost.org/trac/boost/changeset/74062
Log:
Added file deletion functions.
Added wchar_t overloads.
Fixed/updated the mappble_objects\file\flags.hpp header.
Added the file_handle class template (required for Windows platforms to distinguish between file and shared memory handles).
Minor other changes.
Added:
sandbox/mmap/boost/mmap/mappble_objects/file/handle.hpp
- copied, changed from r74032, /sandbox/mmap/boost/mmap/handles/mapping_handle.hpp
Text files modified:
sandbox/mmap/boost/mmap/implementations.hpp | 8 +++---
sandbox/mmap/boost/mmap/mappble_objects/file/file.hpp | 3 ++
sandbox/mmap/boost/mmap/mappble_objects/file/flags.hpp | 8 ++---
sandbox/mmap/boost/mmap/mappble_objects/file/handle.hpp | 12 ++++----
sandbox/mmap/boost/mmap/mappble_objects/file/posix/file.hpp | 13 +++++++--
sandbox/mmap/boost/mmap/mappble_objects/file/posix/file.inl | 30 +++++++++++++++++++++++
sandbox/mmap/boost/mmap/mappble_objects/file/win32/file.hpp | 15 +++++++---
sandbox/mmap/boost/mmap/mappble_objects/file/win32/file.inl | 51 ++++++++++++++++++++++++++++++++++++---
sandbox/mmap/boost/mmap/mappble_objects/file/win32/flags.inl | 2
sandbox/mmap/boost/mmap/mapped_view.inl | 6 ++--
10 files changed, 117 insertions(+), 31 deletions(-)
Modified: sandbox/mmap/boost/mmap/implementations.hpp
==============================================================================
--- sandbox/mmap/boost/mmap/implementations.hpp (original)
+++ sandbox/mmap/boost/mmap/implementations.hpp 2011-08-25 18:24:28 EDT (Thu, 25 Aug 2011)
@@ -24,10 +24,10 @@
{
//------------------------------------------------------------------------------
-struct nt;
-struct posix;
-struct win32;
-struct xsi;
+struct nt {};
+struct posix {};
+struct win32 {};
+struct xsi {};
//------------------------------------------------------------------------------
} // namespace mmap
Modified: sandbox/mmap/boost/mmap/mappble_objects/file/file.hpp
==============================================================================
--- sandbox/mmap/boost/mmap/mappble_objects/file/file.hpp (original)
+++ sandbox/mmap/boost/mmap/mappble_objects/file/file.hpp 2011-08-25 18:24:28 EDT (Thu, 25 Aug 2011)
@@ -31,6 +31,9 @@
typedef file_flags<BOOST_MMAP_IMPL> native_file_flags;
+inline bool delete_file( char const * const file_name ) { delete_file( file_name, BOOST_MMAP_IMPL () ); }
+inline bool delete_file( wchar_t const * const file_name ) { delete_file( file_name, BOOST_MMAP_IMPL () ); }
+
//------------------------------------------------------------------------------
} // namespace mmap
//------------------------------------------------------------------------------
Modified: sandbox/mmap/boost/mmap/mappble_objects/file/flags.hpp
==============================================================================
--- sandbox/mmap/boost/mmap/mappble_objects/file/flags.hpp (original)
+++ sandbox/mmap/boost/mmap/mappble_objects/file/flags.hpp 2011-08-25 18:24:28 EDT (Thu, 25 Aug 2011)
@@ -17,10 +17,8 @@
#define flags_hpp__BFFC0541_21AC_4A80_A9EE_E0450B6D4D8A
#pragma once
//------------------------------------------------------------------------------
-#ifdef _WIN32
-#include "../win32_file/flags.hpp"
-#else
-#include "../posix_file/flags.hpp"
-#endif
+#include "../../detail/impl_selection.hpp"
+
+#include BOOST_MMAP_IMPL_INCLUDE( ./, /flags.hpp )
//------------------------------------------------------------------------------
#endif // flags_hpp
Copied: sandbox/mmap/boost/mmap/mappble_objects/file/handle.hpp (from r74032, /sandbox/mmap/boost/mmap/handles/mapping_handle.hpp)
==============================================================================
--- /sandbox/mmap/boost/mmap/handles/mapping_handle.hpp (original)
+++ sandbox/mmap/boost/mmap/mappble_objects/file/handle.hpp 2011-08-25 18:24:28 EDT (Thu, 25 Aug 2011)
@@ -13,11 +13,10 @@
///
////////////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------------
-#ifndef mapping_handle_hpp__D42BC724_FD9A_4C7B_B521_CF3C29C948B3
-#define mapping_handle_hpp__D42BC724_FD9A_4C7B_B521_CF3C29C948B3
+#ifndef handle_hpp__56DDDE10_05C3_4B18_8DC5_89317D689F99
+#define handle_hpp__56DDDE10_05C3_4B18_8DC5_89317D689F99
#pragma once
//------------------------------------------------------------------------------
-#include "handle.hpp"
//------------------------------------------------------------------------------
namespace boost
{
@@ -29,11 +28,12 @@
template <typename Impl> class handle;
template <typename Impl>
-class mapping_handle : handle<Impl>
+struct file_handle : handle<Impl>
{
-public:
- mapping_handle( typename handle<Impl>::handle_t const native_handle )
+ file_handle( typename handle<Impl>::native_handle_t const native_handle )
: handle<Impl>( native_handle ) {}
+
+ typedef handle_ref< file_handle<Impl> > reference;
};
//------------------------------------------------------------------------------
Modified: sandbox/mmap/boost/mmap/mappble_objects/file/posix/file.hpp
==============================================================================
--- sandbox/mmap/boost/mmap/mappble_objects/file/posix/file.hpp (original)
+++ sandbox/mmap/boost/mmap/mappble_objects/file/posix/file.hpp 2011-08-25 18:24:28 EDT (Thu, 25 Aug 2011)
@@ -17,6 +17,7 @@
#define file_hpp__1E2F9841_1C6C_40D9_9AA7_BAC0003CD909
#pragma once
//------------------------------------------------------------------------------
+#include "../../../implementations.hpp"
#include "../../../handles/posix/handle.hpp"
#include <cstddef>
@@ -38,13 +39,19 @@
#endif // BOOST_HAS_UNISTD_H
-handle<posix> create_file( char const * file_name, file_flags<posix> const & );
+handle<posix> create_file( char const * file_name, file_flags<posix> const & );
+#ifdef BOOST_MSVC
+handle<posix> create_file( wchar_t const * file_name, file_flags<posix> const & );
+#endif // BOOST_MSVC
+
+bool delete_file( char const * file_name, posix );
+bool delete_file( wchar_t const * file_name, posix );
#ifdef BOOST_HAS_UNISTD_H
-bool set_size( handle_ref< handle<posix> >, std::size_t desired_size );
+bool set_size( handle<posix>::reference, std::size_t desired_size );
#endif // BOOST_HAS_UNISTD_H
-std::size_t get_size( handle_ref< handle<posix> > );
+std::size_t get_size( handle<posix>::reference );
//------------------------------------------------------------------------------
} // namespace mmap
Modified: sandbox/mmap/boost/mmap/mappble_objects/file/posix/file.inl
==============================================================================
--- sandbox/mmap/boost/mmap/mappble_objects/file/posix/file.inl (original)
+++ sandbox/mmap/boost/mmap/mappble_objects/file/posix/file.inl 2011-08-25 18:24:28 EDT (Thu, 25 Aug 2011)
@@ -23,6 +23,7 @@
#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"
+ #include "wchar.h"
#else
#include "sys/mman.h" // mmap, munmap.
#include "sys/stat.h"
@@ -52,6 +53,35 @@
return handle<posix>( file_handle );
}
+#ifdef BOOST_MSVC
+BOOST_IMPL_INLINE
+handle<posix> create_file( wchar_t const * const file_name, file_flags<posix> const & flags )
+{
+ BOOST_ASSERT( file_name );
+
+ int const current_mask( ::umask( 0 ) );
+ int const file_handle ( ::_wopen( file_name, flags.oflag, flags.pmode ) );
+ BOOST_VERIFY( ::umask( current_mask ) == 0 );
+
+ return handle<posix>( file_handle );
+}
+#endif // BOOST_MSVC
+
+
+BOOST_IMPL_INLINE
+bool delete_file( char const * const file_name, posix )
+{
+ return ::unlink( file_name ) == 0;
+}
+
+#ifdef BOOST_MSVC
+BOOST_IMPL_INLINE
+bool delete_file( wchar_t const * const file_name, posix )
+{
+ return ::_wunlink( file_name ) == 0;
+}
+#endif // BOOST_MSVC
+
#ifdef BOOST_HAS_UNISTD_H
BOOST_IMPL_INLINE
Modified: sandbox/mmap/boost/mmap/mappble_objects/file/win32/file.hpp
==============================================================================
--- sandbox/mmap/boost/mmap/mappble_objects/file/win32/file.hpp (original)
+++ sandbox/mmap/boost/mmap/mappble_objects/file/win32/file.hpp 2011-08-25 18:24:28 EDT (Thu, 25 Aug 2011)
@@ -17,7 +17,8 @@
#define file_hpp__FB482005_18D9_4E3B_9193_A13DBFE88F45
#pragma once
//------------------------------------------------------------------------------
-#include "../../../handles/win32/handle.hpp"
+#include "../handle.hpp"
+#include "../../../implementations.hpp"
#include <cstddef>
//------------------------------------------------------------------------------
@@ -31,13 +32,17 @@
template <typename Impl > struct file_flags;
template <class Handle> struct is_resizable;
-template <> struct is_resizable< handle<win32> > : mpl::true_ {};
+template <> struct is_resizable< file_handle<win32> > : mpl::true_ {};
-handle<win32> create_file( char const * file_name, file_flags<win32> const & );
+file_handle<win32> create_file( char const * file_name, file_flags<win32> const & );
+file_handle<win32> create_file( wchar_t const * file_name, file_flags<win32> const & );
+bool delete_file( char const * file_name, win32 );
+bool delete_file( wchar_t const * file_name, win32 );
-bool set_size( handle<win32>::reference, std::size_t desired_size );
-std::size_t get_size( handle<win32>::reference );
+
+bool set_size( file_handle<win32>::reference, std::size_t desired_size );
+std::size_t get_size( file_handle<win32>::reference );
//------------------------------------------------------------------------------
Modified: sandbox/mmap/boost/mmap/mappble_objects/file/win32/file.inl
==============================================================================
--- sandbox/mmap/boost/mmap/mappble_objects/file/win32/file.inl (original)
+++ sandbox/mmap/boost/mmap/mappble_objects/file/win32/file.inl 2011-08-25 18:24:28 EDT (Thu, 25 Aug 2011)
@@ -33,8 +33,14 @@
//------------------------------------------------------------------------------
BOOST_IMPL_INLINE
-handle<win32> create_file( char const * const file_name, file_flags<win32> const & flags )
+file_handle<win32> create_file( char const * const file_name, file_flags<win32> const & flags )
{
+ /// \note
+ /// This typedef is required by MSVC++ 10 SP1 and must be placed before
+ /// the CreateFile call, otherwise it breaks at the return statement.
+ /// (25.08.2011.) (Domagoj Saric)
+ typedef file_handle<win32> win32_file_handle;
+
BOOST_ASSERT( file_name );
HANDLE const file_handle
@@ -45,13 +51,50 @@
)
);
BOOST_ASSERT( ( file_handle == INVALID_HANDLE_VALUE ) || ( ::GetLastError() == NO_ERROR ) || ( ::GetLastError() == ERROR_ALREADY_EXISTS ) );
+
+ return win32_file_handle( file_handle );
+}
+
+BOOST_IMPL_INLINE
+file_handle<win32> create_file( wchar_t const * const file_name, file_flags<win32> const & flags )
+{
+ /// \note
+ /// This typedef is required by MSVC++ 10 SP1 and must be placed before
+ /// the CreateFile call, otherwise it breaks at the return statement.
+ /// (25.08.2011.) (Domagoj Saric)
+ typedef file_handle<win32> win32_file_handle;
+
+ BOOST_ASSERT( file_name );
+
+ HANDLE const file_handle
+ (
+ ::CreateFileW
+ (
+ 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 win32_file_handle( file_handle );
+}
+
+
+BOOST_IMPL_INLINE
+bool delete_file( char const * const file_name, win32 )
+{
+ return ::DeleteFileA( file_name ) != false;
+}
- return handle<win32>( file_handle );
+BOOST_IMPL_INLINE
+bool delete_file( wchar_t const * const file_name, win32 )
+{
+ return ::DeleteFileW( file_name ) != false;
}
+
BOOST_IMPL_INLINE
-bool set_size( handle<win32>::reference const file_handle, std::size_t const desired_size )
+bool set_size( file_handle<win32>::reference 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
@@ -85,7 +128,7 @@
BOOST_IMPL_INLINE
-std::size_t get_size( handle<win32>::reference const file_handle )
+std::size_t get_size( file_handle<win32>::reference const file_handle )
{
#ifdef _WIN64
LARGE_INTEGER file_size;
Modified: sandbox/mmap/boost/mmap/mappble_objects/file/win32/flags.inl
==============================================================================
--- sandbox/mmap/boost/mmap/mappble_objects/file/win32/flags.inl (original)
+++ sandbox/mmap/boost/mmap/mappble_objects/file/win32/flags.inl 2011-08-25 18:24:28 EDT (Thu, 25 Aug 2011)
@@ -48,7 +48,7 @@
unsigned int const file_flags<win32>::on_construction_rights::read = FILE_ATTRIBUTE_READONLY;
unsigned int const file_flags<win32>::on_construction_rights::write = FILE_ATTRIBUTE_NORMAL ;
-unsigned int const file_flags<win32>::on_construction_rights::execute = FILE_ATTRIBUTE_NORMAL ;
+unsigned int const file_flags<win32>::on_construction_rights::execute = FILE_ATTRIBUTE_READONLY;
BOOST_IMPL_INLINE
file_flags<win32> file_flags<win32>::create
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-25 18:24:28 EDT (Thu, 25 Aug 2011)
@@ -131,7 +131,7 @@
large_integer.QuadPart = desired_size;
handle<win32> const mapping
(
- ::CreateFileMapping( object_handle, 0, flags.create_mapping_flags, large_integer.HighPart, large_integer.LowPart, 0 )
+ ::CreateFileMappingW( object_handle, 0, flags.create_mapping_flags, large_integer.HighPart, large_integer.LowPart, 0 )
);
BOOST_ASSERT
(
@@ -202,7 +202,7 @@
basic_mapped_view_ref map_file( char const * const file_name, std::size_t desired_size )
{
typedef native_file_flags file_flags;
- native_handle const file_handle
+ file_handle<BOOST_MMAP_IMPL> const file_handle
(
create_file
(
@@ -242,7 +242,7 @@
basic_mapped_read_only_view_ref map_read_only_file( char const * const file_name )
{
typedef native_file_flags file_flags;
- native_handle const file_handle
+ file_handle<BOOST_MMAP_IMPL> const file_handle
(
create_file
(
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