00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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 }
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
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 }
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