Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/gil/io/scanline_read_iterator.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // Copyright 2007-2008 Christian Henning
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 #ifndef BOOST_GIL_IO_SCANLINE_READ_ITERATOR_HPP
0009 #define BOOST_GIL_IO_SCANLINE_READ_ITERATOR_HPP
0010 
0011 #include <boost/gil/io/error.hpp>
0012 #include <boost/gil/io/typedefs.hpp>
0013 
0014 #include <boost/iterator/iterator_facade.hpp>
0015 
0016 #include <iterator>
0017 #include <memory>
0018 #include <vector>
0019 
0020 namespace boost { namespace gil {
0021 
0022 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0023 #pragma warning(push)
0024 #pragma warning(disable:4512) //assignment operator could not be generated
0025 #endif
0026 
0027 /// Input iterator to read images.
0028 template <typename Reader>
0029 class scanline_read_iterator
0030     : public boost::iterator_facade<scanline_read_iterator<Reader>, byte_t*, std::input_iterator_tag>
0031 {
0032 private:
0033     using base_t = boost::iterator_facade
0034         <
0035             scanline_read_iterator<Reader>,
0036             byte_t*,
0037             std::input_iterator_tag
0038         >;
0039 public:
0040     scanline_read_iterator(Reader& reader, int pos = 0)
0041         : reader_(reader), pos_(pos)
0042     {
0043         buffer_       = std::make_shared<buffer_t>(buffer_t(reader_._scanline_length));
0044         buffer_start_ = &buffer_->front();
0045     }
0046 
0047 private:
0048     friend class boost::iterator_core_access;
0049 
0050     void increment()
0051     {
0052         if (skip_scanline_)
0053         {
0054             reader_.skip(buffer_start_, pos_);
0055         }
0056 
0057         ++pos_;
0058 
0059         skip_scanline_ = true;
0060         read_scanline_ = true;
0061     }
0062 
0063     bool equal(scanline_read_iterator const& rhs) const
0064     {
0065         return pos_ == rhs.pos_;
0066     }
0067 
0068     typename base_t::reference dereference() const
0069     {
0070         if (read_scanline_)
0071         {
0072             reader_.read(buffer_start_, pos_);
0073         }
0074         skip_scanline_ = false;
0075         read_scanline_ = false;
0076 
0077         return buffer_start_;
0078     }
0079 
0080 private:
0081     Reader& reader_;
0082 
0083     mutable int pos_            = 0;
0084     mutable bool read_scanline_ = true;
0085     mutable bool skip_scanline_ = true;
0086 
0087     using buffer_t     = std::vector<byte_t>;
0088     using buffer_ptr_t = std::shared_ptr<buffer_t>;
0089     buffer_ptr_t buffer_;
0090     mutable byte_t* buffer_start_ = nullptr;
0091 };
0092 
0093 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0094 #pragma warning(pop)
0095 #endif
0096 
0097 } // namespace gil
0098 } // namespace boost
0099 
0100 #endif