Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65300 - in sandbox/gil/boost/gil/extension/io2: . detail
From: dsaritz_at_[hidden]
Date: 2010-09-05 12:33:57


Author: psiha
Date: 2010-09-05 12:33:46 EDT (Sun, 05 Sep 2010)
New Revision: 65300
URL: http://svn.boost.org/trac/boost/changeset/65300

Log:
Rewrote the io_error.hpp utility header:
 - moved everything to the detail namespace
 - moved the header to the detail directory
 - replaced the usage of std::ios_base::failure exception class with the std::exception class (size optimization/std::string usage avoidance)
 - added more utility overloads
 - removed the unused file_mgr class.

Extracted the libtiff_image::cumulative_result helper class into the detail/libx_shared.hpp header.

Fixed an assertion in the libpng_image::generic_convert_to_prepared_view<> member function.

Added:
   sandbox/gil/boost/gil/extension/io2/detail/io_error.hpp
      - copied, changed from r64224, /sandbox/gil/boost/gil/extension/io2/io_error.hpp
Removed:
   sandbox/gil/boost/gil/extension/io2/io_error.hpp
Text files modified:
   sandbox/gil/boost/gil/extension/io2/detail/io_error.hpp | 112 ++++++++++++++++++++++-----------------
   sandbox/gil/boost/gil/extension/io2/detail/libx_shared.hpp | 43 +++++++++++++++
   sandbox/gil/boost/gil/extension/io2/formatted_image.hpp | 2
   sandbox/gil/boost/gil/extension/io2/gp_private_base.hpp | 2
   sandbox/gil/boost/gil/extension/io2/libjpeg_private_base.hpp | 2
   sandbox/gil/boost/gil/extension/io2/libpng_image.hpp | 6 +-
   sandbox/gil/boost/gil/extension/io2/libtiff_private_base.hpp | 25 ++------
   sandbox/gil/boost/gil/extension/io2/wic_image.hpp | 2
   8 files changed, 120 insertions(+), 74 deletions(-)

Copied: sandbox/gil/boost/gil/extension/io2/detail/io_error.hpp (from r64224, /sandbox/gil/boost/gil/extension/io2/io_error.hpp)
==============================================================================
--- /sandbox/gil/boost/gil/extension/io2/io_error.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/detail/io_error.hpp 2010-09-05 12:33:46 EDT (Sun, 05 Sep 2010)
@@ -1,51 +1,67 @@
-/*
- Copyright 2005-2007 Adobe Systems Incorporated
-
- Use, modification and distribution are 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).
-
- See http://opensource.adobe.com/gil for most recent version including documentation.
-*/
-/*************************************************************************************************/
-
-#ifndef GIL_IO_ERROR_H
-#define GIL_IO_ERROR_H
-
-/// \file
-/// \brief Handle input-output errors
-/// \author Lubomir Bourdev and Hailin Jin \n
-/// Adobe Systems Incorporated
-/// \date 2005-2007 \n Last updated on May 30, 2006
-
-#include <ios>
-#include "../../gil_config.hpp"
-#include <boost/shared_ptr.hpp>
-
-namespace boost { namespace gil {
-
-inline void io_error(const char* descr) { throw std::ios_base::failure(descr); }
-inline void io_error_if(bool expr, const char* descr="") { if (expr) io_error(descr); }
-
-namespace detail {
- class file_mgr {
- protected:
- shared_ptr<FILE> _fp;
-
- struct null_deleter { void operator()(void const*) const {} };
- file_mgr(FILE* file) : _fp(file, null_deleter()) {}
-
- file_mgr(const char* filename, const char* flags) {
- FILE* fp;
- io_error_if((fp=fopen(filename,flags))==NULL, "file_mgr: failed to open file");
- _fp=shared_ptr<FILE>(fp,fclose);
- }
-
- public:
- FILE* get() { return _fp.get(); }
- };
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \file io_error.hpp
+/// ------------------
+///
+/// Copyright (c) Domagoj Saric 2010.
+///
+/// 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
+///
+////////////////////////////////////////////////////////////////////////////////
+//------------------------------------------------------------------------------
+#pragma once
+#ifndef io_error_hpp__71ED3406_D77C_41FB_9981_A94A1D3BDC8A
+#define io_error_hpp__71ED3406_D77C_41FB_9981_A94A1D3BDC8A
+//------------------------------------------------------------------------------
+#include "boost/throw_exception.hpp"
+
+#include <exception>
+//------------------------------------------------------------------------------
+namespace boost
+{
+//------------------------------------------------------------------------------
+namespace gil
+{
+//------------------------------------------------------------------------------
+namespace detail
+{
+//------------------------------------------------------------------------------
+
+__declspec( noreturn noalias )
+inline void io_error ( char const * const description )
+{
+ #ifdef _MSC_VER
+ throw_exception( std::exception( description , 0 ) ); // Assumes the description string is static/non-temporary
+ #else
+ throw_exception( std::exception( description ) );
+ #endif // _MSC_VER
 }
 
-} } // namespace boost::gil
+inline void io_error_if( bool const expression, char const * const description = "" )
+{
+ if ( expression )
+ io_error( description );
+}
+
+inline void io_error_if_not( bool const expression, char const * const description = "" )
+{
+ io_error_if( !expression, description );
+}
+
+inline void io_error_if_not( void const * const pointer, char const * const description = "" )
+{
+ io_error_if( !pointer, description );
+}
 
-#endif
+//------------------------------------------------------------------------------
+} // namespace detail
+//------------------------------------------------------------------------------
+} // namespace gil
+//------------------------------------------------------------------------------
+} // namespace boost
+//------------------------------------------------------------------------------
+#endif // io_error_hpp

Modified: sandbox/gil/boost/gil/extension/io2/detail/libx_shared.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/detail/libx_shared.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/detail/libx_shared.hpp 2010-09-05 12:33:46 EDT (Sun, 05 Sep 2010)
@@ -20,8 +20,10 @@
 #define libx_shared_hpp__ABC7759A_4313_4BFF_B64F_D72BBF2355E8
 //------------------------------------------------------------------------------
 #include "../../../utilities.hpp"
+#include "io_error.hpp"
 
 #include "crtdefs.h"
+#include <cstdio>
 //------------------------------------------------------------------------------
 namespace boost
 {
@@ -33,6 +35,13 @@
 {
 //------------------------------------------------------------------------------
 
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \class generic_vertical_roi
+///
+////////////////////////////////////////////////////////////////////////////////
+
 class generic_vertical_roi
 {
 public:
@@ -60,6 +69,13 @@
 };
 
 
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \class c_file_guard
+///
+////////////////////////////////////////////////////////////////////////////////
+
 class c_file_guard
 {
 public:
@@ -77,6 +93,33 @@
     FILE * const p_file_;
 };
 
+
+////////////////////////////////////////////////////////////////////////////////
+///
+/// \class cumulative_result
+///
+////////////////////////////////////////////////////////////////////////////////
+
+class cumulative_result
+{
+public:
+ cumulative_result() : result_( true ) {}
+
+ void accumulate( bool const new_result ) { result_ &= new_result; }
+ template <typename T1, typename T2>
+ void accumulate_equal( T1 const new_result, T2 const desired_result ) { accumulate( new_result == desired_result ); }
+ template <typename T>
+ void accumulate_different( T const new_result, T const undesired_result ) { accumulate( new_result != undesired_result ); }
+
+ void throw_if_error( char const * const description ) const { io_error_if_not( result_, description ); }
+
+ bool & get() { return result_; }
+
+private:
+ bool result_;
+};
+
+
 //------------------------------------------------------------------------------
 } // namespace detail
 //------------------------------------------------------------------------------

Modified: sandbox/gil/boost/gil/extension/io2/formatted_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/formatted_image.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/formatted_image.hpp 2010-09-05 12:33:46 EDT (Sun, 05 Sep 2010)
@@ -22,8 +22,8 @@
 /// \todo Investigate whether gil_all.hpp is indeed necessary.
 /// (26.07.2010.) (Domagoj Saric)
 #include "../../gil_all.hpp"
-#include "io_error.hpp"
 
+#include "detail/io_error.hpp"
 #include "detail/switch.hpp"
 
 #include <boost/gil/extension/dynamic_image/any_image.hpp>

Modified: sandbox/gil/boost/gil/extension/io2/gp_private_base.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/gp_private_base.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/gp_private_base.hpp 2010-09-05 12:33:46 EDT (Sun, 05 Sep 2010)
@@ -20,11 +20,11 @@
 #define gp_private_base_hpp__3B1ED5BC_42C6_4EC6_B700_01C1B8646431
 //------------------------------------------------------------------------------
 #include "../../gil_all.hpp"
+#include "detail/io_error.hpp"
 #include "detail/gp_extern_lib_guard.hpp"
 #include "detail/windows_shared.hpp"
 #include "detail/windows_shared_istreams.hpp"
 #include "formatted_image.hpp"
-#include "io_error.hpp"
 
 #include <boost/array.hpp>
 #include <boost/mpl/eval_if.hpp>

Deleted: sandbox/gil/boost/gil/extension/io2/io_error.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/io_error.hpp 2010-09-05 12:33:46 EDT (Sun, 05 Sep 2010)
+++ (empty file)
@@ -1,51 +0,0 @@
-/*
- Copyright 2005-2007 Adobe Systems Incorporated
-
- Use, modification and distribution are 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).
-
- See http://opensource.adobe.com/gil for most recent version including documentation.
-*/
-/*************************************************************************************************/
-
-#ifndef GIL_IO_ERROR_H
-#define GIL_IO_ERROR_H
-
-/// \file
-/// \brief Handle input-output errors
-/// \author Lubomir Bourdev and Hailin Jin \n
-/// Adobe Systems Incorporated
-/// \date 2005-2007 \n Last updated on May 30, 2006
-
-#include <ios>
-#include "../../gil_config.hpp"
-#include <boost/shared_ptr.hpp>
-
-namespace boost { namespace gil {
-
-inline void io_error(const char* descr) { throw std::ios_base::failure(descr); }
-inline void io_error_if(bool expr, const char* descr="") { if (expr) io_error(descr); }
-
-namespace detail {
- class file_mgr {
- protected:
- shared_ptr<FILE> _fp;
-
- struct null_deleter { void operator()(void const*) const {} };
- file_mgr(FILE* file) : _fp(file, null_deleter()) {}
-
- file_mgr(const char* filename, const char* flags) {
- FILE* fp;
- io_error_if((fp=fopen(filename,flags))==NULL, "file_mgr: failed to open file");
- _fp=shared_ptr<FILE>(fp,fclose);
- }
-
- public:
- FILE* get() { return _fp.get(); }
- };
-}
-
-} } // namespace boost::gil
-
-#endif

Modified: sandbox/gil/boost/gil/extension/io2/libjpeg_private_base.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/libjpeg_private_base.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/libjpeg_private_base.hpp 2010-09-05 12:33:46 EDT (Sun, 05 Sep 2010)
@@ -18,7 +18,7 @@
 #define libjpeg_private_base_hpp__7C5F6951_A00F_4E0D_9783_488A49B1CA2B
 //------------------------------------------------------------------------------
 #include "formatted_image.hpp"
-#include "io_error.hpp"
+#include "detail/io_error.hpp"
 #include "detail/libx_shared.hpp"
 
 #include <boost/smart_ptr/scoped_ptr.hpp>

Modified: sandbox/gil/boost/gil/extension/io2/libpng_image.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/libpng_image.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/libpng_image.hpp 2010-09-05 12:33:46 EDT (Sun, 05 Sep 2010)
@@ -18,7 +18,7 @@
 #define libpng_image_hpp__9E0C99E6_EAE8_4D71_844B_93518FFCB5CE
 //------------------------------------------------------------------------------
 #include "formatted_image.hpp"
-#include "io_error.hpp"
+#include "detail/io_error.hpp"
 #include "detail/libx_shared.hpp"
 
 #include "png.h"
@@ -262,7 +262,7 @@
 
         unsigned int number_of_passes( ::png_set_interlace_handling( &png_object() ) );
         __assume( ( number_of_passes == 1 ) || ( number_of_passes == 7 ) );
- BOOST_ASSERT( ( number_of_passes == 1 ) && !"Missing interlaced support for the generic conversion case." );
+ BOOST_ASSERT( ( number_of_passes == 1 ) && "Missing interlaced support for the generic conversion case." );
         ignore_unused_variable_warning( number_of_passes );
 
         skip_rows( detail::get_offset<offset_t>( view ) );
@@ -368,7 +368,7 @@
     __declspec( noreturn )
     static void throw_libpng_error()
     {
- io_error( "LibPNG failure" );
+ detail::io_error( "LibPNG failure" );
     }
 
     __declspec( noreturn )

Modified: sandbox/gil/boost/gil/extension/io2/libtiff_private_base.hpp
==============================================================================
--- sandbox/gil/boost/gil/extension/io2/libtiff_private_base.hpp (original)
+++ sandbox/gil/boost/gil/extension/io2/libtiff_private_base.hpp 2010-09-05 12:33:46 EDT (Sun, 05 Sep 2010)
@@ -18,12 +18,12 @@
 #define libtiff_private_base_hpp__0808D24E_CED1_4921_A832_3C12DAE93Ef7
 //------------------------------------------------------------------------------
 #include "formatted_image.hpp"
-#include "io_error.hpp"
 
+#include "detail/io_error.hpp"
 #include "detail/libx_shared.hpp"
 
 #if BOOST_MPL_LIMIT_VECTOR_SIZE < 35
- ...error...libtiff support requires mpl vectors of size 35...
+ ...error...libtiff support requires mpl vectors of size 35 or greater...
 #endif
 
 #include <boost/array.hpp>
@@ -405,7 +405,7 @@
             }
         }
 
- io_error_if( !cumulative_result || unsupported_format || ( orientation != ORIENTATION_TOPLEFT ), "TeeF" );
+ detail::io_error_if( !cumulative_result || unsupported_format || ( orientation != ORIENTATION_TOPLEFT ), "TeeF" );
 
         format_.number = LIBTIFF_FORMAT( samples_per_pixel, bits_per_sample, ( sample_format == SAMPLEFORMAT_VOID ) ? SAMPLEFORMAT_UINT : sample_format, planar_configuration, photometric, ink_set );
     }
@@ -414,7 +414,7 @@
 private:
     void construction_check() const
     {
- io_error_if( !p_tiff_, "Failed to open TIFF input file" );
+ detail::io_error_if_not( p_tiff_, "Failed to open TIFF input file" );
     }
 
     void constructor_tail()
@@ -505,23 +505,10 @@
         unsigned int starting_strip;
     };
 
- class cumulative_result
+ class cumulative_result : public detail::cumulative_result
     {
     public:
- cumulative_result() : result_( true ) {}
-
- void accumulate( bool const new_result ) { result_ &= new_result; }
- template <typename T1, typename T2>
- void accumulate_equal( T1 const new_result, T2 const desired_result ) { accumulate( new_result == desired_result ); }
- template <typename T>
- void accumulate_different( T const new_result, T const undesired_result ) { accumulate( new_result != undesired_result ); }
-
- void throw_if_error() const { io_error_if( result_ != true, "Error reading TIFF file" ); }
-
- bool & get() { return result_; }
-
- private:
- bool result_;
+ void throw_if_error() const { detail::cumulative_result::throw_if_error( "Error reading TIFF file" ); }
     };
 
     void raw_copy_to_prepared_view( tiff_view_data_t const view_data ) const

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-09-05 12:33:46 EDT (Sun, 05 Sep 2010)
@@ -20,10 +20,10 @@
 #define wic_image_hpp__78D710F7_11C8_4023_985A_22B180C9A476
 //------------------------------------------------------------------------------
 #include "../../gil_all.hpp"
+#include "detail/io_error.hpp"
 #include "detail/wic_extern_lib_guard.hpp"
 #include "detail/windows_shared.hpp"
 #include "detail/windows_shared_istreams.hpp"
-#include "io_error.hpp"
 
 #include <boost/array.hpp>
 #include <boost/mpl/eval_if.hpp>


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