Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
from_accu.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 
30 
31 
32 #ifndef MLN_FUN_FROM_ACCU_HH
33 # define MLN_FUN_FROM_ACCU_HH
34 
35 # include <mln/fun/unary_param.hh>
36 # include <mln/core/concept/accumulator.hh>
37 
38 
39 namespace mln
40 {
41 
42  namespace fun
43  {
44 
45 
48  template <typename A>
49  struct from_accu : unary_param<from_accu<A>, A*>
50  {
51  from_accu();
52  from_accu(A* a);
53  };
54 
55  } // end of namespace mln::fun
56 
57  namespace trait
58  {
59 
60  namespace next
61  {
62  template <typename A, typename T>
63  struct set_unary_<mln::fun::from_accu<A>, mln::Object, T>
64  {
65  typedef set_unary_ ret;
66  typedef typename A::result result;
67  typedef typename A::argument argument;
68  typedef A* param_t;
69 
70  static result read(const param_t& accu_, const argument& x);
71 
72  };
73 
74  } // end of namespace mln::trait::next
75 
76  } // end of namespace mln::trait
77 
78 
79 
80 # ifndef MLN_INCLUDE_ONLY
81 
82 
83  namespace fun
84  {
85 
86  template <typename A>
87  inline
88  from_accu<A>::from_accu()
89  : unary_param<from_accu<A>, A*>()
90  {
91 
92  }
93 
94 
95  template <typename A>
96  inline
97  from_accu<A>::from_accu(A* a)
98  : unary_param<from_accu<A>, A*>(a)
99  {
100 
101  }
102 
103  } // end of namespace mln::fun
104 
105 
106 
107  namespace trait
108  {
109 
110  namespace next
111  {
112 
113  template <typename A, typename T>
114  inline
115  typename set_unary_<mln::fun::from_accu<A>, mln::Object, T>::result
116  set_unary_<mln::fun::from_accu<A>,
117  mln::Object, T>::read(const param_t& accu_,
118  const argument& x)
119  {
120  mln_precondition(accu_ != 0);
121 
122  accu_->take(x);
123  return accu_->to_result ();
124  }
125 
126  } // end of namespace mln::trait::next
127 
128  } // end of namespace mln::trait
129 
130 
131 
132 # endif // ! MLN_INCLUDE_ONLY
133 
134 } // end of namespace mln
135 
136 #endif // ! MLN_FUN_FROM_ACCU_HH