data_extractor.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 relation/support/data_extractor.hpp
  9. /// \brief Data extraction functor.
  10. #ifndef BOOST_BIMAP_RELATION_SUPPORT_DATA_EXTRACTOR_HPP
  11. #define BOOST_BIMAP_RELATION_SUPPORT_DATA_EXTRACTOR_HPP
  12. #if defined(_MSC_VER)
  13. #pragma once
  14. #endif
  15. #include <boost/config.hpp>
  16. #include <boost/bimap/relation/detail/metadata_access_builder.hpp>
  17. /** \struct boost::bimaps::relation::support::data_extractor
  18. \brief Data extraction functor.
  19. \ingroup relation_group
  20. **/
  21. #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  22. namespace boost {
  23. namespace bimaps {
  24. namespace relation {
  25. namespace support {
  26. template< class Tag, class Relation >
  27. struct data_extractor_implementation;
  28. template< class Relation >
  29. struct data_extractor_implementation< member_at::left, Relation >
  30. {
  31. typedef Relation argument_type;
  32. typedef BOOST_DEDUCED_TYPENAME Relation::left_value_type result_type;
  33. BOOST_DEDUCED_TYPENAME Relation::left_value_type const &
  34. operator()(Relation const & rel) const
  35. {
  36. return rel.left;
  37. }
  38. BOOST_DEDUCED_TYPENAME Relation::left_value_type &
  39. operator()(Relation & rel) const
  40. {
  41. return rel.left;
  42. }
  43. };
  44. template< class Relation >
  45. struct data_extractor_implementation< member_at::right, Relation >
  46. {
  47. typedef Relation argument_type;
  48. typedef BOOST_DEDUCED_TYPENAME Relation::right_value_type result_type;
  49. BOOST_DEDUCED_TYPENAME Relation::right_value_type const &
  50. operator()(Relation const & rel) const
  51. {
  52. return rel.right;
  53. }
  54. BOOST_DEDUCED_TYPENAME Relation::right_value_type &
  55. operator()(Relation & rel) const
  56. {
  57. return rel.right;
  58. }
  59. };
  60. template< class Tag, class Relation >
  61. struct data_extractor
  62. {
  63. typedef data_extractor_implementation
  64. <
  65. BOOST_DEDUCED_TYPENAME member_with_tag<Tag,Relation>::type,
  66. Relation
  67. > type;
  68. };
  69. template< class Relation >
  70. struct both_keys_extractor
  71. {
  72. typedef BOOST_DEDUCED_TYPENAME Relation::storage_base result_type;
  73. const result_type & operator()(const Relation & rel) const
  74. {
  75. return rel;
  76. }
  77. result_type & operator()( Relation & rel) const
  78. {
  79. return rel;
  80. }
  81. };
  82. } // namespace support
  83. } // namespace relation
  84. } // namespace bimaps
  85. } // namespace boost
  86. #endif // BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
  87. #endif // BOOST_BIMAP_RELATION_SUPPORT_DATA_EXTRACTOR_HPP