Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development 00002 // Laboratory (LRDE) 00003 // 00004 // This file is part of Olena. 00005 // 00006 // Olena is free software: you can redistribute it and/or modify it under 00007 // the terms of the GNU General Public License as published by the Free 00008 // Software Foundation, version 2 of the License. 00009 // 00010 // Olena is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software project without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to produce 00022 // an executable, this file does not by itself cause the resulting 00023 // executable to be covered by the GNU General Public License. This 00024 // exception does not however invalidate any other reasons why the 00025 // executable file might be covered by the GNU General Public License. 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 // Forward declaration. 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 } // end of namespace trait 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; // FIXME 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 // Assignment (write access); "natural" version. 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 // /// Conversion (read access); "natural" version. 00116 // operator mln_value(I)() const; 00117 00118 00119 // /// Conversion (read access); toward a proxy. 00120 // template <typename J> 00121 // operator proxy<J>() const; 00122 00123 00124 // /// Conversion (read access); general version. 00125 // template <typename V> 00126 // operator V() const; 00127 00128 00130 mln_value(I) to_value() const; 00131 00132 00133 // As a proxy: 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 // mln_rvalue(I) (I::*mr)(const mln_psite(I)&) const = & I::read_; 00168 // mr = 0; 00169 // void (I::*mw)(const mln_psite(I)&, const mln_value(I)&) = & I::write_; 00170 // mw = 0; 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; // No-op. 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 // template <typename I> 00207 // template <typename V> 00208 // inline 00209 // proxy<I>::operator V() const 00210 // { 00211 // mln_precondition(ima_ != 0); 00212 // return ima_->read_(p_); 00213 // } 00214 00215 // template <typename I> 00216 // inline 00217 // proxy<I>::operator mln_value(I)() const 00218 // { 00219 // mln_precondition(ima_ != 0); 00220 // return ima_->read_(p_); 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 } // end of namespace mln::value 00245 00246 } // end of namespace mln 00247 00248 00249 #endif // ! MLN_VALUE_PROXY_HH