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 #include <mln/util/graph.hh>
00027 #include <mln/core/alias/point2d.hh>
00028 #include <mln/core/site_set/p_edges.hh>
00029
00030
00031
00032
00033 template <typename G>
00034 struct my_fun : mln::Function< my_fun<G> >
00035 {
00036 typedef mln::point2d result;
00037
00038 const result& operator()(unsigned v) const
00039 {
00040 static mln::point2d res(0, 0);
00041 res.row() = v;
00042 return res;
00043 }
00044 };
00045
00046
00047 int main()
00048 {
00049 using namespace mln;
00050
00051
00052 util::graph g;
00053 g.add_vertex();
00054 g.add_vertex();
00055 g.add_vertex();
00056 g.add_vertex();
00057 g.add_vertex();
00058 g.add_vertex();
00059 g.add_edge(0, 1);
00060 g.add_edge(0, 2);
00061 g.add_edge(3, 4);
00062 g.add_edge(4, 5);
00063 g.add_edge(5, 4);
00064 g.add_edge(1, 0);
00065 g.add_edge(5, 3);
00066 g.add_edge(2, 1);
00067
00068 typedef p_edges<util::graph, my_fun<util::graph> > p_edges;
00069 p_edges pv(g, my_fun<util::graph>());
00070
00071
00072 {
00073 mln_fwd_piter_(p_edges) p(pv);
00074 unsigned i = 0;
00075 for_all(p)
00076 mln_assertion(p.p_hook_().e().id() == i++);
00077 mln_assertion(i == g.e_nmax());
00078 }
00079
00080
00081 {
00082 mln_bkd_piter_(p_edges) p(pv);
00083 unsigned i = g.e_nmax() - 1;
00084 for_all(p)
00085 mln_assertion(p.p_hook_().e().id() == i--);
00086 mln_assertion(i == mln_max(unsigned));
00087 }
00088
00089 }