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) 31 template <
bool IsMutable>
38 template <
typename ByteType>
41 typedef typename add_const<ByteType>::type
type;
49 template <
typename ByteType>
56 template <
typename BufferSequence,
typename ByteType>
61 is_mutable = is_convertible<
62 typename BufferSequence::value_type,
72 template <
typename BufferSequence,
typename ByteType =
char>
77 BufferSequence, ByteType>::buffer_type buffer_type;
86 #if defined(GENERATING_DOCUMENTATION) 93 typedef const_or_non_const_ByteType*
pointer;
94 #else // defined(GENERATING_DOCUMENTATION) 96 BufferSequence, ByteType>::byte_type*
pointer;
97 #endif // defined(GENERATING_DOCUMENTATION) 99 #if defined(GENERATING_DOCUMENTATION) 106 typedef const_or_non_const_ByteType&
reference;
107 #else // defined(GENERATING_DOCUMENTATION) 110 #endif // defined(GENERATING_DOCUMENTATION) 118 current_buffer_position_(0),
128 #if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3) 129 __attribute__ ((__noinline__))
130 #endif // defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3) 133 new_iter.begin_ = buffers.begin();
134 new_iter.current_ = buffers.begin();
135 new_iter.end_ = buffers.end();
136 while (new_iter.current_ != new_iter.end_)
138 new_iter.current_buffer_ = *new_iter.current_;
148 #if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3) 149 __attribute__ ((__noinline__))
150 #endif // defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 3) 153 new_iter.begin_ = buffers.begin();
154 new_iter.current_ = buffers.begin();
155 new_iter.end_ = buffers.end();
156 while (new_iter.current_ != new_iter.end_)
158 buffer_type
buffer = *new_iter.current_;
168 return dereference();
174 return &dereference();
181 tmp.advance(difference);
225 advance(-difference);
231 std::ptrdiff_t difference)
234 tmp.advance(difference);
243 tmp.advance(difference);
249 std::ptrdiff_t difference)
252 tmp.advance(-difference);
260 return b.distance_to(a);
278 return a.distance_to(b) > 0;
301 reference dereference()
const 303 return buffer_cast<pointer>(current_buffer_)[current_buffer_position_];
309 return position_ == other.position_;
315 ASIO_ASSERT(current_ != end_ &&
"iterator out of bounds");
319 ++current_buffer_position_;
325 current_buffer_position_ = 0;
326 while (current_ != end_)
328 current_buffer_ = *current_;
338 ASIO_ASSERT(position_ > 0 &&
"iterator out of bounds");
342 if (current_buffer_position_ != 0)
344 --current_buffer_position_;
349 typename BufferSequence::const_iterator iter = current_;
350 while (iter != begin_)
353 buffer_type
buffer = *iter;
359 current_buffer_position_ = buffer_size - 1;
366 void advance(std::ptrdiff_t n)
370 ASIO_ASSERT(current_ != end_ &&
"iterator out of bounds");
373 std::ptrdiff_t current_buffer_balance
375 - current_buffer_position_;
378 if (current_buffer_balance > n)
381 current_buffer_position_ += n;
386 n -= current_buffer_balance;
387 position_ += current_buffer_balance;
391 if (++current_ == end_)
394 current_buffer_ = buffer_type();
395 current_buffer_position_ = 0;
398 current_buffer_ = *current_;
399 current_buffer_position_ = 0;
404 std::size_t abs_n = -n;
405 ASIO_ASSERT(position_ >= abs_n &&
"iterator out of bounds");
409 if (current_buffer_position_ >= abs_n)
412 current_buffer_position_ -= abs_n;
417 abs_n -= current_buffer_position_;
418 position_ -= current_buffer_position_;
421 if (current_ == begin_)
423 ASIO_ASSERT(abs_n == 0 &&
"iterator out of bounds");
424 current_buffer_position_ = 0;
429 typename BufferSequence::const_iterator iter = current_;
430 while (iter != begin_)
433 buffer_type
buffer = *iter;
450 return other.position_ - position_;
453 buffer_type current_buffer_;
454 std::size_t current_buffer_position_;
455 typename BufferSequence::const_iterator begin_;
456 typename BufferSequence::const_iterator current_;
457 typename BufferSequence::const_iterator end_;
458 std::size_t position_;
462 template <
typename BufferSequence>
464 const BufferSequence& buffers)
470 template <
typename BufferSequence>
472 const BufferSequence& buffers)
481 #endif // ASIO_BUFFERS_ITERATOR_HPP mutable_buffer buffer_type
#define ASIO_ASSERT(expr)
buffers_iterator & operator+=(std::ptrdiff_t difference)
Addition operator.
buffers_iterator & operator-=(std::ptrdiff_t difference)
Subtraction operator.
Holds a buffer that cannot be modified.
helper::template byte_type< ByteType >::type byte_type
buffers_iterator< BufferSequence > buffers_end(const BufferSequence &buffers)
Construct an iterator representing the end of the buffers' data.
friend bool operator>=(const buffers_iterator &a, const buffers_iterator &b)
Compare two iterators.
reference operator*() const
Dereference an iterator.
A random access iterator over the bytes in a buffer sequence.
mutable_buffers_1 buffer(const mutable_buffer &b)
Create a new modifiable buffer from an existing buffer.
friend bool operator!=(const buffers_iterator &a, const buffers_iterator &b)
Test two iterators for inequality.
detail::buffers_iterator_types< BufferSequence, ByteType >::byte_type & reference
buffers_iterator operator--(int)
Decrement operator (postfix).
friend std::ptrdiff_t operator-(const buffers_iterator &a, const buffers_iterator &b)
Subtraction operator.
friend bool operator>(const buffers_iterator &a, const buffers_iterator &b)
Compare two iterators.
friend buffers_iterator operator-(const buffers_iterator &iter, std::ptrdiff_t difference)
Subtraction operator.
asio::basic_streambuf< Allocator > & b
buffers_iterator & operator++()
Increment operator (prefix).
std::size_t buffer_size(const mutable_buffer &b)
Get the number of bytes in a modifiable buffer.
PointerToPodType buffer_cast(const mutable_buffer &b)
Cast a non-modifiable buffer to a specified pointer to POD type.
detail::buffers_iterator_types< BufferSequence, ByteType >::byte_type * pointer
const MutableBufferSequence & buffers
static buffers_iterator end(const BufferSequence &buffers)
Construct an iterator representing the end of the buffers' data.
add_const< ByteType >::type type
friend bool operator==(const buffers_iterator &a, const buffers_iterator &b)
Test two iterators for equality.
friend bool operator<=(const buffers_iterator &a, const buffers_iterator &b)
Compare two iterators.
buffers_iterator< BufferSequence > buffers_begin(const BufferSequence &buffers)
Construct an iterator representing the beginning of the buffers' data.
buffers_iterator operator++(int)
Increment operator (postfix).
Holds a buffer that can be modified.
helper::buffer_type buffer_type
void increment(atomic_count &a, long b)
buffers_iterator_types_helper< is_mutable > helper
buffers_iterator()
Default constructor. Creates an iterator in an undefined state.
std::ptrdiff_t difference_type
The type used for the distance between two iterators.
ByteType value_type
The type of the value pointed to by the iterator.
friend buffers_iterator operator+(std::ptrdiff_t difference, const buffers_iterator &iter)
Addition operator.
pointer operator->() const
Dereference an iterator.
std::random_access_iterator_tag iterator_category
The iterator category.
friend bool operator<(const buffers_iterator &a, const buffers_iterator &b)
Compare two iterators.
static buffers_iterator begin(const BufferSequence &buffers)
Construct an iterator representing the beginning of the buffers' data.
friend buffers_iterator operator+(const buffers_iterator &iter, std::ptrdiff_t difference)
Addition operator.
reference operator[](std::ptrdiff_t difference) const
Access an individual element.
buffers_iterator & operator--()
Decrement operator (prefix).