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

p_transformed.hh

00001 // Copyright (C) 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_SITE_SET_P_TRANSFORMED_HH
00027 # define MLN_CORE_SITE_SET_P_TRANSFORMED_HH
00028 
00033 
00034 # include <mln/core/internal/site_set_base.hh>
00035 # include <mln/core/concept/function.hh>
00036 # include <mln/convert/from_to.hh>
00037 
00038 namespace mln
00039 {
00040 
00041   // Forward declarations.
00042   template <typename S, typename F> struct p_transformed;
00043   template <typename Pi, typename S, typename F> struct p_transformed_piter;
00044 
00045 
00046   namespace trait
00047   {
00048 
00049     template <typename S, typename F>
00050     struct site_set_< p_transformed<S,F> >
00051     {
00052       typedef trait::site_set::nsites::unknown nsites;
00053       typedef trait::site_set::bbox::unknown   bbox;
00054       typedef trait::site_set::contents::fixed contents;
00055       typedef trait::site_set::arity::multiple arity;
00056     };
00057 
00058   } // end of namespace trait
00059 
00060 
00067   //
00068   template <typename S, typename F>
00069   p_transformed<S, F>
00070   ptransform(const Site_Set<S>& s, const Function_v2v<F>& f);
00071 
00072 
00073 
00080   //
00081   template <typename S, typename F>
00082   class p_transformed
00083     : public internal::site_set_base_< mln_psite(S), p_transformed<S,F> >,
00084       private mlc_converts_to(mln_result(F), mln_psite(S))::check_t
00085   {
00086     typedef p_transformed<S,F> self_;
00087     typedef internal::site_set_base_<mln_result(F), self_> super_;
00088   public:
00089 
00091     typedef mln_element(S) element;
00092 
00093 
00095     typedef mln_psite(S) psite;
00096 
00098     typedef p_transformed_piter<mln_fwd_piter(S), S, F> fwd_piter;
00099 
00101     typedef p_transformed_piter<mln_bkd_piter(S), S, F> bkd_piter;
00102 
00104     typedef fwd_piter piter;
00105 
00106 
00108     p_transformed(const S& s, const F& f);
00109 
00111     p_transformed();
00112 
00113 
00115     bool is_valid() const;
00116 
00117 
00119     bool has(const psite& p) const;
00120 
00121 
00123     std::size_t memory_size() const;
00124 
00126     const S& primary_set() const;
00127 
00129     const F& function() const;
00130 
00131   protected:
00132 
00133     S s_;
00134     F f_;
00135   };
00136 
00137 
00138 
00139 # ifndef MLN_INCLUDE_ONLY
00140 
00141 
00142   template <typename S, typename F>
00143   inline
00144   p_transformed<S, F>
00145   ptransform(const Site_Set<S>& s, const Function_v2v<F>& f)
00146   {
00147     mlc_equal(mln_result(F), mln_psite(S))::check();
00148     p_transformed<S, F> tmp(exact(s), exact(f));
00149     return tmp;
00150   }
00151 
00152 
00153   // p_transformed<S,F>
00154 
00155   template <typename S, typename F>
00156   inline
00157   p_transformed<S,F>::p_transformed()
00158   {
00159   }
00160 
00161   template <typename S, typename F>
00162   inline
00163   p_transformed<S,F>::p_transformed(const S& s, const F& f)
00164     : s_(s),
00165       f_(f)
00166   {
00167   }
00168 
00169   template <typename S, typename F>
00170   inline
00171   bool
00172   p_transformed<S,F>::has(const psite& p) const
00173   {
00174     mln_argument(F) arg;
00175     convert::from_to(p, arg);
00176     return s_.has(f_.inverse(arg));
00177   }
00178 
00179   template <typename S, typename F>
00180   inline
00181   bool
00182   p_transformed<S,F>::is_valid() const
00183   {
00184     return s_.is_valid();
00185   }
00186 
00187   template <typename S, typename F>
00188   inline
00189   std::size_t
00190   p_transformed<S,F>::memory_size() const
00191   {
00192     return s_.memory_size() + sizeof(f_);
00193   }
00194 
00195   template <typename S, typename F>
00196   inline
00197   const S&
00198   p_transformed<S,F>::primary_set() const
00199   {
00200     return s_;
00201   }
00202 
00203   template <typename S, typename F>
00204   inline
00205   const F&
00206   p_transformed<S,F>::function() const
00207   {
00208     return f_;
00209   }
00210 
00211 # endif // ! MLN_INCLUDE_ONLY
00212 
00213 } // end of namespace mln
00214 
00215 
00216 
00217 # include <mln/core/site_set/p_transformed_piter.hh>
00218 
00219 
00220 
00221 #endif // ! MLN_CORE_SITE_SET_P_TRANSFORMED_HH

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