Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
set/compute.hh
1 // Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_SET_COMPUTE_HH
27 # define MLN_SET_COMPUTE_HH
28 
32 
33 # include <mln/core/concept/meta_accumulator.hh>
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/site_set.hh>
36 
37 
38 namespace mln
39 {
40 
41  namespace set
42  {
43 
49  //
50  template <typename A, typename S>
51  mln_result(A)
52  compute(const Accumulator<A>& a, const Site_Set<S>& s);
53 
54 
59  // \return The accumulator result.
60  //
61  template <typename A, typename S>
62  mln_meta_accu_result(A, mln_site(S))
63  compute(const Meta_Accumulator<A>& a, const Site_Set<S>& s);
64 
65 
66 
67 # ifndef MLN_INCLUDE_ONLY
68 
69 
70  // Implementation.
71 
72 
73  namespace impl
74  {
75 
76  namespace generic
77  {
78 
79  template <typename A, typename S>
80  inline
81  mln_result(A)
82  compute(const Accumulator<A>& a_, const Site_Set<S>& s_)
83  {
84  trace::entering("set::impl::generic::compute");
85 
86  mlc_converts_to(mln_site(S), mln_argument(A))::check();
87 
88  A a = exact(a_);
89  const S& s = exact(s_);
90 
91  a.init();
92  mln_piter(S) p(s);
93  for_all(p)
94  a.take(p);
95 
96  trace::exiting("set::impl::generic::compute");
97  return a.to_result();
98  }
99 
100  } // end of namespace mln::set::impl::generic
101 
102  } // end of namespace mln::set::impl
103 
104 
105 
106  // Facades.
107 
108 
109  template <typename A, typename S>
110  inline
111  mln_result(A)
112  compute(const Accumulator<A>& a, const Site_Set<S>& s)
113  {
114  trace::entering("set::compute");
115 
116  mlc_converts_to(mln_site(S), mln_argument(A))::check();
117 
118  mln_result(A) r = impl::generic::compute(a, s);
119 
120  trace::exiting("set::compute");
121  return r;
122  }
123 
124 
125  template <typename A, typename S>
126  mln_meta_accu_result(A, mln_site(S))
127  compute(const Meta_Accumulator<A>& a, const Site_Set<S>& s)
128  {
129  trace::entering("set::compute");
130 
131  typedef mln_accu_with(A, mln_site(S)) A_;
132  A_ a_ = accu::unmeta(exact(a), mln_site(S)());
133 
134  mln_result(A_) r = impl::generic::compute(a_, s);
135 
136  trace::exiting("set::compute");
137  return r;
138  }
139 
140 # endif // ! MLN_INCLUDE_ONLY
141 
142  } // end of namespace mln::set
143 
144 } // end of namespace mln
145 
146 
147 #endif // ! MLN_SET_COMPUTE_HH