|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r67140 - in sandbox/gil/boost/gil/extension/io2: . detail
From: dsaritz_at_[hidden]
Date: 2010-12-09 19:10:40
Author: psiha
Date: 2010-12-09 19:10:39 EST (Thu, 09 Dec 2010)
New Revision: 67140
URL: http://svn.boost.org/trac/boost/changeset/67140
Log:
Added an IStream implementation for native Win32 file HANDLEs. Added appropriate wrappers.
Text files modified:
sandbox/gil/boost/gil/extension/io2/detail/windows_shared.hpp | 52 ++++++++++++++++++++++++++++
sandbox/gil/boost/gil/extension/io2/detail/windows_shared_istreams.hpp | 72 ++++++++++++++++++++++++++++++++++++++++
sandbox/gil/boost/gil/extension/io2/wic_image.hpp | 6 +-
3 files changed, 127 insertions(+), 3 deletions(-)
Modified: sandbox/gil/boost/gil/extension/io2/detail/windows_shared.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/detail/windows_shared.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/detail/windows_shared.hpp 2010-12-09 19:10:39 EST (Thu, 09 Dec 2010)
@@ -131,6 +131,58 @@
////////////////////////////////////////////////////////////////////////////////
///
+/// \class output_file_name_for_IStream_extender
+/// \internal
+/// \brief Helper wrapper for classes that can construct from IStream objects.
+///
+////////////////////////////////////////////////////////////////////////////////
+
+template <class IStream_capable_class>
+class __declspec( novtable ) output_file_name_for_IStream_extender
+ :
+ private FileHandleWriteStream,
+ public IStream_capable_class
+{
+public:
+ output_file_name_for_IStream_extender( wchar_t const * const file_name )
+ :
+ FileHandleWriteStream( do_open( file_name ) ),
+ IStream_capable_class( static_cast<IStream &>( *this ) )
+ {}
+
+ template <typename A2> //...zzz...
+ output_file_name_for_IStream_extender( wchar_t const * const file_name, A2 const & a2 )
+ :
+ FileHandleWriteStream( do_open( file_name ) ),
+ IStream_capable_class( static_cast<IStream &>( *this ), a2 )
+ {}
+
+ ~output_file_name_for_IStream_extender() { BOOST_VERIFY( ::CloseHandle( file_ ) ); }
+
+private:
+ static HANDLE do_open( wchar_t const * const file_name )
+ {
+ HANDLE const handle
+ (
+ ::CreateFileW
+ (
+ file_name,
+ GENERIC_WRITE,
+ 0,
+ 0,
+ OPEN_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
+ NULL
+ )
+ );
+ io_error_if_not( handle, "File open failure" );
+ return handle;
+ }
+};
+
+
+////////////////////////////////////////////////////////////////////////////////
+///
/// \class memory_chunk_for_IStream_extender
/// \internal
/// \brief Helper wrapper for classes that can construct from IStream objects.
Modified: sandbox/gil/boost/gil/extension/io2/detail/windows_shared_istreams.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/detail/windows_shared_istreams.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/detail/windows_shared_istreams.hpp 2010-12-09 19:10:39 EST (Thu, 09 Dec 2010)
@@ -255,6 +255,78 @@
////////////////////////////////////////////////////////////////////////////////
///
+/// \class FileHandleStreamBase
+/// ---------------------------
+///
+////////////////////////////////////////////////////////////////////////////////
+
+class __declspec( novtable ) FileHandleStreamBase : public StreamBase
+{
+protected:
+ FileHandleStreamBase( HANDLE const file ) : file_( file ) {}
+
+private:
+ HRESULT STDMETHODCALLTYPE Seek( LARGE_INTEGER const dlibMove, DWORD const dwOrigin, ULARGE_INTEGER * const plibNewPosition ) override
+ {
+ BOOST_STATIC_ASSERT( SEEK_SET == STREAM_SEEK_SET );
+ BOOST_STATIC_ASSERT( SEEK_CUR == STREAM_SEEK_CUR );
+ BOOST_STATIC_ASSERT( SEEK_END == STREAM_SEEK_END );
+
+ assert( ( dwOrigin >= SEEK_SET ) && ( dwOrigin <= SEEK_END ) );
+
+ BOOL const success( ::SetFilePointerEx( file_, dlibMove, reinterpret_cast<PLARGE_INTEGER>( plibNewPosition ), dwOrigin ) );
+ return success ? S_OK : S_FALSE;
+ }
+
+protected:
+ HANDLE const file_;
+};
+
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \class FileHandleReadStream
+/// ---------------------------
+///
+////////////////////////////////////////////////////////////////////////////////
+
+class FileHandleReadStream : public FileHandleStreamBase
+{
+public:
+ FileHandleReadStream( HANDLE const file ) : FileHandleStreamBase( file ) {}
+
+private:
+ HRESULT STDMETHODCALLTYPE Read( void * const pv, ULONG const cb, ULONG * const pcbRead ) override
+ {
+ BOOL const success( ::ReadFile( file_, pv, cb, pcbRead, NULL ) );
+ return success ? S_OK : S_FALSE;
+ }
+};
+
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \class FileWriteStream
+/// ----------------------
+///
+////////////////////////////////////////////////////////////////////////////////
+
+class FileHandleWriteStream : public FileHandleStreamBase
+{
+public:
+ FileHandleWriteStream( HANDLE const file ) : FileHandleStreamBase( file ) {}
+
+private:
+ HRESULT STDMETHODCALLTYPE Write( void const * const pv, ULONG const cb, ULONG * const pcbWritten ) override
+ {
+ BOOL const success( ::WriteFile( file_, pv, cb, pcbWritten, NULL ) );
+ return success ? S_OK : S_FALSE;
+ }
+};
+
+
+////////////////////////////////////////////////////////////////////////////////
+///
/// \class MemoryStreamBase
/// -----------------------
///
Modified: sandbox/gil/boost/gil/extension/io2/wic_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/wic_image.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/wic_image.hpp 2010-12-09 19:10:39 EST (Thu, 09 Dec 2010)
@@ -322,9 +322,9 @@
typedef mpl::map3
<
- mpl::pair<char const *, detail::output_c_str_for_c_file_extender<detail::output_FILE_for_IStream_extender <detail::wic_writer> > >,
- mpl::pair<IStream , detail::wic_writer >,
- mpl::pair<FILE , detail::output_FILE_for_IStream_extender <detail::wic_writer> >
+ mpl::pair<wchar_t const *, detail::output_file_name_for_IStream_extender<detail::wic_writer> >,
+ mpl::pair<IStream , detail::wic_writer >,
+ mpl::pair<FILE , detail::output_FILE_for_IStream_extender <detail::wic_writer> >
> writers;
typedef mpl::vector5_c<format_tag, bmp, gif, jpeg, png, tiff> supported_image_formats;
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