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

image_identity.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_CORE_INTERNAL_IMAGE_IDENTITY_HH
00027 # define MLN_CORE_INTERNAL_IMAGE_IDENTITY_HH
00028 
00035 
00036 # include <mln/core/internal/image_morpher.hh>
00037 
00038 
00039 namespace mln
00040 {
00041 
00042   namespace internal
00043   {
00044 
00045 
00046     // Fastest.
00047 
00048     template <typename trait_speed, typename I, typename E>
00049     struct image_identity_impl__fastest
00050     {
00051       // Nothing.
00052     };
00053 
00054     template <typename I, typename E>
00055     struct image_identity_impl__fastest< mln::trait::image::speed::fastest, I, E >
00056     {
00057     private:
00058 
00059       mlc_const(I)& del_() const
00060       {
00061         return * internal::force_exact<const E>(*this).delegatee_();
00062       }
00063 
00064       I& del_()
00065       {
00066         return * internal::force_exact<E>(*this).delegatee_();
00067       }
00068 
00069     public:
00070 
00071       int delta_index(const mln_deduce(I, psite, delta)& dp) const
00072       {
00073         return del_().delta_index(dp);
00074       }
00075 
00076       mln_site(I) point_at_index(unsigned i) const
00077       {
00078         return del_().point_at_index(i);
00079       }
00080 
00081       unsigned border() const
00082       {
00083         return del_().border();
00084       }
00085 
00086       mln_qlf_value(I)* buffer()
00087       {
00088         return del_().buffer();
00089       }
00090 
00091       const mln_value(I)* buffer() const
00092       {
00093         return del_().buffer();
00094       }
00095 
00096       mln_rvalue(I) element(unsigned i) const
00097       {
00098         return del_().element(i);
00099       }
00100 
00101       mln_lvalue(I) element(unsigned i)
00102       {
00103         return del_().element(i);
00104       }
00105 
00106       unsigned nelements() const
00107       {
00108         return del_().nelements();
00109       }
00110     };
00111 
00112     // Facade.
00113 
00114     template <typename I, typename E>
00115     struct image_identity_impl
00116       : image_identity_impl__fastest< mln_trait_image_speed(E), I, E >
00117     {
00118     };
00119 
00120 
00121 
00126     template <typename I, typename S, typename E>
00127     class image_identity
00128       : public image_identity_impl<I, E>,
00129         public image_morpher<I, mln_value(I), S, E>
00130     {
00131     public:
00132 
00134       typedef mln_value(I) value;
00135 
00137       typedef mln_rvalue(I) rvalue;
00138 
00140       typedef mln_morpher_lvalue(I) lvalue;
00141 
00143       rvalue operator()(const mln_psite(S)& p) const;
00144 
00146       lvalue operator()(const mln_psite(S)& p);
00147 
00148       // FIXME Matthieu: Doc!  Cf. core/concept/doc/image
00149       const mln_domain(I)& domain() const;
00150       bool has(const mln_psite(I)& p) const;
00151 
00152     protected:
00153 
00155       image_identity();
00156     };
00157 
00158 
00159 
00160 # ifndef MLN_INCLUDE_ONLY
00161 
00162     template <typename I, typename S, typename E>
00163     inline
00164     image_identity<I, S, E>::image_identity()
00165     {
00166     }
00167 
00168     template <typename I, typename S, typename E>
00169     inline
00170     mln_rvalue(I)
00171     image_identity<I, S, E>::operator()(const mln_psite(S)& p) const
00172     {
00173       mln_precondition(this->delegatee_() != 0);
00174       return this->delegatee_()->operator()(p);
00175     }
00176 
00177     template <typename I, typename S, typename E>
00178     inline
00179     typename image_identity<I, S, E>::lvalue
00180     image_identity<I, S, E>::operator()(const mln_psite(S)& p)
00181     {
00182       mln_precondition(this->delegatee_() != 0);
00183       return this->delegatee_()->operator()(p);
00184     }
00185 
00186     template <typename I, typename S, typename E>
00187     inline
00188     const mln_domain(I)&
00189     image_identity<I, S, E>::domain() const
00190     {
00191       mln_precondition(this->delegatee_() != 0);
00192       return this->delegatee_()->domain();
00193     }
00194 
00195     template <typename I, typename S, typename E>
00196     inline
00197     bool
00198     image_identity<I, S, E>::has(const mln_psite(I)& p) const
00199     {
00200       mln_precondition(this->delegatee_() != 0);
00201       return this->delegatee_()->has(p);
00202     }
00203 
00204 # endif // ! MLN_INCLUDE_ONLY
00205 
00206   } // end of namespace mln::internal
00207 
00208 } // end of namespace mln
00209 
00210 
00211 #endif // ! MLN_CORE_INTERNAL_IMAGE_IDENTITY_HH

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