Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
meta_accumulator.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_CORE_CONCEPT_META_ACCUMULATOR_HH
28 # define MLN_CORE_CONCEPT_META_ACCUMULATOR_HH
29 
33 
34 # include <mln/core/concept/object.hh>
35 # include <mln/core/concept/accumulator.hh>
36 
37 
38 # define mln_accu_with(A, T) \
39 typename mln::internal::accu_with_helper<A,T>::ret
40 
41 # define mln_accu_with_(A, T) \
42 mln::internal::accu_with_helper<A,T>::ret
43 
44 
45 # define mln_meta_accu_result(A, T) \
46 typename mln::internal::meta_accu_ret_result_helper<A,T>::result
47 
48 
49 # define mln_meta_accu_result_(A, T) \
50 mln::internal::meta_accu_ret_result_helper<A,T>::result
51 
52 
53 
54 
55 namespace mln
56 {
57 
58  // Forward declaration.
59  template <typename E> struct Meta_Accumulator;
60 
61 
62  namespace internal
63  {
64 
67  //
68  template <typename A, typename T>
69  struct meta_accu_ret_result_helper
70  {
71  typedef typename A::template with< T >::ret::result result;
72  };
73 
74 
77  //
78  template <typename A, typename T>
79  struct accu_with_helper
80  {
81  typedef typename A::template with< T >::ret ret;
82  };
83 
84 
85  } // end of namespace mln::internal
86 
87 
88  // Meta_Accumulator category flag type.
89  template <>
90  struct Meta_Accumulator<void>
91  {
92  typedef Object<void> super;
93  };
94 
102  template <typename E>
103  struct Meta_Accumulator : public Object<E>
104  {
105  typedef Meta_Accumulator<void> category;
106  protected:
108  };
109 
110 
111  namespace accu
112  {
113 
114  // To be specialized when some state (attributes) have to be transfered
115  // from the meta-accumulator to the accumulator.
116  // Warning: the first argument has to be an object with the exact type.
117  template <typename M, typename T>
118  mln_accu_with(M, T)
119  unmeta(const M&, T);
120 
121  template <typename M, typename T>
122  void
123  unmeta(const Meta_Accumulator<M>&, T); // Safety.
124 
125  } // end of namespace mln::accu
126 
127 
128 
129 # ifndef MLN_INCLUDE_ONLY
130 
131  template <typename E>
132  inline
134  {
135  // FIXME: Check "with" on E.
136  }
137 
138  namespace accu
139  {
140 
141  template <typename M, typename T>
142  inline
143  mln_accu_with(M, T)
144  unmeta(const M&, T)
145  {
146  mlc_is_a(M, Meta_Accumulator)::check();
147  mln_accu_with(M, T) a;
148  return a;
149  }
150 
151  } // end of namespace mln::accu
152 
153 # endif // ! MLN_INCLUDE_ONLY
154 
155 } // end of namespace mln
156 
157 
158 #endif // ! MLN_CORE_CONCEPT_META_ACCUMULATOR_HH