BufferDetailIterator.hh

Go to the documentation of this file.
00001 
00019 #ifndef avro_BufferDetailIterator_hh__
00020 #define avro_BufferDetailIterator_hh__
00021 
00022 #include "BufferDetail.hh"
00023 
00030 namespace avro {
00031 
00032 namespace detail {
00033 
00043 struct InputIteratorHelper
00044 {
00046     InputIteratorHelper() :
00047         iter_()
00048     {}
00049 
00051     InputIteratorHelper(const BufferImpl::ChunkList::const_iterator &iter) :
00052         iter_(iter)
00053     {}
00054 
00056     const data_type *data() const {
00057         return iter_->tellReadPos();
00058     }
00059 
00061     size_type size() const {
00062         return iter_->dataSize();
00063     }
00064 
00068 #ifdef HAVE_BOOST_ASIO
00069     operator ConstAsioBuffer() const {
00070         return ConstAsioBuffer(data(), size());
00071     }
00072 #endif
00073 
00074     BufferImpl::ChunkList::const_iterator iter_; 
00075 };
00076 
00086 struct OutputIteratorHelper
00087 {
00089     OutputIteratorHelper() :
00090             iter_()
00091     {}
00092 
00094     OutputIteratorHelper(const BufferImpl::ChunkList::const_iterator &iter) :
00095             iter_(iter)
00096     {}
00097 
00099     data_type *data() const {
00100         return iter_->tellWritePos();
00101     }
00102 
00104     size_type size() const {
00105         return iter_->freeSize();
00106     }
00107 
00111 #ifdef HAVE_BOOST_ASIO
00112     operator MutableAsioBuffer() const {
00113         return MutableAsioBuffer(data(), size());
00114     }
00115 #endif
00116 
00117     BufferImpl::ChunkList::const_iterator iter_; 
00118 };
00119 
00125 template<typename Helper>
00126 class BufferIterator 
00127 {
00128 
00129   public:
00130 
00131     typedef BufferIterator<Helper> this_type;
00132 
00144     typedef std::forward_iterator_tag iterator_category; // this is a lie to appease asio
00145     typedef Helper value_type;
00146     typedef std::ptrdiff_t difference_type;
00147     typedef value_type* pointer;
00148     typedef value_type& reference;
00150 
00152     BufferIterator() :
00153         helper_()
00154     { }
00155 
00156     /* The default implementations are good here
00158     BufferIterator(const BufferIterator &src) :
00159         helper_(src.helper_)
00160     { }
00162     this_type& operator= (const this_type &rhs) {
00163         helper_ = rhs.helper_;
00164         return *this;
00165     }
00166     */
00167 
00169     explicit BufferIterator(BufferImpl::ChunkList::const_iterator iter) :
00170         helper_(iter)
00171     { }
00172 
00174     reference operator *() {
00175         return helper_;
00176     }
00177 
00179     const value_type &operator *() const {
00180         return helper_;
00181     }
00182 
00184     pointer operator->() {
00185         return &helper_;
00186     }
00187 
00189     const value_type *operator->() const {
00190         return &helper_;
00191     }
00192     
00194     this_type& operator++() 
00195     {
00196         ++helper_.iter_;
00197         return *this;
00198     }
00199 
00201     this_type operator++(int)
00202     {
00203         this_type ret = *this;
00204         ++helper_.iter_;
00205         return ret;
00206     }
00207 
00209     bool operator==(const this_type &rhs) const {
00210         return (helper_.iter_ == rhs.helper_.iter_);
00211     }
00212 
00214     bool operator!=(const this_type &rhs) const {
00215         return (helper_.iter_ != rhs.helper_.iter_);
00216     }
00217 
00218   private:
00219 
00220     Helper helper_;
00221 };
00222 
00223 typedef BufferIterator<InputIteratorHelper> InputBufferIterator;
00224 typedef BufferIterator<OutputIteratorHelper> OutputBufferIterator;
00225 
00226 } // detail namespace
00227 
00228 } // namespace
00229 
00230 #endif
Generated on Thu Sep 2 18:40:54 2010 for Avro C++ by  doxygen 1.6.3