parameter.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // boost lockfree
  2. //
  3. // Copyright (C) 2011, 2016 Tim Blechmann
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_LOCKFREE_DETAIL_PARAMETER_HPP
  9. #define BOOST_LOCKFREE_DETAIL_PARAMETER_HPP
  10. #include <boost/align/aligned_allocator.hpp>
  11. #include <boost/core/allocator_access.hpp>
  12. #include <boost/lockfree/detail/prefix.hpp>
  13. #include <boost/lockfree/policies.hpp>
  14. #include <boost/parameter/binding.hpp>
  15. #include <type_traits>
  16. namespace boost { namespace lockfree { namespace detail {
  17. //----------------------------------------------------------------------------------------------------------------------
  18. template < typename bound_args, typename tag_type, typename default_ >
  19. using extract_arg_or_default_t = typename parameter::binding< bound_args, tag_type, default_ >::type;
  20. template < typename BoundArgs, typename TypeTag, typename IntegralType, IntegralType default_ = IntegralType {} >
  21. struct extract_integral_arg_or_default_t
  22. {
  23. static constexpr IntegralType value
  24. = extract_arg_or_default_t< BoundArgs, TypeTag, std::integral_constant< IntegralType, default_ > >::value;
  25. };
  26. struct no_such_parameter_t
  27. {};
  28. template < typename bound_args, typename tag_type >
  29. using has_no_arg_t
  30. = std::is_same< extract_arg_or_default_t< bound_args, tag_type, no_such_parameter_t >, no_such_parameter_t >;
  31. //----------------------------------------------------------------------------------------------------------------------
  32. template < typename bound_args >
  33. struct extract_capacity
  34. {
  35. using capacity_t = extract_arg_or_default_t< bound_args, tag::capacity, std::integral_constant< size_t, 0 > >;
  36. using has_no_capacity_t = has_no_arg_t< bound_args, tag::capacity >;
  37. static constexpr std::size_t capacity = capacity_t::value;
  38. static constexpr bool has_capacity = !has_no_capacity_t::value;
  39. };
  40. template < typename bound_args >
  41. using extract_capacity_t = typename extract_capacity< bound_args >::type;
  42. //----------------------------------------------------------------------------------------------------------------------
  43. template < typename bound_args, typename T >
  44. struct extract_allocator
  45. {
  46. using default_allocator = boost::alignment::aligned_allocator< T, cacheline_bytes >;
  47. using allocator_t = extract_arg_or_default_t< bound_args, tag::allocator, default_allocator >;
  48. using has_no_allocator_t = has_no_arg_t< bound_args, tag::allocator >;
  49. static constexpr bool has_allocator = !has_no_allocator_t::value;
  50. typedef typename boost::allocator_rebind< allocator_t, T >::type type;
  51. };
  52. template < typename bound_args, typename T >
  53. using extract_allocator_t = typename extract_allocator< bound_args, T >::type;
  54. //----------------------------------------------------------------------------------------------------------------------
  55. template < typename bound_args, bool default_ = false >
  56. using extract_fixed_sized = extract_integral_arg_or_default_t< bound_args, tag::fixed_sized, bool, default_ >;
  57. //----------------------------------------------------------------------------------------------------------------------
  58. template < typename bound_args, bool default_ = false >
  59. using extract_allow_multiple_reads
  60. = extract_integral_arg_or_default_t< bound_args, tag::allow_multiple_reads, bool, default_ >;
  61. //----------------------------------------------------------------------------------------------------------------------
  62. }}} // namespace boost::lockfree::detail
  63. #endif /* BOOST_LOCKFREE_DETAIL_PARAMETER_HPP */