Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
shell.hh
1 // Copyright (C) 2007, 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_VALUE_SHELL_HH
27 # define MLN_VALUE_SHELL_HH
28 
32 
33 # include <mln/core/concept/proxy.hh>
34 # include <mln/core/concept/function.hh>
35 # include <mln/core/concept/image.hh>
36 
37 
38 namespace mln
39 {
40 
41  // Forward declaration.
42  namespace value {
43  template <typename F, typename I> struct shell;
44  }
45 
46  namespace value
47  {
48 
49  namespace impl
50  {
51 
52  template <typename F, typename I, class C>
53  struct shell_ { };
54 
55 
56  template <typename F, typename I>
57  struct shell_<F, I, Function_v2v<void> >
58  {
59  const mln_value(I)&
60  set_(I& ima, const mln_site(I)& s, mln_result(F) v);
61  };
62 
63  } // end of namespace mln::value::impl
64 
65 
66  template <typename F, typename I>
67  struct shell
68  : public Proxy< shell<F,I> >,
69  public mln::internal::proxy_impl< mln_result(F), shell<F,I> >,
70  public impl::shell_<F, I, typename F::category>
71  {
72  typedef mln_result(F) value;
73 
74  // Ctor
75  shell(Image<I> &ima, const mln_site(I) &s);
76 
77  // Write
78  value operator=(value);
79 
80  // Enc
81  typedef void enc; // FIXME
82 
83  // Equiv
84  typedef value equiv;
85 
86  mln_result(F) subj_();
87 
88  // <<
89  // std::ostream& operator<<(std::ostream& ostr);
90 
91  // >>
92  // std::istream& operator>>(std::istream& istr);
93 
94 
95  protected:
96  I& ima_;
97  mln_site(I) s_;
98  mln_result(F) v_;
99  };
100 
101 
102 # ifndef MLN_INCLUDE_ONLY
103 
104  // Constructor.
105  template <typename F, typename I>
106  shell<F,I>::shell(Image<I>& ima, const mln_site(I)& s)
107  :
108  ima_(exact(ima)),
109  s_(s),
110  v_(F()(exact(ima)(s)))
111  {
112  }
113 
114  // Write for everyone
115  template <typename F, typename I>
116  typename F::result
117  shell<F,I>::operator=(mln_result(F) v)
118  {
119  v_ = F()(set_(ima_, s_, v));
120  return v_;
121  }
122 
123  template <typename F, typename I>
124  mln_result(F)
125  shell<F,I>::subj_()
126  {
127  return v_;
128  }
129 
130 
131  namespace impl
132  {
133 
134 // template <typename F, typename I>
135 // const mln_value(I)&
136 // shell_<F, I, Function_v2v<void> >::set_(I& ima,
137 // const mln_site(I)& s,
138 // mln_result(F) v)
139 // {
140 // ima(s) = F().f_1(v);
141 // return ima(s);
142 // }
143 
144  template <typename F, typename I>
145  const mln_value(I)&
146  shell_<F, I, Function_v2v<void> >::set_(I& ima,
147  const mln_site(I)& s,
148  mln_result(F) v)
149  {
150  ima(s) = F().f_1(v, ima(s));
151  return ima(s);
152  }
153 
154  } // end of namespace mln::value::impl
155 
156 
157 # endif // MLN_INCLUDE_ONLY
158 
159 
160  } // end of namespace mln::value
161 
162 } // end of namespace mln
163 
164 #endif // ! MLN_VALUE_SHELL_HH