• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

shell.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_VALUE_SHELL_HH
00027 # define MLN_VALUE_SHELL_HH
00028 
00032 
00033 # include <mln/core/concept/proxy.hh>
00034 # include <mln/core/concept/function.hh>
00035 # include <mln/core/concept/image.hh>
00036 
00037 
00038 namespace mln
00039 {
00040 
00041   // Forward declaration.
00042   namespace value {
00043     template <typename F, typename I> struct shell;
00044   }
00045 
00046   namespace value
00047   {
00048 
00049     namespace impl
00050     {
00051 
00052       template <typename F, typename I, class C>
00053       struct shell_ { };
00054 
00055 
00056       template <typename F, typename I>
00057       struct shell_<F, I, Function_v2v<void> >
00058       {
00059         const mln_value(I)&
00060         set_(I& ima, const mln_site(I)& s, mln_result(F) v);
00061       };
00062 
00063     } // end of namespace mln::value::impl
00064 
00065 
00066     template <typename F, typename I>
00067     struct shell
00068       : public Proxy< shell<F,I> >,
00069         public mln::internal::proxy_impl< mln_result(F), shell<F,I> >,
00070         public impl::shell_<F, I, typename F::category>
00071     {
00072       typedef mln_result(F) value;
00073 
00074       // Ctor
00075       shell(Image<I> &ima, const mln_site(I) &s);
00076 
00077       // Write
00078       value operator=(value);
00079 
00080       // Enc
00081       typedef void enc; // FIXME
00082 
00083       // Equiv
00084       typedef value equiv;
00085 
00086       mln_result(F) subj_();
00087 
00088       // <<
00089       // std::ostream& operator<<(std::ostream& ostr);
00090 
00091       // >>
00092       // std::istream& operator>>(std::istream& istr);
00093 
00094 
00095     protected:
00096       I& ima_;
00097       mln_site(I) s_;
00098       mln_result(F) v_;
00099     };
00100 
00101 
00102 # ifndef MLN_INCLUDE_ONLY
00103 
00104     // Constructor.
00105     template <typename F, typename I>
00106     shell<F,I>::shell(Image<I>& ima, const mln_site(I)& s)
00107       :
00108       ima_(exact(ima)),
00109       s_(s),
00110       v_(F()(exact(ima)(s)))
00111     {
00112     }
00113 
00114     // Write for everyone
00115     template <typename F, typename I>
00116     typename F::result
00117     shell<F,I>::operator=(mln_result(F) v)
00118     {
00119       v_ = F()(set_(ima_, s_, v));
00120       return v_;
00121     }
00122 
00123     template <typename F, typename I>
00124     mln_result(F)
00125     shell<F,I>::subj_()
00126     {
00127       return v_;
00128     }
00129 
00130 
00131     namespace impl
00132     {
00133 
00134 //      template <typename F, typename I>
00135 //      const mln_value(I)&
00136 //      shell_<F, I, Function_v2v<void> >::set_(I& ima,
00137 //                                              const mln_site(I)& s,
00138 //                                              mln_result(F) v)
00139 //      {
00140 //      ima(s) = F().f_1(v);
00141 //      return ima(s);
00142 //      }
00143 
00144       template <typename F, typename I>
00145       const mln_value(I)&
00146       shell_<F, I, Function_v2v<void> >::set_(I& ima,
00147                                                   const mln_site(I)& s,
00148                                                   mln_result(F) v)
00149       {
00150         ima(s) = F().f_1(v, ima(s));
00151         return ima(s);
00152       }
00153 
00154     } // end of namespace mln::value::impl
00155 
00156 
00157 # endif // MLN_INCLUDE_ONLY
00158 
00159 
00160   } // end of namespace mln::value
00161 
00162 } // end of namespace mln
00163 
00164 #endif // ! MLN_VALUE_SHELL_HH

Generated on Tue Oct 4 2011 15:24:25 for Milena (Olena) by  doxygen 1.7.1