Realistic 3D camera system
3D camera system components
write_at.hpp
Go to the documentation of this file.
1 //
2 // impl/write_at.hpp
3 // ~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_IMPL_WRITE_AT_HPP
12 #define ASIO_IMPL_WRITE_AT_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/buffer.hpp"
30 
32 
33 namespace asio {
34 
35 template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence,
36  typename CompletionCondition>
37 std::size_t write_at(SyncRandomAccessWriteDevice& d,
38  uint64_t offset, const ConstBufferSequence& buffers,
39  CompletionCondition completion_condition, asio::error_code& ec)
40 {
41  ec = asio::error_code();
43  const_buffer, ConstBufferSequence> tmp(buffers);
44  std::size_t total_transferred = 0;
46  completion_condition(ec, total_transferred)));
47  while (tmp.begin() != tmp.end())
48  {
49  std::size_t bytes_transferred = d.write_some_at(
50  offset + total_transferred, tmp, ec);
51  tmp.consume(bytes_transferred);
52  total_transferred += bytes_transferred;
54  completion_condition(ec, total_transferred)));
55  }
56  return total_transferred;
57 }
58 
59 template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence>
60 inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
61  uint64_t offset, const ConstBufferSequence& buffers)
62 {
64  std::size_t bytes_transferred = write_at(
65  d, offset, buffers, transfer_all(), ec);
66  asio::detail::throw_error(ec, "write_at");
67  return bytes_transferred;
68 }
69 
70 template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence>
71 inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
72  uint64_t offset, const ConstBufferSequence& buffers,
73  asio::error_code& ec)
74 {
75  return write_at(d, offset, buffers, transfer_all(), ec);
76 }
77 
78 template <typename SyncRandomAccessWriteDevice, typename ConstBufferSequence,
79  typename CompletionCondition>
80 inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
81  uint64_t offset, const ConstBufferSequence& buffers,
82  CompletionCondition completion_condition)
83 {
85  std::size_t bytes_transferred = write_at(
86  d, offset, buffers, completion_condition, ec);
87  asio::detail::throw_error(ec, "write_at");
88  return bytes_transferred;
89 }
90 
91 #if !defined(ASIO_NO_IOSTREAM)
92 
93 template <typename SyncRandomAccessWriteDevice, typename Allocator,
94  typename CompletionCondition>
95 std::size_t write_at(SyncRandomAccessWriteDevice& d,
97  CompletionCondition completion_condition, asio::error_code& ec)
98 {
99  std::size_t bytes_transferred = write_at(
100  d, offset, b.data(), completion_condition, ec);
101  b.consume(bytes_transferred);
102  return bytes_transferred;
103 }
104 
105 template <typename SyncRandomAccessWriteDevice, typename Allocator>
106 inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
108 {
109  asio::error_code ec;
110  std::size_t bytes_transferred = write_at(d, offset, b, transfer_all(), ec);
111  asio::detail::throw_error(ec, "write_at");
112  return bytes_transferred;
113 }
114 
115 template <typename SyncRandomAccessWriteDevice, typename Allocator>
116 inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
118  asio::error_code& ec)
119 {
120  return write_at(d, offset, b, transfer_all(), ec);
121 }
122 
123 template <typename SyncRandomAccessWriteDevice, typename Allocator,
124  typename CompletionCondition>
125 inline std::size_t write_at(SyncRandomAccessWriteDevice& d,
127  CompletionCondition completion_condition)
128 {
129  asio::error_code ec;
130  std::size_t bytes_transferred = write_at(
131  d, offset, b, completion_condition, ec);
132  asio::detail::throw_error(ec, "write_at");
133  return bytes_transferred;
134 }
135 
136 #endif // !defined(ASIO_NO_IOSTREAM)
137 
138 namespace detail
139 {
140  template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
141  typename CompletionCondition, typename WriteHandler>
143  : detail::base_from_completion_cond<CompletionCondition>
144  {
145  public:
146  write_at_op(AsyncRandomAccessWriteDevice& device,
147  uint64_t offset, const ConstBufferSequence& buffers,
148  CompletionCondition completion_condition, WriteHandler& handler)
149  : detail::base_from_completion_cond<
150  CompletionCondition>(completion_condition),
151  device_(device),
152  offset_(offset),
153  buffers_(buffers),
154  start_(0),
156  handler_(ASIO_MOVE_CAST(WriteHandler)(handler))
157  {
158  }
159 
160 #if defined(ASIO_HAS_MOVE)
161  write_at_op(const write_at_op& other)
163  device_(other.device_),
164  offset_(other.offset_),
165  buffers_(other.buffers_),
166  start_(other.start_),
168  handler_(other.handler_)
169  {
170  }
171 
172  write_at_op(write_at_op&& other)
174  device_(other.device_),
175  offset_(other.offset_),
176  buffers_(other.buffers_),
177  start_(other.start_),
179  handler_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
180  {
181  }
182 #endif // defined(ASIO_HAS_MOVE)
183 
184  void operator()(const asio::error_code& ec,
185  std::size_t bytes_transferred, int start = 0)
186  {
187  switch (start_ = start)
188  {
189  case 1:
191  for (;;)
192  {
193  device_.async_write_some_at(
195  ASIO_MOVE_CAST(write_at_op)(*this));
196  return; default:
197  total_transferred_ += bytes_transferred;
198  buffers_.consume(bytes_transferred);
200  if ((!ec && bytes_transferred == 0)
201  || buffers_.begin() == buffers_.end())
202  break;
203  }
204 
205  handler_(ec, static_cast<const std::size_t&>(total_transferred_));
206  }
207  }
208 
209  //private:
210  AsyncRandomAccessWriteDevice& device_;
211  uint64_t offset_;
213  const_buffer, ConstBufferSequence> buffers_;
214  int start_;
215  std::size_t total_transferred_;
216  WriteHandler handler_;
217  };
218 
219  template <typename AsyncRandomAccessWriteDevice,
220  typename CompletionCondition, typename WriteHandler>
221  class write_at_op<AsyncRandomAccessWriteDevice,
222  asio::mutable_buffers_1, CompletionCondition, WriteHandler>
223  : detail::base_from_completion_cond<CompletionCondition>
224  {
225  public:
226  write_at_op(AsyncRandomAccessWriteDevice& device,
227  uint64_t offset, const asio::mutable_buffers_1& buffers,
228  CompletionCondition completion_condition,
229  WriteHandler& handler)
230  : detail::base_from_completion_cond<
231  CompletionCondition>(completion_condition),
232  device_(device),
233  offset_(offset),
234  buffer_(buffers),
235  start_(0),
237  handler_(ASIO_MOVE_CAST(WriteHandler)(handler))
238  {
239  }
240 
241 #if defined(ASIO_HAS_MOVE)
242  write_at_op(const write_at_op& other)
244  device_(other.device_),
245  offset_(other.offset_),
246  buffer_(other.buffer_),
247  start_(other.start_),
249  handler_(other.handler_)
250  {
251  }
252 
253  write_at_op(write_at_op&& other)
255  device_(other.device_),
256  offset_(other.offset_),
257  buffer_(other.buffer_),
258  start_(other.start_),
260  handler_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
261  {
262  }
263 #endif // defined(ASIO_HAS_MOVE)
264 
265  void operator()(const asio::error_code& ec,
266  std::size_t bytes_transferred, int start = 0)
267  {
268  std::size_t n = 0;
269  switch (start_ = start)
270  {
271  case 1:
273  for (;;)
274  {
275  device_.async_write_some_at(offset_ + total_transferred_,
276  asio::buffer(buffer_ + total_transferred_, n),
277  ASIO_MOVE_CAST(write_at_op)(*this));
278  return; default:
279  total_transferred_ += bytes_transferred;
280  if ((!ec && bytes_transferred == 0)
281  || (n = this->check_for_completion(ec, total_transferred_)) == 0
282  || total_transferred_ == asio::buffer_size(buffer_))
283  break;
284  }
285 
286  handler_(ec, static_cast<const std::size_t&>(total_transferred_));
287  }
288  }
289 
290  //private:
291  AsyncRandomAccessWriteDevice& device_;
292  uint64_t offset_;
294  int start_;
295  std::size_t total_transferred_;
296  WriteHandler handler_;
297  };
298 
299  template <typename AsyncRandomAccessWriteDevice,
300  typename CompletionCondition, typename WriteHandler>
301  class write_at_op<AsyncRandomAccessWriteDevice, asio::const_buffers_1,
302  CompletionCondition, WriteHandler>
303  : detail::base_from_completion_cond<CompletionCondition>
304  {
305  public:
306  write_at_op(AsyncRandomAccessWriteDevice& device,
307  uint64_t offset, const asio::const_buffers_1& buffers,
308  CompletionCondition completion_condition,
309  WriteHandler& handler)
310  : detail::base_from_completion_cond<
311  CompletionCondition>(completion_condition),
312  device_(device),
313  offset_(offset),
314  buffer_(buffers),
315  start_(0),
317  handler_(ASIO_MOVE_CAST(WriteHandler)(handler))
318  {
319  }
320 
321 #if defined(ASIO_HAS_MOVE)
322  write_at_op(const write_at_op& other)
324  device_(other.device_),
325  offset_(other.offset_),
326  buffer_(other.buffer_),
327  start_(other.start_),
329  handler_(other.handler_)
330  {
331  }
332 
333  write_at_op(write_at_op&& other)
335  device_(other.device_),
336  offset_(other.offset_),
337  buffer_(other.buffer_),
338  start_(other.start_),
340  handler_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
341  {
342  }
343 #endif // defined(ASIO_HAS_MOVE)
344 
345  void operator()(const asio::error_code& ec,
346  std::size_t bytes_transferred, int start = 0)
347  {
348  std::size_t n = 0;
349  switch (start_ = start)
350  {
351  case 1:
353  for (;;)
354  {
355  device_.async_write_some_at(offset_ + total_transferred_,
356  asio::buffer(buffer_ + total_transferred_, n),
357  ASIO_MOVE_CAST(write_at_op)(*this));
358  return; default:
359  total_transferred_ += bytes_transferred;
360  if ((!ec && bytes_transferred == 0)
361  || (n = this->check_for_completion(ec, total_transferred_)) == 0
362  || total_transferred_ == asio::buffer_size(buffer_))
363  break;
364  }
365 
366  handler_(ec, static_cast<const std::size_t&>(total_transferred_));
367  }
368  }
369 
370  //private:
371  AsyncRandomAccessWriteDevice& device_;
372  uint64_t offset_;
374  int start_;
375  std::size_t total_transferred_;
376  WriteHandler handler_;
377  };
378 
379  template <typename AsyncRandomAccessWriteDevice, typename Elem,
380  typename CompletionCondition, typename WriteHandler>
381  class write_at_op<AsyncRandomAccessWriteDevice, boost::array<Elem, 2>,
382  CompletionCondition, WriteHandler>
383  : detail::base_from_completion_cond<CompletionCondition>
384  {
385  public:
386  write_at_op(AsyncRandomAccessWriteDevice& device,
387  uint64_t offset, const boost::array<Elem, 2>& buffers,
388  CompletionCondition completion_condition, WriteHandler& handler)
389  : detail::base_from_completion_cond<
390  CompletionCondition>(completion_condition),
391  device_(device),
392  offset_(offset),
393  buffers_(buffers),
394  start_(0),
396  handler_(ASIO_MOVE_CAST(WriteHandler)(handler))
397  {
398  }
399 
400 #if defined(ASIO_HAS_MOVE)
401  write_at_op(const write_at_op& other)
403  device_(other.device_),
404  offset_(other.offset_),
405  buffers_(other.buffers_),
406  start_(other.start_),
408  handler_(other.handler_)
409  {
410  }
411 
412  write_at_op(write_at_op&& other)
414  device_(other.device_),
415  offset_(other.offset_),
416  buffers_(other.buffers_),
417  start_(other.start_),
419  handler_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
420  {
421  }
422 #endif // defined(ASIO_HAS_MOVE)
423 
424  void operator()(const asio::error_code& ec,
425  std::size_t bytes_transferred, int start = 0)
426  {
427  typename asio::detail::dependent_type<Elem,
428  boost::array<asio::const_buffer, 2> >::type bufs = {{
431  std::size_t buffer_size0 = asio::buffer_size(bufs[0]);
432  std::size_t buffer_size1 = asio::buffer_size(bufs[1]);
433  std::size_t n = 0;
434  switch (start_ = start)
435  {
436  case 1:
438  for (;;)
439  {
440  bufs[0] = asio::buffer(bufs[0] + total_transferred_, n);
441  bufs[1] = asio::buffer(
442  bufs[1] + (total_transferred_ < buffer_size0
443  ? 0 : total_transferred_ - buffer_size0),
444  n - asio::buffer_size(bufs[0]));
445  device_.async_write_some_at(offset_ + total_transferred_,
446  bufs, ASIO_MOVE_CAST(write_at_op)(*this));
447  return; default:
448  total_transferred_ += bytes_transferred;
449  if ((!ec && bytes_transferred == 0)
450  || (n = this->check_for_completion(ec, total_transferred_)) == 0
451  || total_transferred_ == buffer_size0 + buffer_size1)
452  break;
453  }
454 
455  handler_(ec, static_cast<const std::size_t&>(total_transferred_));
456  }
457  }
458 
459  //private:
460  AsyncRandomAccessWriteDevice& device_;
461  uint64_t offset_;
463  int start_;
464  std::size_t total_transferred_;
465  WriteHandler handler_;
466  };
467 
468 #if defined(ASIO_HAS_STD_ARRAY)
469 
470  template <typename AsyncRandomAccessWriteDevice, typename Elem,
471  typename CompletionCondition, typename WriteHandler>
472  class write_at_op<AsyncRandomAccessWriteDevice, std::array<Elem, 2>,
473  CompletionCondition, WriteHandler>
474  : detail::base_from_completion_cond<CompletionCondition>
475  {
476  public:
477  write_at_op(AsyncRandomAccessWriteDevice& device,
478  uint64_t offset, const std::array<Elem, 2>& buffers,
479  CompletionCondition completion_condition, WriteHandler& handler)
481  CompletionCondition>(completion_condition),
482  device_(device),
483  offset_(offset),
484  buffers_(buffers),
485  start_(0),
487  handler_(ASIO_MOVE_CAST(WriteHandler)(handler))
488  {
489  }
490 
491 #if defined(ASIO_HAS_MOVE)
492  write_at_op(const write_at_op& other)
494  device_(other.device_),
495  offset_(other.offset_),
496  buffers_(other.buffers_),
497  start_(other.start_),
499  handler_(other.handler_)
500  {
501  }
502 
503  write_at_op(write_at_op&& other)
505  device_(other.device_),
506  offset_(other.offset_),
507  buffers_(other.buffers_),
508  start_(other.start_),
510  handler_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
511  {
512  }
513 #endif // defined(ASIO_HAS_MOVE)
514 
515  void operator()(const asio::error_code& ec,
516  std::size_t bytes_transferred, int start = 0)
517  {
518  typename asio::detail::dependent_type<Elem,
519  std::array<asio::const_buffer, 2> >::type bufs = {{
522  std::size_t buffer_size0 = asio::buffer_size(bufs[0]);
523  std::size_t buffer_size1 = asio::buffer_size(bufs[1]);
524  std::size_t n = 0;
525  switch (start_ = start)
526  {
527  case 1:
529  for (;;)
530  {
531  bufs[0] = asio::buffer(bufs[0] + total_transferred_, n);
532  bufs[1] = asio::buffer(
533  bufs[1] + (total_transferred_ < buffer_size0
534  ? 0 : total_transferred_ - buffer_size0),
535  n - asio::buffer_size(bufs[0]));
536  device_.async_write_some_at(offset_ + total_transferred_,
537  bufs, ASIO_MOVE_CAST(write_at_op)(*this));
538  return; default:
539  total_transferred_ += bytes_transferred;
540  if ((!ec && bytes_transferred == 0)
541  || (n = this->check_for_completion(ec, total_transferred_)) == 0
542  || total_transferred_ == buffer_size0 + buffer_size1)
543  break;
544  }
545 
546  handler_(ec, static_cast<const std::size_t&>(total_transferred_));
547  }
548  }
549 
550  //private:
551  AsyncRandomAccessWriteDevice& device_;
552  uint64_t offset_;
553  std::array<Elem, 2> buffers_;
554  int start_;
555  std::size_t total_transferred_;
556  WriteHandler handler_;
557  };
558 
559 #endif // defined(ASIO_HAS_STD_ARRAY)
560 
561  template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
562  typename CompletionCondition, typename WriteHandler>
563  inline void* asio_handler_allocate(std::size_t size,
564  write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
565  CompletionCondition, WriteHandler>* this_handler)
566  {
568  size, this_handler->handler_);
569  }
570 
571  template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
572  typename CompletionCondition, typename WriteHandler>
573  inline void asio_handler_deallocate(void* pointer, std::size_t size,
574  write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
575  CompletionCondition, WriteHandler>* this_handler)
576  {
578  pointer, size, this_handler->handler_);
579  }
580 
581  template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
582  typename CompletionCondition, typename WriteHandler>
584  write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
585  CompletionCondition, WriteHandler>* this_handler)
586  {
587  return this_handler->start_ == 0 ? true
589  this_handler->handler_);
590  }
591 
592  template <typename Function, typename AsyncRandomAccessWriteDevice,
593  typename ConstBufferSequence, typename CompletionCondition,
594  typename WriteHandler>
595  inline void asio_handler_invoke(Function& function,
596  write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
597  CompletionCondition, WriteHandler>* this_handler)
598  {
600  function, this_handler->handler_);
601  }
602 
603  template <typename Function, typename AsyncRandomAccessWriteDevice,
604  typename ConstBufferSequence, typename CompletionCondition,
605  typename WriteHandler>
606  inline void asio_handler_invoke(const Function& function,
607  write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
608  CompletionCondition, WriteHandler>* this_handler)
609  {
611  function, this_handler->handler_);
612  }
613 
614  template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
615  typename CompletionCondition, typename WriteHandler>
616  inline write_at_op<AsyncRandomAccessWriteDevice,
617  ConstBufferSequence, CompletionCondition, WriteHandler>
618  make_write_at_op(AsyncRandomAccessWriteDevice& d,
619  uint64_t offset, const ConstBufferSequence& buffers,
620  CompletionCondition completion_condition, WriteHandler handler)
621  {
622  return write_at_op<AsyncRandomAccessWriteDevice,
623  ConstBufferSequence, CompletionCondition, WriteHandler>(
624  d, offset, buffers, completion_condition, handler);
625  }
626 } // namespace detail
627 
628 template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
629  typename CompletionCondition, typename WriteHandler>
630 inline ASIO_INITFN_RESULT_TYPE(WriteHandler,
631  void (asio::error_code, std::size_t))
632 async_write_at(AsyncRandomAccessWriteDevice& d,
633  uint64_t offset, const ConstBufferSequence& buffers,
634  CompletionCondition completion_condition,
635  ASIO_MOVE_ARG(WriteHandler) handler)
636 {
637  // If you get an error on the following line it means that your handler does
638  // not meet the documented type requirements for a WriteHandler.
639  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
640 
642  WriteHandler, void (asio::error_code, std::size_t)> init(
643  ASIO_MOVE_CAST(WriteHandler)(handler));
644 
645  detail::write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
646  CompletionCondition, ASIO_HANDLER_TYPE(
647  WriteHandler, void (asio::error_code, std::size_t))>(
649  asio::error_code(), 0, 1);
650 
651  return init.result.get();
652 }
653 
654 template <typename AsyncRandomAccessWriteDevice, typename ConstBufferSequence,
655  typename WriteHandler>
656 inline ASIO_INITFN_RESULT_TYPE(WriteHandler,
657  void (asio::error_code, std::size_t))
658 async_write_at(AsyncRandomAccessWriteDevice& d,
659  uint64_t offset, const ConstBufferSequence& buffers,
660  ASIO_MOVE_ARG(WriteHandler) handler)
661 {
662  // If you get an error on the following line it means that your handler does
663  // not meet the documented type requirements for a WriteHandler.
664  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
665 
667  WriteHandler, void (asio::error_code, std::size_t)> init(
668  ASIO_MOVE_CAST(WriteHandler)(handler));
669 
670  detail::write_at_op<AsyncRandomAccessWriteDevice, ConstBufferSequence,
672  WriteHandler, void (asio::error_code, std::size_t))>(
673  d, offset, buffers, transfer_all(), init.handler)(
674  asio::error_code(), 0, 1);
675 
676  return init.result.get();
677 }
678 
679 #if !defined(ASIO_NO_IOSTREAM)
680 
681 namespace detail
682 {
683  template <typename Allocator, typename WriteHandler>
685  {
686  public:
689  WriteHandler& handler)
690  : streambuf_(streambuf),
691  handler_(ASIO_MOVE_CAST(WriteHandler)(handler))
692  {
693  }
694 
695 #if defined(ASIO_HAS_MOVE)
697  : streambuf_(other.streambuf_),
698  handler_(other.handler_)
699  {
700  }
701 
703  : streambuf_(other.streambuf_),
704  handler_(ASIO_MOVE_CAST(WriteHandler)(other.handler_))
705  {
706  }
707 #endif // defined(ASIO_HAS_MOVE)
708 
709  void operator()(const asio::error_code& ec,
710  const std::size_t bytes_transferred)
711  {
712  streambuf_.consume(bytes_transferred);
713  handler_(ec, bytes_transferred);
714  }
715 
716  //private:
718  WriteHandler handler_;
719  };
720 
721  template <typename Allocator, typename WriteHandler>
722  inline void* asio_handler_allocate(std::size_t size,
724  {
726  size, this_handler->handler_);
727  }
728 
729  template <typename Allocator, typename WriteHandler>
730  inline void asio_handler_deallocate(void* pointer, std::size_t size,
732  {
734  pointer, size, this_handler->handler_);
735  }
736 
737  template <typename Allocator, typename WriteHandler>
740  {
742  this_handler->handler_);
743  }
744 
745  template <typename Function, typename Allocator, typename WriteHandler>
746  inline void asio_handler_invoke(Function& function,
748  {
750  function, this_handler->handler_);
751  }
752 
753  template <typename Function, typename Allocator, typename WriteHandler>
754  inline void asio_handler_invoke(const Function& function,
756  {
758  function, this_handler->handler_);
759  }
760 
761  template <typename Allocator, typename WriteHandler>
764  asio::basic_streambuf<Allocator>& b, WriteHandler handler)
765  {
767  }
768 } // namespace detail
769 
770 template <typename AsyncRandomAccessWriteDevice, typename Allocator,
771  typename CompletionCondition, typename WriteHandler>
772 inline ASIO_INITFN_RESULT_TYPE(WriteHandler,
773  void (asio::error_code, std::size_t))
774 async_write_at(AsyncRandomAccessWriteDevice& d,
775  uint64_t offset, asio::basic_streambuf<Allocator>& b,
776  CompletionCondition completion_condition,
777  ASIO_MOVE_ARG(WriteHandler) handler)
778 {
779  // If you get an error on the following line it means that your handler does
780  // not meet the documented type requirements for a WriteHandler.
781  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
782 
784  WriteHandler, void (asio::error_code, std::size_t)> init(
785  ASIO_MOVE_CAST(WriteHandler)(handler));
786 
787  async_write_at(d, offset, b.data(), completion_condition,
789  WriteHandler, void (asio::error_code, std::size_t))>(
790  b, init.handler));
791 
792  return init.result.get();
793 }
794 
795 template <typename AsyncRandomAccessWriteDevice, typename Allocator,
796  typename WriteHandler>
797 inline ASIO_INITFN_RESULT_TYPE(WriteHandler,
798  void (asio::error_code, std::size_t))
799 async_write_at(AsyncRandomAccessWriteDevice& d,
800  uint64_t offset, asio::basic_streambuf<Allocator>& b,
801  ASIO_MOVE_ARG(WriteHandler) handler)
802 {
803  // If you get an error on the following line it means that your handler does
804  // not meet the documented type requirements for a WriteHandler.
805  ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
806 
808  WriteHandler, void (asio::error_code, std::size_t)> init(
809  ASIO_MOVE_CAST(WriteHandler)(handler));
810 
811  async_write_at(d, offset, b.data(), transfer_all(),
813  WriteHandler, void (asio::error_code, std::size_t))>(
814  b, init.handler));
815 
816  return init.result.get();
817 }
818 
819 #endif // !defined(ASIO_NO_IOSTREAM)
820 
821 } // namespace asio
822 
824 
825 #endif // ASIO_IMPL_WRITE_AT_HPP
void asio_handler_deallocate(void *pointer, std::size_t size, binder1< Handler, Arg1 > *this_handler)
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
Definition: write_at.hpp:265
asio::detail::consuming_buffers< const_buffer, ConstBufferSequence > buffers_
Definition: write_at.hpp:213
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
Definition: write_at.hpp:345
void throw_error(const asio::error_code &err)
Definition: throw_error.hpp:31
asio::basic_streambuf< Allocator > & streambuf_
Definition: write_at.hpp:717
Holds a buffer that cannot be modified.
Definition: buffer.hpp:211
std::size_t check_for_completion(const asio::error_code &ec, std::size_t total_transferred)
void * asio_handler_allocate(std::size_t size, binder1< Handler, Arg1 > *this_handler)
AsyncRandomAccessWriteDevice & device_
Definition: write_at.hpp:210
std::size_t total_transferred_
Definition: write_at.hpp:215
asio::basic_streambuf< Allocator > MatchCondition enable_if< is_match_condition< MatchCondition >::value >::type *detail::async_result_init< ReadHandler, void(asio::error_code, std::size_t)> init(ASIO_MOVE_CAST(ReadHandler)(handler))
#define ASIO_HANDLER_TYPE(h, sig)
STL namespace.
mutable_buffers_1 buffer(const mutable_buffer &b)
Create a new modifiable buffer from an existing buffer.
Definition: buffer.hpp:706
write_at_op(AsyncRandomAccessWriteDevice &device, uint64_t offset, const boost::array< Elem, 2 > &buffers, CompletionCondition completion_condition, WriteHandler &handler)
Definition: write_at.hpp:386
uint64_t offset
Definition: read_at.hpp:571
detail::transfer_all_t transfer_all()
write_at_streambuf_op(asio::basic_streambuf< Allocator > &streambuf, WriteHandler &handler)
Definition: write_at.hpp:687
write_at_op(AsyncRandomAccessWriteDevice &device, uint64_t offset, const asio::const_buffers_1 &buffers, CompletionCondition completion_condition, WriteHandler &handler)
Definition: write_at.hpp:306
asio::basic_streambuf< Allocator > & b
Definition: read.hpp:702
ASIO_INITFN_RESULT_TYPE(ComposedConnectHandler, void(asio::error_code, Iterator)) async_connect(basic_socket< Protocol
std::size_t buffer_size(const mutable_buffer &b)
Get the number of bytes in a modifiable buffer.
Definition: buffer.hpp:357
std::size_t write_at(SyncRandomAccessWriteDevice &d, uint64_t offset, const ConstBufferSequence &buffers, CompletionCondition completion_condition, asio::error_code &ec)
Write a certain amount of data at a specified offset before returning.
Definition: write_at.hpp:37
void invoke(Function &function, Context &context)
const MutableBufferSequence & buffers
Definition: read.hpp:521
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
Definition: write_at.hpp:424
void operator()(const asio::error_code &ec, std::size_t bytes_transferred, int start=0)
Definition: write_at.hpp:184
Holds a buffer that can be modified.
Definition: buffer.hpp:91
write_at_streambuf_op< Allocator, WriteHandler > make_write_at_streambuf_op(asio::basic_streambuf< Allocator > &b, WriteHandler handler)
Definition: write_at.hpp:763
void asio_handler_invoke(Function &function, binder1< Handler, Arg1 > *this_handler)
write_at_op(AsyncRandomAccessWriteDevice &device, uint64_t offset, const asio::mutable_buffers_1 &buffers, CompletionCondition completion_condition, WriteHandler &handler)
Definition: write_at.hpp:226
asio::basic_streambuf< Allocator > CompletionCondition ASIO_MOVE_ARG(ReadHandler) handler)
Definition: read.hpp:704
bool is_continuation(Context &context)
Class to represent an error code value.
Definition: error_code.hpp:80
void deallocate(void *p, std::size_t s, Handler &h)
std::size_t adapt_completion_condition_result(bool result)
void operator()(const asio::error_code &ec, const std::size_t bytes_transferred)
Definition: write_at.hpp:709
Automatically resizable buffer class based on std::streambuf.
void * allocate(std::size_t s, Handler &h)
write_at_op(AsyncRandomAccessWriteDevice &device, uint64_t offset, const ConstBufferSequence &buffers, CompletionCondition completion_condition, WriteHandler &handler)
Definition: write_at.hpp:146
const MutableBufferSequence CompletionCondition completion_condition
Definition: read.hpp:521
handler_type< Handler, Signature >::type handler
#define ASIO_MOVE_CAST(type)
Definition: config.hpp:138
write_at_op< AsyncRandomAccessWriteDevice, ConstBufferSequence, CompletionCondition, WriteHandler > make_write_at_op(AsyncRandomAccessWriteDevice &d, uint64_t offset, const ConstBufferSequence &buffers, CompletionCondition completion_condition, WriteHandler handler)
Definition: write_at.hpp:618
async_result< typename handler_type< Handler, Signature >::type > result
const_buffers_type data() const
Get a list of buffers that represents the input sequence.
void consume(std::size_t n)
Remove characters from the input sequence.
#define ASIO_WRITE_HANDLER_CHECK(handler_type, handler)
bool asio_handler_is_continuation(binder1< Handler, Arg1 > *this_handler)