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