Statistics
| Revision:

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

History | View | Annotate | Download (10 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// detail/buffer_sequence_adapter.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_DETAIL_BUFFER_SEQUENCE_ADAPTER_HPP
12 2486 sjacqu01
#define BOOST_ASIO_DETAIL_BUFFER_SEQUENCE_ADAPTER_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 <boost/asio/buffer.hpp>
20 2486 sjacqu01
#include <boost/asio/detail/array_fwd.hpp>
21 2486 sjacqu01
#include <boost/asio/detail/socket_types.hpp>
22 2486 sjacqu01
23 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
24 2486 sjacqu01
25 2486 sjacqu01
namespace boost {
26 2486 sjacqu01
namespace asio {
27 2486 sjacqu01
namespace detail {
28 2486 sjacqu01
29 2486 sjacqu01
class buffer_sequence_adapter_base
30 2486 sjacqu01
{
31 2486 sjacqu01
protected:
32 2486 sjacqu01
#if defined(BOOST_ASIO_WINDOWS_RUNTIME)
33 2486 sjacqu01
  // The maximum number of buffers to support in a single operation.
34 2486 sjacqu01
  enum { max_buffers = 1 };
35 2486 sjacqu01
36 2486 sjacqu01
  typedef Windows::Storage::Streams::IBuffer^ native_buffer_type;
37 2486 sjacqu01
38 2486 sjacqu01
  BOOST_ASIO_DECL static void init_native_buffer(
39 2486 sjacqu01
      native_buffer_type& buf,
40 2486 sjacqu01
      const boost::asio::mutable_buffer& buffer);
41 2486 sjacqu01
42 2486 sjacqu01
  BOOST_ASIO_DECL static void init_native_buffer(
43 2486 sjacqu01
      native_buffer_type& buf,
44 2486 sjacqu01
      const boost::asio::const_buffer& buffer);
45 2486 sjacqu01
#elif defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
46 2486 sjacqu01
  // The maximum number of buffers to support in a single operation.
47 2486 sjacqu01
  enum { max_buffers = 64 < max_iov_len ? 64 : max_iov_len };
48 2486 sjacqu01
49 2486 sjacqu01
  typedef WSABUF native_buffer_type;
50 2486 sjacqu01
51 2486 sjacqu01
  static void init_native_buffer(WSABUF& buf,
52 2486 sjacqu01
      const boost::asio::mutable_buffer& buffer)
53 2486 sjacqu01
  {
54 2486 sjacqu01
    buf.buf = boost::asio::buffer_cast<char*>(buffer);
55 2486 sjacqu01
    buf.len = static_cast<ULONG>(boost::asio::buffer_size(buffer));
56 2486 sjacqu01
  }
57 2486 sjacqu01
58 2486 sjacqu01
  static void init_native_buffer(WSABUF& buf,
59 2486 sjacqu01
      const boost::asio::const_buffer& buffer)
60 2486 sjacqu01
  {
61 2486 sjacqu01
    buf.buf = const_cast<char*>(boost::asio::buffer_cast<const char*>(buffer));
62 2486 sjacqu01
    buf.len = static_cast<ULONG>(boost::asio::buffer_size(buffer));
63 2486 sjacqu01
  }
64 2486 sjacqu01
#else // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
65 2486 sjacqu01
  // The maximum number of buffers to support in a single operation.
66 2486 sjacqu01
  enum { max_buffers = 64 < max_iov_len ? 64 : max_iov_len };
67 2486 sjacqu01
68 2486 sjacqu01
  typedef iovec native_buffer_type;
69 2486 sjacqu01
70 2486 sjacqu01
  static void init_iov_base(void*& base, void* addr)
71 2486 sjacqu01
  {
72 2486 sjacqu01
    base = addr;
73 2486 sjacqu01
  }
74 2486 sjacqu01
75 2486 sjacqu01
  template <typename T>
76 2486 sjacqu01
  static void init_iov_base(T& base, void* addr)
77 2486 sjacqu01
  {
78 2486 sjacqu01
    base = static_cast<T>(addr);
79 2486 sjacqu01
  }
80 2486 sjacqu01
81 2486 sjacqu01
  static void init_native_buffer(iovec& iov,
82 2486 sjacqu01
      const boost::asio::mutable_buffer& buffer)
83 2486 sjacqu01
  {
84 2486 sjacqu01
    init_iov_base(iov.iov_base, boost::asio::buffer_cast<void*>(buffer));
85 2486 sjacqu01
    iov.iov_len = boost::asio::buffer_size(buffer);
86 2486 sjacqu01
  }
87 2486 sjacqu01
88 2486 sjacqu01
  static void init_native_buffer(iovec& iov,
89 2486 sjacqu01
      const boost::asio::const_buffer& buffer)
90 2486 sjacqu01
  {
91 2486 sjacqu01
    init_iov_base(iov.iov_base, const_cast<void*>(
92 2486 sjacqu01
          boost::asio::buffer_cast<const void*>(buffer)));
93 2486 sjacqu01
    iov.iov_len = boost::asio::buffer_size(buffer);
94 2486 sjacqu01
  }
95 2486 sjacqu01
#endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
96 2486 sjacqu01
};
97 2486 sjacqu01
98 2486 sjacqu01
// Helper class to translate buffers into the native buffer representation.
99 2486 sjacqu01
template <typename Buffer, typename Buffers>
100 2486 sjacqu01
class buffer_sequence_adapter
101 2486 sjacqu01
  : buffer_sequence_adapter_base
102 2486 sjacqu01
{
103 2486 sjacqu01
public:
104 2486 sjacqu01
  explicit buffer_sequence_adapter(const Buffers& buffer_sequence)
105 2486 sjacqu01
    : count_(0), total_buffer_size_(0)
106 2486 sjacqu01
  {
107 2486 sjacqu01
    typename Buffers::const_iterator iter = buffer_sequence.begin();
108 2486 sjacqu01
    typename Buffers::const_iterator end = buffer_sequence.end();
109 2486 sjacqu01
    for (; iter != end && count_ < max_buffers; ++iter, ++count_)
110 2486 sjacqu01
    {
111 2486 sjacqu01
      Buffer buffer(*iter);
112 2486 sjacqu01
      init_native_buffer(buffers_[count_], buffer);
113 2486 sjacqu01
      total_buffer_size_ += boost::asio::buffer_size(buffer);
114 2486 sjacqu01
    }
115 2486 sjacqu01
  }
116 2486 sjacqu01
117 2486 sjacqu01
  native_buffer_type* buffers()
118 2486 sjacqu01
  {
119 2486 sjacqu01
    return buffers_;
120 2486 sjacqu01
  }
121 2486 sjacqu01
122 2486 sjacqu01
  std::size_t count() const
123 2486 sjacqu01
  {
124 2486 sjacqu01
    return count_;
125 2486 sjacqu01
  }
126 2486 sjacqu01
127 2486 sjacqu01
  bool all_empty() const
128 2486 sjacqu01
  {
129 2486 sjacqu01
    return total_buffer_size_ == 0;
130 2486 sjacqu01
  }
131 2486 sjacqu01
132 2486 sjacqu01
  static bool all_empty(const Buffers& buffer_sequence)
133 2486 sjacqu01
  {
134 2486 sjacqu01
    typename Buffers::const_iterator iter = buffer_sequence.begin();
135 2486 sjacqu01
    typename Buffers::const_iterator end = buffer_sequence.end();
136 2486 sjacqu01
    std::size_t i = 0;
137 2486 sjacqu01
    for (; iter != end && i < max_buffers; ++iter, ++i)
138 2486 sjacqu01
      if (boost::asio::buffer_size(Buffer(*iter)) > 0)
139 2486 sjacqu01
        return false;
140 2486 sjacqu01
    return true;
141 2486 sjacqu01
  }
142 2486 sjacqu01
143 2486 sjacqu01
  static void validate(const Buffers& buffer_sequence)
144 2486 sjacqu01
  {
145 2486 sjacqu01
    typename Buffers::const_iterator iter = buffer_sequence.begin();
146 2486 sjacqu01
    typename Buffers::const_iterator end = buffer_sequence.end();
147 2486 sjacqu01
    for (; iter != end; ++iter)
148 2486 sjacqu01
    {
149 2486 sjacqu01
      Buffer buffer(*iter);
150 2486 sjacqu01
      boost::asio::buffer_cast<const void*>(buffer);
151 2486 sjacqu01
    }
152 2486 sjacqu01
  }
153 2486 sjacqu01
154 2486 sjacqu01
  static Buffer first(const Buffers& buffer_sequence)
155 2486 sjacqu01
  {
156 2486 sjacqu01
    typename Buffers::const_iterator iter = buffer_sequence.begin();
157 2486 sjacqu01
    typename Buffers::const_iterator end = buffer_sequence.end();
158 2486 sjacqu01
    for (; iter != end; ++iter)
159 2486 sjacqu01
    {
160 2486 sjacqu01
      Buffer buffer(*iter);
161 2486 sjacqu01
      if (boost::asio::buffer_size(buffer) != 0)
162 2486 sjacqu01
        return buffer;
163 2486 sjacqu01
    }
164 2486 sjacqu01
    return Buffer();
165 2486 sjacqu01
  }
166 2486 sjacqu01
167 2486 sjacqu01
private:
168 2486 sjacqu01
  native_buffer_type buffers_[max_buffers];
169 2486 sjacqu01
  std::size_t count_;
170 2486 sjacqu01
  std::size_t total_buffer_size_;
171 2486 sjacqu01
};
172 2486 sjacqu01
173 2486 sjacqu01
template <typename Buffer>
174 2486 sjacqu01
class buffer_sequence_adapter<Buffer, boost::asio::mutable_buffers_1>
175 2486 sjacqu01
  : buffer_sequence_adapter_base
176 2486 sjacqu01
{
177 2486 sjacqu01
public:
178 2486 sjacqu01
  explicit buffer_sequence_adapter(
179 2486 sjacqu01
      const boost::asio::mutable_buffers_1& buffer_sequence)
180 2486 sjacqu01
  {
181 2486 sjacqu01
    init_native_buffer(buffer_, Buffer(buffer_sequence));
182 2486 sjacqu01
    total_buffer_size_ = boost::asio::buffer_size(buffer_sequence);
183 2486 sjacqu01
  }
184 2486 sjacqu01
185 2486 sjacqu01
  native_buffer_type* buffers()
186 2486 sjacqu01
  {
187 2486 sjacqu01
    return &buffer_;
188 2486 sjacqu01
  }
189 2486 sjacqu01
190 2486 sjacqu01
  std::size_t count() const
191 2486 sjacqu01
  {
192 2486 sjacqu01
    return 1;
193 2486 sjacqu01
  }
194 2486 sjacqu01
195 2486 sjacqu01
  bool all_empty() const
196 2486 sjacqu01
  {
197 2486 sjacqu01
    return total_buffer_size_ == 0;
198 2486 sjacqu01
  }
199 2486 sjacqu01
200 2486 sjacqu01
  static bool all_empty(const boost::asio::mutable_buffers_1& buffer_sequence)
201 2486 sjacqu01
  {
202 2486 sjacqu01
    return boost::asio::buffer_size(buffer_sequence) == 0;
203 2486 sjacqu01
  }
204 2486 sjacqu01
205 2486 sjacqu01
  static void validate(const boost::asio::mutable_buffers_1& buffer_sequence)
206 2486 sjacqu01
  {
207 2486 sjacqu01
    boost::asio::buffer_cast<const void*>(buffer_sequence);
208 2486 sjacqu01
  }
209 2486 sjacqu01
210 2486 sjacqu01
  static Buffer first(const boost::asio::mutable_buffers_1& buffer_sequence)
211 2486 sjacqu01
  {
212 2486 sjacqu01
    return Buffer(buffer_sequence);
213 2486 sjacqu01
  }
214 2486 sjacqu01
215 2486 sjacqu01
private:
216 2486 sjacqu01
  native_buffer_type buffer_;
217 2486 sjacqu01
  std::size_t total_buffer_size_;
218 2486 sjacqu01
};
219 2486 sjacqu01
220 2486 sjacqu01
template <typename Buffer>
221 2486 sjacqu01
class buffer_sequence_adapter<Buffer, boost::asio::const_buffers_1>
222 2486 sjacqu01
  : buffer_sequence_adapter_base
223 2486 sjacqu01
{
224 2486 sjacqu01
public:
225 2486 sjacqu01
  explicit buffer_sequence_adapter(
226 2486 sjacqu01
      const boost::asio::const_buffers_1& buffer_sequence)
227 2486 sjacqu01
  {
228 2486 sjacqu01
    init_native_buffer(buffer_, Buffer(buffer_sequence));
229 2486 sjacqu01
    total_buffer_size_ = boost::asio::buffer_size(buffer_sequence);
230 2486 sjacqu01
  }
231 2486 sjacqu01
232 2486 sjacqu01
  native_buffer_type* buffers()
233 2486 sjacqu01
  {
234 2486 sjacqu01
    return &buffer_;
235 2486 sjacqu01
  }
236 2486 sjacqu01
237 2486 sjacqu01
  std::size_t count() const
238 2486 sjacqu01
  {
239 2486 sjacqu01
    return 1;
240 2486 sjacqu01
  }
241 2486 sjacqu01
242 2486 sjacqu01
  bool all_empty() const
243 2486 sjacqu01
  {
244 2486 sjacqu01
    return total_buffer_size_ == 0;
245 2486 sjacqu01
  }
246 2486 sjacqu01
247 2486 sjacqu01
  static bool all_empty(const boost::asio::const_buffers_1& buffer_sequence)
248 2486 sjacqu01
  {
249 2486 sjacqu01
    return boost::asio::buffer_size(buffer_sequence) == 0;
250 2486 sjacqu01
  }
251 2486 sjacqu01
252 2486 sjacqu01
  static void validate(const boost::asio::const_buffers_1& buffer_sequence)
253 2486 sjacqu01
  {
254 2486 sjacqu01
    boost::asio::buffer_cast<const void*>(buffer_sequence);
255 2486 sjacqu01
  }
256 2486 sjacqu01
257 2486 sjacqu01
  static Buffer first(const boost::asio::const_buffers_1& buffer_sequence)
258 2486 sjacqu01
  {
259 2486 sjacqu01
    return Buffer(buffer_sequence);
260 2486 sjacqu01
  }
261 2486 sjacqu01
262 2486 sjacqu01
private:
263 2486 sjacqu01
  native_buffer_type buffer_;
264 2486 sjacqu01
  std::size_t total_buffer_size_;
265 2486 sjacqu01
};
266 2486 sjacqu01
267 2486 sjacqu01
template <typename Buffer, typename Elem>
268 2486 sjacqu01
class buffer_sequence_adapter<Buffer, boost::array<Elem, 2> >
269 2486 sjacqu01
  : buffer_sequence_adapter_base
270 2486 sjacqu01
{
271 2486 sjacqu01
public:
272 2486 sjacqu01
  explicit buffer_sequence_adapter(
273 2486 sjacqu01
      const boost::array<Elem, 2>& buffer_sequence)
274 2486 sjacqu01
  {
275 2486 sjacqu01
    init_native_buffer(buffers_[0], Buffer(buffer_sequence[0]));
276 2486 sjacqu01
    init_native_buffer(buffers_[1], Buffer(buffer_sequence[1]));
277 2486 sjacqu01
    total_buffer_size_ = boost::asio::buffer_size(buffer_sequence[0])
278 2486 sjacqu01
      + boost::asio::buffer_size(buffer_sequence[1]);
279 2486 sjacqu01
  }
280 2486 sjacqu01
281 2486 sjacqu01
  native_buffer_type* buffers()
282 2486 sjacqu01
  {
283 2486 sjacqu01
    return buffers_;
284 2486 sjacqu01
  }
285 2486 sjacqu01
286 2486 sjacqu01
  std::size_t count() const
287 2486 sjacqu01
  {
288 2486 sjacqu01
    return 2;
289 2486 sjacqu01
  }
290 2486 sjacqu01
291 2486 sjacqu01
  bool all_empty() const
292 2486 sjacqu01
  {
293 2486 sjacqu01
    return total_buffer_size_ == 0;
294 2486 sjacqu01
  }
295 2486 sjacqu01
296 2486 sjacqu01
  static bool all_empty(const boost::array<Elem, 2>& buffer_sequence)
297 2486 sjacqu01
  {
298 2486 sjacqu01
    return boost::asio::buffer_size(buffer_sequence[0]) == 0
299 2486 sjacqu01
      && boost::asio::buffer_size(buffer_sequence[1]) == 0;
300 2486 sjacqu01
  }
301 2486 sjacqu01
302 2486 sjacqu01
  static void validate(const boost::array<Elem, 2>& buffer_sequence)
303 2486 sjacqu01
  {
304 2486 sjacqu01
    boost::asio::buffer_cast<const void*>(buffer_sequence[0]);
305 2486 sjacqu01
    boost::asio::buffer_cast<const void*>(buffer_sequence[1]);
306 2486 sjacqu01
  }
307 2486 sjacqu01
308 2486 sjacqu01
  static Buffer first(const boost::array<Elem, 2>& buffer_sequence)
309 2486 sjacqu01
  {
310 2486 sjacqu01
    return Buffer(boost::asio::buffer_size(buffer_sequence[0]) != 0
311 2486 sjacqu01
        ? buffer_sequence[0] : buffer_sequence[1]);
312 2486 sjacqu01
  }
313 2486 sjacqu01
314 2486 sjacqu01
private:
315 2486 sjacqu01
  native_buffer_type buffers_[2];
316 2486 sjacqu01
  std::size_t total_buffer_size_;
317 2486 sjacqu01
};
318 2486 sjacqu01
319 2486 sjacqu01
#if defined(BOOST_ASIO_HAS_STD_ARRAY)
320 2486 sjacqu01
321 2486 sjacqu01
template <typename Buffer, typename Elem>
322 2486 sjacqu01
class buffer_sequence_adapter<Buffer, std::array<Elem, 2> >
323 2486 sjacqu01
  : buffer_sequence_adapter_base
324 2486 sjacqu01
{
325 2486 sjacqu01
public:
326 2486 sjacqu01
  explicit buffer_sequence_adapter(
327 2486 sjacqu01
      const std::array<Elem, 2>& buffer_sequence)
328 2486 sjacqu01
  {
329 2486 sjacqu01
    init_native_buffer(buffers_[0], Buffer(buffer_sequence[0]));
330 2486 sjacqu01
    init_native_buffer(buffers_[1], Buffer(buffer_sequence[1]));
331 2486 sjacqu01
    total_buffer_size_ = boost::asio::buffer_size(buffer_sequence[0])
332 2486 sjacqu01
      + boost::asio::buffer_size(buffer_sequence[1]);
333 2486 sjacqu01
  }
334 2486 sjacqu01
335 2486 sjacqu01
  native_buffer_type* buffers()
336 2486 sjacqu01
  {
337 2486 sjacqu01
    return buffers_;
338 2486 sjacqu01
  }
339 2486 sjacqu01
340 2486 sjacqu01
  std::size_t count() const
341 2486 sjacqu01
  {
342 2486 sjacqu01
    return 2;
343 2486 sjacqu01
  }
344 2486 sjacqu01
345 2486 sjacqu01
  bool all_empty() const
346 2486 sjacqu01
  {
347 2486 sjacqu01
    return total_buffer_size_ == 0;
348 2486 sjacqu01
  }
349 2486 sjacqu01
350 2486 sjacqu01
  static bool all_empty(const std::array<Elem, 2>& buffer_sequence)
351 2486 sjacqu01
  {
352 2486 sjacqu01
    return boost::asio::buffer_size(buffer_sequence[0]) == 0
353 2486 sjacqu01
      && boost::asio::buffer_size(buffer_sequence[1]) == 0;
354 2486 sjacqu01
  }
355 2486 sjacqu01
356 2486 sjacqu01
  static void validate(const std::array<Elem, 2>& buffer_sequence)
357 2486 sjacqu01
  {
358 2486 sjacqu01
    boost::asio::buffer_cast<const void*>(buffer_sequence[0]);
359 2486 sjacqu01
    boost::asio::buffer_cast<const void*>(buffer_sequence[1]);
360 2486 sjacqu01
  }
361 2486 sjacqu01
362 2486 sjacqu01
  static Buffer first(const std::array<Elem, 2>& buffer_sequence)
363 2486 sjacqu01
  {
364 2486 sjacqu01
    return Buffer(boost::asio::buffer_size(buffer_sequence[0]) != 0
365 2486 sjacqu01
        ? buffer_sequence[0] : buffer_sequence[1]);
366 2486 sjacqu01
  }
367 2486 sjacqu01
368 2486 sjacqu01
private:
369 2486 sjacqu01
  native_buffer_type buffers_[2];
370 2486 sjacqu01
  std::size_t total_buffer_size_;
371 2486 sjacqu01
};
372 2486 sjacqu01
373 2486 sjacqu01
#endif // defined(BOOST_ASIO_HAS_STD_ARRAY)
374 2486 sjacqu01
375 2486 sjacqu01
} // namespace detail
376 2486 sjacqu01
} // namespace asio
377 2486 sjacqu01
} // namespace boost
378 2486 sjacqu01
379 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
380 2486 sjacqu01
381 2486 sjacqu01
#if defined(BOOST_ASIO_HEADER_ONLY)
382 2486 sjacqu01
# include <boost/asio/detail/impl/buffer_sequence_adapter.ipp>
383 2486 sjacqu01
#endif // defined(BOOST_ASIO_HEADER_ONLY)
384 2486 sjacqu01
385 2486 sjacqu01
#endif // BOOST_ASIO_DETAIL_BUFFER_SEQUENCE_ADAPTER_HPP