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

image_base.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_BASE_HH
00027 # define MLN_CORE_INTERNAL_IMAGE_BASE_HH
00028 
00034 
00035 # include <mln/core/concept/image.hh>
00036 # include <mln/core/grids.hh>
00037 # include <mln/core/trait/qlf_value.hh>
00038 # include <mln/core/internal/check/image_all.hh>
00039 # include <mln/core/internal/data.hh>
00040 # include <mln/core/internal/morpher_lvalue.hh>
00041 # include <mln/util/tracked_ptr.hh>
00042 # include <mln/value/set.hh>
00043 # include <mln/value/super_value.hh>
00044 
00045 //              image_base
00046 //                   ^
00047 //                   |
00048 //       ---------------------------
00049 //      |                           |
00050 // image_primary               image_morpher
00051 //      ^                            ^
00052 //      |                            |
00053 //      |                    -----------------------------------------
00054 //      |                   |                    |                    |
00055 // pw_image_base    image_domain_morpher  image_value_morpher   image_identity
00056 
00057 
00058 namespace mln
00059 {
00060 
00061   namespace internal
00062   {
00063 
00064 
00065     template <typename E>
00066     struct image_checked_
00067       :
00068       public check::image_all_<E>,
00069       public Image<E>
00070     {
00071     };
00072 
00073 
00074 
00079     //
00080     template <typename T, typename S, typename E>
00081     struct image_base
00082       :
00083       public image_checked_<E>
00084 
00085     {
00087       typedef T value;
00088 
00090       typedef mln::value::set<T> t_eligible_values_set;
00091 
00092       // Return the set of the image eligigle values
00093       const t_eligible_values_set& values_eligible() const;
00094 
00096       typedef mln::value::set<
00097         typename mln::value::super_value<T>::ret > t_values_space;
00098 
00100       const t_values_space& values_space() const;
00101 
00102 
00104       typedef S domain_t;
00105 
00107       typedef mln_psite(S) psite;
00108 
00110       typedef mln_site(S) site;
00111 
00112 
00114       typedef mln_fwd_piter(S) fwd_piter;
00115 
00117       typedef mln_bkd_piter(S) bkd_piter;
00118 
00119 
00122       typedef fwd_piter        piter;
00123 
00124 
00125 
00127       bool has(const psite& p) const;
00128 
00130       std::size_t nsites() const;
00131 
00133       bool is_valid() const;
00134 
00135       // FIXME: Add void init_data(..);
00136 
00137 
00139       image_base& operator=(const image_base& rhs);
00140 
00142       image_base(const image_base& rhs);
00143 
00147       const void* id_() const;
00148 
00149 
00151       void destroy();
00152 
00154       const util::tracked_ptr< internal::data<E> >& hook_data_() const;
00155 
00156     protected:
00157 
00159       image_base();
00160 
00161       // Internal data, sharable by several images.
00162       util::tracked_ptr< internal::data<E> > data_;
00163     };
00164 
00165 
00166 
00167 # ifndef MLN_INCLUDE_ONLY
00168 
00169     template <typename T, typename S, typename E>
00170     inline
00171     image_base<T, S, E>::image_base()
00172     {
00173     }
00174 
00175     template <typename T, typename S, typename E>
00176     inline
00177     image_base<T, S, E>::image_base(const image_base& rhs)
00178       : image_checked_<E>()
00179     {
00180       mln_precondition(exact(rhs).is_valid()); // FIXME: Is-it too restrictive?
00181       this->data_ = rhs.data_;
00182     }
00183 
00184     template <typename T, typename S, typename E>
00185     inline
00186     image_base<T, S, E>&
00187     image_base<T, S, E>::operator=(const image_base<T, S, E>& rhs)
00188     {
00189       mln_precondition(exact(rhs).is_valid()); // FIXME: Is-it too restrictive?
00190       if (& rhs == this) // || ! exact(rhs).is_valid())
00191         return *this;
00192       this->data_ = rhs.data_;
00193       return *this;
00194     }
00195 
00196     template <typename T, typename S, typename E>
00197     inline
00198     const void*
00199     image_base<T, S, E>::id_() const
00200     {
00201       return data_.ptr_;
00202     }
00203 
00204     template <typename T, typename S, typename E>
00205     inline
00206     bool
00207     image_base<T, S, E>::is_valid() const
00208     {
00209       return data_ != 0;
00210     }
00211 
00212     template <typename T, typename S, typename E>
00213     inline
00214     bool
00215     image_base<T, S, E>::has(const psite& p) const
00216     {
00217       mln_precondition(exact(this)->is_valid());
00218       return exact(this)->domain().has(p);
00219     }
00220 
00221     template <typename T, typename S, typename E>
00222     inline
00223     std::size_t
00224     image_base<T, S, E>::nsites() const
00225     {
00226       mlc_equal(mln_trait_site_set_nsites(S),
00227                 mln::trait::site_set::nsites::known)::check();
00228       mln_precondition(exact(this)->is_valid());
00229       return exact(this)->domain().nsites();
00230     }
00231 
00232     template <typename T, typename S, typename E>
00233     inline
00234     const typename image_base<T, S, E>::t_eligible_values_set&
00235     image_base<T, S, E>::values_eligible() const
00236     {
00237       return t_eligible_values_set::the();
00238     }
00239 
00240     template <typename T, typename S, typename E>
00241     inline
00242     const typename image_base<T, S, E>::t_values_space&
00243     image_base<T, S, E>::values_space() const
00244     {
00245       return t_values_space::the();
00246     }
00247 
00248     template <typename T, typename S, typename E>
00249     inline
00250     void
00251     image_base<T, S, E>::destroy()
00252     {
00253       data_.clean_();
00254     }
00255 
00256     template <typename T, typename S, typename E>
00257     inline
00258     const util::tracked_ptr< internal::data<E> >&
00259     image_base<T, S, E>::hook_data_() const
00260     {
00261       return data_;
00262     }
00263 
00264 # endif // ! MLN_INCLUDE_ONLY
00265 
00266   } // end of namespace mln::internal
00267 
00268 } // end of namespace mln
00269 
00270 
00271 #endif // ! MLN_CORE_INTERNAL_IMAGE_BASE_HH

Generated on Thu Sep 8 2011 18:31:59 for Milena (Olena) by  doxygen 1.7.1