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

image_morpher.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_MORPHER_HH
00027 # define MLN_CORE_INTERNAL_IMAGE_MORPHER_HH
00028 
00034 
00035 # include <mln/core/internal/image_base.hh>
00036 # include <mln/metal/const.hh>
00037 # include <mln/metal/is_const.hh>
00038 # include <mln/metal/is_not_const.hh>
00039 
00040 
00041 namespace mln
00042 {
00043 
00044   namespace internal
00045   {
00046 
00050     //
00051     template <typename I, typename T, typename S, typename E>
00052     class image_morpher : public image_base<T, S, E>
00053     {
00054     public:
00055 
00057       typedef I delegatee;
00058 
00060       mlc_const(I)* delegatee_() const;
00061 
00063       I* delegatee_();
00064 
00065 
00066 
00068       typedef I unmorph;
00069 
00071       I& unmorph_();
00072 
00074       mlc_const(I)& unmorph_() const;
00075 
00076 
00077       /* \brief Test if this image has been initialized; default impl.
00078        *
00079        * This default impl is stronger than the one inherited from
00080        * image_base because it also tests that the morphed image is
00081        * also initialized.
00082        */
00083       bool is_valid() const;
00084 
00085 
00088       E& rw();
00089 
00090 
00091     protected:
00092       image_morpher();
00093     };
00094 
00095   } // end of namespace mln::internal
00096 
00097 
00098 
00099   namespace impl
00100   {
00101 
00102     // Default is delegation for morphers.
00103 
00104 //     template <typename Subject, typename T,
00105 //            typename I, typename S, typename E>
00106 //     void init_(Subject s, T& target,
00107 //             const internal::image_morpher<I,S,E>& model);
00108 
00109 // FIXME: Lines above have been inactivated because they are either
00110 // prioritary or ambiguous.
00111 
00112     template <typename Subject, typename T,
00113               typename J>
00114     void init_(Subject s, T& target, const Image<J>& model);
00115 
00116   } // end of namespace mln::impl
00117 
00118 
00119 
00120 # ifndef MLN_INCLUDE_ONLY
00121 
00122   namespace internal
00123   {
00124 
00125     template <typename I, typename T, typename S, typename E>
00126     inline
00127     image_morpher<I, T, S, E>::image_morpher()
00128     {
00129     }
00130 
00131     template <typename I, typename T, typename S, typename E>
00132     inline
00133     mlc_const(I)*
00134     image_morpher<I, T, S, E>::delegatee_() const
00135     {
00136       return this->data_ == 0 ? 0 : & this->data_->ima_;
00137     }
00138 
00139     template <typename I, typename T, typename S, typename E>
00140     inline
00141     I*
00142     image_morpher<I, T, S, E>::delegatee_()
00143     {
00144       return this->data_ == 0 ? 0 : & this->data_->ima_;
00145     }
00146 
00147     template <typename I, typename T, typename S, typename E>
00148     inline
00149     I&
00150     image_morpher<I, T, S, E>::unmorph_()
00151     {
00152       I* ptr = delegatee_();
00153       mln_assertion(ptr != 0);
00154       return *ptr;
00155     }
00156 
00157     template <typename I, typename T, typename S, typename E>
00158     inline
00159     mlc_const(I)&
00160     image_morpher<I, T, S, E>::unmorph_() const
00161     {
00162       mlc_const(I)* ptr = delegatee_();
00163       mln_assertion(ptr != 0);
00164       return *ptr;
00165     }
00166 
00167     template <typename I, typename T, typename S, typename E>
00168     inline
00169     bool
00170     image_morpher<I, T, S, E>::is_valid() const
00171     {
00172       return
00173         this->data_ != 0 &&
00174         this->delegatee_() != 0 &&
00175         this->delegatee_()->is_valid();
00176     }
00177 
00178     template <typename I, typename T, typename S, typename E>
00179     inline
00180     E&
00181     image_morpher<I, T, S, E>::rw()
00182     {
00183       mlc_is_not_const(I)::check();
00184       mlc_equal(mln_trait_image_value_io(I),
00185                 mln::trait::image::value_io::read_write)::check();
00186       // FIXME Nicolas: pw_io == read_write OR vw_io == read_write...
00187       return exact(*this);
00188     }
00189 
00190   } // end of namespace mln::internal
00191 
00192 
00193 
00194 //   template <typename Subject, typename T,
00195 //          typename I, typename S, typename E>
00196 //   void init_(Subject s, T& target,
00197 //           const internal::image_morpher<I,S,E>& model)
00198 //   {
00199 //     std::cout << "deleg... ";
00200 //     // FIXME: Precondition.
00201 //     init_(s, target, * model.delegatee_());
00202 //   }
00203 
00204     template <typename Subject, typename T,
00205               typename J>
00206     inline
00207     void init_(Subject s, T& target, const Image<J>& model_)
00208     {
00209       mlc_is(mln_trait_image_category(J),
00210              trait::image::category::morpher)::check();
00211       const J& model = exact(model_);
00212       init_(s, target, * model.delegatee_());
00213     }
00214 
00215 # endif // ! MLN_INCLUDE_ONLY
00216 
00217 } // end of namespace mln
00218 
00219 
00220 #endif // ! MLN_CORE_INTERNAL_IMAGE_MORPHER_HH

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