]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
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> | |
18 | ||
19 | namespace boost{namespace icl | |
20 | { | |
21 | namespace segmental | |
22 | { | |
23 | template <typename ElementContainerT, typename IntervalContainerT> | |
24 | void atomize(ElementContainerT& result, const IntervalContainerT& src) | |
25 | { | |
26 | ICL_const_FORALL(typename IntervalContainerT, itv_, src) | |
27 | { | |
28 | const typename IntervalContainerT::key_type& itv = icl::key_value<IntervalContainerT>(itv_); | |
29 | typename IntervalContainerT::codomain_type coval = icl::co_value<IntervalContainerT>(itv_); | |
30 | ||
31 | for(typename IntervalContainerT::domain_type element = first(itv); element <= last(itv); ++element) | |
32 | icl::insert(result, icl::make_value<ElementContainerT>(element, coval)); | |
33 | } | |
34 | } | |
35 | ||
36 | template <typename IntervalContainerT, typename ElementContainerT> | |
37 | void cluster(IntervalContainerT& result, const ElementContainerT& src) | |
38 | { | |
39 | typedef typename IntervalContainerT::key_type key_type; | |
40 | ICL_const_FORALL(typename ElementContainerT, element_, src) | |
41 | { | |
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_); | |
46 | ||
47 | result += icl::make_value<IntervalContainerT>(key_type(key), coval); | |
48 | } | |
49 | } | |
50 | ||
51 | template <typename AtomizedType, typename ClusteredType> | |
52 | struct atomizer | |
53 | { | |
54 | void operator()(AtomizedType& atomized, const ClusteredType& clustered) | |
55 | { | |
56 | segmental::atomize(atomized, clustered); | |
57 | } | |
58 | }; | |
59 | ||
60 | template <typename ClusteredType, typename AtomizedType> | |
61 | struct clusterer | |
62 | { | |
63 | void operator()(ClusteredType& clustered, const AtomizedType& atomized) | |
64 | { | |
65 | segmental::cluster(clustered, atomized); | |
66 | } | |
67 | }; | |
68 | ||
69 | template <typename JointType, typename SplitType> | |
70 | struct joiner | |
71 | { | |
72 | void operator()(JointType& joint, SplitType& split) | |
73 | { | |
74 | icl::join(split); | |
75 | ICL_FORALL(typename SplitType, split_, split) | |
76 | joint.insert(*split_); | |
77 | } | |
78 | }; | |
79 | ||
80 | template <typename AbsorberType, typename EnricherType> | |
81 | struct identity_absorber | |
82 | { | |
83 | void operator()(AbsorberType& absorber, EnricherType& enricher) | |
84 | { | |
85 | icl::absorb_identities(enricher); | |
86 | ICL_FORALL(typename EnricherType, enricher_, enricher) | |
87 | absorber.insert(*enricher_); | |
88 | } | |
89 | }; | |
90 | ||
91 | } // namespace Interval | |
92 | ||
93 | ||
94 | template<> | |
95 | inline std::string binary_template_to_string<segmental::atomizer>::apply() { return "@"; } | |
96 | template<> | |
97 | inline std::string binary_template_to_string<segmental::clusterer>::apply() { return "&"; } | |
98 | template<> | |
99 | inline std::string binary_template_to_string<segmental::joiner>::apply() { return "j"; } | |
100 | template<> | |
101 | inline std::string binary_template_to_string<segmental::identity_absorber>::apply() { return "a0"; } | |
102 | }} // namespace boost icl | |
103 | ||
104 | #endif // BOOST_ICL_DETAIL_INTERVAL_MORPHISM_HPP_JOFA_080315 | |
105 | ||
106 | ||
107 |