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

p_edges.cc

00001 // Copyright (C) 2008, 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 #include <mln/util/graph.hh>
00027 #include <mln/core/alias/point2d.hh>
00028 #include <mln/core/site_set/p_edges.hh>
00029 
00030 
00031 // Function mapping an edge to a specific site.
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   // Create a graph.
00052   util::graph g;
00053   g.add_vertex(); // 0
00054   g.add_vertex(); // 1
00055   g.add_vertex(); // 2
00056   g.add_vertex(); // 3
00057   g.add_vertex(); // 4
00058   g.add_vertex(); // 5
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   // Forward iterator.
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   // Backward iterator.
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 }

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