Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83141 - in trunk/boost/gil/extension/io: detail formats/targa
From: chhenning_at_[hidden]
Date: 2013-02-24 16:06:55


Author: chhenning
Date: 2013-02-24 16:06:54 EST (Sun, 24 Feb 2013)
New Revision: 83141
URL: http://svn.boost.org/trac/boost/changeset/83141

Log:
Using iterator_facade as base for scanline_read_iterator.
Text files modified:
   trunk/boost/gil/extension/io/detail/scanline_read_iterator.hpp | 94 ++++++++++++++-------------------------
   trunk/boost/gil/extension/io/formats/targa/scanline_read.hpp | 4 +
   2 files changed, 36 insertions(+), 62 deletions(-)

Modified: trunk/boost/gil/extension/io/detail/scanline_read_iterator.hpp
==============================================================================
--- trunk/boost/gil/extension/io/detail/scanline_read_iterator.hpp (original)
+++ trunk/boost/gil/extension/io/detail/scanline_read_iterator.hpp 2013-02-24 16:06:54 EST (Sun, 24 Feb 2013)
@@ -13,13 +13,15 @@
 ////////////////////////////////////////////////////////////////////////////////////////
 /// \file
 /// \brief
-/// \author Christian Henning \n
+/// \author Christian Henning
 ///
 /// \date 2012 \n
 ///
 ////////////////////////////////////////////////////////////////////////////////////////
 
-#include <vector>
+#include <boost/shared_ptr.hpp>
+#include <boost/make_shared.hpp>
+#include <boost/iterator/iterator_facade.hpp>
 
 #include <boost/gil/extension/io/detail/io_error.hpp>
 
@@ -32,106 +34,76 @@
 
 /// Input iterator to read images.
 template< typename Reader >
-class scanline_read_iterator
+class scanline_read_iterator : public boost::iterator_facade< scanline_read_iterator< Reader >
+ , byte_t*
+ , std::input_iterator_tag
+ >
 {
 public:
 
- typedef typename Reader::backend_t backend_t;
-
- typedef std::input_iterator_tag iterator_category;
- typedef byte_t* value_type;
- typedef value_type const* pointer;
- typedef value_type const& reference;
- typedef int difference_type;
-
-public:
-
- /// Constructor with preallocated image. Reading starts at first scanline of source image.
     scanline_read_iterator( Reader& reader
- , int pos = 0
+ , int pos = 0
                           )
     : _pos( pos )
     , _read_scanline( true )
     , _skip_scanline( true )
     , _reader( reader )
     {
- init();
- }
-
- /// Dereference Operator
- reference operator*()
- {
- if( _read_scanline == true )
- {
- _reader.read( _buffer_start
- , _pos
- );
- }
-
- _skip_scanline = false;
- _read_scanline = false;
-
- return _buffer_start;
+ _buffer = boost::make_shared< buffer_t >( buffer_t( _reader._scanline_length ));
+ _buffer_start = &_buffer->front();
     }
 
- /// Pointer-To-Memper Operator.
- pointer operator->() const
- {
- return &(operator*());
- }
+private:
+ friend class boost::iterator_core_access;
 
- /// Pre-Increment Operator
- scanline_read_iterator< Reader >& operator++()
+ void increment()
     {
         if( _skip_scanline == true )
         {
- _skip();
+ _reader.skip( _buffer_start
+ , _pos
+ );
         }
 
         ++_pos;
 
         _skip_scanline = true;
         _read_scanline = true;
-
- return (*this);
     }
 
- bool operator ==( const scanline_read_iterator< Reader >& rhs ) const
+ bool equal( const scanline_read_iterator& rhs ) const
     {
         return _pos == rhs._pos;
     }
 
- bool operator !=( const scanline_read_iterator< Reader >& rhs ) const
+ reference dereference() const
     {
- return _pos < rhs._pos;
- }
-
-private:
+ if( _read_scanline == true )
+ {
+ _reader.read( _buffer_start
+ , _pos
+ );
+ }
 
- void init()
- {
- _buffer = std::vector< byte_t >( _reader._scanline_length );
- _buffer_start = &_buffer.front();
- }
+ _skip_scanline = false;
+ _read_scanline = false;
 
- void _skip()
- {
- _reader.skip( _buffer_start
- , _pos
- );
+ return _buffer_start;
     }
 
 private:
+ Reader& _reader;
 
     mutable int _pos;
 
     mutable bool _read_scanline;
     mutable bool _skip_scanline;
 
- Reader& _reader;
+ typedef std::vector< byte_t > buffer_t;
+ typedef boost::shared_ptr< buffer_t > buffer_ptr_t;
 
- std::vector< byte_t > _buffer;
- byte_t* _buffer_start;
+ buffer_ptr_t _buffer;
+ mutable byte_t* _buffer_start;
 };
 
 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)

Modified: trunk/boost/gil/extension/io/formats/targa/scanline_read.hpp
==============================================================================
--- trunk/boost/gil/extension/io/formats/targa/scanline_read.hpp (original)
+++ trunk/boost/gil/extension/io/formats/targa/scanline_read.hpp 2013-02-24 16:06:54 EST (Sun, 24 Feb 2013)
@@ -91,7 +91,9 @@
     /// Skip over a scanline.
     void skip( byte_t*, int )
     {
- this->_io_dev.seek( static_cast<long>( this->_scanline_length ), SEEK_CUR );
+ this->_io_dev.seek( static_cast<long>( this->_scanline_length )
+ , SEEK_CUR
+ );
     }
 
     iterator_t begin() { return iterator_t( *this ); }


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