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

sub_image_if.hh

00001 // Copyright (C) 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_IMAGE_DMORPH_SUB_IMAGE_IF_HH
00027 # define MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_IF_HH
00028 
00029 
00035 
00036 
00037 # include <mln/core/internal/image_domain_morpher.hh>
00038 # include <mln/core/site_set/p_if.hh>
00039 # include <mln/fun/p2b/has.hh>
00040 
00041 # include <mln/debug/println.hh>
00042 
00043 
00044 namespace mln
00045 {
00046 
00047 
00048   // Forward declaration.
00049   template <typename I, typename S> class sub_image_if;
00050 
00051 
00052   namespace internal
00053   {
00054 
00056     template <typename I, typename S>
00057     struct data< sub_image_if<I,S> >
00058     {
00059       data(I& ima, const S& s);
00060 
00061       I ima_;
00062       p_if< S, fun::p2b::has<I> > s_;
00063     };
00064 
00065   } // end of namespace mln::internal
00066 
00067 
00068 
00069   namespace trait
00070   {
00071 
00072     template <typename I, typename S>
00073     struct image_< sub_image_if<I,S> > : default_image_morpher< I,
00074                                                                 mln_value(I),
00075                                                                 sub_image_if<I,S> >
00076     {
00077 //     private:
00078 //       typedef mln_trait_image_data(I) I_data_;
00079 //       typedef mlc_equal(I_data_, trait::data::linear) I_data_are_linear_;
00080 //     public:
00081 
00082       typedef trait::image::category::domain_morpher category;
00083 
00084       typedef trait::image::ext_domain::none      ext_domain;  // No extension of domain.
00085       typedef trait::image::ext_value::irrelevant ext_value;
00086       typedef trait::image::ext_io::irrelevant    ext_io;
00087 
00088       typedef trait::image::value_storage::disrupted value_storage;
00089       // HOT FIXME: except if S is a Box
00090     };
00091 
00092   } // end of namespace mln::trait
00093 
00094 
00095 
00099   //
00100   template <typename I, typename S>
00101   struct sub_image_if : public internal::image_domain_morpher< I,
00102                                                                p_if< S, fun::p2b::has<I> >,
00103                                                                sub_image_if<I,S> >
00104   {
00106     typedef sub_image_if< tag::image_<I>, tag::domain_<S> > skeleton;
00107 
00109     sub_image_if();
00110 
00112     sub_image_if(I& ima, const S& s);
00113 
00115     void init_(I& ima, const S& s);
00116 
00118     const p_if< S, fun::p2b::has<I> >& domain() const;
00119 
00120 //     /// Const promotion via conversion.
00121 //     operator sub_image_if<const I, S>() const;
00122   };
00123 
00124 
00125 
00126 
00127 
00128   template <typename I, typename S>
00129   sub_image_if<const I, S>
00130   operator / (const Image<I>& ima, const Site_Set<S>& s);
00131 
00132 
00133   template <typename I, typename S>
00134   sub_image_if<I, S>
00135   operator / (Image<I>& ima, const Site_Set<S>& s);
00136 
00137 
00138   template <typename I, typename S, typename J>
00139   void init_(tag::image_t, sub_image_if<I,S>& target, const J& model);
00140 
00141 
00142 
00143 # ifndef MLN_INCLUDE_ONLY
00144 
00145   // init_
00146 
00147   template <typename I, typename S, typename J>
00148   inline
00149   void init_(tag::image_t, sub_image_if<I,S>& target, const J& model)
00150   {
00151     I ima;
00152     init_(tag::image, ima, model);
00153     S s;
00154     init_(tag::domain, s, model);
00155     target.init_(ima, s);
00156   }
00157 
00158 
00159   // internal::data< sub_image_if<I,S> >
00160 
00161   namespace internal
00162   {
00163 
00164     template <typename I, typename S>
00165     inline
00166     data< sub_image_if<I,S> >::data(I& ima, const S& s)
00167       : ima_(ima)
00168     {
00169       typedef fun::p2b::has<I> F;
00170       F f(ima);
00171       s_ = p_if<S,F>(s, f); 
00172     }
00173 
00174   } // end of namespace mln::internal
00175 
00176 
00177   // sub_image_if<I,S>
00178 
00179   template <typename I, typename S>
00180   inline
00181   sub_image_if<I,S>::sub_image_if()
00182   {
00183   }
00184 
00185   template <typename I, typename S>
00186   inline
00187   sub_image_if<I,S>::sub_image_if(I& ima, const S& s)
00188   {
00189     init_(ima, s);
00190   }
00191 
00192   template <typename I, typename S>
00193   inline
00194   void
00195   sub_image_if<I,S>::init_(I& ima, const S& s)
00196   {
00197     mln_precondition(! this->is_valid());
00198     this->data_ = new internal::data< sub_image_if<I,S> >(ima, s);
00199   }
00200 
00201   template <typename I, typename S>
00202   inline
00203   const p_if< S, fun::p2b::has<I> >&
00204   sub_image_if<I,S>::domain() const
00205   {
00206     return this->data_->s_;
00207   }
00208 
00209 //   template <typename I, typename S>
00210 //   inline
00211 //   sub_image_if<I,S>::operator sub_image_if<const I, S>() const
00212 //   {
00213 //     sub_image_if<const I, S> tmp(this->data_->ima_,
00214 //                            this->data_->s_);
00215 //     return tmp;
00216 //   }
00217 
00218 
00219   // Operators.
00220 
00221   template <typename I, typename S>
00222   inline
00223   sub_image_if<const I, S>
00224   operator / (const Image<I>& ima, const Site_Set<S>& s)
00225   {
00226     // FIXME: mln_precondition(set::inter(ima.domain(), s) != 0);
00227     sub_image_if<const I, S> tmp(exact(ima), exact(s));
00228     return tmp;
00229   }
00230 
00231   template <typename I, typename S>
00232   inline
00233   sub_image_if<I, S>
00234   operator / (Image<I>& ima, const Site_Set<S>& s)
00235   {
00236     // FIXME: mln_precondition(set::inter(ima.domain(), s) != 0);
00237     sub_image_if<I, S> tmp(exact(ima), exact(s));
00238     return tmp;
00239   }
00240 
00241 # endif // ! MLN_INCLUDE_ONLY
00242 
00243 } // end of namespace mln
00244 
00245 
00246 #endif // ! MLN_CORE_IMAGE_DMORPH_SUB_IMAGE_IF_HH

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