Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / buffer.hpp @ 2486

History | View | Annotate | Download (69.2 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// buffer.hpp
3 2486 sjacqu01
// ~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_BUFFER_HPP
12 2486 sjacqu01
#define BOOST_ASIO_BUFFER_HPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
19 2486 sjacqu01
#include <cstddef>
20 2486 sjacqu01
#include <cstring>
21 2486 sjacqu01
#include <string>
22 2486 sjacqu01
#include <vector>
23 2486 sjacqu01
#include <boost/asio/detail/array_fwd.hpp>
24 2486 sjacqu01
25 2486 sjacqu01
#if defined(BOOST_ASIO_MSVC)
26 2486 sjacqu01
# if defined(_HAS_ITERATOR_DEBUGGING) && (_HAS_ITERATOR_DEBUGGING != 0)
27 2486 sjacqu01
#  if !defined(BOOST_ASIO_DISABLE_BUFFER_DEBUGGING)
28 2486 sjacqu01
#   define BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
29 2486 sjacqu01
#  endif // !defined(BOOST_ASIO_DISABLE_BUFFER_DEBUGGING)
30 2486 sjacqu01
# endif // defined(_HAS_ITERATOR_DEBUGGING)
31 2486 sjacqu01
#endif // defined(BOOST_ASIO_MSVC)
32 2486 sjacqu01
33 2486 sjacqu01
#if defined(__GNUC__)
34 2486 sjacqu01
# if defined(_GLIBCXX_DEBUG)
35 2486 sjacqu01
#  if !defined(BOOST_ASIO_DISABLE_BUFFER_DEBUGGING)
36 2486 sjacqu01
#   define BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
37 2486 sjacqu01
#  endif // !defined(BOOST_ASIO_DISABLE_BUFFER_DEBUGGING)
38 2486 sjacqu01
# endif // defined(_GLIBCXX_DEBUG)
39 2486 sjacqu01
#endif // defined(__GNUC__)
40 2486 sjacqu01
41 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
42 2486 sjacqu01
# include <boost/asio/detail/function.hpp>
43 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
44 2486 sjacqu01
45 2486 sjacqu01
#if defined(BOOST_ASIO_HAS_BOOST_WORKAROUND)
46 2486 sjacqu01
# include <boost/detail/workaround.hpp>
47 2486 sjacqu01
# if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582)) \
48 2486 sjacqu01
    || BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
49 2486 sjacqu01
#  define BOOST_ASIO_ENABLE_ARRAY_BUFFER_WORKAROUND
50 2486 sjacqu01
# endif // BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
51 2486 sjacqu01
        // || BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
52 2486 sjacqu01
#endif // defined(BOOST_ASIO_HAS_BOOST_WORKAROUND)
53 2486 sjacqu01
54 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_ARRAY_BUFFER_WORKAROUND)
55 2486 sjacqu01
# include <boost/asio/detail/type_traits.hpp>
56 2486 sjacqu01
#endif // defined(BOOST_ASIO_ENABLE_ARRAY_BUFFER_WORKAROUND)
57 2486 sjacqu01
58 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
59 2486 sjacqu01
60 2486 sjacqu01
namespace boost {
61 2486 sjacqu01
namespace asio {
62 2486 sjacqu01
63 2486 sjacqu01
class mutable_buffer;
64 2486 sjacqu01
class const_buffer;
65 2486 sjacqu01
66 2486 sjacqu01
namespace detail {
67 2486 sjacqu01
void* buffer_cast_helper(const mutable_buffer&);
68 2486 sjacqu01
const void* buffer_cast_helper(const const_buffer&);
69 2486 sjacqu01
std::size_t buffer_size_helper(const mutable_buffer&);
70 2486 sjacqu01
std::size_t buffer_size_helper(const const_buffer&);
71 2486 sjacqu01
} // namespace detail
72 2486 sjacqu01
73 2486 sjacqu01
/// Holds a buffer that can be modified.
74 2486 sjacqu01
/**
75 2486 sjacqu01
 * The mutable_buffer class provides a safe representation of a buffer that can
76 2486 sjacqu01
 * be modified. It does not own the underlying data, and so is cheap to copy or
77 2486 sjacqu01
 * assign.
78 2486 sjacqu01
 *
79 2486 sjacqu01
 * @par Accessing Buffer Contents
80 2486 sjacqu01
 *
81 2486 sjacqu01
 * The contents of a buffer may be accessed using the @ref buffer_size
82 2486 sjacqu01
 * and @ref buffer_cast functions:
83 2486 sjacqu01
 *
84 2486 sjacqu01
 * @code boost::asio::mutable_buffer b1 = ...;
85 2486 sjacqu01
 * std::size_t s1 = boost::asio::buffer_size(b1);
86 2486 sjacqu01
 * unsigned char* p1 = boost::asio::buffer_cast<unsigned char*>(b1);
87 2486 sjacqu01
 * @endcode
88 2486 sjacqu01
 *
89 2486 sjacqu01
 * The boost::asio::buffer_cast function permits violations of type safety, so
90 2486 sjacqu01
 * uses of it in application code should be carefully considered.
91 2486 sjacqu01
 */
92 2486 sjacqu01
class mutable_buffer
93 2486 sjacqu01
{
94 2486 sjacqu01
public:
95 2486 sjacqu01
  /// Construct an empty buffer.
96 2486 sjacqu01
  mutable_buffer()
97 2486 sjacqu01
    : data_(0),
98 2486 sjacqu01
      size_(0)
99 2486 sjacqu01
  {
100 2486 sjacqu01
  }
101 2486 sjacqu01
102 2486 sjacqu01
  /// Construct a buffer to represent a given memory range.
103 2486 sjacqu01
  mutable_buffer(void* data, std::size_t size)
104 2486 sjacqu01
    : data_(data),
105 2486 sjacqu01
      size_(size)
106 2486 sjacqu01
  {
107 2486 sjacqu01
  }
108 2486 sjacqu01
109 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
110 2486 sjacqu01
  mutable_buffer(void* data, std::size_t size,
111 2486 sjacqu01
      boost::asio::detail::function<void()> debug_check)
112 2486 sjacqu01
    : data_(data),
113 2486 sjacqu01
      size_(size),
114 2486 sjacqu01
      debug_check_(debug_check)
115 2486 sjacqu01
  {
116 2486 sjacqu01
  }
117 2486 sjacqu01
118 2486 sjacqu01
  const boost::asio::detail::function<void()>& get_debug_check() const
119 2486 sjacqu01
  {
120 2486 sjacqu01
    return debug_check_;
121 2486 sjacqu01
  }
122 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
123 2486 sjacqu01
124 2486 sjacqu01
private:
125 2486 sjacqu01
  friend void* boost::asio::detail::buffer_cast_helper(
126 2486 sjacqu01
      const mutable_buffer& b);
127 2486 sjacqu01
  friend std::size_t boost::asio::detail::buffer_size_helper(
128 2486 sjacqu01
      const mutable_buffer& b);
129 2486 sjacqu01
130 2486 sjacqu01
  void* data_;
131 2486 sjacqu01
  std::size_t size_;
132 2486 sjacqu01
133 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
134 2486 sjacqu01
  boost::asio::detail::function<void()> debug_check_;
135 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
136 2486 sjacqu01
};
137 2486 sjacqu01
138 2486 sjacqu01
namespace detail {
139 2486 sjacqu01
140 2486 sjacqu01
inline void* buffer_cast_helper(const mutable_buffer& b)
141 2486 sjacqu01
{
142 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
143 2486 sjacqu01
  if (b.size_ && b.debug_check_)
144 2486 sjacqu01
    b.debug_check_();
145 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
146 2486 sjacqu01
  return b.data_;
147 2486 sjacqu01
}
148 2486 sjacqu01
149 2486 sjacqu01
inline std::size_t buffer_size_helper(const mutable_buffer& b)
150 2486 sjacqu01
{
151 2486 sjacqu01
  return b.size_;
152 2486 sjacqu01
}
153 2486 sjacqu01
154 2486 sjacqu01
} // namespace detail
155 2486 sjacqu01
156 2486 sjacqu01
/// Adapts a single modifiable buffer so that it meets the requirements of the
157 2486 sjacqu01
/// MutableBufferSequence concept.
158 2486 sjacqu01
class mutable_buffers_1
159 2486 sjacqu01
  : public mutable_buffer
160 2486 sjacqu01
{
161 2486 sjacqu01
public:
162 2486 sjacqu01
  /// The type for each element in the list of buffers.
163 2486 sjacqu01
  typedef mutable_buffer value_type;
164 2486 sjacqu01
165 2486 sjacqu01
  /// A random-access iterator type that may be used to read elements.
166 2486 sjacqu01
  typedef const mutable_buffer* const_iterator;
167 2486 sjacqu01
168 2486 sjacqu01
  /// Construct to represent a given memory range.
169 2486 sjacqu01
  mutable_buffers_1(void* data, std::size_t size)
170 2486 sjacqu01
    : mutable_buffer(data, size)
171 2486 sjacqu01
  {
172 2486 sjacqu01
  }
173 2486 sjacqu01
174 2486 sjacqu01
  /// Construct to represent a single modifiable buffer.
175 2486 sjacqu01
  explicit mutable_buffers_1(const mutable_buffer& b)
176 2486 sjacqu01
    : mutable_buffer(b)
177 2486 sjacqu01
  {
178 2486 sjacqu01
  }
179 2486 sjacqu01
180 2486 sjacqu01
  /// Get a random-access iterator to the first element.
181 2486 sjacqu01
  const_iterator begin() const
182 2486 sjacqu01
  {
183 2486 sjacqu01
    return this;
184 2486 sjacqu01
  }
185 2486 sjacqu01
186 2486 sjacqu01
  /// Get a random-access iterator for one past the last element.
187 2486 sjacqu01
  const_iterator end() const
188 2486 sjacqu01
  {
189 2486 sjacqu01
    return begin() + 1;
190 2486 sjacqu01
  }
191 2486 sjacqu01
};
192 2486 sjacqu01
193 2486 sjacqu01
/// Holds a buffer that cannot be modified.
194 2486 sjacqu01
/**
195 2486 sjacqu01
 * The const_buffer class provides a safe representation of a buffer that cannot
196 2486 sjacqu01
 * be modified. It does not own the underlying data, and so is cheap to copy or
197 2486 sjacqu01
 * assign.
198 2486 sjacqu01
 *
199 2486 sjacqu01
 * @par Accessing Buffer Contents
200 2486 sjacqu01
 *
201 2486 sjacqu01
 * The contents of a buffer may be accessed using the @ref buffer_size
202 2486 sjacqu01
 * and @ref buffer_cast functions:
203 2486 sjacqu01
 *
204 2486 sjacqu01
 * @code boost::asio::const_buffer b1 = ...;
205 2486 sjacqu01
 * std::size_t s1 = boost::asio::buffer_size(b1);
206 2486 sjacqu01
 * const unsigned char* p1 = boost::asio::buffer_cast<const unsigned char*>(b1);
207 2486 sjacqu01
 * @endcode
208 2486 sjacqu01
 *
209 2486 sjacqu01
 * The boost::asio::buffer_cast function permits violations of type safety, so
210 2486 sjacqu01
 * uses of it in application code should be carefully considered.
211 2486 sjacqu01
 */
212 2486 sjacqu01
class const_buffer
213 2486 sjacqu01
{
214 2486 sjacqu01
public:
215 2486 sjacqu01
  /// Construct an empty buffer.
216 2486 sjacqu01
  const_buffer()
217 2486 sjacqu01
    : data_(0),
218 2486 sjacqu01
      size_(0)
219 2486 sjacqu01
  {
220 2486 sjacqu01
  }
221 2486 sjacqu01
222 2486 sjacqu01
  /// Construct a buffer to represent a given memory range.
223 2486 sjacqu01
  const_buffer(const void* data, std::size_t size)
224 2486 sjacqu01
    : data_(data),
225 2486 sjacqu01
      size_(size)
226 2486 sjacqu01
  {
227 2486 sjacqu01
  }
228 2486 sjacqu01
229 2486 sjacqu01
  /// Construct a non-modifiable buffer from a modifiable one.
230 2486 sjacqu01
  const_buffer(const mutable_buffer& b)
231 2486 sjacqu01
    : data_(boost::asio::detail::buffer_cast_helper(b)),
232 2486 sjacqu01
      size_(boost::asio::detail::buffer_size_helper(b))
233 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
234 2486 sjacqu01
      , debug_check_(b.get_debug_check())
235 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
236 2486 sjacqu01
  {
237 2486 sjacqu01
  }
238 2486 sjacqu01
239 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
240 2486 sjacqu01
  const_buffer(const void* data, std::size_t size,
241 2486 sjacqu01
      boost::asio::detail::function<void()> debug_check)
242 2486 sjacqu01
    : data_(data),
243 2486 sjacqu01
      size_(size),
244 2486 sjacqu01
      debug_check_(debug_check)
245 2486 sjacqu01
  {
246 2486 sjacqu01
  }
247 2486 sjacqu01
248 2486 sjacqu01
  const boost::asio::detail::function<void()>& get_debug_check() const
249 2486 sjacqu01
  {
250 2486 sjacqu01
    return debug_check_;
251 2486 sjacqu01
  }
252 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
253 2486 sjacqu01
254 2486 sjacqu01
private:
255 2486 sjacqu01
  friend const void* boost::asio::detail::buffer_cast_helper(
256 2486 sjacqu01
      const const_buffer& b);
257 2486 sjacqu01
  friend std::size_t boost::asio::detail::buffer_size_helper(
258 2486 sjacqu01
      const const_buffer& b);
259 2486 sjacqu01
260 2486 sjacqu01
  const void* data_;
261 2486 sjacqu01
  std::size_t size_;
262 2486 sjacqu01
263 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
264 2486 sjacqu01
  boost::asio::detail::function<void()> debug_check_;
265 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
266 2486 sjacqu01
};
267 2486 sjacqu01
268 2486 sjacqu01
namespace detail {
269 2486 sjacqu01
270 2486 sjacqu01
inline const void* buffer_cast_helper(const const_buffer& b)
271 2486 sjacqu01
{
272 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
273 2486 sjacqu01
  if (b.size_ && b.debug_check_)
274 2486 sjacqu01
    b.debug_check_();
275 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
276 2486 sjacqu01
  return b.data_;
277 2486 sjacqu01
}
278 2486 sjacqu01
279 2486 sjacqu01
inline std::size_t buffer_size_helper(const const_buffer& b)
280 2486 sjacqu01
{
281 2486 sjacqu01
  return b.size_;
282 2486 sjacqu01
}
283 2486 sjacqu01
284 2486 sjacqu01
} // namespace detail
285 2486 sjacqu01
286 2486 sjacqu01
/// Adapts a single non-modifiable buffer so that it meets the requirements of
287 2486 sjacqu01
/// the ConstBufferSequence concept.
288 2486 sjacqu01
class const_buffers_1
289 2486 sjacqu01
  : public const_buffer
290 2486 sjacqu01
{
291 2486 sjacqu01
public:
292 2486 sjacqu01
  /// The type for each element in the list of buffers.
293 2486 sjacqu01
  typedef const_buffer value_type;
294 2486 sjacqu01
295 2486 sjacqu01
  /// A random-access iterator type that may be used to read elements.
296 2486 sjacqu01
  typedef const const_buffer* const_iterator;
297 2486 sjacqu01
298 2486 sjacqu01
  /// Construct to represent a given memory range.
299 2486 sjacqu01
  const_buffers_1(const void* data, std::size_t size)
300 2486 sjacqu01
    : const_buffer(data, size)
301 2486 sjacqu01
  {
302 2486 sjacqu01
  }
303 2486 sjacqu01
304 2486 sjacqu01
  /// Construct to represent a single non-modifiable buffer.
305 2486 sjacqu01
  explicit const_buffers_1(const const_buffer& b)
306 2486 sjacqu01
    : const_buffer(b)
307 2486 sjacqu01
  {
308 2486 sjacqu01
  }
309 2486 sjacqu01
310 2486 sjacqu01
  /// Get a random-access iterator to the first element.
311 2486 sjacqu01
  const_iterator begin() const
312 2486 sjacqu01
  {
313 2486 sjacqu01
    return this;
314 2486 sjacqu01
  }
315 2486 sjacqu01
316 2486 sjacqu01
  /// Get a random-access iterator for one past the last element.
317 2486 sjacqu01
  const_iterator end() const
318 2486 sjacqu01
  {
319 2486 sjacqu01
    return begin() + 1;
320 2486 sjacqu01
  }
321 2486 sjacqu01
};
322 2486 sjacqu01
323 2486 sjacqu01
/// An implementation of both the ConstBufferSequence and MutableBufferSequence
324 2486 sjacqu01
/// concepts to represent a null buffer sequence.
325 2486 sjacqu01
class null_buffers
326 2486 sjacqu01
{
327 2486 sjacqu01
public:
328 2486 sjacqu01
  /// The type for each element in the list of buffers.
329 2486 sjacqu01
  typedef mutable_buffer value_type;
330 2486 sjacqu01
331 2486 sjacqu01
  /// A random-access iterator type that may be used to read elements.
332 2486 sjacqu01
  typedef const mutable_buffer* const_iterator;
333 2486 sjacqu01
334 2486 sjacqu01
  /// Get a random-access iterator to the first element.
335 2486 sjacqu01
  const_iterator begin() const
336 2486 sjacqu01
  {
337 2486 sjacqu01
    return &buf_;
338 2486 sjacqu01
  }
339 2486 sjacqu01
340 2486 sjacqu01
  /// Get a random-access iterator for one past the last element.
341 2486 sjacqu01
  const_iterator end() const
342 2486 sjacqu01
  {
343 2486 sjacqu01
    return &buf_;
344 2486 sjacqu01
  }
345 2486 sjacqu01
346 2486 sjacqu01
private:
347 2486 sjacqu01
  mutable_buffer buf_;
348 2486 sjacqu01
};
349 2486 sjacqu01
350 2486 sjacqu01
/** @defgroup buffer_size boost::asio::buffer_size
351 2486 sjacqu01
 *
352 2486 sjacqu01
 * @brief The boost::asio::buffer_size function determines the total number of
353 2486 sjacqu01
 * bytes in a buffer or buffer sequence.
354 2486 sjacqu01
 */
355 2486 sjacqu01
/*@{*/
356 2486 sjacqu01
357 2486 sjacqu01
/// Get the number of bytes in a modifiable buffer.
358 2486 sjacqu01
inline std::size_t buffer_size(const mutable_buffer& b)
359 2486 sjacqu01
{
360 2486 sjacqu01
  return detail::buffer_size_helper(b);
361 2486 sjacqu01
}
362 2486 sjacqu01
363 2486 sjacqu01
/// Get the number of bytes in a modifiable buffer.
364 2486 sjacqu01
inline std::size_t buffer_size(const mutable_buffers_1& b)
365 2486 sjacqu01
{
366 2486 sjacqu01
  return detail::buffer_size_helper(b);
367 2486 sjacqu01
}
368 2486 sjacqu01
369 2486 sjacqu01
/// Get the number of bytes in a non-modifiable buffer.
370 2486 sjacqu01
inline std::size_t buffer_size(const const_buffer& b)
371 2486 sjacqu01
{
372 2486 sjacqu01
  return detail::buffer_size_helper(b);
373 2486 sjacqu01
}
374 2486 sjacqu01
375 2486 sjacqu01
/// Get the number of bytes in a non-modifiable buffer.
376 2486 sjacqu01
inline std::size_t buffer_size(const const_buffers_1& b)
377 2486 sjacqu01
{
378 2486 sjacqu01
  return detail::buffer_size_helper(b);
379 2486 sjacqu01
}
380 2486 sjacqu01
381 2486 sjacqu01
/// Get the total number of bytes in a buffer sequence.
382 2486 sjacqu01
/**
383 2486 sjacqu01
 * The @c BufferSequence template parameter may meet either of the @c
384 2486 sjacqu01
 * ConstBufferSequence or @c MutableBufferSequence type requirements.
385 2486 sjacqu01
 */
386 2486 sjacqu01
template <typename BufferSequence>
387 2486 sjacqu01
inline std::size_t buffer_size(const BufferSequence& b)
388 2486 sjacqu01
{
389 2486 sjacqu01
  std::size_t total_buffer_size = 0;
390 2486 sjacqu01
391 2486 sjacqu01
  typename BufferSequence::const_iterator iter = b.begin();
392 2486 sjacqu01
  typename BufferSequence::const_iterator end = b.end();
393 2486 sjacqu01
  for (; iter != end; ++iter)
394 2486 sjacqu01
    total_buffer_size += detail::buffer_size_helper(*iter);
395 2486 sjacqu01
396 2486 sjacqu01
  return total_buffer_size;
397 2486 sjacqu01
}
398 2486 sjacqu01
399 2486 sjacqu01
/*@}*/
400 2486 sjacqu01
401 2486 sjacqu01
/** @defgroup buffer_cast boost::asio::buffer_cast
402 2486 sjacqu01
 *
403 2486 sjacqu01
 * @brief The boost::asio::buffer_cast function is used to obtain a pointer to
404 2486 sjacqu01
 * the underlying memory region associated with a buffer.
405 2486 sjacqu01
 *
406 2486 sjacqu01
 * @par Examples:
407 2486 sjacqu01
 *
408 2486 sjacqu01
 * To access the memory of a non-modifiable buffer, use:
409 2486 sjacqu01
 * @code boost::asio::const_buffer b1 = ...;
410 2486 sjacqu01
 * const unsigned char* p1 = boost::asio::buffer_cast<const unsigned char*>(b1);
411 2486 sjacqu01
 * @endcode
412 2486 sjacqu01
 *
413 2486 sjacqu01
 * To access the memory of a modifiable buffer, use:
414 2486 sjacqu01
 * @code boost::asio::mutable_buffer b2 = ...;
415 2486 sjacqu01
 * unsigned char* p2 = boost::asio::buffer_cast<unsigned char*>(b2);
416 2486 sjacqu01
 * @endcode
417 2486 sjacqu01
 *
418 2486 sjacqu01
 * The boost::asio::buffer_cast function permits violations of type safety, so
419 2486 sjacqu01
 * uses of it in application code should be carefully considered.
420 2486 sjacqu01
 */
421 2486 sjacqu01
/*@{*/
422 2486 sjacqu01
423 2486 sjacqu01
/// Cast a non-modifiable buffer to a specified pointer to POD type.
424 2486 sjacqu01
template <typename PointerToPodType>
425 2486 sjacqu01
inline PointerToPodType buffer_cast(const mutable_buffer& b)
426 2486 sjacqu01
{
427 2486 sjacqu01
  return static_cast<PointerToPodType>(detail::buffer_cast_helper(b));
428 2486 sjacqu01
}
429 2486 sjacqu01
430 2486 sjacqu01
/// Cast a non-modifiable buffer to a specified pointer to POD type.
431 2486 sjacqu01
template <typename PointerToPodType>
432 2486 sjacqu01
inline PointerToPodType buffer_cast(const const_buffer& b)
433 2486 sjacqu01
{
434 2486 sjacqu01
  return static_cast<PointerToPodType>(detail::buffer_cast_helper(b));
435 2486 sjacqu01
}
436 2486 sjacqu01
437 2486 sjacqu01
/*@}*/
438 2486 sjacqu01
439 2486 sjacqu01
/// Create a new modifiable buffer that is offset from the start of another.
440 2486 sjacqu01
/**
441 2486 sjacqu01
 * @relates mutable_buffer
442 2486 sjacqu01
 */
443 2486 sjacqu01
inline mutable_buffer operator+(const mutable_buffer& b, std::size_t start)
444 2486 sjacqu01
{
445 2486 sjacqu01
  if (start > buffer_size(b))
446 2486 sjacqu01
    return mutable_buffer();
447 2486 sjacqu01
  char* new_data = buffer_cast<char*>(b) + start;
448 2486 sjacqu01
  std::size_t new_size = buffer_size(b) - start;
449 2486 sjacqu01
  return mutable_buffer(new_data, new_size
450 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
451 2486 sjacqu01
      , b.get_debug_check()
452 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
453 2486 sjacqu01
      );
454 2486 sjacqu01
}
455 2486 sjacqu01
456 2486 sjacqu01
/// Create a new modifiable buffer that is offset from the start of another.
457 2486 sjacqu01
/**
458 2486 sjacqu01
 * @relates mutable_buffer
459 2486 sjacqu01
 */
460 2486 sjacqu01
inline mutable_buffer operator+(std::size_t start, const mutable_buffer& b)
461 2486 sjacqu01
{
462 2486 sjacqu01
  if (start > buffer_size(b))
463 2486 sjacqu01
    return mutable_buffer();
464 2486 sjacqu01
  char* new_data = buffer_cast<char*>(b) + start;
465 2486 sjacqu01
  std::size_t new_size = buffer_size(b) - start;
466 2486 sjacqu01
  return mutable_buffer(new_data, new_size
467 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
468 2486 sjacqu01
      , b.get_debug_check()
469 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
470 2486 sjacqu01
      );
471 2486 sjacqu01
}
472 2486 sjacqu01
473 2486 sjacqu01
/// Create a new non-modifiable buffer that is offset from the start of another.
474 2486 sjacqu01
/**
475 2486 sjacqu01
 * @relates const_buffer
476 2486 sjacqu01
 */
477 2486 sjacqu01
inline const_buffer operator+(const const_buffer& b, std::size_t start)
478 2486 sjacqu01
{
479 2486 sjacqu01
  if (start > buffer_size(b))
480 2486 sjacqu01
    return const_buffer();
481 2486 sjacqu01
  const char* new_data = buffer_cast<const char*>(b) + start;
482 2486 sjacqu01
  std::size_t new_size = buffer_size(b) - start;
483 2486 sjacqu01
  return const_buffer(new_data, new_size
484 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
485 2486 sjacqu01
      , b.get_debug_check()
486 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
487 2486 sjacqu01
      );
488 2486 sjacqu01
}
489 2486 sjacqu01
490 2486 sjacqu01
/// Create a new non-modifiable buffer that is offset from the start of another.
491 2486 sjacqu01
/**
492 2486 sjacqu01
 * @relates const_buffer
493 2486 sjacqu01
 */
494 2486 sjacqu01
inline const_buffer operator+(std::size_t start, const const_buffer& b)
495 2486 sjacqu01
{
496 2486 sjacqu01
  if (start > buffer_size(b))
497 2486 sjacqu01
    return const_buffer();
498 2486 sjacqu01
  const char* new_data = buffer_cast<const char*>(b) + start;
499 2486 sjacqu01
  std::size_t new_size = buffer_size(b) - start;
500 2486 sjacqu01
  return const_buffer(new_data, new_size
501 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
502 2486 sjacqu01
      , b.get_debug_check()
503 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
504 2486 sjacqu01
      );
505 2486 sjacqu01
}
506 2486 sjacqu01
507 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
508 2486 sjacqu01
namespace detail {
509 2486 sjacqu01
510 2486 sjacqu01
template <typename Iterator>
511 2486 sjacqu01
class buffer_debug_check
512 2486 sjacqu01
{
513 2486 sjacqu01
public:
514 2486 sjacqu01
  buffer_debug_check(Iterator iter)
515 2486 sjacqu01
    : iter_(iter)
516 2486 sjacqu01
  {
517 2486 sjacqu01
  }
518 2486 sjacqu01
519 2486 sjacqu01
  ~buffer_debug_check()
520 2486 sjacqu01
  {
521 2486 sjacqu01
#if defined(BOOST_ASIO_MSVC) && (BOOST_ASIO_MSVC == 1400)
522 2486 sjacqu01
    // MSVC 8's string iterator checking may crash in a std::string::iterator
523 2486 sjacqu01
    // object's destructor when the iterator points to an already-destroyed
524 2486 sjacqu01
    // std::string object, unless the iterator is cleared first.
525 2486 sjacqu01
    iter_ = Iterator();
526 2486 sjacqu01
#endif // defined(BOOST_ASIO_MSVC) && (BOOST_ASIO_MSVC == 1400)
527 2486 sjacqu01
  }
528 2486 sjacqu01
529 2486 sjacqu01
  void operator()()
530 2486 sjacqu01
  {
531 2486 sjacqu01
    *iter_;
532 2486 sjacqu01
  }
533 2486 sjacqu01
534 2486 sjacqu01
private:
535 2486 sjacqu01
  Iterator iter_;
536 2486 sjacqu01
};
537 2486 sjacqu01
538 2486 sjacqu01
} // namespace detail
539 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
540 2486 sjacqu01
541 2486 sjacqu01
/** @defgroup buffer boost::asio::buffer
542 2486 sjacqu01
 *
543 2486 sjacqu01
 * @brief The boost::asio::buffer function is used to create a buffer object to
544 2486 sjacqu01
 * represent raw memory, an array of POD elements, a vector of POD elements,
545 2486 sjacqu01
 * or a std::string.
546 2486 sjacqu01
 *
547 2486 sjacqu01
 * A buffer object represents a contiguous region of memory as a 2-tuple
548 2486 sjacqu01
 * consisting of a pointer and size in bytes. A tuple of the form <tt>{void*,
549 2486 sjacqu01
 * size_t}</tt> specifies a mutable (modifiable) region of memory. Similarly, a
550 2486 sjacqu01
 * tuple of the form <tt>{const void*, size_t}</tt> specifies a const
551 2486 sjacqu01
 * (non-modifiable) region of memory. These two forms correspond to the classes
552 2486 sjacqu01
 * mutable_buffer and const_buffer, respectively. To mirror C++'s conversion
553 2486 sjacqu01
 * rules, a mutable_buffer is implicitly convertible to a const_buffer, and the
554 2486 sjacqu01
 * opposite conversion is not permitted.
555 2486 sjacqu01
 *
556 2486 sjacqu01
 * The simplest use case involves reading or writing a single buffer of a
557 2486 sjacqu01
 * specified size:
558 2486 sjacqu01
 *
559 2486 sjacqu01
 * @code sock.send(boost::asio::buffer(data, size)); @endcode
560 2486 sjacqu01
 *
561 2486 sjacqu01
 * In the above example, the return value of boost::asio::buffer meets the
562 2486 sjacqu01
 * requirements of the ConstBufferSequence concept so that it may be directly
563 2486 sjacqu01
 * passed to the socket's write function. A buffer created for modifiable
564 2486 sjacqu01
 * memory also meets the requirements of the MutableBufferSequence concept.
565 2486 sjacqu01
 *
566 2486 sjacqu01
 * An individual buffer may be created from a builtin array, std::vector,
567 2486 sjacqu01
 * std::array or boost::array of POD elements. This helps prevent buffer
568 2486 sjacqu01
 * overruns by automatically determining the size of the buffer:
569 2486 sjacqu01
 *
570 2486 sjacqu01
 * @code char d1[128];
571 2486 sjacqu01
 * size_t bytes_transferred = sock.receive(boost::asio::buffer(d1));
572 2486 sjacqu01
 *
573 2486 sjacqu01
 * std::vector<char> d2(128);
574 2486 sjacqu01
 * bytes_transferred = sock.receive(boost::asio::buffer(d2));
575 2486 sjacqu01
 *
576 2486 sjacqu01
 * std::array<char, 128> d3;
577 2486 sjacqu01
 * bytes_transferred = sock.receive(boost::asio::buffer(d3));
578 2486 sjacqu01
 *
579 2486 sjacqu01
 * boost::array<char, 128> d4;
580 2486 sjacqu01
 * bytes_transferred = sock.receive(boost::asio::buffer(d4)); @endcode
581 2486 sjacqu01
 *
582 2486 sjacqu01
 * In all three cases above, the buffers created are exactly 128 bytes long.
583 2486 sjacqu01
 * Note that a vector is @e never automatically resized when creating or using
584 2486 sjacqu01
 * a buffer. The buffer size is determined using the vector's <tt>size()</tt>
585 2486 sjacqu01
 * member function, and not its capacity.
586 2486 sjacqu01
 *
587 2486 sjacqu01
 * @par Accessing Buffer Contents
588 2486 sjacqu01
 *
589 2486 sjacqu01
 * The contents of a buffer may be accessed using the @ref buffer_size and
590 2486 sjacqu01
 * @ref buffer_cast functions:
591 2486 sjacqu01
 *
592 2486 sjacqu01
 * @code boost::asio::mutable_buffer b1 = ...;
593 2486 sjacqu01
 * std::size_t s1 = boost::asio::buffer_size(b1);
594 2486 sjacqu01
 * unsigned char* p1 = boost::asio::buffer_cast<unsigned char*>(b1);
595 2486 sjacqu01
 *
596 2486 sjacqu01
 * boost::asio::const_buffer b2 = ...;
597 2486 sjacqu01
 * std::size_t s2 = boost::asio::buffer_size(b2);
598 2486 sjacqu01
 * const void* p2 = boost::asio::buffer_cast<const void*>(b2); @endcode
599 2486 sjacqu01
 *
600 2486 sjacqu01
 * The boost::asio::buffer_cast function permits violations of type safety, so
601 2486 sjacqu01
 * uses of it in application code should be carefully considered.
602 2486 sjacqu01
 *
603 2486 sjacqu01
 * For convenience, the @ref buffer_size function also works on buffer
604 2486 sjacqu01
 * sequences (that is, types meeting the ConstBufferSequence or
605 2486 sjacqu01
 * MutableBufferSequence type requirements). In this case, the function returns
606 2486 sjacqu01
 * the total size of all buffers in the sequence.
607 2486 sjacqu01
 *
608 2486 sjacqu01
 * @par Buffer Copying
609 2486 sjacqu01
 *
610 2486 sjacqu01
 * The @ref buffer_copy function may be used to copy raw bytes between
611 2486 sjacqu01
 * individual buffers and buffer sequences.
612 2486 sjacqu01
 *
613 2486 sjacqu01
 * In particular, when used with the @ref buffer_size, the @ref buffer_copy
614 2486 sjacqu01
 * function can be used to linearise a sequence of buffers. For example:
615 2486 sjacqu01
 *
616 2486 sjacqu01
 * @code vector<const_buffer> buffers = ...;
617 2486 sjacqu01
 *
618 2486 sjacqu01
 * vector<unsigned char> data(boost::asio::buffer_size(buffers));
619 2486 sjacqu01
 * boost::asio::buffer_copy(boost::asio::buffer(data), buffers); @endcode
620 2486 sjacqu01
 *
621 2486 sjacqu01
 * Note that @ref buffer_copy is implemented in terms of @c memcpy, and
622 2486 sjacqu01
 * consequently it cannot be used to copy between overlapping memory regions.
623 2486 sjacqu01
 *
624 2486 sjacqu01
 * @par Buffer Invalidation
625 2486 sjacqu01
 *
626 2486 sjacqu01
 * A buffer object does not have any ownership of the memory it refers to. It
627 2486 sjacqu01
 * is the responsibility of the application to ensure the memory region remains
628 2486 sjacqu01
 * valid until it is no longer required for an I/O operation. When the memory
629 2486 sjacqu01
 * is no longer available, the buffer is said to have been invalidated.
630 2486 sjacqu01
 *
631 2486 sjacqu01
 * For the boost::asio::buffer overloads that accept an argument of type
632 2486 sjacqu01
 * std::vector, the buffer objects returned are invalidated by any vector
633 2486 sjacqu01
 * operation that also invalidates all references, pointers and iterators
634 2486 sjacqu01
 * referring to the elements in the sequence (C++ Std, 23.2.4)
635 2486 sjacqu01
 *
636 2486 sjacqu01
 * For the boost::asio::buffer overloads that accept an argument of type
637 2486 sjacqu01
 * std::basic_string, the buffer objects returned are invalidated according to
638 2486 sjacqu01
 * the rules defined for invalidation of references, pointers and iterators
639 2486 sjacqu01
 * referring to elements of the sequence (C++ Std, 21.3).
640 2486 sjacqu01
 *
641 2486 sjacqu01
 * @par Buffer Arithmetic
642 2486 sjacqu01
 *
643 2486 sjacqu01
 * Buffer objects may be manipulated using simple arithmetic in a safe way
644 2486 sjacqu01
 * which helps prevent buffer overruns. Consider an array initialised as
645 2486 sjacqu01
 * follows:
646 2486 sjacqu01
 *
647 2486 sjacqu01
 * @code boost::array<char, 6> a = { 'a', 'b', 'c', 'd', 'e' }; @endcode
648 2486 sjacqu01
 *
649 2486 sjacqu01
 * A buffer object @c b1 created using:
650 2486 sjacqu01
 *
651 2486 sjacqu01
 * @code b1 = boost::asio::buffer(a); @endcode
652 2486 sjacqu01
 *
653 2486 sjacqu01
 * represents the entire array, <tt>{ 'a', 'b', 'c', 'd', 'e' }</tt>. An
654 2486 sjacqu01
 * optional second argument to the boost::asio::buffer function may be used to
655 2486 sjacqu01
 * limit the size, in bytes, of the buffer:
656 2486 sjacqu01
 *
657 2486 sjacqu01
 * @code b2 = boost::asio::buffer(a, 3); @endcode
658 2486 sjacqu01
 *
659 2486 sjacqu01
 * such that @c b2 represents the data <tt>{ 'a', 'b', 'c' }</tt>. Even if the
660 2486 sjacqu01
 * size argument exceeds the actual size of the array, the size of the buffer
661 2486 sjacqu01
 * object created will be limited to the array size.
662 2486 sjacqu01
 *
663 2486 sjacqu01
 * An offset may be applied to an existing buffer to create a new one:
664 2486 sjacqu01
 *
665 2486 sjacqu01
 * @code b3 = b1 + 2; @endcode
666 2486 sjacqu01
 *
667 2486 sjacqu01
 * where @c b3 will set to represent <tt>{ 'c', 'd', 'e' }</tt>. If the offset
668 2486 sjacqu01
 * exceeds the size of the existing buffer, the newly created buffer will be
669 2486 sjacqu01
 * empty.
670 2486 sjacqu01
 *
671 2486 sjacqu01
 * Both an offset and size may be specified to create a buffer that corresponds
672 2486 sjacqu01
 * to a specific range of bytes within an existing buffer:
673 2486 sjacqu01
 *
674 2486 sjacqu01
 * @code b4 = boost::asio::buffer(b1 + 1, 3); @endcode
675 2486 sjacqu01
 *
676 2486 sjacqu01
 * so that @c b4 will refer to the bytes <tt>{ 'b', 'c', 'd' }</tt>.
677 2486 sjacqu01
 *
678 2486 sjacqu01
 * @par Buffers and Scatter-Gather I/O
679 2486 sjacqu01
 *
680 2486 sjacqu01
 * To read or write using multiple buffers (i.e. scatter-gather I/O), multiple
681 2486 sjacqu01
 * buffer objects may be assigned into a container that supports the
682 2486 sjacqu01
 * MutableBufferSequence (for read) or ConstBufferSequence (for write) concepts:
683 2486 sjacqu01
 *
684 2486 sjacqu01
 * @code
685 2486 sjacqu01
 * char d1[128];
686 2486 sjacqu01
 * std::vector<char> d2(128);
687 2486 sjacqu01
 * boost::array<char, 128> d3;
688 2486 sjacqu01
 *
689 2486 sjacqu01
 * boost::array<mutable_buffer, 3> bufs1 = {
690 2486 sjacqu01
 *   boost::asio::buffer(d1),
691 2486 sjacqu01
 *   boost::asio::buffer(d2),
692 2486 sjacqu01
 *   boost::asio::buffer(d3) };
693 2486 sjacqu01
 * bytes_transferred = sock.receive(bufs1);
694 2486 sjacqu01
 *
695 2486 sjacqu01
 * std::vector<const_buffer> bufs2;
696 2486 sjacqu01
 * bufs2.push_back(boost::asio::buffer(d1));
697 2486 sjacqu01
 * bufs2.push_back(boost::asio::buffer(d2));
698 2486 sjacqu01
 * bufs2.push_back(boost::asio::buffer(d3));
699 2486 sjacqu01
 * bytes_transferred = sock.send(bufs2); @endcode
700 2486 sjacqu01
 */
701 2486 sjacqu01
/*@{*/
702 2486 sjacqu01
703 2486 sjacqu01
/// Create a new modifiable buffer from an existing buffer.
704 2486 sjacqu01
/**
705 2486 sjacqu01
 * @returns <tt>mutable_buffers_1(b)</tt>.
706 2486 sjacqu01
 */
707 2486 sjacqu01
inline mutable_buffers_1 buffer(const mutable_buffer& b)
708 2486 sjacqu01
{
709 2486 sjacqu01
  return mutable_buffers_1(b);
710 2486 sjacqu01
}
711 2486 sjacqu01
712 2486 sjacqu01
/// Create a new modifiable buffer from an existing buffer.
713 2486 sjacqu01
/**
714 2486 sjacqu01
 * @returns A mutable_buffers_1 value equivalent to:
715 2486 sjacqu01
 * @code mutable_buffers_1(
716 2486 sjacqu01
 *     buffer_cast<void*>(b),
717 2486 sjacqu01
 *     min(buffer_size(b), max_size_in_bytes)); @endcode
718 2486 sjacqu01
 */
719 2486 sjacqu01
inline mutable_buffers_1 buffer(const mutable_buffer& b,
720 2486 sjacqu01
    std::size_t max_size_in_bytes)
721 2486 sjacqu01
{
722 2486 sjacqu01
  return mutable_buffers_1(
723 2486 sjacqu01
      mutable_buffer(buffer_cast<void*>(b),
724 2486 sjacqu01
        buffer_size(b) < max_size_in_bytes
725 2486 sjacqu01
        ? buffer_size(b) : max_size_in_bytes
726 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
727 2486 sjacqu01
        , b.get_debug_check()
728 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
729 2486 sjacqu01
        ));
730 2486 sjacqu01
}
731 2486 sjacqu01
732 2486 sjacqu01
/// Create a new non-modifiable buffer from an existing buffer.
733 2486 sjacqu01
/**
734 2486 sjacqu01
 * @returns <tt>const_buffers_1(b)</tt>.
735 2486 sjacqu01
 */
736 2486 sjacqu01
inline const_buffers_1 buffer(const const_buffer& b)
737 2486 sjacqu01
{
738 2486 sjacqu01
  return const_buffers_1(b);
739 2486 sjacqu01
}
740 2486 sjacqu01
741 2486 sjacqu01
/// Create a new non-modifiable buffer from an existing buffer.
742 2486 sjacqu01
/**
743 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
744 2486 sjacqu01
 * @code const_buffers_1(
745 2486 sjacqu01
 *     buffer_cast<const void*>(b),
746 2486 sjacqu01
 *     min(buffer_size(b), max_size_in_bytes)); @endcode
747 2486 sjacqu01
 */
748 2486 sjacqu01
inline const_buffers_1 buffer(const const_buffer& b,
749 2486 sjacqu01
    std::size_t max_size_in_bytes)
750 2486 sjacqu01
{
751 2486 sjacqu01
  return const_buffers_1(
752 2486 sjacqu01
      const_buffer(buffer_cast<const void*>(b),
753 2486 sjacqu01
        buffer_size(b) < max_size_in_bytes
754 2486 sjacqu01
        ? buffer_size(b) : max_size_in_bytes
755 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
756 2486 sjacqu01
        , b.get_debug_check()
757 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
758 2486 sjacqu01
        ));
759 2486 sjacqu01
}
760 2486 sjacqu01
761 2486 sjacqu01
/// Create a new modifiable buffer that represents the given memory range.
762 2486 sjacqu01
/**
763 2486 sjacqu01
 * @returns <tt>mutable_buffers_1(data, size_in_bytes)</tt>.
764 2486 sjacqu01
 */
765 2486 sjacqu01
inline mutable_buffers_1 buffer(void* data, std::size_t size_in_bytes)
766 2486 sjacqu01
{
767 2486 sjacqu01
  return mutable_buffers_1(mutable_buffer(data, size_in_bytes));
768 2486 sjacqu01
}
769 2486 sjacqu01
770 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given memory range.
771 2486 sjacqu01
/**
772 2486 sjacqu01
 * @returns <tt>const_buffers_1(data, size_in_bytes)</tt>.
773 2486 sjacqu01
 */
774 2486 sjacqu01
inline const_buffers_1 buffer(const void* data,
775 2486 sjacqu01
    std::size_t size_in_bytes)
776 2486 sjacqu01
{
777 2486 sjacqu01
  return const_buffers_1(const_buffer(data, size_in_bytes));
778 2486 sjacqu01
}
779 2486 sjacqu01
780 2486 sjacqu01
/// Create a new modifiable buffer that represents the given POD array.
781 2486 sjacqu01
/**
782 2486 sjacqu01
 * @returns A mutable_buffers_1 value equivalent to:
783 2486 sjacqu01
 * @code mutable_buffers_1(
784 2486 sjacqu01
 *     static_cast<void*>(data),
785 2486 sjacqu01
 *     N * sizeof(PodType)); @endcode
786 2486 sjacqu01
 */
787 2486 sjacqu01
template <typename PodType, std::size_t N>
788 2486 sjacqu01
inline mutable_buffers_1 buffer(PodType (&data)[N])
789 2486 sjacqu01
{
790 2486 sjacqu01
  return mutable_buffers_1(mutable_buffer(data, N * sizeof(PodType)));
791 2486 sjacqu01
}
792 2486 sjacqu01
793 2486 sjacqu01
/// Create a new modifiable buffer that represents the given POD array.
794 2486 sjacqu01
/**
795 2486 sjacqu01
 * @returns A mutable_buffers_1 value equivalent to:
796 2486 sjacqu01
 * @code mutable_buffers_1(
797 2486 sjacqu01
 *     static_cast<void*>(data),
798 2486 sjacqu01
 *     min(N * sizeof(PodType), max_size_in_bytes)); @endcode
799 2486 sjacqu01
 */
800 2486 sjacqu01
template <typename PodType, std::size_t N>
801 2486 sjacqu01
inline mutable_buffers_1 buffer(PodType (&data)[N],
802 2486 sjacqu01
    std::size_t max_size_in_bytes)
803 2486 sjacqu01
{
804 2486 sjacqu01
  return mutable_buffers_1(
805 2486 sjacqu01
      mutable_buffer(data,
806 2486 sjacqu01
        N * sizeof(PodType) < max_size_in_bytes
807 2486 sjacqu01
        ? N * sizeof(PodType) : max_size_in_bytes));
808 2486 sjacqu01
}
809 2486 sjacqu01
810 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given POD array.
811 2486 sjacqu01
/**
812 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
813 2486 sjacqu01
 * @code const_buffers_1(
814 2486 sjacqu01
 *     static_cast<const void*>(data),
815 2486 sjacqu01
 *     N * sizeof(PodType)); @endcode
816 2486 sjacqu01
 */
817 2486 sjacqu01
template <typename PodType, std::size_t N>
818 2486 sjacqu01
inline const_buffers_1 buffer(const PodType (&data)[N])
819 2486 sjacqu01
{
820 2486 sjacqu01
  return const_buffers_1(const_buffer(data, N * sizeof(PodType)));
821 2486 sjacqu01
}
822 2486 sjacqu01
823 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given POD array.
824 2486 sjacqu01
/**
825 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
826 2486 sjacqu01
 * @code const_buffers_1(
827 2486 sjacqu01
 *     static_cast<const void*>(data),
828 2486 sjacqu01
 *     min(N * sizeof(PodType), max_size_in_bytes)); @endcode
829 2486 sjacqu01
 */
830 2486 sjacqu01
template <typename PodType, std::size_t N>
831 2486 sjacqu01
inline const_buffers_1 buffer(const PodType (&data)[N],
832 2486 sjacqu01
    std::size_t max_size_in_bytes)
833 2486 sjacqu01
{
834 2486 sjacqu01
  return const_buffers_1(
835 2486 sjacqu01
      const_buffer(data,
836 2486 sjacqu01
        N * sizeof(PodType) < max_size_in_bytes
837 2486 sjacqu01
        ? N * sizeof(PodType) : max_size_in_bytes));
838 2486 sjacqu01
}
839 2486 sjacqu01
840 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_ARRAY_BUFFER_WORKAROUND)
841 2486 sjacqu01
842 2486 sjacqu01
// Borland C++ and Sun Studio think the overloads:
843 2486 sjacqu01
//
844 2486 sjacqu01
//   unspecified buffer(boost::array<PodType, N>& array ...);
845 2486 sjacqu01
//
846 2486 sjacqu01
// and
847 2486 sjacqu01
//
848 2486 sjacqu01
//   unspecified buffer(boost::array<const PodType, N>& array ...);
849 2486 sjacqu01
//
850 2486 sjacqu01
// are ambiguous. This will be worked around by using a buffer_types traits
851 2486 sjacqu01
// class that contains typedefs for the appropriate buffer and container
852 2486 sjacqu01
// classes, based on whether PodType is const or non-const.
853 2486 sjacqu01
854 2486 sjacqu01
namespace detail {
855 2486 sjacqu01
856 2486 sjacqu01
template <bool IsConst>
857 2486 sjacqu01
struct buffer_types_base;
858 2486 sjacqu01
859 2486 sjacqu01
template <>
860 2486 sjacqu01
struct buffer_types_base<false>
861 2486 sjacqu01
{
862 2486 sjacqu01
  typedef mutable_buffer buffer_type;
863 2486 sjacqu01
  typedef mutable_buffers_1 container_type;
864 2486 sjacqu01
};
865 2486 sjacqu01
866 2486 sjacqu01
template <>
867 2486 sjacqu01
struct buffer_types_base<true>
868 2486 sjacqu01
{
869 2486 sjacqu01
  typedef const_buffer buffer_type;
870 2486 sjacqu01
  typedef const_buffers_1 container_type;
871 2486 sjacqu01
};
872 2486 sjacqu01
873 2486 sjacqu01
template <typename PodType>
874 2486 sjacqu01
struct buffer_types
875 2486 sjacqu01
  : public buffer_types_base<is_const<PodType>::value>
876 2486 sjacqu01
{
877 2486 sjacqu01
};
878 2486 sjacqu01
879 2486 sjacqu01
} // namespace detail
880 2486 sjacqu01
881 2486 sjacqu01
template <typename PodType, std::size_t N>
882 2486 sjacqu01
inline typename detail::buffer_types<PodType>::container_type
883 2486 sjacqu01
buffer(boost::array<PodType, N>& data)
884 2486 sjacqu01
{
885 2486 sjacqu01
  typedef typename boost::asio::detail::buffer_types<PodType>::buffer_type
886 2486 sjacqu01
    buffer_type;
887 2486 sjacqu01
  typedef typename boost::asio::detail::buffer_types<PodType>::container_type
888 2486 sjacqu01
    container_type;
889 2486 sjacqu01
  return container_type(
890 2486 sjacqu01
      buffer_type(data.c_array(), data.size() * sizeof(PodType)));
891 2486 sjacqu01
}
892 2486 sjacqu01
893 2486 sjacqu01
template <typename PodType, std::size_t N>
894 2486 sjacqu01
inline typename detail::buffer_types<PodType>::container_type
895 2486 sjacqu01
buffer(boost::array<PodType, N>& data, std::size_t max_size_in_bytes)
896 2486 sjacqu01
{
897 2486 sjacqu01
  typedef typename boost::asio::detail::buffer_types<PodType>::buffer_type
898 2486 sjacqu01
    buffer_type;
899 2486 sjacqu01
  typedef typename boost::asio::detail::buffer_types<PodType>::container_type
900 2486 sjacqu01
    container_type;
901 2486 sjacqu01
  return container_type(
902 2486 sjacqu01
      buffer_type(data.c_array(),
903 2486 sjacqu01
        data.size() * sizeof(PodType) < max_size_in_bytes
904 2486 sjacqu01
        ? data.size() * sizeof(PodType) : max_size_in_bytes));
905 2486 sjacqu01
}
906 2486 sjacqu01
907 2486 sjacqu01
#else // defined(BOOST_ASIO_ENABLE_ARRAY_BUFFER_WORKAROUND)
908 2486 sjacqu01
909 2486 sjacqu01
/// Create a new modifiable buffer that represents the given POD array.
910 2486 sjacqu01
/**
911 2486 sjacqu01
 * @returns A mutable_buffers_1 value equivalent to:
912 2486 sjacqu01
 * @code mutable_buffers_1(
913 2486 sjacqu01
 *     data.data(),
914 2486 sjacqu01
 *     data.size() * sizeof(PodType)); @endcode
915 2486 sjacqu01
 */
916 2486 sjacqu01
template <typename PodType, std::size_t N>
917 2486 sjacqu01
inline mutable_buffers_1 buffer(boost::array<PodType, N>& data)
918 2486 sjacqu01
{
919 2486 sjacqu01
  return mutable_buffers_1(
920 2486 sjacqu01
      mutable_buffer(data.c_array(), data.size() * sizeof(PodType)));
921 2486 sjacqu01
}
922 2486 sjacqu01
923 2486 sjacqu01
/// Create a new modifiable buffer that represents the given POD array.
924 2486 sjacqu01
/**
925 2486 sjacqu01
 * @returns A mutable_buffers_1 value equivalent to:
926 2486 sjacqu01
 * @code mutable_buffers_1(
927 2486 sjacqu01
 *     data.data(),
928 2486 sjacqu01
 *     min(data.size() * sizeof(PodType), max_size_in_bytes)); @endcode
929 2486 sjacqu01
 */
930 2486 sjacqu01
template <typename PodType, std::size_t N>
931 2486 sjacqu01
inline mutable_buffers_1 buffer(boost::array<PodType, N>& data,
932 2486 sjacqu01
    std::size_t max_size_in_bytes)
933 2486 sjacqu01
{
934 2486 sjacqu01
  return mutable_buffers_1(
935 2486 sjacqu01
      mutable_buffer(data.c_array(),
936 2486 sjacqu01
        data.size() * sizeof(PodType) < max_size_in_bytes
937 2486 sjacqu01
        ? data.size() * sizeof(PodType) : max_size_in_bytes));
938 2486 sjacqu01
}
939 2486 sjacqu01
940 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given POD array.
941 2486 sjacqu01
/**
942 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
943 2486 sjacqu01
 * @code const_buffers_1(
944 2486 sjacqu01
 *     data.data(),
945 2486 sjacqu01
 *     data.size() * sizeof(PodType)); @endcode
946 2486 sjacqu01
 */
947 2486 sjacqu01
template <typename PodType, std::size_t N>
948 2486 sjacqu01
inline const_buffers_1 buffer(boost::array<const PodType, N>& data)
949 2486 sjacqu01
{
950 2486 sjacqu01
  return const_buffers_1(
951 2486 sjacqu01
      const_buffer(data.data(), data.size() * sizeof(PodType)));
952 2486 sjacqu01
}
953 2486 sjacqu01
954 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given POD array.
955 2486 sjacqu01
/**
956 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
957 2486 sjacqu01
 * @code const_buffers_1(
958 2486 sjacqu01
 *     data.data(),
959 2486 sjacqu01
 *     min(data.size() * sizeof(PodType), max_size_in_bytes)); @endcode
960 2486 sjacqu01
 */
961 2486 sjacqu01
template <typename PodType, std::size_t N>
962 2486 sjacqu01
inline const_buffers_1 buffer(boost::array<const PodType, N>& data,
963 2486 sjacqu01
    std::size_t max_size_in_bytes)
964 2486 sjacqu01
{
965 2486 sjacqu01
  return const_buffers_1(
966 2486 sjacqu01
      const_buffer(data.data(),
967 2486 sjacqu01
        data.size() * sizeof(PodType) < max_size_in_bytes
968 2486 sjacqu01
        ? data.size() * sizeof(PodType) : max_size_in_bytes));
969 2486 sjacqu01
}
970 2486 sjacqu01
971 2486 sjacqu01
#endif // defined(BOOST_ASIO_ENABLE_ARRAY_BUFFER_WORKAROUND)
972 2486 sjacqu01
973 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given POD array.
974 2486 sjacqu01
/**
975 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
976 2486 sjacqu01
 * @code const_buffers_1(
977 2486 sjacqu01
 *     data.data(),
978 2486 sjacqu01
 *     data.size() * sizeof(PodType)); @endcode
979 2486 sjacqu01
 */
980 2486 sjacqu01
template <typename PodType, std::size_t N>
981 2486 sjacqu01
inline const_buffers_1 buffer(const boost::array<PodType, N>& data)
982 2486 sjacqu01
{
983 2486 sjacqu01
  return const_buffers_1(
984 2486 sjacqu01
      const_buffer(data.data(), data.size() * sizeof(PodType)));
985 2486 sjacqu01
}
986 2486 sjacqu01
987 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given POD array.
988 2486 sjacqu01
/**
989 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
990 2486 sjacqu01
 * @code const_buffers_1(
991 2486 sjacqu01
 *     data.data(),
992 2486 sjacqu01
 *     min(data.size() * sizeof(PodType), max_size_in_bytes)); @endcode
993 2486 sjacqu01
 */
994 2486 sjacqu01
template <typename PodType, std::size_t N>
995 2486 sjacqu01
inline const_buffers_1 buffer(const boost::array<PodType, N>& data,
996 2486 sjacqu01
    std::size_t max_size_in_bytes)
997 2486 sjacqu01
{
998 2486 sjacqu01
  return const_buffers_1(
999 2486 sjacqu01
      const_buffer(data.data(),
1000 2486 sjacqu01
        data.size() * sizeof(PodType) < max_size_in_bytes
1001 2486 sjacqu01
        ? data.size() * sizeof(PodType) : max_size_in_bytes));
1002 2486 sjacqu01
}
1003 2486 sjacqu01
1004 2486 sjacqu01
#if defined(BOOST_ASIO_HAS_STD_ARRAY) || defined(GENERATING_DOCUMENTATION)
1005 2486 sjacqu01
1006 2486 sjacqu01
/// Create a new modifiable buffer that represents the given POD array.
1007 2486 sjacqu01
/**
1008 2486 sjacqu01
 * @returns A mutable_buffers_1 value equivalent to:
1009 2486 sjacqu01
 * @code mutable_buffers_1(
1010 2486 sjacqu01
 *     data.data(),
1011 2486 sjacqu01
 *     data.size() * sizeof(PodType)); @endcode
1012 2486 sjacqu01
 */
1013 2486 sjacqu01
template <typename PodType, std::size_t N>
1014 2486 sjacqu01
inline mutable_buffers_1 buffer(std::array<PodType, N>& data)
1015 2486 sjacqu01
{
1016 2486 sjacqu01
  return mutable_buffers_1(
1017 2486 sjacqu01
      mutable_buffer(data.data(), data.size() * sizeof(PodType)));
1018 2486 sjacqu01
}
1019 2486 sjacqu01
1020 2486 sjacqu01
/// Create a new modifiable buffer that represents the given POD array.
1021 2486 sjacqu01
/**
1022 2486 sjacqu01
 * @returns A mutable_buffers_1 value equivalent to:
1023 2486 sjacqu01
 * @code mutable_buffers_1(
1024 2486 sjacqu01
 *     data.data(),
1025 2486 sjacqu01
 *     min(data.size() * sizeof(PodType), max_size_in_bytes)); @endcode
1026 2486 sjacqu01
 */
1027 2486 sjacqu01
template <typename PodType, std::size_t N>
1028 2486 sjacqu01
inline mutable_buffers_1 buffer(std::array<PodType, N>& data,
1029 2486 sjacqu01
    std::size_t max_size_in_bytes)
1030 2486 sjacqu01
{
1031 2486 sjacqu01
  return mutable_buffers_1(
1032 2486 sjacqu01
      mutable_buffer(data.data(),
1033 2486 sjacqu01
        data.size() * sizeof(PodType) < max_size_in_bytes
1034 2486 sjacqu01
        ? data.size() * sizeof(PodType) : max_size_in_bytes));
1035 2486 sjacqu01
}
1036 2486 sjacqu01
1037 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given POD array.
1038 2486 sjacqu01
/**
1039 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
1040 2486 sjacqu01
 * @code const_buffers_1(
1041 2486 sjacqu01
 *     data.data(),
1042 2486 sjacqu01
 *     data.size() * sizeof(PodType)); @endcode
1043 2486 sjacqu01
 */
1044 2486 sjacqu01
template <typename PodType, std::size_t N>
1045 2486 sjacqu01
inline const_buffers_1 buffer(std::array<const PodType, N>& data)
1046 2486 sjacqu01
{
1047 2486 sjacqu01
  return const_buffers_1(
1048 2486 sjacqu01
      const_buffer(data.data(), data.size() * sizeof(PodType)));
1049 2486 sjacqu01
}
1050 2486 sjacqu01
1051 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given POD array.
1052 2486 sjacqu01
/**
1053 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
1054 2486 sjacqu01
 * @code const_buffers_1(
1055 2486 sjacqu01
 *     data.data(),
1056 2486 sjacqu01
 *     min(data.size() * sizeof(PodType), max_size_in_bytes)); @endcode
1057 2486 sjacqu01
 */
1058 2486 sjacqu01
template <typename PodType, std::size_t N>
1059 2486 sjacqu01
inline const_buffers_1 buffer(std::array<const PodType, N>& data,
1060 2486 sjacqu01
    std::size_t max_size_in_bytes)
1061 2486 sjacqu01
{
1062 2486 sjacqu01
  return const_buffers_1(
1063 2486 sjacqu01
      const_buffer(data.data(),
1064 2486 sjacqu01
        data.size() * sizeof(PodType) < max_size_in_bytes
1065 2486 sjacqu01
        ? data.size() * sizeof(PodType) : max_size_in_bytes));
1066 2486 sjacqu01
}
1067 2486 sjacqu01
1068 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given POD array.
1069 2486 sjacqu01
/**
1070 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
1071 2486 sjacqu01
 * @code const_buffers_1(
1072 2486 sjacqu01
 *     data.data(),
1073 2486 sjacqu01
 *     data.size() * sizeof(PodType)); @endcode
1074 2486 sjacqu01
 */
1075 2486 sjacqu01
template <typename PodType, std::size_t N>
1076 2486 sjacqu01
inline const_buffers_1 buffer(const std::array<PodType, N>& data)
1077 2486 sjacqu01
{
1078 2486 sjacqu01
  return const_buffers_1(
1079 2486 sjacqu01
      const_buffer(data.data(), data.size() * sizeof(PodType)));
1080 2486 sjacqu01
}
1081 2486 sjacqu01
1082 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given POD array.
1083 2486 sjacqu01
/**
1084 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
1085 2486 sjacqu01
 * @code const_buffers_1(
1086 2486 sjacqu01
 *     data.data(),
1087 2486 sjacqu01
 *     min(data.size() * sizeof(PodType), max_size_in_bytes)); @endcode
1088 2486 sjacqu01
 */
1089 2486 sjacqu01
template <typename PodType, std::size_t N>
1090 2486 sjacqu01
inline const_buffers_1 buffer(const std::array<PodType, N>& data,
1091 2486 sjacqu01
    std::size_t max_size_in_bytes)
1092 2486 sjacqu01
{
1093 2486 sjacqu01
  return const_buffers_1(
1094 2486 sjacqu01
      const_buffer(data.data(),
1095 2486 sjacqu01
        data.size() * sizeof(PodType) < max_size_in_bytes
1096 2486 sjacqu01
        ? data.size() * sizeof(PodType) : max_size_in_bytes));
1097 2486 sjacqu01
}
1098 2486 sjacqu01
1099 2486 sjacqu01
#endif // defined(BOOST_ASIO_HAS_STD_ARRAY) || defined(GENERATING_DOCUMENTATION)
1100 2486 sjacqu01
1101 2486 sjacqu01
/// Create a new modifiable buffer that represents the given POD vector.
1102 2486 sjacqu01
/**
1103 2486 sjacqu01
 * @returns A mutable_buffers_1 value equivalent to:
1104 2486 sjacqu01
 * @code mutable_buffers_1(
1105 2486 sjacqu01
 *     data.size() ? &data[0] : 0,
1106 2486 sjacqu01
 *     data.size() * sizeof(PodType)); @endcode
1107 2486 sjacqu01
 *
1108 2486 sjacqu01
 * @note The buffer is invalidated by any vector operation that would also
1109 2486 sjacqu01
 * invalidate iterators.
1110 2486 sjacqu01
 */
1111 2486 sjacqu01
template <typename PodType, typename Allocator>
1112 2486 sjacqu01
inline mutable_buffers_1 buffer(std::vector<PodType, Allocator>& data)
1113 2486 sjacqu01
{
1114 2486 sjacqu01
  return mutable_buffers_1(
1115 2486 sjacqu01
      mutable_buffer(data.size() ? &data[0] : 0, data.size() * sizeof(PodType)
1116 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
1117 2486 sjacqu01
        , detail::buffer_debug_check<
1118 2486 sjacqu01
            typename std::vector<PodType, Allocator>::iterator
1119 2486 sjacqu01
          >(data.begin())
1120 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
1121 2486 sjacqu01
        ));
1122 2486 sjacqu01
}
1123 2486 sjacqu01
1124 2486 sjacqu01
/// Create a new modifiable buffer that represents the given POD vector.
1125 2486 sjacqu01
/**
1126 2486 sjacqu01
 * @returns A mutable_buffers_1 value equivalent to:
1127 2486 sjacqu01
 * @code mutable_buffers_1(
1128 2486 sjacqu01
 *     data.size() ? &data[0] : 0,
1129 2486 sjacqu01
 *     min(data.size() * sizeof(PodType), max_size_in_bytes)); @endcode
1130 2486 sjacqu01
 *
1131 2486 sjacqu01
 * @note The buffer is invalidated by any vector operation that would also
1132 2486 sjacqu01
 * invalidate iterators.
1133 2486 sjacqu01
 */
1134 2486 sjacqu01
template <typename PodType, typename Allocator>
1135 2486 sjacqu01
inline mutable_buffers_1 buffer(std::vector<PodType, Allocator>& data,
1136 2486 sjacqu01
    std::size_t max_size_in_bytes)
1137 2486 sjacqu01
{
1138 2486 sjacqu01
  return mutable_buffers_1(
1139 2486 sjacqu01
      mutable_buffer(data.size() ? &data[0] : 0,
1140 2486 sjacqu01
        data.size() * sizeof(PodType) < max_size_in_bytes
1141 2486 sjacqu01
        ? data.size() * sizeof(PodType) : max_size_in_bytes
1142 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
1143 2486 sjacqu01
        , detail::buffer_debug_check<
1144 2486 sjacqu01
            typename std::vector<PodType, Allocator>::iterator
1145 2486 sjacqu01
          >(data.begin())
1146 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
1147 2486 sjacqu01
        ));
1148 2486 sjacqu01
}
1149 2486 sjacqu01
1150 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given POD vector.
1151 2486 sjacqu01
/**
1152 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
1153 2486 sjacqu01
 * @code const_buffers_1(
1154 2486 sjacqu01
 *     data.size() ? &data[0] : 0,
1155 2486 sjacqu01
 *     data.size() * sizeof(PodType)); @endcode
1156 2486 sjacqu01
 *
1157 2486 sjacqu01
 * @note The buffer is invalidated by any vector operation that would also
1158 2486 sjacqu01
 * invalidate iterators.
1159 2486 sjacqu01
 */
1160 2486 sjacqu01
template <typename PodType, typename Allocator>
1161 2486 sjacqu01
inline const_buffers_1 buffer(
1162 2486 sjacqu01
    const std::vector<PodType, Allocator>& data)
1163 2486 sjacqu01
{
1164 2486 sjacqu01
  return const_buffers_1(
1165 2486 sjacqu01
      const_buffer(data.size() ? &data[0] : 0, data.size() * sizeof(PodType)
1166 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
1167 2486 sjacqu01
        , detail::buffer_debug_check<
1168 2486 sjacqu01
            typename std::vector<PodType, Allocator>::const_iterator
1169 2486 sjacqu01
          >(data.begin())
1170 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
1171 2486 sjacqu01
        ));
1172 2486 sjacqu01
}
1173 2486 sjacqu01
1174 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given POD vector.
1175 2486 sjacqu01
/**
1176 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
1177 2486 sjacqu01
 * @code const_buffers_1(
1178 2486 sjacqu01
 *     data.size() ? &data[0] : 0,
1179 2486 sjacqu01
 *     min(data.size() * sizeof(PodType), max_size_in_bytes)); @endcode
1180 2486 sjacqu01
 *
1181 2486 sjacqu01
 * @note The buffer is invalidated by any vector operation that would also
1182 2486 sjacqu01
 * invalidate iterators.
1183 2486 sjacqu01
 */
1184 2486 sjacqu01
template <typename PodType, typename Allocator>
1185 2486 sjacqu01
inline const_buffers_1 buffer(
1186 2486 sjacqu01
    const std::vector<PodType, Allocator>& data, std::size_t max_size_in_bytes)
1187 2486 sjacqu01
{
1188 2486 sjacqu01
  return const_buffers_1(
1189 2486 sjacqu01
      const_buffer(data.size() ? &data[0] : 0,
1190 2486 sjacqu01
        data.size() * sizeof(PodType) < max_size_in_bytes
1191 2486 sjacqu01
        ? data.size() * sizeof(PodType) : max_size_in_bytes
1192 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
1193 2486 sjacqu01
        , detail::buffer_debug_check<
1194 2486 sjacqu01
            typename std::vector<PodType, Allocator>::const_iterator
1195 2486 sjacqu01
          >(data.begin())
1196 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
1197 2486 sjacqu01
        ));
1198 2486 sjacqu01
}
1199 2486 sjacqu01
1200 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given string.
1201 2486 sjacqu01
/**
1202 2486 sjacqu01
 * @returns <tt>const_buffers_1(data.data(), data.size() * sizeof(Elem))</tt>.
1203 2486 sjacqu01
 *
1204 2486 sjacqu01
 * @note The buffer is invalidated by any non-const operation called on the
1205 2486 sjacqu01
 * given string object.
1206 2486 sjacqu01
 */
1207 2486 sjacqu01
template <typename Elem, typename Traits, typename Allocator>
1208 2486 sjacqu01
inline const_buffers_1 buffer(
1209 2486 sjacqu01
    const std::basic_string<Elem, Traits, Allocator>& data)
1210 2486 sjacqu01
{
1211 2486 sjacqu01
  return const_buffers_1(const_buffer(data.data(), data.size() * sizeof(Elem)
1212 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
1213 2486 sjacqu01
        , detail::buffer_debug_check<
1214 2486 sjacqu01
            typename std::basic_string<Elem, Traits, Allocator>::const_iterator
1215 2486 sjacqu01
          >(data.begin())
1216 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
1217 2486 sjacqu01
        ));
1218 2486 sjacqu01
}
1219 2486 sjacqu01
1220 2486 sjacqu01
/// Create a new non-modifiable buffer that represents the given string.
1221 2486 sjacqu01
/**
1222 2486 sjacqu01
 * @returns A const_buffers_1 value equivalent to:
1223 2486 sjacqu01
 * @code const_buffers_1(
1224 2486 sjacqu01
 *     data.data(),
1225 2486 sjacqu01
 *     min(data.size() * sizeof(Elem), max_size_in_bytes)); @endcode
1226 2486 sjacqu01
 *
1227 2486 sjacqu01
 * @note The buffer is invalidated by any non-const operation called on the
1228 2486 sjacqu01
 * given string object.
1229 2486 sjacqu01
 */
1230 2486 sjacqu01
template <typename Elem, typename Traits, typename Allocator>
1231 2486 sjacqu01
inline const_buffers_1 buffer(
1232 2486 sjacqu01
    const std::basic_string<Elem, Traits, Allocator>& data,
1233 2486 sjacqu01
    std::size_t max_size_in_bytes)
1234 2486 sjacqu01
{
1235 2486 sjacqu01
  return const_buffers_1(
1236 2486 sjacqu01
      const_buffer(data.data(),
1237 2486 sjacqu01
        data.size() * sizeof(Elem) < max_size_in_bytes
1238 2486 sjacqu01
        ? data.size() * sizeof(Elem) : max_size_in_bytes
1239 2486 sjacqu01
#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
1240 2486 sjacqu01
        , detail::buffer_debug_check<
1241 2486 sjacqu01
            typename std::basic_string<Elem, Traits, Allocator>::const_iterator
1242 2486 sjacqu01
          >(data.begin())
1243 2486 sjacqu01
#endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING
1244 2486 sjacqu01
        ));
1245 2486 sjacqu01
}
1246 2486 sjacqu01
1247 2486 sjacqu01
/*@}*/
1248 2486 sjacqu01
1249 2486 sjacqu01
/** @defgroup buffer_copy boost::asio::buffer_copy
1250 2486 sjacqu01
 *
1251 2486 sjacqu01
 * @brief The boost::asio::buffer_copy function is used to copy bytes from a
1252 2486 sjacqu01
 * source buffer (or buffer sequence) to a target buffer (or buffer sequence).
1253 2486 sjacqu01
 *
1254 2486 sjacqu01
 * The @c buffer_copy function is available in two forms:
1255 2486 sjacqu01
 *
1256 2486 sjacqu01
 * @li A 2-argument form: @c buffer_copy(target, source)
1257 2486 sjacqu01
 *
1258 2486 sjacqu01
 * @li A 3-argument form: @c buffer_copy(target, source, max_bytes_to_copy)
1259 2486 sjacqu01

1260 2486 sjacqu01
 * Both forms return the number of bytes actually copied. The number of bytes
1261 2486 sjacqu01
 * copied is the lesser of:
1262 2486 sjacqu01
 *
1263 2486 sjacqu01
 * @li @c buffer_size(target)
1264 2486 sjacqu01
 *
1265 2486 sjacqu01
 * @li @c buffer_size(source)
1266 2486 sjacqu01
 *
1267 2486 sjacqu01
 * @li @c If specified, @c max_bytes_to_copy.
1268 2486 sjacqu01
 *
1269 2486 sjacqu01
 * This prevents buffer overflow, regardless of the buffer sizes used in the
1270 2486 sjacqu01
 * copy operation.
1271 2486 sjacqu01
 *
1272 2486 sjacqu01
 * Note that @ref buffer_copy is implemented in terms of @c memcpy, and
1273 2486 sjacqu01
 * consequently it cannot be used to copy between overlapping memory regions.
1274 2486 sjacqu01
 */
1275 2486 sjacqu01
/*@{*/
1276 2486 sjacqu01
1277 2486 sjacqu01
/// Copies bytes from a source buffer to a target buffer.
1278 2486 sjacqu01
/**
1279 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1280 2486 sjacqu01
 * the bytes will be copied.
1281 2486 sjacqu01
 *
1282 2486 sjacqu01
 * @param source A non-modifiable buffer representing the memory region from
1283 2486 sjacqu01
 * which the bytes will be copied.
1284 2486 sjacqu01
 *
1285 2486 sjacqu01
 * @returns The number of bytes copied.
1286 2486 sjacqu01
 *
1287 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1288 2486 sjacqu01
 *
1289 2486 sjacqu01
 * @li @c buffer_size(target)
1290 2486 sjacqu01
 *
1291 2486 sjacqu01
 * @li @c buffer_size(source)
1292 2486 sjacqu01
 *
1293 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1294 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1295 2486 sjacqu01
 */
1296 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffer& target,
1297 2486 sjacqu01
    const const_buffer& source)
1298 2486 sjacqu01
{
1299 2486 sjacqu01
  using namespace std; // For memcpy.
1300 2486 sjacqu01
  std::size_t target_size = buffer_size(target);
1301 2486 sjacqu01
  std::size_t source_size = buffer_size(source);
1302 2486 sjacqu01
  std::size_t n = target_size < source_size ? target_size : source_size;
1303 2486 sjacqu01
  memcpy(buffer_cast<void*>(target), buffer_cast<const void*>(source), n);
1304 2486 sjacqu01
  return n;
1305 2486 sjacqu01
}
1306 2486 sjacqu01
1307 2486 sjacqu01
/// Copies bytes from a source buffer to a target buffer.
1308 2486 sjacqu01
/**
1309 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1310 2486 sjacqu01
 * the bytes will be copied.
1311 2486 sjacqu01
 *
1312 2486 sjacqu01
 * @param source A non-modifiable buffer representing the memory region from
1313 2486 sjacqu01
 * which the bytes will be copied.
1314 2486 sjacqu01
 *
1315 2486 sjacqu01
 * @returns The number of bytes copied.
1316 2486 sjacqu01
 *
1317 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1318 2486 sjacqu01
 *
1319 2486 sjacqu01
 * @li @c buffer_size(target)
1320 2486 sjacqu01
 *
1321 2486 sjacqu01
 * @li @c buffer_size(source)
1322 2486 sjacqu01
 *
1323 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1324 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1325 2486 sjacqu01
 */
1326 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffer& target,
1327 2486 sjacqu01
    const const_buffers_1& source)
1328 2486 sjacqu01
{
1329 2486 sjacqu01
  return buffer_copy(target, static_cast<const const_buffer&>(source));
1330 2486 sjacqu01
}
1331 2486 sjacqu01
1332 2486 sjacqu01
/// Copies bytes from a source buffer to a target buffer.
1333 2486 sjacqu01
/**
1334 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1335 2486 sjacqu01
 * the bytes will be copied.
1336 2486 sjacqu01
 *
1337 2486 sjacqu01
 * @param source A modifiable buffer representing the memory region from which
1338 2486 sjacqu01
 * the bytes will be copied. The contents of the source buffer will not be
1339 2486 sjacqu01
 * modified.
1340 2486 sjacqu01
 *
1341 2486 sjacqu01
 * @returns The number of bytes copied.
1342 2486 sjacqu01
 *
1343 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1344 2486 sjacqu01
 *
1345 2486 sjacqu01
 * @li @c buffer_size(target)
1346 2486 sjacqu01
 *
1347 2486 sjacqu01
 * @li @c buffer_size(source)
1348 2486 sjacqu01
 *
1349 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1350 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1351 2486 sjacqu01
 */
1352 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffer& target,
1353 2486 sjacqu01
    const mutable_buffer& source)
1354 2486 sjacqu01
{
1355 2486 sjacqu01
  return buffer_copy(target, const_buffer(source));
1356 2486 sjacqu01
}
1357 2486 sjacqu01
1358 2486 sjacqu01
/// Copies bytes from a source buffer to a target buffer.
1359 2486 sjacqu01
/**
1360 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1361 2486 sjacqu01
 * the bytes will be copied.
1362 2486 sjacqu01
 *
1363 2486 sjacqu01
 * @param source A modifiable buffer representing the memory region from which
1364 2486 sjacqu01
 * the bytes will be copied. The contents of the source buffer will not be
1365 2486 sjacqu01
 * modified.
1366 2486 sjacqu01
 *
1367 2486 sjacqu01
 * @returns The number of bytes copied.
1368 2486 sjacqu01
 *
1369 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1370 2486 sjacqu01
 *
1371 2486 sjacqu01
 * @li @c buffer_size(target)
1372 2486 sjacqu01
 *
1373 2486 sjacqu01
 * @li @c buffer_size(source)
1374 2486 sjacqu01
 *
1375 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1376 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1377 2486 sjacqu01
 */
1378 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffer& target,
1379 2486 sjacqu01
    const mutable_buffers_1& source)
1380 2486 sjacqu01
{
1381 2486 sjacqu01
  return buffer_copy(target, const_buffer(source));
1382 2486 sjacqu01
}
1383 2486 sjacqu01
1384 2486 sjacqu01
/// Copies bytes from a source buffer sequence to a target buffer.
1385 2486 sjacqu01
/**
1386 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1387 2486 sjacqu01
 * the bytes will be copied.
1388 2486 sjacqu01
 *
1389 2486 sjacqu01
 * @param source A non-modifiable buffer sequence representing the memory
1390 2486 sjacqu01
 * regions from which the bytes will be copied.
1391 2486 sjacqu01
 *
1392 2486 sjacqu01
 * @returns The number of bytes copied.
1393 2486 sjacqu01
 *
1394 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1395 2486 sjacqu01
 *
1396 2486 sjacqu01
 * @li @c buffer_size(target)
1397 2486 sjacqu01
 *
1398 2486 sjacqu01
 * @li @c buffer_size(source)
1399 2486 sjacqu01
 *
1400 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1401 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1402 2486 sjacqu01
 */
1403 2486 sjacqu01
template <typename ConstBufferSequence>
1404 2486 sjacqu01
std::size_t buffer_copy(const mutable_buffer& target,
1405 2486 sjacqu01
    const ConstBufferSequence& source)
1406 2486 sjacqu01
{
1407 2486 sjacqu01
  std::size_t total_bytes_copied = 0;
1408 2486 sjacqu01
1409 2486 sjacqu01
  typename ConstBufferSequence::const_iterator source_iter = source.begin();
1410 2486 sjacqu01
  typename ConstBufferSequence::const_iterator source_end = source.end();
1411 2486 sjacqu01
1412 2486 sjacqu01
  for (mutable_buffer target_buffer(target);
1413 2486 sjacqu01
      buffer_size(target_buffer) && source_iter != source_end; ++source_iter)
1414 2486 sjacqu01
  {
1415 2486 sjacqu01
    const_buffer source_buffer(*source_iter);
1416 2486 sjacqu01
    std::size_t bytes_copied = buffer_copy(target_buffer, source_buffer);
1417 2486 sjacqu01
    total_bytes_copied += bytes_copied;
1418 2486 sjacqu01
    target_buffer = target_buffer + bytes_copied;
1419 2486 sjacqu01
  }
1420 2486 sjacqu01
1421 2486 sjacqu01
  return total_bytes_copied;
1422 2486 sjacqu01
}
1423 2486 sjacqu01
1424 2486 sjacqu01
/// Copies bytes from a source buffer to a target buffer.
1425 2486 sjacqu01
/**
1426 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1427 2486 sjacqu01
 * the bytes will be copied.
1428 2486 sjacqu01
 *
1429 2486 sjacqu01
 * @param source A non-modifiable buffer representing the memory region from
1430 2486 sjacqu01
 * which the bytes will be copied.
1431 2486 sjacqu01
 *
1432 2486 sjacqu01
 * @returns The number of bytes copied.
1433 2486 sjacqu01
 *
1434 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1435 2486 sjacqu01
 *
1436 2486 sjacqu01
 * @li @c buffer_size(target)
1437 2486 sjacqu01
 *
1438 2486 sjacqu01
 * @li @c buffer_size(source)
1439 2486 sjacqu01
 *
1440 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1441 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1442 2486 sjacqu01
 */
1443 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffers_1& target,
1444 2486 sjacqu01
    const const_buffer& source)
1445 2486 sjacqu01
{
1446 2486 sjacqu01
  return buffer_copy(static_cast<const mutable_buffer&>(target), source);
1447 2486 sjacqu01
}
1448 2486 sjacqu01
1449 2486 sjacqu01
/// Copies bytes from a source buffer to a target buffer.
1450 2486 sjacqu01
/**
1451 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1452 2486 sjacqu01
 * the bytes will be copied.
1453 2486 sjacqu01
 *
1454 2486 sjacqu01
 * @param source A non-modifiable buffer representing the memory region from
1455 2486 sjacqu01
 * which the bytes will be copied.
1456 2486 sjacqu01
 *
1457 2486 sjacqu01
 * @returns The number of bytes copied.
1458 2486 sjacqu01
 *
1459 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1460 2486 sjacqu01
 *
1461 2486 sjacqu01
 * @li @c buffer_size(target)
1462 2486 sjacqu01
 *
1463 2486 sjacqu01
 * @li @c buffer_size(source)
1464 2486 sjacqu01
 *
1465 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1466 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1467 2486 sjacqu01
 */
1468 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffers_1& target,
1469 2486 sjacqu01
    const const_buffers_1& source)
1470 2486 sjacqu01
{
1471 2486 sjacqu01
  return buffer_copy(static_cast<const mutable_buffer&>(target),
1472 2486 sjacqu01
      static_cast<const const_buffer&>(source));
1473 2486 sjacqu01
}
1474 2486 sjacqu01
1475 2486 sjacqu01
/// Copies bytes from a source buffer to a target buffer.
1476 2486 sjacqu01
/**
1477 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1478 2486 sjacqu01
 * the bytes will be copied.
1479 2486 sjacqu01
 *
1480 2486 sjacqu01
 * @param source A modifiable buffer representing the memory region from which
1481 2486 sjacqu01
 * the bytes will be copied. The contents of the source buffer will not be
1482 2486 sjacqu01
 * modified.
1483 2486 sjacqu01
 *
1484 2486 sjacqu01
 * @returns The number of bytes copied.
1485 2486 sjacqu01
 *
1486 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1487 2486 sjacqu01
 *
1488 2486 sjacqu01
 * @li @c buffer_size(target)
1489 2486 sjacqu01
 *
1490 2486 sjacqu01
 * @li @c buffer_size(source)
1491 2486 sjacqu01
 *
1492 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1493 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1494 2486 sjacqu01
 */
1495 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffers_1& target,
1496 2486 sjacqu01
    const mutable_buffer& source)
1497 2486 sjacqu01
{
1498 2486 sjacqu01
  return buffer_copy(static_cast<const mutable_buffer&>(target),
1499 2486 sjacqu01
      const_buffer(source));
1500 2486 sjacqu01
}
1501 2486 sjacqu01
1502 2486 sjacqu01
/// Copies bytes from a source buffer to a target buffer.
1503 2486 sjacqu01
/**
1504 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1505 2486 sjacqu01
 * the bytes will be copied.
1506 2486 sjacqu01
 *
1507 2486 sjacqu01
 * @param source A modifiable buffer representing the memory region from which
1508 2486 sjacqu01
 * the bytes will be copied. The contents of the source buffer will not be
1509 2486 sjacqu01
 * modified.
1510 2486 sjacqu01
 *
1511 2486 sjacqu01
 * @returns The number of bytes copied.
1512 2486 sjacqu01
 *
1513 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1514 2486 sjacqu01
 *
1515 2486 sjacqu01
 * @li @c buffer_size(target)
1516 2486 sjacqu01
 *
1517 2486 sjacqu01
 * @li @c buffer_size(source)
1518 2486 sjacqu01
 *
1519 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1520 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1521 2486 sjacqu01
 */
1522 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffers_1& target,
1523 2486 sjacqu01
    const mutable_buffers_1& source)
1524 2486 sjacqu01
{
1525 2486 sjacqu01
  return buffer_copy(static_cast<const mutable_buffer&>(target),
1526 2486 sjacqu01
      const_buffer(source));
1527 2486 sjacqu01
}
1528 2486 sjacqu01
1529 2486 sjacqu01
/// Copies bytes from a source buffer sequence to a target buffer.
1530 2486 sjacqu01
/**
1531 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1532 2486 sjacqu01
 * the bytes will be copied.
1533 2486 sjacqu01
 *
1534 2486 sjacqu01
 * @param source A non-modifiable buffer sequence representing the memory
1535 2486 sjacqu01
 * regions from which the bytes will be copied.
1536 2486 sjacqu01
 *
1537 2486 sjacqu01
 * @returns The number of bytes copied.
1538 2486 sjacqu01
 *
1539 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1540 2486 sjacqu01
 *
1541 2486 sjacqu01
 * @li @c buffer_size(target)
1542 2486 sjacqu01
 *
1543 2486 sjacqu01
 * @li @c buffer_size(source)
1544 2486 sjacqu01
 *
1545 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1546 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1547 2486 sjacqu01
 */
1548 2486 sjacqu01
template <typename ConstBufferSequence>
1549 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffers_1& target,
1550 2486 sjacqu01
    const ConstBufferSequence& source)
1551 2486 sjacqu01
{
1552 2486 sjacqu01
  return buffer_copy(static_cast<const mutable_buffer&>(target), source);
1553 2486 sjacqu01
}
1554 2486 sjacqu01
1555 2486 sjacqu01
/// Copies bytes from a source buffer to a target buffer sequence.
1556 2486 sjacqu01
/**
1557 2486 sjacqu01
 * @param target A modifiable buffer sequence representing the memory regions to
1558 2486 sjacqu01
 * which the bytes will be copied.
1559 2486 sjacqu01
 *
1560 2486 sjacqu01
 * @param source A non-modifiable buffer representing the memory region from
1561 2486 sjacqu01
 * which the bytes will be copied.
1562 2486 sjacqu01
 *
1563 2486 sjacqu01
 * @returns The number of bytes copied.
1564 2486 sjacqu01
 *
1565 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1566 2486 sjacqu01
 *
1567 2486 sjacqu01
 * @li @c buffer_size(target)
1568 2486 sjacqu01
 *
1569 2486 sjacqu01
 * @li @c buffer_size(source)
1570 2486 sjacqu01
 *
1571 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1572 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1573 2486 sjacqu01
 */
1574 2486 sjacqu01
template <typename MutableBufferSequence>
1575 2486 sjacqu01
std::size_t buffer_copy(const MutableBufferSequence& target,
1576 2486 sjacqu01
    const const_buffer& source)
1577 2486 sjacqu01
{
1578 2486 sjacqu01
  std::size_t total_bytes_copied = 0;
1579 2486 sjacqu01
1580 2486 sjacqu01
  typename MutableBufferSequence::const_iterator target_iter = target.begin();
1581 2486 sjacqu01
  typename MutableBufferSequence::const_iterator target_end = target.end();
1582 2486 sjacqu01
1583 2486 sjacqu01
  for (const_buffer source_buffer(source);
1584 2486 sjacqu01
      buffer_size(source_buffer) && target_iter != target_end; ++target_iter)
1585 2486 sjacqu01
  {
1586 2486 sjacqu01
    mutable_buffer target_buffer(*target_iter);
1587 2486 sjacqu01
    std::size_t bytes_copied = buffer_copy(target_buffer, source_buffer);
1588 2486 sjacqu01
    total_bytes_copied += bytes_copied;
1589 2486 sjacqu01
    source_buffer = source_buffer + bytes_copied;
1590 2486 sjacqu01
  }
1591 2486 sjacqu01
1592 2486 sjacqu01
  return total_bytes_copied;
1593 2486 sjacqu01
}
1594 2486 sjacqu01
1595 2486 sjacqu01
/// Copies bytes from a source buffer to a target buffer sequence.
1596 2486 sjacqu01
/**
1597 2486 sjacqu01
 * @param target A modifiable buffer sequence representing the memory regions to
1598 2486 sjacqu01
 * which the bytes will be copied.
1599 2486 sjacqu01
 *
1600 2486 sjacqu01
 * @param source A non-modifiable buffer representing the memory region from
1601 2486 sjacqu01
 * which the bytes will be copied.
1602 2486 sjacqu01
 *
1603 2486 sjacqu01
 * @returns The number of bytes copied.
1604 2486 sjacqu01
 *
1605 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1606 2486 sjacqu01
 *
1607 2486 sjacqu01
 * @li @c buffer_size(target)
1608 2486 sjacqu01
 *
1609 2486 sjacqu01
 * @li @c buffer_size(source)
1610 2486 sjacqu01
 *
1611 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1612 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1613 2486 sjacqu01
 */
1614 2486 sjacqu01
template <typename MutableBufferSequence>
1615 2486 sjacqu01
inline std::size_t buffer_copy(const MutableBufferSequence& target,
1616 2486 sjacqu01
    const const_buffers_1& source)
1617 2486 sjacqu01
{
1618 2486 sjacqu01
  return buffer_copy(target, static_cast<const const_buffer&>(source));
1619 2486 sjacqu01
}
1620 2486 sjacqu01
1621 2486 sjacqu01
/// Copies bytes from a source buffer to a target buffer sequence.
1622 2486 sjacqu01
/**
1623 2486 sjacqu01
 * @param target A modifiable buffer sequence representing the memory regions to
1624 2486 sjacqu01
 * which the bytes will be copied.
1625 2486 sjacqu01
 *
1626 2486 sjacqu01
 * @param source A modifiable buffer representing the memory region from which
1627 2486 sjacqu01
 * the bytes will be copied. The contents of the source buffer will not be
1628 2486 sjacqu01
 * modified.
1629 2486 sjacqu01
 *
1630 2486 sjacqu01
 * @returns The number of bytes copied.
1631 2486 sjacqu01
 *
1632 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1633 2486 sjacqu01
 *
1634 2486 sjacqu01
 * @li @c buffer_size(target)
1635 2486 sjacqu01
 *
1636 2486 sjacqu01
 * @li @c buffer_size(source)
1637 2486 sjacqu01
 *
1638 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1639 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1640 2486 sjacqu01
 */
1641 2486 sjacqu01
template <typename MutableBufferSequence>
1642 2486 sjacqu01
inline std::size_t buffer_copy(const MutableBufferSequence& target,
1643 2486 sjacqu01
    const mutable_buffer& source)
1644 2486 sjacqu01
{
1645 2486 sjacqu01
  return buffer_copy(target, const_buffer(source));
1646 2486 sjacqu01
}
1647 2486 sjacqu01
1648 2486 sjacqu01
/// Copies bytes from a source buffer to a target buffer sequence.
1649 2486 sjacqu01
/**
1650 2486 sjacqu01
 * @param target A modifiable buffer sequence representing the memory regions to
1651 2486 sjacqu01
 * which the bytes will be copied.
1652 2486 sjacqu01
 *
1653 2486 sjacqu01
 * @param source A modifiable buffer representing the memory region from which
1654 2486 sjacqu01
 * the bytes will be copied. The contents of the source buffer will not be
1655 2486 sjacqu01
 * modified.
1656 2486 sjacqu01
 *
1657 2486 sjacqu01
 * @returns The number of bytes copied.
1658 2486 sjacqu01
 *
1659 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1660 2486 sjacqu01
 *
1661 2486 sjacqu01
 * @li @c buffer_size(target)
1662 2486 sjacqu01
 *
1663 2486 sjacqu01
 * @li @c buffer_size(source)
1664 2486 sjacqu01
 *
1665 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1666 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1667 2486 sjacqu01
 */
1668 2486 sjacqu01
template <typename MutableBufferSequence>
1669 2486 sjacqu01
inline std::size_t buffer_copy(const MutableBufferSequence& target,
1670 2486 sjacqu01
    const mutable_buffers_1& source)
1671 2486 sjacqu01
{
1672 2486 sjacqu01
  return buffer_copy(target, const_buffer(source));
1673 2486 sjacqu01
}
1674 2486 sjacqu01
1675 2486 sjacqu01
/// Copies bytes from a source buffer sequence to a target buffer sequence.
1676 2486 sjacqu01
/**
1677 2486 sjacqu01
 * @param target A modifiable buffer sequence representing the memory regions to
1678 2486 sjacqu01
 * which the bytes will be copied.
1679 2486 sjacqu01
 *
1680 2486 sjacqu01
 * @param source A non-modifiable buffer sequence representing the memory
1681 2486 sjacqu01
 * regions from which the bytes will be copied.
1682 2486 sjacqu01
 *
1683 2486 sjacqu01
 * @returns The number of bytes copied.
1684 2486 sjacqu01
 *
1685 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1686 2486 sjacqu01
 *
1687 2486 sjacqu01
 * @li @c buffer_size(target)
1688 2486 sjacqu01
 *
1689 2486 sjacqu01
 * @li @c buffer_size(source)
1690 2486 sjacqu01
 *
1691 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1692 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1693 2486 sjacqu01
 */
1694 2486 sjacqu01
template <typename MutableBufferSequence, typename ConstBufferSequence>
1695 2486 sjacqu01
std::size_t buffer_copy(const MutableBufferSequence& target,
1696 2486 sjacqu01
    const ConstBufferSequence& source)
1697 2486 sjacqu01
{
1698 2486 sjacqu01
  std::size_t total_bytes_copied = 0;
1699 2486 sjacqu01
1700 2486 sjacqu01
  typename MutableBufferSequence::const_iterator target_iter = target.begin();
1701 2486 sjacqu01
  typename MutableBufferSequence::const_iterator target_end = target.end();
1702 2486 sjacqu01
  std::size_t target_buffer_offset = 0;
1703 2486 sjacqu01
1704 2486 sjacqu01
  typename ConstBufferSequence::const_iterator source_iter = source.begin();
1705 2486 sjacqu01
  typename ConstBufferSequence::const_iterator source_end = source.end();
1706 2486 sjacqu01
  std::size_t source_buffer_offset = 0;
1707 2486 sjacqu01
1708 2486 sjacqu01
  while (target_iter != target_end && source_iter != source_end)
1709 2486 sjacqu01
  {
1710 2486 sjacqu01
    mutable_buffer target_buffer =
1711 2486 sjacqu01
      mutable_buffer(*target_iter) + target_buffer_offset;
1712 2486 sjacqu01
1713 2486 sjacqu01
    const_buffer source_buffer =
1714 2486 sjacqu01
      const_buffer(*source_iter) + source_buffer_offset;
1715 2486 sjacqu01
1716 2486 sjacqu01
    std::size_t bytes_copied = buffer_copy(target_buffer, source_buffer);
1717 2486 sjacqu01
    total_bytes_copied += bytes_copied;
1718 2486 sjacqu01
1719 2486 sjacqu01
    if (bytes_copied == buffer_size(target_buffer))
1720 2486 sjacqu01
    {
1721 2486 sjacqu01
      ++target_iter;
1722 2486 sjacqu01
      target_buffer_offset = 0;
1723 2486 sjacqu01
    }
1724 2486 sjacqu01
    else
1725 2486 sjacqu01
      target_buffer_offset += bytes_copied;
1726 2486 sjacqu01
1727 2486 sjacqu01
    if (bytes_copied == buffer_size(source_buffer))
1728 2486 sjacqu01
    {
1729 2486 sjacqu01
      ++source_iter;
1730 2486 sjacqu01
      source_buffer_offset = 0;
1731 2486 sjacqu01
    }
1732 2486 sjacqu01
    else
1733 2486 sjacqu01
      source_buffer_offset += bytes_copied;
1734 2486 sjacqu01
  }
1735 2486 sjacqu01
1736 2486 sjacqu01
  return total_bytes_copied;
1737 2486 sjacqu01
}
1738 2486 sjacqu01
1739 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer to a target buffer.
1740 2486 sjacqu01
/**
1741 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1742 2486 sjacqu01
 * the bytes will be copied.
1743 2486 sjacqu01
 *
1744 2486 sjacqu01
 * @param source A non-modifiable buffer representing the memory region from
1745 2486 sjacqu01
 * which the bytes will be copied.
1746 2486 sjacqu01
 *
1747 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
1748 2486 sjacqu01
 *
1749 2486 sjacqu01
 * @returns The number of bytes copied.
1750 2486 sjacqu01
 *
1751 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1752 2486 sjacqu01
 *
1753 2486 sjacqu01
 * @li @c buffer_size(target)
1754 2486 sjacqu01
 *
1755 2486 sjacqu01
 * @li @c buffer_size(source)
1756 2486 sjacqu01
 *
1757 2486 sjacqu01
 * @li @c max_bytes_to_copy
1758 2486 sjacqu01
 *
1759 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1760 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1761 2486 sjacqu01
 */
1762 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffer& target,
1763 2486 sjacqu01
    const const_buffer& source, std::size_t max_bytes_to_copy)
1764 2486 sjacqu01
{
1765 2486 sjacqu01
  return buffer_copy(buffer(target, max_bytes_to_copy), source);
1766 2486 sjacqu01
}
1767 2486 sjacqu01
1768 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer to a target buffer.
1769 2486 sjacqu01
/**
1770 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1771 2486 sjacqu01
 * the bytes will be copied.
1772 2486 sjacqu01
 *
1773 2486 sjacqu01
 * @param source A non-modifiable buffer representing the memory region from
1774 2486 sjacqu01
 * which the bytes will be copied.
1775 2486 sjacqu01
 *
1776 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
1777 2486 sjacqu01
 *
1778 2486 sjacqu01
 * @returns The number of bytes copied.
1779 2486 sjacqu01
 *
1780 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1781 2486 sjacqu01
 *
1782 2486 sjacqu01
 * @li @c buffer_size(target)
1783 2486 sjacqu01
 *
1784 2486 sjacqu01
 * @li @c buffer_size(source)
1785 2486 sjacqu01
 *
1786 2486 sjacqu01
 * @li @c max_bytes_to_copy
1787 2486 sjacqu01
 *
1788 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1789 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1790 2486 sjacqu01
 */
1791 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffer& target,
1792 2486 sjacqu01
    const const_buffers_1& source, std::size_t max_bytes_to_copy)
1793 2486 sjacqu01
{
1794 2486 sjacqu01
  return buffer_copy(buffer(target, max_bytes_to_copy), source);
1795 2486 sjacqu01
}
1796 2486 sjacqu01
1797 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer to a target buffer.
1798 2486 sjacqu01
/**
1799 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1800 2486 sjacqu01
 * the bytes will be copied.
1801 2486 sjacqu01
 *
1802 2486 sjacqu01
 * @param source A modifiable buffer representing the memory region from which
1803 2486 sjacqu01
 * the bytes will be copied. The contents of the source buffer will not be
1804 2486 sjacqu01
 * modified.
1805 2486 sjacqu01
 *
1806 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
1807 2486 sjacqu01
 *
1808 2486 sjacqu01
 * @returns The number of bytes copied.
1809 2486 sjacqu01
 *
1810 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1811 2486 sjacqu01
 *
1812 2486 sjacqu01
 * @li @c buffer_size(target)
1813 2486 sjacqu01
 *
1814 2486 sjacqu01
 * @li @c buffer_size(source)
1815 2486 sjacqu01
 *
1816 2486 sjacqu01
 * @li @c max_bytes_to_copy
1817 2486 sjacqu01
 *
1818 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1819 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1820 2486 sjacqu01
 */
1821 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffer& target,
1822 2486 sjacqu01
    const mutable_buffer& source, std::size_t max_bytes_to_copy)
1823 2486 sjacqu01
{
1824 2486 sjacqu01
  return buffer_copy(buffer(target, max_bytes_to_copy), source);
1825 2486 sjacqu01
}
1826 2486 sjacqu01
1827 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer to a target buffer.
1828 2486 sjacqu01
/**
1829 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1830 2486 sjacqu01
 * the bytes will be copied.
1831 2486 sjacqu01
 *
1832 2486 sjacqu01
 * @param source A modifiable buffer representing the memory region from which
1833 2486 sjacqu01
 * the bytes will be copied. The contents of the source buffer will not be
1834 2486 sjacqu01
 * modified.
1835 2486 sjacqu01
 *
1836 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
1837 2486 sjacqu01
 *
1838 2486 sjacqu01
 * @returns The number of bytes copied.
1839 2486 sjacqu01
 *
1840 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1841 2486 sjacqu01
 *
1842 2486 sjacqu01
 * @li @c buffer_size(target)
1843 2486 sjacqu01
 *
1844 2486 sjacqu01
 * @li @c buffer_size(source)
1845 2486 sjacqu01
 *
1846 2486 sjacqu01
 * @li @c max_bytes_to_copy
1847 2486 sjacqu01
 *
1848 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1849 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1850 2486 sjacqu01
 */
1851 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffer& target,
1852 2486 sjacqu01
    const mutable_buffers_1& source, std::size_t max_bytes_to_copy)
1853 2486 sjacqu01
{
1854 2486 sjacqu01
  return buffer_copy(buffer(target, max_bytes_to_copy), source);
1855 2486 sjacqu01
}
1856 2486 sjacqu01
1857 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer sequence to a target
1858 2486 sjacqu01
/// buffer.
1859 2486 sjacqu01
/**
1860 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1861 2486 sjacqu01
 * the bytes will be copied.
1862 2486 sjacqu01
 *
1863 2486 sjacqu01
 * @param source A non-modifiable buffer sequence representing the memory
1864 2486 sjacqu01
 * regions from which the bytes will be copied.
1865 2486 sjacqu01
 *
1866 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
1867 2486 sjacqu01
 *
1868 2486 sjacqu01
 * @returns The number of bytes copied.
1869 2486 sjacqu01
 *
1870 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1871 2486 sjacqu01
 *
1872 2486 sjacqu01
 * @li @c buffer_size(target)
1873 2486 sjacqu01
 *
1874 2486 sjacqu01
 * @li @c buffer_size(source)
1875 2486 sjacqu01
 *
1876 2486 sjacqu01
 * @li @c max_bytes_to_copy
1877 2486 sjacqu01
 *
1878 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1879 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1880 2486 sjacqu01
 */
1881 2486 sjacqu01
template <typename ConstBufferSequence>
1882 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffer& target,
1883 2486 sjacqu01
    const ConstBufferSequence& source, std::size_t max_bytes_to_copy)
1884 2486 sjacqu01
{
1885 2486 sjacqu01
  return buffer_copy(buffer(target, max_bytes_to_copy), source);
1886 2486 sjacqu01
}
1887 2486 sjacqu01
1888 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer to a target buffer.
1889 2486 sjacqu01
/**
1890 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1891 2486 sjacqu01
 * the bytes will be copied.
1892 2486 sjacqu01
 *
1893 2486 sjacqu01
 * @param source A non-modifiable buffer representing the memory region from
1894 2486 sjacqu01
 * which the bytes will be copied.
1895 2486 sjacqu01
 *
1896 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
1897 2486 sjacqu01
 *
1898 2486 sjacqu01
 * @returns The number of bytes copied.
1899 2486 sjacqu01
 *
1900 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1901 2486 sjacqu01
 *
1902 2486 sjacqu01
 * @li @c buffer_size(target)
1903 2486 sjacqu01
 *
1904 2486 sjacqu01
 * @li @c buffer_size(source)
1905 2486 sjacqu01
 *
1906 2486 sjacqu01
 * @li @c max_bytes_to_copy
1907 2486 sjacqu01
 *
1908 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1909 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1910 2486 sjacqu01
 */
1911 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffers_1& target,
1912 2486 sjacqu01
    const const_buffer& source, std::size_t max_bytes_to_copy)
1913 2486 sjacqu01
{
1914 2486 sjacqu01
  return buffer_copy(buffer(target, max_bytes_to_copy), source);
1915 2486 sjacqu01
}
1916 2486 sjacqu01
1917 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer to a target buffer.
1918 2486 sjacqu01
/**
1919 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1920 2486 sjacqu01
 * the bytes will be copied.
1921 2486 sjacqu01
 *
1922 2486 sjacqu01
 * @param source A non-modifiable buffer representing the memory region from
1923 2486 sjacqu01
 * which the bytes will be copied.
1924 2486 sjacqu01
 *
1925 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
1926 2486 sjacqu01
 *
1927 2486 sjacqu01
 * @returns The number of bytes copied.
1928 2486 sjacqu01
 *
1929 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1930 2486 sjacqu01
 *
1931 2486 sjacqu01
 * @li @c buffer_size(target)
1932 2486 sjacqu01
 *
1933 2486 sjacqu01
 * @li @c buffer_size(source)
1934 2486 sjacqu01
 *
1935 2486 sjacqu01
 * @li @c max_bytes_to_copy
1936 2486 sjacqu01
 *
1937 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1938 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1939 2486 sjacqu01
 */
1940 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffers_1& target,
1941 2486 sjacqu01
    const const_buffers_1& source, std::size_t max_bytes_to_copy)
1942 2486 sjacqu01
{
1943 2486 sjacqu01
  return buffer_copy(buffer(target, max_bytes_to_copy), source);
1944 2486 sjacqu01
}
1945 2486 sjacqu01
1946 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer to a target buffer.
1947 2486 sjacqu01
/**
1948 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1949 2486 sjacqu01
 * the bytes will be copied.
1950 2486 sjacqu01
 *
1951 2486 sjacqu01
 * @param source A modifiable buffer representing the memory region from which
1952 2486 sjacqu01
 * the bytes will be copied. The contents of the source buffer will not be
1953 2486 sjacqu01
 * modified.
1954 2486 sjacqu01
 *
1955 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
1956 2486 sjacqu01
 *
1957 2486 sjacqu01
 * @returns The number of bytes copied.
1958 2486 sjacqu01
 *
1959 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1960 2486 sjacqu01
 *
1961 2486 sjacqu01
 * @li @c buffer_size(target)
1962 2486 sjacqu01
 *
1963 2486 sjacqu01
 * @li @c buffer_size(source)
1964 2486 sjacqu01
 *
1965 2486 sjacqu01
 * @li @c max_bytes_to_copy
1966 2486 sjacqu01
 *
1967 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1968 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1969 2486 sjacqu01
 */
1970 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffers_1& target,
1971 2486 sjacqu01
    const mutable_buffer& source, std::size_t max_bytes_to_copy)
1972 2486 sjacqu01
{
1973 2486 sjacqu01
  return buffer_copy(buffer(target, max_bytes_to_copy), source);
1974 2486 sjacqu01
}
1975 2486 sjacqu01
1976 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer to a target buffer.
1977 2486 sjacqu01
/**
1978 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
1979 2486 sjacqu01
 * the bytes will be copied.
1980 2486 sjacqu01
 *
1981 2486 sjacqu01
 * @param source A modifiable buffer representing the memory region from which
1982 2486 sjacqu01
 * the bytes will be copied. The contents of the source buffer will not be
1983 2486 sjacqu01
 * modified.
1984 2486 sjacqu01
 *
1985 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
1986 2486 sjacqu01
 *
1987 2486 sjacqu01
 * @returns The number of bytes copied.
1988 2486 sjacqu01
 *
1989 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
1990 2486 sjacqu01
 *
1991 2486 sjacqu01
 * @li @c buffer_size(target)
1992 2486 sjacqu01
 *
1993 2486 sjacqu01
 * @li @c buffer_size(source)
1994 2486 sjacqu01
 *
1995 2486 sjacqu01
 * @li @c max_bytes_to_copy
1996 2486 sjacqu01
 *
1997 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
1998 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
1999 2486 sjacqu01
 */
2000 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffers_1& target,
2001 2486 sjacqu01
    const mutable_buffers_1& source, std::size_t max_bytes_to_copy)
2002 2486 sjacqu01
{
2003 2486 sjacqu01
  return buffer_copy(buffer(target, max_bytes_to_copy), source);
2004 2486 sjacqu01
}
2005 2486 sjacqu01
2006 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer sequence to a target
2007 2486 sjacqu01
/// buffer.
2008 2486 sjacqu01
/**
2009 2486 sjacqu01
 * @param target A modifiable buffer representing the memory region to which
2010 2486 sjacqu01
 * the bytes will be copied.
2011 2486 sjacqu01
 *
2012 2486 sjacqu01
 * @param source A non-modifiable buffer sequence representing the memory
2013 2486 sjacqu01
 * regions from which the bytes will be copied.
2014 2486 sjacqu01
 *
2015 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
2016 2486 sjacqu01
 *
2017 2486 sjacqu01
 * @returns The number of bytes copied.
2018 2486 sjacqu01
 *
2019 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
2020 2486 sjacqu01
 *
2021 2486 sjacqu01
 * @li @c buffer_size(target)
2022 2486 sjacqu01
 *
2023 2486 sjacqu01
 * @li @c buffer_size(source)
2024 2486 sjacqu01
 *
2025 2486 sjacqu01
 * @li @c max_bytes_to_copy
2026 2486 sjacqu01
 *
2027 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
2028 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
2029 2486 sjacqu01
 */
2030 2486 sjacqu01
template <typename ConstBufferSequence>
2031 2486 sjacqu01
inline std::size_t buffer_copy(const mutable_buffers_1& target,
2032 2486 sjacqu01
    const ConstBufferSequence& source, std::size_t max_bytes_to_copy)
2033 2486 sjacqu01
{
2034 2486 sjacqu01
  return buffer_copy(buffer(target, max_bytes_to_copy), source);
2035 2486 sjacqu01
}
2036 2486 sjacqu01
2037 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer to a target buffer
2038 2486 sjacqu01
/// sequence.
2039 2486 sjacqu01
/**
2040 2486 sjacqu01
 * @param target A modifiable buffer sequence representing the memory regions to
2041 2486 sjacqu01
 * which the bytes will be copied.
2042 2486 sjacqu01
 *
2043 2486 sjacqu01
 * @param source A non-modifiable buffer representing the memory region from
2044 2486 sjacqu01
 * which the bytes will be copied.
2045 2486 sjacqu01
 *
2046 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
2047 2486 sjacqu01
 *
2048 2486 sjacqu01
 * @returns The number of bytes copied.
2049 2486 sjacqu01
 *
2050 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
2051 2486 sjacqu01
 *
2052 2486 sjacqu01
 * @li @c buffer_size(target)
2053 2486 sjacqu01
 *
2054 2486 sjacqu01
 * @li @c buffer_size(source)
2055 2486 sjacqu01
 *
2056 2486 sjacqu01
 * @li @c max_bytes_to_copy
2057 2486 sjacqu01
 *
2058 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
2059 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
2060 2486 sjacqu01
 */
2061 2486 sjacqu01
template <typename MutableBufferSequence>
2062 2486 sjacqu01
inline std::size_t buffer_copy(const MutableBufferSequence& target,
2063 2486 sjacqu01
    const const_buffer& source, std::size_t max_bytes_to_copy)
2064 2486 sjacqu01
{
2065 2486 sjacqu01
  return buffer_copy(target, buffer(source, max_bytes_to_copy));
2066 2486 sjacqu01
}
2067 2486 sjacqu01
2068 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer to a target buffer
2069 2486 sjacqu01
/// sequence.
2070 2486 sjacqu01
/**
2071 2486 sjacqu01
 * @param target A modifiable buffer sequence representing the memory regions to
2072 2486 sjacqu01
 * which the bytes will be copied.
2073 2486 sjacqu01
 *
2074 2486 sjacqu01
 * @param source A non-modifiable buffer representing the memory region from
2075 2486 sjacqu01
 * which the bytes will be copied.
2076 2486 sjacqu01
 *
2077 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
2078 2486 sjacqu01
 *
2079 2486 sjacqu01
 * @returns The number of bytes copied.
2080 2486 sjacqu01
 *
2081 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
2082 2486 sjacqu01
 *
2083 2486 sjacqu01
 * @li @c buffer_size(target)
2084 2486 sjacqu01
 *
2085 2486 sjacqu01
 * @li @c buffer_size(source)
2086 2486 sjacqu01
 *
2087 2486 sjacqu01
 * @li @c max_bytes_to_copy
2088 2486 sjacqu01
 *
2089 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
2090 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
2091 2486 sjacqu01
 */
2092 2486 sjacqu01
template <typename MutableBufferSequence>
2093 2486 sjacqu01
inline std::size_t buffer_copy(const MutableBufferSequence& target,
2094 2486 sjacqu01
    const const_buffers_1& source, std::size_t max_bytes_to_copy)
2095 2486 sjacqu01
{
2096 2486 sjacqu01
  return buffer_copy(target, buffer(source, max_bytes_to_copy));
2097 2486 sjacqu01
}
2098 2486 sjacqu01
2099 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer to a target buffer
2100 2486 sjacqu01
/// sequence.
2101 2486 sjacqu01
/**
2102 2486 sjacqu01
 * @param target A modifiable buffer sequence representing the memory regions to
2103 2486 sjacqu01
 * which the bytes will be copied.
2104 2486 sjacqu01
 *
2105 2486 sjacqu01
 * @param source A modifiable buffer representing the memory region from which
2106 2486 sjacqu01
 * the bytes will be copied. The contents of the source buffer will not be
2107 2486 sjacqu01
 * modified.
2108 2486 sjacqu01
 *
2109 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
2110 2486 sjacqu01
 *
2111 2486 sjacqu01
 * @returns The number of bytes copied.
2112 2486 sjacqu01
 *
2113 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
2114 2486 sjacqu01
 *
2115 2486 sjacqu01
 * @li @c buffer_size(target)
2116 2486 sjacqu01
 *
2117 2486 sjacqu01
 * @li @c buffer_size(source)
2118 2486 sjacqu01
 *
2119 2486 sjacqu01
 * @li @c max_bytes_to_copy
2120 2486 sjacqu01
 *
2121 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
2122 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
2123 2486 sjacqu01
 */
2124 2486 sjacqu01
template <typename MutableBufferSequence>
2125 2486 sjacqu01
inline std::size_t buffer_copy(const MutableBufferSequence& target,
2126 2486 sjacqu01
    const mutable_buffer& source, std::size_t max_bytes_to_copy)
2127 2486 sjacqu01
{
2128 2486 sjacqu01
  return buffer_copy(target, buffer(source, max_bytes_to_copy));
2129 2486 sjacqu01
}
2130 2486 sjacqu01
2131 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer to a target buffer
2132 2486 sjacqu01
/// sequence.
2133 2486 sjacqu01
/**
2134 2486 sjacqu01
 * @param target A modifiable buffer sequence representing the memory regions to
2135 2486 sjacqu01
 * which the bytes will be copied.
2136 2486 sjacqu01
 *
2137 2486 sjacqu01
 * @param source A modifiable buffer representing the memory region from which
2138 2486 sjacqu01
 * the bytes will be copied. The contents of the source buffer will not be
2139 2486 sjacqu01
 * modified.
2140 2486 sjacqu01
 *
2141 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
2142 2486 sjacqu01
 *
2143 2486 sjacqu01
 * @returns The number of bytes copied.
2144 2486 sjacqu01
 *
2145 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
2146 2486 sjacqu01
 *
2147 2486 sjacqu01
 * @li @c buffer_size(target)
2148 2486 sjacqu01
 *
2149 2486 sjacqu01
 * @li @c buffer_size(source)
2150 2486 sjacqu01
 *
2151 2486 sjacqu01
 * @li @c max_bytes_to_copy
2152 2486 sjacqu01
 *
2153 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
2154 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
2155 2486 sjacqu01
 */
2156 2486 sjacqu01
template <typename MutableBufferSequence>
2157 2486 sjacqu01
inline std::size_t buffer_copy(const MutableBufferSequence& target,
2158 2486 sjacqu01
    const mutable_buffers_1& source, std::size_t max_bytes_to_copy)
2159 2486 sjacqu01
{
2160 2486 sjacqu01
  return buffer_copy(target, buffer(source, max_bytes_to_copy));
2161 2486 sjacqu01
}
2162 2486 sjacqu01
2163 2486 sjacqu01
/// Copies a limited number of bytes from a source buffer sequence to a target
2164 2486 sjacqu01
/// buffer sequence.
2165 2486 sjacqu01
/**
2166 2486 sjacqu01
 * @param target A modifiable buffer sequence representing the memory regions to
2167 2486 sjacqu01
 * which the bytes will be copied.
2168 2486 sjacqu01
 *
2169 2486 sjacqu01
 * @param source A non-modifiable buffer sequence representing the memory
2170 2486 sjacqu01
 * regions from which the bytes will be copied.
2171 2486 sjacqu01
 *
2172 2486 sjacqu01
 * @param max_bytes_to_copy The maximum number of bytes to be copied.
2173 2486 sjacqu01
 *
2174 2486 sjacqu01
 * @returns The number of bytes copied.
2175 2486 sjacqu01
 *
2176 2486 sjacqu01
 * @note The number of bytes copied is the lesser of:
2177 2486 sjacqu01
 *
2178 2486 sjacqu01
 * @li @c buffer_size(target)
2179 2486 sjacqu01
 *
2180 2486 sjacqu01
 * @li @c buffer_size(source)
2181 2486 sjacqu01
 *
2182 2486 sjacqu01
 * @li @c max_bytes_to_copy
2183 2486 sjacqu01
 *
2184 2486 sjacqu01
 * This function is implemented in terms of @c memcpy, and consequently it
2185 2486 sjacqu01
 * cannot be used to copy between overlapping memory regions.
2186 2486 sjacqu01
 */
2187 2486 sjacqu01
template <typename MutableBufferSequence, typename ConstBufferSequence>
2188 2486 sjacqu01
std::size_t buffer_copy(const MutableBufferSequence& target,
2189 2486 sjacqu01
    const ConstBufferSequence& source, std::size_t max_bytes_to_copy)
2190 2486 sjacqu01
{
2191 2486 sjacqu01
  std::size_t total_bytes_copied = 0;
2192 2486 sjacqu01
2193 2486 sjacqu01
  typename MutableBufferSequence::const_iterator target_iter = target.begin();
2194 2486 sjacqu01
  typename MutableBufferSequence::const_iterator target_end = target.end();
2195 2486 sjacqu01
  std::size_t target_buffer_offset = 0;
2196 2486 sjacqu01
2197 2486 sjacqu01
  typename ConstBufferSequence::const_iterator source_iter = source.begin();
2198 2486 sjacqu01
  typename ConstBufferSequence::const_iterator source_end = source.end();
2199 2486 sjacqu01
  std::size_t source_buffer_offset = 0;
2200 2486 sjacqu01
2201 2486 sjacqu01
  while (total_bytes_copied != max_bytes_to_copy
2202 2486 sjacqu01
      && target_iter != target_end && source_iter != source_end)
2203 2486 sjacqu01
  {
2204 2486 sjacqu01
    mutable_buffer target_buffer =
2205 2486 sjacqu01
      mutable_buffer(*target_iter) + target_buffer_offset;
2206 2486 sjacqu01
2207 2486 sjacqu01
    const_buffer source_buffer =
2208 2486 sjacqu01
      const_buffer(*source_iter) + source_buffer_offset;
2209 2486 sjacqu01
2210 2486 sjacqu01
    std::size_t bytes_copied = buffer_copy(target_buffer,
2211 2486 sjacqu01
        source_buffer, max_bytes_to_copy - total_bytes_copied);
2212 2486 sjacqu01
    total_bytes_copied += bytes_copied;
2213 2486 sjacqu01
2214 2486 sjacqu01
    if (bytes_copied == buffer_size(target_buffer))
2215 2486 sjacqu01
    {
2216 2486 sjacqu01
      ++target_iter;
2217 2486 sjacqu01
      target_buffer_offset = 0;
2218 2486 sjacqu01
    }
2219 2486 sjacqu01
    else
2220 2486 sjacqu01
      target_buffer_offset += bytes_copied;
2221 2486 sjacqu01
2222 2486 sjacqu01
    if (bytes_copied == buffer_size(source_buffer))
2223 2486 sjacqu01
    {
2224 2486 sjacqu01
      ++source_iter;
2225 2486 sjacqu01
      source_buffer_offset = 0;
2226 2486 sjacqu01
    }
2227 2486 sjacqu01
    else
2228 2486 sjacqu01
      source_buffer_offset += bytes_copied;
2229 2486 sjacqu01
  }
2230 2486 sjacqu01
2231 2486 sjacqu01
  return total_bytes_copied;
2232 2486 sjacqu01
}
2233 2486 sjacqu01
2234 2486 sjacqu01
/*@}*/
2235 2486 sjacqu01
2236 2486 sjacqu01
} // namespace asio
2237 2486 sjacqu01
} // namespace boost
2238 2486 sjacqu01
2239 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
2240 2486 sjacqu01
2241 2486 sjacqu01
#endif // BOOST_ASIO_BUFFER_HPP