00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef MLN_VALUE_PROXY_HH
00028 # define MLN_VALUE_PROXY_HH
00029
00042
00043 # include <mln/core/concept/proxy.hh>
00044 # include <mln/trait/value_.hh>
00045 # include <mln/metal/unconst.hh>
00046
00047
00048 namespace mln
00049 {
00050
00051
00052 namespace value {
00053 template <typename I> class proxy;
00054 }
00055
00056
00057 namespace trait
00058 {
00059
00060 template <typename I>
00061 struct value_< mln::value::proxy<I> >
00062 :
00063 value_< mln_value(I) >
00064 {
00065 };
00066
00067 template <typename I>
00068 struct value_< mln::value::proxy<const I> >
00069 :
00070 value_< mln_value(I) >
00071 {
00072 };
00073
00074 }
00075
00076
00077 namespace value
00078 {
00079
00083
00084 template <typename I>
00085 class proxy : public Proxy< proxy<I> >,
00086 public mln::internal::proxy_impl< mln_value(I), proxy<I> >
00087 {
00088 public:
00089
00091 typedef void enc;
00092
00094 typedef mln_value(I) equiv;
00095
00097 proxy();
00098
00100 proxy(I& ima, const mln_psite(I)& p);
00101
00103 ~proxy();
00104
00105
00106 proxy<I>& operator=(const mln_value(I)& v);
00107
00109 proxy<I>& operator=(const proxy<I>& rhs);
00110
00112 template <typename J>
00113 proxy<I>& operator=(const proxy<J>& rhs);
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00130 mln_value(I) to_value() const;
00131
00132
00133
00134
00136 mln_value(I) subj_();
00137
00138 protected:
00139 I* ima_;
00140 mln_psite(I) p_;
00141 };
00142
00143
00144
00145
00146 # ifndef MLN_INCLUDE_ONLY
00147
00148 template <typename I>
00149 inline
00150 proxy<I>::proxy()
00151 : ima_(0)
00152 {
00153 }
00154
00155 template <typename I>
00156 inline
00157 proxy<I>::proxy(I& ima, const mln_psite(I)& p)
00158 : ima_(&ima),
00159 p_(p)
00160 {
00161 }
00162
00163 template <typename I>
00164 inline
00165 proxy<I>::~proxy()
00166 {
00167
00168
00169
00170
00171 }
00172
00173 template <typename I>
00174 inline
00175 proxy<I>&
00176 proxy<I>::operator=(const mln_value(I)& v)
00177 {
00178 mln_precondition(ima_ != 0);
00179 ima_->write_(p_, v);
00180 return *this;
00181 }
00182
00183 template <typename I>
00184 inline
00185 proxy<I>&
00186 proxy<I>::operator=(const proxy<I>& rhs)
00187 {
00188 mln_precondition(ima_ != 0);
00189 if (&rhs == this)
00190 return *this;
00191 this->operator=(rhs.to_value());
00192 return *this;
00193 }
00194
00195 template <typename I>
00196 template <typename J>
00197 inline
00198 proxy<I>&
00199 proxy<I>::operator=(const proxy<J>& rhs)
00200 {
00201 mln_precondition(ima_ != 0);
00202 this->operator=(rhs.to_value());
00203 return *this;
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 template <typename I>
00224 inline
00225 mln_value(I)
00226 proxy<I>::to_value() const
00227 {
00228 mln_precondition(ima_ != 0);
00229 return ima_->read_(p_);
00230 }
00231
00232 template <typename I>
00233 inline
00234 mln_value(I)
00235 proxy<I>::subj_()
00236 {
00237 mln_precondition(ima_ != 0);
00238 return ima_->read_(p_);
00239 }
00240
00241
00242 # endif // ! MLN_INCLUDE_ONLY
00243
00244 }
00245
00246 }
00247
00248
00249 #endif // ! MLN_VALUE_PROXY_HH