Milena (Olena)  User documentation 2.0a Id
flat_image.hh
00001 // Copyright (C) 2008, 2009, 2011 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_CORE_IMAGE_FLAT_IMAGE_HH
00028 # define MLN_CORE_IMAGE_FLAT_IMAGE_HH
00029 
00035 
00036 # include <mln/core/internal/image_primary.hh>
00037 # include <mln/value/set.hh>
00038 
00039 
00040 namespace mln
00041 {
00042 
00043 
00044   // Forward declaration.
00045   template <typename T, typename S> struct flat_image;
00046 
00047 
00048   namespace internal
00049   {
00050 
00052     template <typename T, typename S>
00053     struct data< flat_image<T,S> >
00054     {
00055       data(const T& val, const S& pset);
00056 
00057       T val_;
00058       S domain_;
00059     };
00060 
00061   } // end of namespace mln::internal
00062 
00063 
00064 
00065   namespace trait
00066   {
00067 
00068     template <typename T, typename S>
00069     struct image_< flat_image<T,S> > : default_image_< T, flat_image<T,S> >
00070     {
00071       // misc
00072       typedef trait::image::category::primary category;
00073       typedef trait::image::speed::fast       speed;
00074       typedef trait::image::size::regular     size;
00075 
00076       // value
00077       typedef trait::image::vw_io::read_write               vw_io;
00079       typedef trait::image::vw_set::none                    vw_set;
00080       typedef trait::image::value_access::direct            value_access;
00081       typedef trait::image::value_storage::singleton        value_storage;
00082       typedef mln::trait::image::value_browsing::value_wise value_browsing;
00083       typedef trait::image::value_alignment::with_grid      value_alignment;
00084       typedef trait::image::value_io::read_only             value_io;
00085 
00086       // site / domain
00087       typedef trait::image::pw_io::read              pw_io;
00088       typedef trait::image::localization::basic_grid localization; // FIXME
00089       typedef trait::image::dimension::two_d         dimension;    // FIXME
00090 
00091       // extended domain
00092       typedef trait::image::ext_domain::infinite ext_domain;
00093       typedef trait::image::ext_value::single    ext_value;
00094       typedef trait::image::ext_io::read_only    ext_io;
00095     };
00096 
00097   } // end of namespace mln::trait
00098 
00099 
00100 
00104   //
00105   template <typename T, typename S>
00106   struct flat_image : public internal::image_primary< T, S, flat_image<T,S> >
00107   {
00109     typedef flat_image< tag::value_<T>, tag::domain_<S> > skeleton;
00110 
00111 
00113     typedef T value;
00114 
00116     typedef const T& rvalue;
00117 
00119     typedef T& lvalue;
00120 
00121 
00123     flat_image();
00124 
00126     flat_image(const T& val, const S& pset);
00127 
00129     void init_(const T& val, const S& pset);
00130 
00132     const S& domain() const;
00133 
00135     bool has(const mln_psite(S)& p) const;
00136 
00137 
00139     const T& operator()(const mln_psite(S)& p) const;
00140 
00142     T& operator()(const mln_psite(S)& p);
00143 
00144 
00146     const T& value_() const;
00147     T& value_();
00148   };
00149 
00150 
00151 
00152   template <typename T, typename S, typename J>
00153   void init_(tag::image_t, flat_image<T,S>& target, const J& model);
00154 
00155 
00156 
00157 # ifndef MLN_INCLUDE_ONLY
00158 
00159   // init_
00160 
00161   template <typename T, typename S, typename J>
00162   inline
00163   void init_(tag::image_t, flat_image<T,S>& target, const J& model)
00164   {
00165     S pset;
00166     init_(tag::domain, pset, model);
00167     T dummy;
00168     target.init_(dummy, pset);
00169   }
00170 
00171 
00172   // internal::data< flat_image<T,S> >
00173 
00174   namespace internal
00175   {
00176 
00177     template <typename T, typename S>
00178     inline
00179     data< flat_image<T,S> >::data(const T& val, const S& pset)
00180       : val_(val),
00181         domain_(pset)
00182     {
00183     }
00184 
00185   } // end of namespace mln::internal
00186 
00187 
00188   // flat_image<T,S>
00189 
00190   template <typename T, typename S>
00191   inline
00192   flat_image<T,S>::flat_image()
00193   {
00194   }
00195 
00196   template <typename T, typename S>
00197   inline
00198   flat_image<T,S>::flat_image(const T& val, const S& pset)
00199   {
00200     init_(val, pset);
00201   }
00202 
00203   template <typename T, typename S>
00204   inline
00205   void
00206   flat_image<T,S>::init_(const T& val, const S& pset)
00207   {
00208     mln_precondition(! this->is_valid());
00209     this->data_ = new internal::data< flat_image<T,S> >(val, pset);
00210   }
00211 
00212   template <typename T, typename S>
00213   inline
00214   const S&
00215   flat_image<T,S>::domain() const
00216   {
00217     return this->data_->domain_;
00218   }
00219 
00220   template <typename T, typename S>
00221   inline
00222   bool
00223   flat_image<T,S>::has(const mln_psite(S)&) const
00224   {
00225     return true;
00226   }
00227 
00228   template <typename T, typename S>
00229   inline
00230   const T&
00231   flat_image<T,S>::operator()(const mln_psite(S)&) const
00232   {
00233     mln_precondition(this->is_valid());
00234     return this->data_->val_;
00235   }
00236 
00237   template <typename T, typename S>
00238   inline
00239   T&
00240   flat_image<T,S>::operator()(const mln_psite(S)&)
00241   {
00242     mln_precondition(this->is_valid());
00243     return this->data_->val_;
00244   }
00245 
00246   template <typename T, typename S>
00247   inline
00248   const T&
00249   flat_image<T,S>::value_() const
00250   {
00251     mln_precondition(this->is_valid());
00252     return this->data_->val_;
00253   }
00254 
00255   template <typename T, typename S>
00256   inline
00257   T&
00258   flat_image<T,S>::value_()
00259   {
00260     mln_precondition(this->is_valid());
00261     return this->data_->val_;
00262   }
00263 
00264 
00265 
00266 # endif // ! MLN_INCLUDE_ONLY
00267 
00268 } // end of namespace mln
00269 
00270 
00271 #endif // ! MLN_CORE_IMAGE_FLAT_IMAGE_HH
 All Classes Namespaces Functions Variables Typedefs Enumerator