interval_morphism.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*-----------------------------------------------------------------------------+
  2. Copyright (c) 2008-2009: Joachim Faulhaber
  3. +------------------------------------------------------------------------------+
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENCE.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. +-----------------------------------------------------------------------------*/
  8. #ifndef BOOST_ICL_DETAIL_INTERVAL_MORPHISM_HPP_JOFA_080315
  9. #define BOOST_ICL_DETAIL_INTERVAL_MORPHISM_HPP_JOFA_080315
  10. #include <boost/icl/detail/notate.hpp>
  11. #include <boost/icl/concept/interval_set_value.hpp>
  12. #include <boost/icl/concept/element_set_value.hpp>
  13. #include <boost/icl/concept/set_value.hpp>
  14. #include <boost/icl/concept/map_value.hpp>
  15. #include <boost/icl/associative_interval_container.hpp>
  16. #include <boost/icl/associative_element_container.hpp>
  17. namespace boost{namespace icl
  18. {
  19. namespace segmental
  20. {
  21. template <typename ElementContainerT, typename IntervalContainerT>
  22. void atomize(ElementContainerT& result, const IntervalContainerT& src)
  23. {
  24. ICL_const_FORALL(typename IntervalContainerT, itv_, src)
  25. {
  26. const typename IntervalContainerT::key_type& itv = icl::key_value<IntervalContainerT>(itv_);
  27. typename IntervalContainerT::codomain_type coval = icl::co_value<IntervalContainerT>(itv_);
  28. for(typename IntervalContainerT::domain_type element = first(itv); element <= last(itv); ++element)
  29. icl::insert(result, icl::make_value<ElementContainerT>(element, coval));
  30. }
  31. }
  32. template <typename IntervalContainerT, typename ElementContainerT>
  33. void cluster(IntervalContainerT& result, const ElementContainerT& src)
  34. {
  35. typedef typename IntervalContainerT::key_type key_type;
  36. ICL_const_FORALL(typename ElementContainerT, element_, src)
  37. {
  38. const typename ElementContainerT::key_type& key
  39. = key_value<ElementContainerT>(element_);
  40. const typename codomain_type_of<ElementContainerT>::type& coval
  41. = co_value<ElementContainerT>(element_);
  42. result += icl::make_value<IntervalContainerT>(key_type(key), coval);
  43. }
  44. }
  45. template <typename AtomizedType, typename ClusteredType>
  46. struct atomizer
  47. {
  48. void operator()(AtomizedType& atomized, const ClusteredType& clustered)
  49. {
  50. segmental::atomize(atomized, clustered);
  51. }
  52. };
  53. template <typename ClusteredType, typename AtomizedType>
  54. struct clusterer
  55. {
  56. void operator()(ClusteredType& clustered, const AtomizedType& atomized)
  57. {
  58. segmental::cluster(clustered, atomized);
  59. }
  60. };
  61. template <typename JointType, typename SplitType>
  62. struct joiner
  63. {
  64. void operator()(JointType& joint, SplitType& split)
  65. {
  66. icl::join(split);
  67. ICL_FORALL(typename SplitType, split_, split)
  68. joint.insert(*split_);
  69. }
  70. };
  71. template <typename AbsorberType, typename EnricherType>
  72. struct identity_absorber
  73. {
  74. void operator()(AbsorberType& absorber, EnricherType& enricher)
  75. {
  76. icl::absorb_identities(enricher);
  77. ICL_FORALL(typename EnricherType, enricher_, enricher)
  78. absorber.insert(*enricher_);
  79. }
  80. };
  81. } // namespace Interval
  82. template<>
  83. inline std::string binary_template_to_string<segmental::atomizer>::apply() { return "@"; }
  84. template<>
  85. inline std::string binary_template_to_string<segmental::clusterer>::apply() { return "&"; }
  86. template<>
  87. inline std::string binary_template_to_string<segmental::joiner>::apply() { return "j"; }
  88. template<>
  89. inline std::string binary_template_to_string<segmental::identity_absorber>::apply() { return "a0"; }
  90. }} // namespace boost icl
  91. #endif // BOOST_ICL_DETAIL_INTERVAL_MORPHISM_HPP_JOFA_080315