manage_additional_parameters.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. // Boost.Bimap
  2. //
  3. // Copyright (c) 2006-2007 Matias Capeletto
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. /// \file detail/manage_additional_parameters.hpp
  9. /// \brief Utility class to extract the additional parameters from the template parameters.
  10. #ifndef BOOST_BIMAP_DETAIL_MANAGE_ADDITIONAL_PARAMETERS_HPP
  11. #define BOOST_BIMAP_DETAIL_MANAGE_ADDITIONAL_PARAMETERS_HPP
  12. #if defined(_MSC_VER)
  13. #pragma once
  14. #endif
  15. #include <boost/config.hpp>
  16. #include <memory>
  17. // Boost.MPL
  18. #include <boost/mpl/bool.hpp>
  19. #include <boost/mpl/if.hpp>
  20. #include <boost/mpl/aux_/na.hpp>
  21. #include <boost/type_traits/is_same.hpp>
  22. #include <boost/bimap/detail/is_set_type_of.hpp>
  23. namespace boost {
  24. namespace bimaps {
  25. template< class Type >
  26. struct with_info
  27. {
  28. typedef Type value_type;
  29. };
  30. namespace detail {
  31. /// \brief Metafunction to check if a given type is a data_hook specification.
  32. template< class Type >
  33. struct is_with_info : ::boost::mpl::false_ {};
  34. template< class ValueType >
  35. struct is_with_info< with_info<ValueType> > : ::boost::mpl::true_ {};
  36. /** \struct boost::bimaps::detail::manage_additional_parameters
  37. \brief Utility class to extract the additional parameters from the template parameters.
  38. \code
  39. template< class AP1, class AP2, class AP3 >
  40. struct manage_additional_parameters
  41. {
  42. struct parameters
  43. {
  44. typedef -unspecified- set_type_of_relation;
  45. typedef -unspecified- data_hook;
  46. typedef -unspecified- allocator;
  47. };
  48. typedef parameters type;
  49. };
  50. \endcode
  51. See also bimap, bimap_core.
  52. **/
  53. #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  54. template< class AP1, class AP2, class AP3 >
  55. struct manage_additional_parameters
  56. {
  57. // (1) manage_additional_parameters<
  58. // not_specified,not_specified,not_specified>
  59. //
  60. // set_type_of_relation: based on the left key type
  61. // info_hook: no additional info
  62. // allocator: default allocator
  63. struct case_NNN
  64. {
  65. typedef left_based set_type_of_relation;
  66. typedef std::allocator<char> allocator;
  67. typedef ::boost::mpl::na additional_info;
  68. };
  69. // (2) manage_additional_parameters<Allocator,not_specified,not_specified>
  70. //
  71. // set_type_of_relation: based on the left key type
  72. // info_hook: no additional info
  73. // allocator: Allocator
  74. struct case_ANN
  75. {
  76. typedef left_based set_type_of_relation;
  77. typedef AP1 allocator;
  78. typedef ::boost::mpl::na additional_info;
  79. };
  80. // (3) manage_additional_parameters<
  81. // SetOfRelationType,not_specified,not_specified>
  82. //
  83. // set_type_of_relation: SetTypeOfRelation
  84. // info_hook: no additional info
  85. // allocator: default allocator
  86. struct case_SNN
  87. {
  88. typedef AP1 set_type_of_relation;
  89. typedef std::allocator<char> allocator;
  90. typedef ::boost::mpl::na additional_info;
  91. };
  92. // (4) manage_additional_parameters<
  93. // SetTypeOfRelation,Allocator,not_specified>
  94. //
  95. // set_type_of_relation: SetTypeOfRelation
  96. // info_hook: no additional info
  97. // allocator: Allocator
  98. struct case_SAN
  99. {
  100. typedef AP1 set_type_of_relation;
  101. typedef AP2 allocator;
  102. typedef ::boost::mpl::na additional_info;
  103. };
  104. // (5) manage_additional_parameters<InfoToHook,not_specified,not_specified>
  105. //
  106. // set_type_of_relation: based on the left key type
  107. // info_hook: InfoToHook
  108. // allocator: default allocator
  109. struct case_HNN
  110. {
  111. typedef left_based set_type_of_relation;
  112. typedef std::allocator<char> allocator;
  113. typedef BOOST_DEDUCED_TYPENAME AP1::value_type additional_info;
  114. };
  115. // (6) manage_additional_parameters<
  116. // SetTypeOfRelation,InfoToHook,not_specified>
  117. //
  118. // set_type_of_relation: SetTypeOfRelation
  119. // info_hook: InfoToHook
  120. // allocator: default allocator
  121. struct case_SHN
  122. {
  123. typedef AP1 set_type_of_relation;
  124. typedef std::allocator<char> allocator;
  125. typedef BOOST_DEDUCED_TYPENAME AP2::value_type additional_info;
  126. };
  127. // (7) manage_additional_parameters<
  128. // DataToHook,Allocator,not_specified>
  129. //
  130. // set_type_of_relation: SetTypeOfRelation
  131. // info_hook: InfoToHook
  132. // allocator: default allocator
  133. struct case_HAN
  134. {
  135. typedef left_based set_type_of_relation;
  136. typedef AP2 allocator;
  137. typedef BOOST_DEDUCED_TYPENAME AP1::value_type additional_info;
  138. };
  139. // (8) manage_additional_parameters<
  140. // SetTypeOfRelation,DataToHook,Allocator>
  141. //
  142. // set_type_of_relation: SetTypeOfRelation
  143. // info_hook: InfoToHook
  144. // allocator: Allocator
  145. struct case_SHA
  146. {
  147. typedef AP1 set_type_of_relation;
  148. typedef AP2 allocator;
  149. typedef BOOST_DEDUCED_TYPENAME AP2::value_type additional_info;
  150. };
  151. // Some annidated mpl::if_ and we are done!
  152. typedef BOOST_DEDUCED_TYPENAME mpl::if_
  153. <
  154. ::boost::mpl::is_na<AP1>,
  155. case_NNN, // (1)
  156. BOOST_DEDUCED_TYPENAME mpl::if_
  157. <
  158. ::boost::mpl::is_na<AP2>,
  159. BOOST_DEDUCED_TYPENAME mpl::if_
  160. <
  161. is_set_type_of_relation<AP1>,
  162. case_SNN, // (3)
  163. BOOST_DEDUCED_TYPENAME mpl::if_
  164. <
  165. is_with_info<AP1>,
  166. case_HNN, // (5)
  167. case_ANN // (2)
  168. >::type
  169. >::type,
  170. BOOST_DEDUCED_TYPENAME mpl::if_
  171. <
  172. ::boost::mpl::is_na<AP3>,
  173. BOOST_DEDUCED_TYPENAME mpl::if_
  174. <
  175. is_with_info<AP1>,
  176. case_HAN, // (7)
  177. BOOST_DEDUCED_TYPENAME mpl::if_
  178. <
  179. is_with_info<AP2>,
  180. case_SHN, // (6)
  181. case_SAN // (4)
  182. >::type
  183. >::type,
  184. case_SHA // (8)
  185. >::type
  186. >::type
  187. >::type type;
  188. };
  189. #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  190. } // namespace detail
  191. } // namespace bimaps
  192. } // namespace boost
  193. #endif // BOOST_BIMAP_DETAIL_MANAGE_ADDITIONAL_PARAMETERS_HPP