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

count_adjacent_vertices.hh

00001 // Copyright (C) 2007, 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 #ifndef MLN_MORPHO_ATTRIBUTE_COUNT_ADJACENT_VERTICES_HH
00027 # define MLN_MORPHO_ATTRIBUTE_COUNT_ADJACENT_VERTICES_HH
00028 
00035 
00036 # include <mln/pw/internal/image_base.hh>
00037 # include <mln/accu/internal/base.hh>
00038 # include <mln/pw/image.hh>
00039 # include <mln/util/pix.hh>
00040 # include <mln/util/graph_ids.hh>
00041 
00042 namespace mln
00043 {
00044 
00045   // Forward declaration.
00046   namespace morpho {
00047     namespace attribute {
00048       template <typename I>
00049       struct count_adjacent_vertices;
00050     }
00051   }
00052 
00053 
00054   // Traits.
00055 
00056   namespace trait
00057   {
00058 
00059     template <typename I>
00060     struct accumulator_< morpho::attribute::count_adjacent_vertices<I> >
00061     {
00062       typedef accumulator::has_untake::no    has_untake;
00063       typedef accumulator::has_set_value::no has_set_value;
00064       typedef accumulator::has_stop::no      has_stop;
00065       typedef accumulator::when_pix::use_p   when_pix;
00066     };
00067 
00068   } // end of namespace mln::trait
00069 
00070 
00071   namespace morpho
00072   {
00073 
00074     namespace attribute
00075     {
00076 
00081       //
00082       template <typename I>
00083       struct count_adjacent_vertices
00084         : public accu::internal::base< unsigned ,
00085                                        count_adjacent_vertices<I> >
00086       {
00087         typedef mln_psite(I)    argument;
00088 
00089         count_adjacent_vertices();
00090 
00093         void init();
00094 
00095         void take(const argument& px);
00096         void take(const count_adjacent_vertices<I>& other);
00097 
00098         void take_as_init_(const argument& px);
00100 
00102         unsigned to_result() const;
00103 
00105         bool is_valid() const;
00106 
00107 
00108       protected:
00110         void update_ ();
00111 
00113         unsigned count__;
00115         std::set<util::vertex_id_t> vertices_;
00116       };
00117 
00118 
00119 
00120 # ifndef MLN_INCLUDE_ONLY
00121 
00122       template <typename I>
00123       inline
00124       count_adjacent_vertices<I>::count_adjacent_vertices()
00125       {
00126         init();
00127       }
00128 
00129       template <typename I>
00130       inline
00131       void
00132       count_adjacent_vertices<I>::init()
00133       {
00134         vertices_.clear();
00135         update_();
00136       }
00137 
00138       template <typename I>
00139       inline
00140       void
00141       count_adjacent_vertices<I>::take(const argument& p)
00142       {
00143         vertices_.insert(p.v1());
00144         vertices_.insert(p.v2());
00145         update_();
00146       }
00147 
00148       template <typename I>
00149       inline
00150       void
00151       count_adjacent_vertices<I>::take(const count_adjacent_vertices<I>& other)
00152       {
00153         vertices_.insert (other.vertices_.begin(), other.vertices_.end());
00154         update_();
00155       }
00156 
00157       template <typename I>
00158       inline
00159       void
00160       count_adjacent_vertices<I>::take_as_init_(const argument& px)
00161       {
00162         vertices_.clear();
00163         take(px);
00164       }
00165 
00166       template <typename I>
00167       inline
00168       unsigned
00169       count_adjacent_vertices<I>::to_result() const
00170       {
00171         return count__;
00172       }
00173 
00174       template <typename I>
00175       inline
00176       void
00177       count_adjacent_vertices<I>::update_()
00178       {
00179         count__ = vertices_.size();
00180       }
00181 
00182       template <typename I>
00183       inline
00184       bool
00185       count_adjacent_vertices<I>::is_valid() const
00186       {
00187         return true;
00188       }
00189 
00190 
00191 # endif // ! MLN_INCLUDE_ONLY
00192 
00193     } // end of namespace mln::morpho::attribute
00194 
00195   } // end of namespace mln::morpho
00196 
00197 } // end of namespace mln
00198 
00199 #endif // ! MLN_MORPHO_ATTRIBUTE_COUNT_ADJACENT_VERTICES_HH

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