Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

is_buffer_sequence.hpp 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. //
  2. // detail/is_buffer_sequence.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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. #ifndef ASIO_DETAIL_IS_BUFFER_SEQUENCE_HPP
  11. #define ASIO_DETAIL_IS_BUFFER_SEQUENCE_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #include "asio/detail/type_traits.hpp"
  17. #include "asio/detail/push_options.hpp"
  18. namespace asio {
  19. class mutable_buffer;
  20. class const_buffer;
  21. namespace detail {
  22. struct buffer_sequence_memfns_base
  23. {
  24. void begin();
  25. void end();
  26. void size();
  27. void max_size();
  28. void capacity();
  29. void data();
  30. void prepare();
  31. void commit();
  32. void consume();
  33. void grow();
  34. void shrink();
  35. };
  36. template <typename T>
  37. struct buffer_sequence_memfns_derived
  38. : T, buffer_sequence_memfns_base
  39. {
  40. };
  41. template <typename T, T>
  42. struct buffer_sequence_memfns_check
  43. {
  44. };
  45. template <typename>
  46. char (&buffer_sequence_begin_helper(...))[2];
  47. #if defined(ASIO_HAS_DECLTYPE)
  48. template <typename T>
  49. char buffer_sequence_begin_helper(T* t,
  50. typename enable_if<!is_same<
  51. decltype(asio::buffer_sequence_begin(*t)),
  52. void>::value>::type*);
  53. #else // defined(ASIO_HAS_DECLTYPE)
  54. template <typename T>
  55. char buffer_sequence_begin_helper(T* t,
  56. buffer_sequence_memfns_check<
  57. void (buffer_sequence_memfns_base::*)(),
  58. &buffer_sequence_memfns_derived<T>::begin>*);
  59. #endif // defined(ASIO_HAS_DECLTYPE)
  60. template <typename>
  61. char (&buffer_sequence_end_helper(...))[2];
  62. #if defined(ASIO_HAS_DECLTYPE)
  63. template <typename T>
  64. char buffer_sequence_end_helper(T* t,
  65. typename enable_if<!is_same<
  66. decltype(asio::buffer_sequence_end(*t)),
  67. void>::value>::type*);
  68. #else // defined(ASIO_HAS_DECLTYPE)
  69. template <typename T>
  70. char buffer_sequence_end_helper(T* t,
  71. buffer_sequence_memfns_check<
  72. void (buffer_sequence_memfns_base::*)(),
  73. &buffer_sequence_memfns_derived<T>::end>*);
  74. #endif // defined(ASIO_HAS_DECLTYPE)
  75. template <typename>
  76. char (&size_memfn_helper(...))[2];
  77. template <typename T>
  78. char size_memfn_helper(
  79. buffer_sequence_memfns_check<
  80. void (buffer_sequence_memfns_base::*)(),
  81. &buffer_sequence_memfns_derived<T>::size>*);
  82. template <typename>
  83. char (&max_size_memfn_helper(...))[2];
  84. template <typename T>
  85. char max_size_memfn_helper(
  86. buffer_sequence_memfns_check<
  87. void (buffer_sequence_memfns_base::*)(),
  88. &buffer_sequence_memfns_derived<T>::max_size>*);
  89. template <typename>
  90. char (&capacity_memfn_helper(...))[2];
  91. template <typename T>
  92. char capacity_memfn_helper(
  93. buffer_sequence_memfns_check<
  94. void (buffer_sequence_memfns_base::*)(),
  95. &buffer_sequence_memfns_derived<T>::capacity>*);
  96. template <typename>
  97. char (&data_memfn_helper(...))[2];
  98. template <typename T>
  99. char data_memfn_helper(
  100. buffer_sequence_memfns_check<
  101. void (buffer_sequence_memfns_base::*)(),
  102. &buffer_sequence_memfns_derived<T>::data>*);
  103. template <typename>
  104. char (&prepare_memfn_helper(...))[2];
  105. template <typename T>
  106. char prepare_memfn_helper(
  107. buffer_sequence_memfns_check<
  108. void (buffer_sequence_memfns_base::*)(),
  109. &buffer_sequence_memfns_derived<T>::prepare>*);
  110. template <typename>
  111. char (&commit_memfn_helper(...))[2];
  112. template <typename T>
  113. char commit_memfn_helper(
  114. buffer_sequence_memfns_check<
  115. void (buffer_sequence_memfns_base::*)(),
  116. &buffer_sequence_memfns_derived<T>::commit>*);
  117. template <typename>
  118. char (&consume_memfn_helper(...))[2];
  119. template <typename T>
  120. char consume_memfn_helper(
  121. buffer_sequence_memfns_check<
  122. void (buffer_sequence_memfns_base::*)(),
  123. &buffer_sequence_memfns_derived<T>::consume>*);
  124. template <typename>
  125. char (&grow_memfn_helper(...))[2];
  126. template <typename T>
  127. char grow_memfn_helper(
  128. buffer_sequence_memfns_check<
  129. void (buffer_sequence_memfns_base::*)(),
  130. &buffer_sequence_memfns_derived<T>::grow>*);
  131. template <typename>
  132. char (&shrink_memfn_helper(...))[2];
  133. template <typename T>
  134. char shrink_memfn_helper(
  135. buffer_sequence_memfns_check<
  136. void (buffer_sequence_memfns_base::*)(),
  137. &buffer_sequence_memfns_derived<T>::shrink>*);
  138. template <typename, typename>
  139. char (&buffer_sequence_element_type_helper(...))[2];
  140. #if defined(ASIO_HAS_DECLTYPE)
  141. template <typename T, typename Buffer>
  142. char buffer_sequence_element_type_helper(T* t,
  143. typename enable_if<is_convertible<
  144. decltype(*asio::buffer_sequence_begin(*t)),
  145. Buffer>::value>::type*);
  146. #else // defined(ASIO_HAS_DECLTYPE)
  147. template <typename T, typename Buffer>
  148. char buffer_sequence_element_type_helper(
  149. typename T::const_iterator*,
  150. typename enable_if<is_convertible<
  151. typename T::value_type, Buffer>::value>::type*);
  152. #endif // defined(ASIO_HAS_DECLTYPE)
  153. template <typename>
  154. char (&const_buffers_type_typedef_helper(...))[2];
  155. template <typename T>
  156. char const_buffers_type_typedef_helper(
  157. typename T::const_buffers_type*);
  158. template <typename>
  159. char (&mutable_buffers_type_typedef_helper(...))[2];
  160. template <typename T>
  161. char mutable_buffers_type_typedef_helper(
  162. typename T::mutable_buffers_type*);
  163. template <typename T, typename Buffer>
  164. struct is_buffer_sequence_class
  165. : integral_constant<bool,
  166. sizeof(buffer_sequence_begin_helper<T>(0)) != 1 &&
  167. sizeof(buffer_sequence_end_helper<T>(0)) != 1 &&
  168. sizeof(buffer_sequence_element_type_helper<T, Buffer>(0, 0)) == 1>
  169. {
  170. };
  171. template <typename T, typename Buffer>
  172. struct is_buffer_sequence
  173. : conditional<is_class<T>::value,
  174. is_buffer_sequence_class<T, Buffer>,
  175. false_type>::type
  176. {
  177. };
  178. template <>
  179. struct is_buffer_sequence<mutable_buffer, mutable_buffer>
  180. : true_type
  181. {
  182. };
  183. template <>
  184. struct is_buffer_sequence<mutable_buffer, const_buffer>
  185. : true_type
  186. {
  187. };
  188. template <>
  189. struct is_buffer_sequence<const_buffer, const_buffer>
  190. : true_type
  191. {
  192. };
  193. template <>
  194. struct is_buffer_sequence<const_buffer, mutable_buffer>
  195. : false_type
  196. {
  197. };
  198. template <typename T>
  199. struct is_dynamic_buffer_class_v1
  200. : integral_constant<bool,
  201. sizeof(size_memfn_helper<T>(0)) != 1 &&
  202. sizeof(max_size_memfn_helper<T>(0)) != 1 &&
  203. sizeof(capacity_memfn_helper<T>(0)) != 1 &&
  204. sizeof(data_memfn_helper<T>(0)) != 1 &&
  205. sizeof(consume_memfn_helper<T>(0)) != 1 &&
  206. sizeof(prepare_memfn_helper<T>(0)) != 1 &&
  207. sizeof(commit_memfn_helper<T>(0)) != 1 &&
  208. sizeof(const_buffers_type_typedef_helper<T>(0)) == 1 &&
  209. sizeof(mutable_buffers_type_typedef_helper<T>(0)) == 1>
  210. {
  211. };
  212. template <typename T>
  213. struct is_dynamic_buffer_v1
  214. : conditional<is_class<T>::value,
  215. is_dynamic_buffer_class_v1<T>,
  216. false_type>::type
  217. {
  218. };
  219. template <typename T>
  220. struct is_dynamic_buffer_class_v2
  221. : integral_constant<bool,
  222. sizeof(size_memfn_helper<T>(0)) != 1 &&
  223. sizeof(max_size_memfn_helper<T>(0)) != 1 &&
  224. sizeof(capacity_memfn_helper<T>(0)) != 1 &&
  225. sizeof(data_memfn_helper<T>(0)) != 1 &&
  226. sizeof(consume_memfn_helper<T>(0)) != 1 &&
  227. sizeof(grow_memfn_helper<T>(0)) != 1 &&
  228. sizeof(shrink_memfn_helper<T>(0)) != 1 &&
  229. sizeof(const_buffers_type_typedef_helper<T>(0)) == 1 &&
  230. sizeof(mutable_buffers_type_typedef_helper<T>(0)) == 1>
  231. {
  232. };
  233. template <typename T>
  234. struct is_dynamic_buffer_v2
  235. : conditional<is_class<T>::value,
  236. is_dynamic_buffer_class_v2<T>,
  237. false_type>::type
  238. {
  239. };
  240. } // namespace detail
  241. } // namespace asio
  242. #include "asio/detail/pop_options.hpp"
  243. #endif // ASIO_DETAIL_IS_BUFFER_SEQUENCE_HPP