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_EDGES_HH
00028 # define MLN_CORE_SITE_SET_P_EDGES_HH
00029
00033
00034 # include <mln/core/concept/function.hh>
00035 # include <mln/core/concept/graph.hh>
00036 # include <mln/core/internal/site_set_base.hh>
00037 # include <mln/core/site_set/p_graph_piter.hh>
00038 # include <mln/core/site_set/p_edges_psite.hh>
00039 # include <mln/util/graph.hh>
00040 # include <mln/util/internal/id2element.hh>
00041
00042 # include <mln/metal/equal.hh>
00043
00044
00045 namespace mln
00046 {
00047
00048
00049 template <typename G, typename F> class p_edges;
00050
00051
00052 namespace trait
00053 {
00054 template <typename G, typename F>
00055 struct site_set_< p_edges<G, F> >
00056 {
00057
00058 typedef trait::site_set::nsites::known nsites;
00059 typedef trait::site_set::bbox::unknown bbox;
00060 typedef trait::site_set::contents::fixed contents;
00061 typedef trait::site_set::arity::unique arity;
00062 };
00063 }
00064
00065
00069
00070 template <typename G, typename F = util::internal::id2element<G,util::edge<G> > >
00071 class p_edges
00072 : public internal::site_set_base_< mln_result(F), p_edges<G, F> >
00073 {
00074
00075 typedef p_edges<G, F> self_;
00076 typedef internal::site_set_base_< mln_result(F), self_ > super_;
00077
00078 public:
00079
00081 typedef G graph_t;
00082
00084 typedef F fun_t;
00085
00087 typedef util::edge<G> edge;
00088
00090 typedef util::edge<G> graph_element;
00091
00095 p_edges();
00096
00100 p_edges(const Graph<G>& gr);
00101
00106 p_edges(const Graph<G>& gr, const Function<F>& f);
00107
00113 template <typename F2>
00114 p_edges(const Graph<G>& gr, const Function<F2>& f);
00116
00120 typedef mln_site(super_) element;
00121
00123 typedef p_edges_psite<G, F> psite;
00124
00126 typedef p_graph_piter< self_, mln_edge_fwd_iter(G) > fwd_piter;
00127
00129 typedef p_graph_piter< self_, mln_edge_bkd_iter(G) > bkd_piter;
00130
00132 typedef fwd_piter piter;
00134
00137 unsigned nsites() const;
00138
00140 unsigned nedges() const;
00141
00143 bool is_valid() const;
00145 void invalidate();
00146
00148 bool has(const psite& p) const;
00149
00151 template <typename G2>
00152 bool has(const util::edge<G2>& e) const;
00153
00157
00158
00159 std::size_t memory_size() const;
00160
00164 const G& graph() const;
00166 const F& function() const;
00168
00169 private:
00170
00171 G g_;
00172 F f_;
00173 };
00174
00175
00180 template <typename G, typename F>
00181 bool
00182 operator==(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs);
00183
00184
00189 template <typename G, typename F>
00190 bool
00191 operator<=(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs);
00192
00193 }
00194
00195
00196 # ifndef MLN_INCLUDE_ONLY
00197
00198 namespace mln
00199 {
00200
00201
00202 template <typename G, typename F>
00203 inline
00204 p_edges<G, F>::p_edges()
00205 {
00206 }
00207
00208 template <typename G, typename F>
00209 inline
00210 p_edges<G, F>::p_edges(const Graph<G>& g)
00211 {
00212 typedef util::internal::id2element<G,util::edge<G> > F_REF;
00213 mlc_equal(F, F_REF)::check();
00214
00215 mln_precondition(exact(g).is_valid());
00216 g_ = exact(g);
00217 f_ = util::internal::id2element< G, util::edge<G> >(g);
00218 }
00219
00220 template <typename G, typename F>
00221 inline
00222 p_edges<G, F>::p_edges(const Graph<G>& g, const Function<F>& f)
00223 {
00224 mln_precondition(exact(g).is_valid());
00225 g_ = exact(g);
00226 f_ = exact(f);
00227 }
00228
00229 template <typename G, typename F>
00230 template <typename F2>
00231 inline
00232 p_edges<G, F>::p_edges(const Graph<G>& g, const Function<F2>& f)
00233 {
00234 mln_precondition(exact(g).is_valid());
00235 mlc_converts_to(F2,F)::check();
00236
00237 g_ = exact(g);
00238 convert::from_to(f, f_);
00239 }
00240
00241
00242 template <typename G, typename F>
00243 inline
00244 unsigned
00245 p_edges<G, F>::nsites() const
00246 {
00247 return nedges();
00248 }
00249
00250 template <typename G, typename F>
00251 inline
00252 unsigned
00253 p_edges<G, F>::nedges() const
00254 {
00255 return this->g_.e_nmax();
00256 }
00257
00258 template <typename G, typename F>
00259 inline
00260 bool
00261 p_edges<G, F>::is_valid() const
00262 {
00263 return g_.is_valid();
00264 }
00265
00266 template <typename G, typename F>
00267 inline
00268 void
00269 p_edges<G, F>::invalidate()
00270 {
00271 g_.invalidate();
00272 }
00273
00274 template <typename G, typename F>
00275 inline
00276 bool
00277 p_edges<G, F>::has(const psite& p) const
00278 {
00279 mln_precondition(is_valid());
00280 return has(p.e());
00281 }
00282
00283 template <typename G, typename F>
00284 template <typename G2>
00285 inline
00286 bool
00287 p_edges<G, F>::has(const util::edge<G2>& e) const
00288 {
00289 mln_precondition(is_valid());
00290 return e.graph().is_subgraph_of(g_) && g_.has(e) && e.is_valid();
00291 }
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 template <typename G, typename F>
00304 inline
00305 std::size_t
00306 p_edges<G, F>::memory_size() const
00307 {
00308
00309 abort();
00310 return 0;
00311 }
00312
00313 template <typename G, typename F>
00314 inline
00315 const G&
00316 p_edges<G, F>::graph() const
00317 {
00318 mln_precondition(is_valid());
00319 return g_;
00320 }
00321
00322 template <typename G, typename F>
00323 inline
00324 const F&
00325 p_edges<G, F>::function() const
00326 {
00327 return f_;
00328 }
00329
00330 template <typename G, typename F>
00331 bool
00332 operator==(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs)
00333 {
00334 return lhs.graph() == rhs.graph();
00335 }
00336
00337 template <typename G, typename F>
00338 bool
00339 operator<=(const p_edges<G, F>& lhs, const p_edges<G, F>& rhs)
00340 {
00341 return lhs == rhs;
00342 }
00343
00344 }
00345
00346 # endif // ! MLN_INCLUDE_ONLY
00347
00348 #endif // ! MLN_CORE_SITE_SET_P_EDGES_HH