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
11 #include <boost/icl/detail/notate.hpp>
12 #include <boost/icl/concept/interval_set_value.hpp>
13 #include <boost/icl/concept/element_set_value.hpp>
14 #include <boost/icl/concept/set_value.hpp>
15 #include <boost/icl/concept/map_value.hpp>
16 #include <boost/icl/associative_interval_container.hpp>
17 #include <boost/icl/associative_element_container.hpp>
19 namespace boost{namespace icl
23 template <typename ElementContainerT, typename IntervalContainerT>
24 void atomize(ElementContainerT& result, const IntervalContainerT& src)
26 ICL_const_FORALL(typename IntervalContainerT, itv_, src)
28 const typename IntervalContainerT::key_type& itv = icl::key_value<IntervalContainerT>(itv_);
29 typename IntervalContainerT::codomain_type coval = icl::co_value<IntervalContainerT>(itv_);
31 for(typename IntervalContainerT::domain_type element = first(itv); element <= last(itv); ++element)
32 icl::insert(result, icl::make_value<ElementContainerT>(element, coval));
36 template <typename IntervalContainerT, typename ElementContainerT>
37 void cluster(IntervalContainerT& result, const ElementContainerT& src)
39 typedef typename IntervalContainerT::key_type key_type;
40 ICL_const_FORALL(typename ElementContainerT, element_, src)
42 const typename ElementContainerT::key_type& key
43 = key_value<ElementContainerT>(element_);
44 const typename codomain_type_of<ElementContainerT>::type& coval
45 = co_value<ElementContainerT>(element_);
47 result += icl::make_value<IntervalContainerT>(key_type(key), coval);
51 template <typename AtomizedType, typename ClusteredType>
54 void operator()(AtomizedType& atomized, const ClusteredType& clustered)
56 segmental::atomize(atomized, clustered);
60 template <typename ClusteredType, typename AtomizedType>
63 void operator()(ClusteredType& clustered, const AtomizedType& atomized)
65 segmental::cluster(clustered, atomized);
69 template <typename JointType, typename SplitType>
72 void operator()(JointType& joint, SplitType& split)
75 ICL_FORALL(typename SplitType, split_, split)
76 joint.insert(*split_);
80 template <typename AbsorberType, typename EnricherType>
81 struct identity_absorber
83 void operator()(AbsorberType& absorber, EnricherType& enricher)
85 icl::absorb_identities(enricher);
86 ICL_FORALL(typename EnricherType, enricher_, enricher)
87 absorber.insert(*enricher_);
91 } // namespace Interval
95 inline std::string binary_template_to_string<segmental::atomizer>::apply() { return "@"; }
97 inline std::string binary_template_to_string<segmental::clusterer>::apply() { return "&"; }
99 inline std::string binary_template_to_string<segmental::joiner>::apply() { return "j"; }
101 inline std::string binary_template_to_string<segmental::identity_absorber>::apply() { return "a0"; }
102 }} // namespace boost icl
104 #endif // BOOST_ICL_DETAIL_INTERVAL_MORPHISM_HPP_JOFA_080315