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

card.hh

00001 // Copyright (C) 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_CARD_HH
00027 # define MLN_MORPHO_ATTRIBUTE_CARD_HH
00028 
00036 
00037 # include <mln/accu/internal/base.hh>
00038 # include <mln/util/pix.hh>
00039 
00040 
00041 namespace mln
00042 {
00043 
00044 
00045   // Forward declaration.
00046 
00047   namespace morpho {
00048     namespace attribute {
00049       template <typename I> class card;
00050     }
00051   }
00052 
00053 
00054   // Traits.
00055 
00056   namespace trait
00057   {
00058 
00059     template <typename I>
00060     struct accumulator_< morpho::attribute::card<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_none when_pix;
00066     };
00067 
00068   } // end of namespace mln::trait
00069 
00070 
00071   namespace morpho
00072   {
00073 
00074     namespace attribute
00075     {
00076 
00078 
00079       template <typename I>
00080       class card : public mln::accu::internal::base< unsigned, card<I> >
00081       {
00082         typedef mln::accu::internal::base< unsigned, card<I> > super_;
00083       public:
00084 
00085         typedef mln_psite(I) argument;
00086 
00087         card();
00088 
00091         void init();
00092 
00093         void take();
00094         void take(const argument& s);
00095         void take(const util::pix<I>& px);
00096         void take(const card<I>& other);
00097 
00098         void take_as_init(); // Extra version.
00099         void take_as_init_(const util::pix<I>& px); // Overload.
00101 
00103         unsigned to_result() const;
00104 
00107         bool is_valid() const;
00108 
00109       protected:
00111         unsigned c_;
00112       };
00113 
00114 
00115 
00116 # ifndef MLN_INCLUDE_ONLY
00117 
00118       template <typename I>
00119       inline
00120       card<I>::card()
00121       {
00122         init();
00123       }
00124 
00125       template <typename I>
00126       inline
00127       void
00128       card<I>::init()
00129       {
00130         c_ = 0;
00131       }
00132 
00133       // take.
00134 
00135       template <typename I>
00136       inline
00137       void
00138       card<I>::take()
00139       {
00140         ++c_;
00141       }
00142 
00143       template <typename I>
00144       inline
00145       void
00146       card<I>::take(const argument&)
00147       {
00148         take();
00149       }
00150 
00151       template <typename I>
00152       inline
00153       void
00154       card<I>::take(const util::pix<I>&)
00155       {
00156         take();
00157       }
00158 
00159       template <typename I>
00160       inline
00161       void
00162       card<I>::take(const card<I>& other)
00163       {
00164         c_ += other.c_;
00165       }
00166 
00167       // take_as_init.
00168 
00169       template <typename I>
00170       inline
00171       void
00172       card<I>::take_as_init()
00173       {
00174         init();
00175         take();
00176       }
00177 
00178       template <typename I>
00179       inline
00180       void
00181       card<I>::take_as_init_(const util::pix<I>&)
00182       {
00183         this->take_as_init();
00184       }
00185 
00186       template <typename I>
00187       inline
00188       unsigned
00189       card<I>::to_result() const
00190       {
00191         return c_;
00192       }
00193 
00194       template <typename I>
00195       inline
00196       bool
00197       card<I>::is_valid() const
00198       {
00199         return true;
00200       }
00201 
00202 # endif // ! MLN_INCLUDE_ONLY
00203 
00204     } // end of namespace mln::morpho::attribute
00205 
00206   } // end of namespace mln::morpho
00207 
00208 } // end of namespace mln
00209 
00210 
00211 #endif // ! MLN_MORPHO_ATTRIBUTE_CARD_HH

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