$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
value/proxy.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_VALUE_PROXY_HH
28 # define MLN_VALUE_PROXY_HH
29 
42 
43 # include <mln/core/concept/proxy.hh>
44 # include <mln/trait/value_.hh>
45 # include <mln/metal/unconst.hh>
46 
47 
48 namespace mln
49 {
50 
51  // Forward declaration.
52  namespace value {
53  template <typename I> class proxy;
54  }
55 
56 
57  namespace trait
58  {
59 
60  template <typename I>
61  struct value_< mln::value::proxy<I> >
62  :
63  value_< mln_value(I) >
64  {
65  };
66 
67  template <typename I>
68  struct value_< mln::value::proxy<const I> >
69  :
70  value_< mln_value(I) >
71  {
72  };
73 
74  } // end of namespace trait
75 
76 
77  namespace value
78  {
79 
83  //
84  template <typename I>
85  class proxy : public Proxy< proxy<I> >,
86  public mln::internal::proxy_impl< mln_value(I), proxy<I> >
87  {
88  public:
89 
91  typedef void enc; // FIXME
92 
94  typedef mln_value(I) equiv;
95 
97  proxy();
98 
100  proxy(I& ima, const mln_psite(I)& p);
101 
103  ~proxy();
104 
105  // Assignment (write access); "natural" version.
106  proxy<I>& operator=(const mln_value(I)& v);
107 
109  proxy<I>& operator=(const proxy<I>& rhs);
110 
112  template <typename J>
113  proxy<I>& operator=(const proxy<J>& rhs);
114 
115 // /// Conversion (read access); "natural" version.
116 // operator mln_value(I)() const;
117 
118 
119 // /// Conversion (read access); toward a proxy.
120 // template <typename J>
121 // operator proxy<J>() const;
122 
123 
124 // /// Conversion (read access); general version.
125 // template <typename V>
126 // operator V() const;
127 
128 
130  mln_value(I) to_value() const;
131 
132 
133  // As a proxy:
134 
136  mln_value(I) subj_();
137 
138  protected:
139  I* ima_;
140  mln_psite(I) p_;
141  };
142 
143 
144 
145 
146 # ifndef MLN_INCLUDE_ONLY
147 
148  template <typename I>
149  inline
151  : ima_(0)
152  {
153  }
154 
155  template <typename I>
156  inline
157  proxy<I>::proxy(I& ima, const mln_psite(I)& p)
158  : ima_(&ima),
159  p_(p)
160  {
161  }
162 
163  template <typename I>
164  inline
166  {
167 // mln_rvalue(I) (I::*mr)(const mln_psite(I)&) const = & I::read_;
168 // mr = 0;
169 // void (I::*mw)(const mln_psite(I)&, const mln_value(I)&) = & I::write_;
170 // mw = 0;
171  }
172 
173  template <typename I>
174  inline
175  proxy<I>&
176  proxy<I>::operator=(const mln_value(I)& v)
177  {
178  mln_precondition(ima_ != 0);
179  ima_->write_(p_, v);
180  return *this;
181  }
182 
183  template <typename I>
184  inline
185  proxy<I>&
186  proxy<I>::operator=(const proxy<I>& rhs)
187  {
188  mln_precondition(ima_ != 0);
189  if (&rhs == this)
190  return *this; // No-op.
191  this->operator=(rhs.to_value());
192  return *this;
193  }
194 
195  template <typename I>
196  template <typename J>
197  inline
198  proxy<I>&
199  proxy<I>::operator=(const proxy<J>& rhs)
200  {
201  mln_precondition(ima_ != 0);
202  this->operator=(rhs.to_value());
203  return *this;
204  }
205 
206 // template <typename I>
207 // template <typename V>
208 // inline
209 // proxy<I>::operator V() const
210 // {
211 // mln_precondition(ima_ != 0);
212 // return ima_->read_(p_);
213 // }
214 
215 // template <typename I>
216 // inline
217 // proxy<I>::operator mln_value(I)() const
218 // {
219 // mln_precondition(ima_ != 0);
220 // return ima_->read_(p_);
221 // }
222 
223  template <typename I>
224  inline
225  mln_value(I)
226  proxy<I>::to_value() const
227  {
228  mln_precondition(ima_ != 0);
229  return ima_->read_(p_);
230  }
231 
232  template <typename I>
233  inline
234  mln_value(I)
235  proxy<I>::subj_()
236  {
237  mln_precondition(ima_ != 0);
238  return ima_->read_(p_);
239  }
240 
241 
242 # endif // ! MLN_INCLUDE_ONLY
243 
244  } // end of namespace mln::value
245 
246 } // end of namespace mln
247 
248 
249 #endif // ! MLN_VALUE_PROXY_HH