Realistic 3D camera system
3D camera system components
completion_condition.hpp
Go to the documentation of this file.
1 //
2 // completion_condition.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_COMPLETION_CONDITION_HPP
12 #define ASIO_COMPLETION_CONDITION_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/detail/config.hpp"
19 #include <cstddef>
20 
22 
23 namespace asio {
24 
25 namespace detail {
26 
27 // The default maximum number of bytes to transfer in a single operation.
29 
30 // Adapt result of old-style completion conditions (which had a bool result
31 // where true indicated that the operation was complete).
32 inline std::size_t adapt_completion_condition_result(bool result)
33 {
34  return result ? 0 : default_max_transfer_size;
35 }
36 
37 // Adapt result of current completion conditions (which have a size_t result
38 // where 0 means the operation is complete, and otherwise the result is the
39 // maximum number of bytes to transfer on the next underlying operation).
40 inline std::size_t adapt_completion_condition_result(std::size_t result)
41 {
42  return result;
43 }
44 
46 {
47 public:
48  typedef std::size_t result_type;
49 
50  template <typename Error>
51  std::size_t operator()(const Error& err, std::size_t)
52  {
53  return !!err ? 0 : default_max_transfer_size;
54  }
55 };
56 
58 {
59 public:
60  typedef std::size_t result_type;
61 
62  explicit transfer_at_least_t(std::size_t minimum)
63  : minimum_(minimum)
64  {
65  }
66 
67  template <typename Error>
68  std::size_t operator()(const Error& err, std::size_t bytes_transferred)
69  {
70  return (!!err || bytes_transferred >= minimum_)
72  }
73 
74 private:
75  std::size_t minimum_;
76 };
77 
79 {
80 public:
81  typedef std::size_t result_type;
82 
83  explicit transfer_exactly_t(std::size_t size)
84  : size_(size)
85  {
86  }
87 
88  template <typename Error>
89  std::size_t operator()(const Error& err, std::size_t bytes_transferred)
90  {
91  return (!!err || bytes_transferred >= size_) ? 0 :
92  (size_ - bytes_transferred < default_max_transfer_size
93  ? size_ - bytes_transferred : std::size_t(default_max_transfer_size));
94  }
95 
96 private:
97  std::size_t size_;
98 };
99 
100 } // namespace detail
101 
109 
113 
135 #if defined(GENERATING_DOCUMENTATION)
136 unspecified transfer_all();
137 #else
139 {
140  return detail::transfer_all_t();
141 }
142 #endif
143 
147 
169 #if defined(GENERATING_DOCUMENTATION)
170 unspecified transfer_at_least(std::size_t minimum);
171 #else
173 {
174  return detail::transfer_at_least_t(minimum);
175 }
176 #endif
177 
181 
203 #if defined(GENERATING_DOCUMENTATION)
204 unspecified transfer_exactly(std::size_t size);
205 #else
207 {
208  return detail::transfer_exactly_t(size);
209 }
210 #endif
211 
214 } // namespace asio
215 
217 
218 #endif // ASIO_COMPLETION_CONDITION_HPP
detail::transfer_exactly_t transfer_exactly(std::size_t size)
std::size_t operator()(const Error &err, std::size_t bytes_transferred)
std::size_t operator()(const Error &err, std::size_t bytes_transferred)
detail::transfer_all_t transfer_all()
detail::transfer_at_least_t transfer_at_least(std::size_t minimum)
std::size_t adapt_completion_condition_result(bool result)
std::size_t operator()(const Error &err, std::size_t)