Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73406 - in sandbox/gil/boost/gil/extension/io2: backends/detail backends/libtiff devices
From: dsaritz_at_[hidden]
Date: 2011-07-27 18:55:01


Author: psiha
Date: 2011-07-27 18:54:59 EDT (Wed, 27 Jul 2011)
New Revision: 73406
URL: http://svn.boost.org/trac/boost/changeset/73406

Log:
Refactored the devices base classes hierarchy, added the device class template (for shared parts of/for input and output devices).
Text files modified:
   sandbox/gil/boost/gil/extension/io2/backends/detail/reader_for.hpp | 2
   sandbox/gil/boost/gil/extension/io2/backends/detail/writer_for.hpp | 2
   sandbox/gil/boost/gil/extension/io2/backends/libtiff/backend.hpp | 18 +++--
   sandbox/gil/boost/gil/extension/io2/devices/c_file.hpp | 93 ++++++++++++++-------------
   sandbox/gil/boost/gil/extension/io2/devices/c_file_descriptor.hpp | 133 ++++++++++++++++++++-------------------
   sandbox/gil/boost/gil/extension/io2/devices/c_file_name.hpp | 17 ++++
   sandbox/gil/boost/gil/extension/io2/devices/device.hpp | 15 +--
   7 files changed, 150 insertions(+), 130 deletions(-)

Modified: sandbox/gil/boost/gil/extension/io2/backends/detail/reader_for.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/detail/reader_for.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/backends/detail/reader_for.hpp 2011-07-27 18:54:59 EDT (Wed, 27 Jul 2011)
@@ -72,7 +72,7 @@
     BOOST_STATIC_ASSERT
     ((
         supported_by_native_reader_t::value ||
- !unknown_input_device<Source>::value
+ !unknown_device<Source> ::value
     ));
 
     typedef typename mpl::if_

Modified: sandbox/gil/boost/gil/extension/io2/backends/detail/writer_for.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/detail/writer_for.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/backends/detail/writer_for.hpp 2011-07-27 18:54:59 EDT (Wed, 27 Jul 2011)
@@ -171,7 +171,7 @@
     BOOST_STATIC_ASSERT
     ((
         supported_by_native_writer_t::value ||
- !unknown_output_device<Target>::value
+ !unknown_device<Target> ::value
     ));
 
     typedef typename mpl::if_

Modified: sandbox/gil/boost/gil/extension/io2/backends/libtiff/backend.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/backends/libtiff/backend.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/backends/libtiff/backend.hpp 2011-07-27 18:54:59 EDT (Wed, 27 Jul 2011)
@@ -168,13 +168,13 @@
 template <typename Handle>
 toff_t seek( thandle_t const handle, toff_t const off, int const whence )
 {
- return static_cast<tsize_t>( input_device<Handle>::seek( static_cast<device_base::seek_origin>( whence ), off, reinterpret_cast<Handle>( handle ) ) );
+ return static_cast<tsize_t>( device<Handle>::seek( static_cast<device_base::seek_origin>( whence ), off, reinterpret_cast<Handle>( handle ) ) );
 }
 
 template <typename Handle>
 int close( thandle_t const handle )
 {
- input_device<Handle>::close( reinterpret_cast<Handle>( handle ) );
+ device<Handle>::close( reinterpret_cast<Handle>( handle ) );
     return 0;
 }
 
@@ -186,7 +186,7 @@
 template <typename Handle>
 toff_t size( thandle_t const fd )
 {
- return static_cast<toff_t>( input_device<Handle>::size( reinterpret_cast<Handle>( handle ) ) );
+ return static_cast<toff_t>( device<Handle>::size( reinterpret_cast<Handle>( handle ) ) );
 }
 
 
@@ -253,9 +253,7 @@
 
     void set_format( full_format_t::format_id const format )
     {
- #ifdef _DEBUG
- BOOST_ASSERT( ( format_id_ == format ) && !"libtiff does not provide builtin conversion." );
- #endif // _DEBUG
+ BOOST_ASSERT_MSG( format_id_ == format, "LibTIFF does not provide builtin conversion." );
         ignore_unused_variable_warning( format );
     }
 
@@ -336,6 +334,12 @@
 };
 
 
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \class libtiff_image
+///
+////////////////////////////////////////////////////////////////////////////////
+
 class libtiff_image
     :
     public detail::backend<libtiff_image>
@@ -380,7 +384,7 @@
                     read_proc,
                     write_proc,
                     &detail::seek<DeviceHandle>,
- &detail::nop_close, //&detail::close<<DeviceHandle>>
+ device<DeviceHandle>::auto_closes ? &detail::nop_close : &detail::close<<DeviceHandle>
                     &detail::size<<DeviceHandle>,
                     map_proc,
                     unmap_proc

Modified: sandbox/gil/boost/gil/extension/io2/devices/c_file.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/devices/c_file.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/devices/c_file.hpp 2011-07-27 18:54:59 EDT (Wed, 27 Jul 2011)
@@ -34,55 +34,57 @@
 {
 //------------------------------------------------------------------------------
 
-namespace detail
+template <>
+struct device<FILE *> : detail::device_base
 {
- struct device_FILE_base
+ typedef FILE * handle_t;
+
+ static bool const auto_closes = false;
+
+ static handle_t transform ( handle_t const handle ) { return handle; }
+ static bool is_valid ( handle_t const handle ) { return handle != 0; }
+ static void close ( handle_t const handle ) { BOOST_VERIFY( /*std*/::fclose( handle ) == 0 ); }
+ static std::size_t position ( handle_t const handle ) { return std::ftell( handle ); }
+ static uintmax_t position_long( handle_t const handle )
+ {
+ #ifdef BOOST_MSVC
+ return /*std*/::_ftelli64( handle );
+ #else
+ return /*std*/::ftell64 ( handle );
+ #endif // BOOST_MSVC
+ }
+
+ static std::size_t size( handle_t const handle )
     {
- typedef FILE * handle_t;
+ return device<c_file_descriptor_t>::size( /*std*/::_fileno( handle ) );
+ }
+
+ static uintmax_t size_long( handle_t const handle )
+ {
+ return device<c_file_descriptor_t>::size_long( /*std*/::_fileno( handle ) );
+ }
+
+ static bool seek( seek_origin const origin, off_t const offset, handle_t const handle )
+ {
+ return std::fseek( handle, offset, origin ) != 0;
+ }
+
+ static bool seek_long( seek_origin const origin, intmax_t const offset, handle_t const handle )
+ {
+ #ifdef BOOST_MSVC
+ return /*std*/::_fseeki64( handle, offset, origin ) != 0;
+ #else
+ return /*std*/::fseeko ( handle, offset, origin ) != 0;
+ #endif
+ }
+};
 
- static handle_t transform ( handle_t const handle ) { return handle; }
- static bool is_valid ( handle_t const handle ) { return handle != 0; }
- static void close ( handle_t const handle ) { BOOST_VERIFY( /*std*/::fclose( handle ) == 0 ); }
- static std::size_t position ( handle_t const handle ) { return std::ftell( handle ); }
- static uintmax_t position_long( handle_t const handle )
- {
- #ifdef BOOST_MSVC
- return /*std*/::_ftelli64( handle );
- #else
- return /*std*/::ftell64 ( handle );
- #endif // BOOST_MSVC
- }
-
- static std::size_t size( handle_t const handle )
- {
- return device<c_file_descriptor_t>::size( /*std*/::_fileno( handle ) );
- }
-
- static uintmax_t size_long( handle_t const handle )
- {
- return device<c_file_descriptor_t>::size_long( /*std*/::_fileno( handle ) );
- }
-
- static bool seek( seek_origin const origin, off_t const offset, handle_t const handle )
- {
- return std::fseek( handle, offset, origin ) != 0;
- }
-
- static bool seek_long( seek_origin const origin, intmax_t const offset, handle_t const handle )
- {
- #ifdef BOOST_MSVC
- return /*std*/::_fseeki64( handle, offset, origin ) != 0;
- #else
- return /*std*/::fseeko ( handle, offset, origin ) != 0;
- #endif
- }
- };
-} // namespace detail
 
-template <> struct input_device<FILE *>
+template <>
+struct input_device<FILE *>
     :
     detail::input_device_base,
- detail::device_FILE_base
+ device<FILE *>
 {
     input_device( handle_t /*handle*/ ) {}
 
@@ -98,10 +100,11 @@
 };
 
 
-template <> struct output_device<FILE *>
+template <>
+struct output_device<FILE *>
     :
     detail::output_device_base,
- detail::device_FILE_base
+ device<FILE *>
 {
     output_device( handle_t /*handle*/ ) {}
 

Modified: sandbox/gil/boost/gil/extension/io2/devices/c_file_descriptor.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/devices/c_file_descriptor.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/devices/c_file_descriptor.hpp 2011-07-27 18:54:59 EDT (Wed, 27 Jul 2011)
@@ -47,75 +47,77 @@
 
 typedef int c_file_descriptor_t;
 
-namespace detail
+template <>
+struct device<c_file_descriptor_t> : detail::device_base
 {
- struct device_c_file_descriptor_base
+ typedef c_file_descriptor_t handle_t;
+
+ static bool const auto_closes = false;
+
+ static bool is_valid( handle_t const handle )
+ {
+ return handle >= 0;
+ }
+
+ static void close( handle_t const handle ) { BOOST_VERIFY( /*std*/::close( handle ) == 0 ); }
+
+ static std::size_t position( handle_t const handle )
+ {
+ return /*std*/::tell( handle );
+ }
+
+ static uintmax_t position_long( handle_t const handle )
+ {
+ #ifdef BOOST_MSVC
+ return /*std*/::_telli64( handle );
+ #else
+ return /*std*/::tell64 ( handle );
+ #endif // BOOST_MSVC
+ }
+
+ static std::size_t size( handle_t const handle )
+ {
+ #ifdef BOOST_MSVC
+ return /*std*/::_filelength( handle );
+ #else
+ struct stat file_status;
+ BOOST_VERIFY( ::fstat( handle, &file_status ) == 0 );
+ return file_status.st_size;
+ #endif // BOOST_MSVC
+ }
+
+ static uintmax_t size_long( handle_t const handle )
+ {
+ #ifdef BOOST_MSVC
+ return /*std*/::_filelengthi64( handle );
+ #else
+ struct stat64 file_status;
+ BOOST_VERIFY( ::fstat64( handle, &file_status ) == 0 );
+ return file_status.st_size;
+ #endif // BOOST_MSVC
+ }
+
+ static bool seek( seek_origin const origin, off_t offset, handle_t const handle )
     {
- typedef c_file_descriptor_t handle_t;
+ return /*std*/::lseek( handle, offset, origin ) != 0;
+ }
+
+ static bool seek_long( seek_origin const origin, intmax_t offset, handle_t const handle )
+ {
+ #ifdef BOOST_MSVC
+ return /*std*/::_lseeki64( handle, offset, origin ) != 0;
+ #else
+ return /*std*/::lseeko ( handle, offset, origin ) != 0;
+ #endif
+ }
+};
 
- static bool is_valid( handle_t const handle )
- {
- return handle >= 0;
- }
-
- static void close( handle_t const handle ) { BOOST_VERIFY( /*std*/::close( handle ) == 0 ); }
-
- static std::size_t position( handle_t const handle )
- {
- return /*std*/::tell( handle );
- }
-
- static uintmax_t position_long( handle_t const handle )
- {
- #ifdef BOOST_MSVC
- return /*std*/::_telli64( handle );
- #else
- return /*std*/::tell64 ( handle );
- #endif // BOOST_MSVC
- }
-
- static std::size_t size( handle_t const handle )
- {
- #ifdef BOOST_MSVC
- return /*std*/::_filelength( handle );
- #else
- struct stat file_status;
- BOOST_VERIFY( ::fstat( handle, &file_status ) == 0 );
- return file_status.st_size;
- #endif // BOOST_MSVC
- }
-
- static uintmax_t size_long( handle_t const handle )
- {
- #ifdef BOOST_MSVC
- return /*std*/::_filelengthi64( handle );
- #else
- struct stat64 file_status;
- BOOST_VERIFY( ::fstat64( handle, &file_status ) == 0 );
- return file_status.st_size;
- #endif // BOOST_MSVC
- }
-
- static bool seek( device_base::seek_origin const origin, off_t offset, handle_t const handle )
- {
- return /*std*/::lseek( handle, offset, origin ) != 0;
- }
-
- static bool seek_long( device_base::seek_origin const origin, intmax_t offset, handle_t const handle )
- {
- #ifdef BOOST_MSVC
- return /*std*/::_lseeki64( handle, offset, origin ) != 0;
- #else
- return /*std*/::lseeko ( handle, offset, origin ) != 0;
- #endif
- }
- };
-} // namespace detail
 
-template <> struct input_device<c_file_descriptor_t>
+template <>
+struct input_device<c_file_descriptor_t>
     :
     detail::input_device_base,
- detail::device_c_file_descriptor_base
+ device<c_file_descriptor_t>
 {
     static handle_t open( char const * const p_file_name )
     {
@@ -130,10 +132,11 @@
 };
 
 
-template <> struct output_device<c_file_descriptor_t>
+template <>
+struct output_device<c_file_descriptor_t>
     :
     detail::output_device_base,
- detail::device_c_file_descriptor_base
+ device<c_file_descriptor_t>
 {
     static handle_t open( char const * const p_file_name )
     {

Modified: sandbox/gil/boost/gil/extension/io2/devices/c_file_name.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/devices/c_file_name.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/devices/c_file_name.hpp 2011-07-27 18:54:59 EDT (Wed, 27 Jul 2011)
@@ -30,10 +30,20 @@
 {
 //------------------------------------------------------------------------------
 
-template <> struct input_device<char const *>
+
+template <>
+struct device<char const *> : device<c_file_descriptor_t>
+{
+ static bool const auto_closes = true;
+};
+
+template <>
+struct input_device<char const *>
     :
     input_device<c_file_descriptor_t>
 {
+ static bool const auto_closes = true;
+
     input_device( char const * const p_file_name )
         :
         file_descriptor_( input_device<c_file_descriptor_t>::open( p_file_name ) )
@@ -49,10 +59,13 @@
 };
 
 
-template <> struct output_device<char const *>
+template <>
+struct output_device<char const *>
     :
     output_device<c_file_descriptor_t>
 {
+ static bool const auto_closes = true;
+
     output_device( char const * const p_file_name )
         :
         file_descriptor_( output_device<c_file_descriptor_t>::open( p_file_name ) )

Modified: sandbox/gil/boost/gil/extension/io2/devices/device.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/devices/device.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/devices/device.hpp 2011-07-27 18:54:59 EDT (Wed, 27 Jul 2011)
@@ -32,16 +32,13 @@
 //------------------------------------------------------------------------------
 
 template <typename Handle>
-struct input_device : mpl::false_ {};
+struct device : mpl::false_ {};
 
-template <typename Handle>
-struct output_device : mpl::false_ {};
-
-template <typename Device>
-struct unknown_input_device : is_convertible<input_device<Device>, mpl::false_> {};
+template <typename Handle> struct input_device;
+template <typename Handle> struct output_device;
 
 template <typename Device>
-struct unknown_output_device : is_convertible<output_device<Device>, mpl::false_> {};
+struct unknown_device : is_convertible<device<Device>, mpl::false_> {};
 
 
 namespace detail
@@ -51,7 +48,7 @@
         enum seek_origin { beginning = SEEK_SET, current_position = SEEK_CUR, end = SEEK_END };
     };
 
- struct input_device_base : device_base
+ struct input_device_base
     {
         void ensure( bool const condition )
         {
@@ -59,7 +56,7 @@
         }
     };
 
- struct output_device_base : device_base
+ struct output_device_base
     {
         void ensure( bool const condition )
         {


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