11 #ifndef ASIO_BUFFERS_ITERATOR_HPP 12 #define ASIO_BUFFERS_ITERATOR_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 18 #include "asio/detail/config.hpp" 21 #include "asio/buffer.hpp" 22 #include "asio/detail/assert.hpp" 23 #include "asio/detail/type_traits.hpp" 25 #include "asio/detail/push_options.hpp" 31 template <
bool IsMutable>
38 template <
typename ByteType>
41 typedef typename add_const<ByteType>::type type;
49 template <
typename ByteType>
52 typedef ByteType type;
56 template <
typename BufferSequence,
typename ByteType>
61 is_mutable = is_convertible<
62 typename BufferSequence::value_type,
66 typedef typename helper::buffer_type buffer_type;
67 typedef typename helper::template byte_type<ByteType>::type byte_type;
68 typedef typename BufferSequence::const_iterator const_iterator;
71 template <
typename ByteType>
75 typedef ByteType byte_type;
79 template <
typename ByteType>
83 typedef typename add_const<ByteType>::type byte_type;
87 #if !defined(ASIO_NO_DEPRECATED) 89 template <
typename ByteType>
93 typedef ByteType byte_type;
97 template <
typename ByteType>
101 typedef typename add_const<ByteType>::type byte_type;
105 #endif // !defined(ASIO_NO_DEPRECATED) 109 template <
typename BufferSequence,
typename ByteType =
char>
114 BufferSequence, ByteType>::buffer_type buffer_type;
117 ByteType>::const_iterator buffer_sequence_iterator_type;
126 #if defined(GENERATING_DOCUMENTATION) 133 typedef const_or_non_const_ByteType* pointer;
134 #else // defined(GENERATING_DOCUMENTATION) 136 BufferSequence, ByteType>::byte_type* pointer;
137 #endif // defined(GENERATING_DOCUMENTATION) 139 #if defined(GENERATING_DOCUMENTATION) 146 typedef const_or_non_const_ByteType& reference;
147 #else // defined(GENERATING_DOCUMENTATION) 149 BufferSequence, ByteType>::byte_type& reference;
150 #endif // defined(GENERATING_DOCUMENTATION) 158 current_buffer_position_(0),
168 #if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3) 169 __attribute__ ((__noinline__))
170 #endif // defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3) 176 while (new_iter.current_ != new_iter.end_)
178 new_iter.current_buffer_ = *new_iter.current_;
179 if (new_iter.current_buffer_.size() > 0)
188 #if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3) 189 __attribute__ ((__noinline__))
190 #endif // defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3) 196 while (new_iter.current_ != new_iter.end_)
198 buffer_type buffer = *new_iter.current_;
199 new_iter.position_ += buffer.size();
208 return dereference();
214 return &dereference();
221 tmp.advance(difference);
265 advance(-difference);
271 std::ptrdiff_t difference)
274 tmp.advance(difference);
283 tmp.advance(difference);
289 std::ptrdiff_t difference)
292 tmp.advance(-difference);
300 return b.distance_to(a);
318 return a.distance_to(b) > 0;
341 reference dereference()
const 343 return static_cast<pointer
>(
344 current_buffer_.data())[current_buffer_position_];
350 return position_ == other.position_;
356 ASIO_ASSERT(current_ != end_ &&
"iterator out of bounds");
360 ++current_buffer_position_;
361 if (current_buffer_position_ != current_buffer_.size())
366 current_buffer_position_ = 0;
367 while (current_ != end_)
369 current_buffer_ = *current_;
370 if (current_buffer_.size() > 0)
379 ASIO_ASSERT(position_ > 0 &&
"iterator out of bounds");
383 if (current_buffer_position_ != 0)
385 --current_buffer_position_;
390 buffer_sequence_iterator_type iter = current_;
391 while (iter != begin_)
394 buffer_type buffer = *iter;
395 std::size_t buffer_size = buffer.size();
400 current_buffer_position_ = buffer_size - 1;
407 void advance(std::ptrdiff_t n)
411 ASIO_ASSERT(current_ != end_ &&
"iterator out of bounds");
414 std::ptrdiff_t current_buffer_balance
415 = current_buffer_.size() - current_buffer_position_;
418 if (current_buffer_balance > n)
421 current_buffer_position_ += n;
426 n -= current_buffer_balance;
427 position_ += current_buffer_balance;
431 if (++current_ == end_)
433 ASIO_ASSERT(n == 0 &&
"iterator out of bounds");
434 current_buffer_ = buffer_type();
435 current_buffer_position_ = 0;
438 current_buffer_ = *current_;
439 current_buffer_position_ = 0;
444 std::size_t abs_n = -n;
445 ASIO_ASSERT(position_ >= abs_n &&
"iterator out of bounds");
449 if (current_buffer_position_ >= abs_n)
452 current_buffer_position_ -= abs_n;
457 abs_n -= current_buffer_position_;
458 position_ -= current_buffer_position_;
461 if (current_ == begin_)
463 ASIO_ASSERT(abs_n == 0 &&
"iterator out of bounds");
464 current_buffer_position_ = 0;
469 buffer_sequence_iterator_type iter = current_;
470 while (iter != begin_)
473 buffer_type buffer = *iter;
474 std::size_t buffer_size = buffer.size();
479 current_buffer_position_ = buffer_size;
490 return other.position_ - position_;
493 buffer_type current_buffer_;
494 std::size_t current_buffer_position_;
495 buffer_sequence_iterator_type begin_;
496 buffer_sequence_iterator_type current_;
497 buffer_sequence_iterator_type end_;
498 std::size_t position_;
502 template <
typename BufferSequence>
504 const BufferSequence& buffers)
510 template <
typename BufferSequence>
512 const BufferSequence& buffers)
519 #include "asio/detail/pop_options.hpp" 521 #endif // ASIO_BUFFERS_ITERATOR_HPP buffers_iterator & operator+=(std::ptrdiff_t difference)
Addition operator.
Definition: buffers_iterator.hpp:256
reference operator[](std::ptrdiff_t difference) const
Access an individual element.
Definition: buffers_iterator.hpp:218
buffers_iterator & operator-=(std::ptrdiff_t difference)
Subtraction operator.
Definition: buffers_iterator.hpp:263
Holds a buffer that cannot be modified.
Definition: buffer.hpp:226
friend bool operator>=(const buffers_iterator &a, const buffers_iterator &b)
Compare two iterators.
Definition: buffers_iterator.hpp:334
A random access iterator over the bytes in a buffer sequence.
Definition: buffers_iterator.hpp:110
friend bool operator!=(const buffers_iterator &a, const buffers_iterator &b)
Test two iterators for inequality.
Definition: buffers_iterator.hpp:310
buffers_iterator operator--(int)
Decrement operator (postfix).
Definition: buffers_iterator.hpp:248
friend std::ptrdiff_t operator-(const buffers_iterator &a, const buffers_iterator &b)
Subtraction operator.
Definition: buffers_iterator.hpp:297
friend bool operator>(const buffers_iterator &a, const buffers_iterator &b)
Compare two iterators.
Definition: buffers_iterator.hpp:328
friend buffers_iterator operator-(const buffers_iterator &iter, std::ptrdiff_t difference)
Subtraction operator.
Definition: buffers_iterator.hpp:288
buffers_iterator & operator++()
Increment operator (prefix).
Definition: buffers_iterator.hpp:226
(Deprecated: Use const_buffer.) Adapts a single non-modifiable buffer so that it meets the requiremen...
Definition: buffer.hpp:306
ASIO_MUTABLE_BUFFER buffer(const mutable_buffer &b) ASIO_NOEXCEPT
Create a new modifiable buffer from an existing buffer.
Definition: buffer.hpp:909
static buffers_iterator end(const BufferSequence &buffers)
Construct an iterator representing the end of the buffers' data.
Definition: buffers_iterator.hpp:187
Definition: buffers_iterator.hpp:57
friend bool operator==(const buffers_iterator &a, const buffers_iterator &b)
Test two iterators for equality.
Definition: buffers_iterator.hpp:304
friend bool operator<=(const buffers_iterator &a, const buffers_iterator &b)
Compare two iterators.
Definition: buffers_iterator.hpp:322
buffers_iterator operator++(int)
Increment operator (postfix).
Definition: buffers_iterator.hpp:233
Holds a buffer that can be modified.
Definition: buffer.hpp:92
Definition: buffers_iterator.hpp:32
reference operator*() const
Dereference an iterator.
Definition: buffers_iterator.hpp:206
buffers_iterator()
Default constructor. Creates an iterator in an undefined state.
Definition: buffers_iterator.hpp:156
std::ptrdiff_t difference_type
The type used for the distance between two iterators.
Definition: buffers_iterator.hpp:121
ByteType value_type
The type of the value pointed to by the iterator.
Definition: buffers_iterator.hpp:124
friend buffers_iterator operator+(std::ptrdiff_t difference, const buffers_iterator &iter)
Addition operator.
Definition: buffers_iterator.hpp:279
const mutable_buffer * buffer_sequence_begin(const MutableBuffer &b, typename enable_if< is_convertible< const MutableBuffer *, const mutable_buffer *>::value >::type *=0) ASIO_NOEXCEPT
Get an iterator to the first element in a buffer sequence.
Definition: buffer.hpp:388
const mutable_buffer * buffer_sequence_end(const MutableBuffer &b, typename enable_if< is_convertible< const MutableBuffer *, const mutable_buffer *>::value >::type *=0) ASIO_NOEXCEPT
Get an iterator to one past the end element in a buffer sequence.
Definition: buffer.hpp:465
std::random_access_iterator_tag iterator_category
The iterator category.
Definition: buffers_iterator.hpp:153
friend bool operator<(const buffers_iterator &a, const buffers_iterator &b)
Compare two iterators.
Definition: buffers_iterator.hpp:316
static buffers_iterator begin(const BufferSequence &buffers)
Construct an iterator representing the beginning of the buffers' data.
Definition: buffers_iterator.hpp:167
friend buffers_iterator operator+(const buffers_iterator &iter, std::ptrdiff_t difference)
Addition operator.
Definition: buffers_iterator.hpp:270
Definition: any_io_executor.hpp:28
(Deprecated: Use mutable_buffer.) Adapts a single modifiable buffer so that it meets the requirements...
Definition: buffer.hpp:162
buffers_iterator & operator--()
Decrement operator (prefix).
Definition: buffers_iterator.hpp:241
pointer operator->() const
Dereference an iterator.
Definition: buffers_iterator.hpp:212