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

rank_bool.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_ACCU_STAT_RANK_BOOL_HH
00027 # define MLN_ACCU_STAT_RANK_BOOL_HH
00028 
00037 
00038 # include <mln/accu/internal/base.hh>
00039 
00040 
00041 namespace mln
00042 {
00043 
00044   namespace accu
00045   {
00046 
00047     namespace stat
00048     {
00049 
00050       // Forward declaration.
00051       template <typename T> struct rank;
00052 
00056       //
00057       template <>
00058       struct rank<bool> : public mln::accu::internal::base< bool, rank<bool> >
00059       {
00060         typedef bool argument;
00061 
00062         rank();
00063         rank(unsigned k);
00064 
00067         void init();
00068         void take_as_init_(const argument& t);
00069         void take(const argument& t);
00070         void take(const rank<bool>& other);
00071         void untake(const argument& t);
00072         void untake(const rank<bool>& other);
00074 
00076         bool to_result() const;
00077 
00080         bool is_valid() const;
00081 
00082       protected:
00083         unsigned nfalse_;
00084         unsigned k_; // 0 <= k_
00085       };
00086 
00087 
00088 # ifndef MLN_INCLUDE_ONLY
00089 
00090       inline
00091       rank<bool>::rank()
00092       {
00093         init();
00094       }
00095 
00096       inline
00097       rank<bool>::rank(unsigned k)
00098         : k_(k)
00099       {
00100         init();
00101       }
00102 
00103       inline
00104       void
00105       rank<bool>::init()
00106       {
00107         nfalse_ = 0;
00108       }
00109 
00110       inline
00111       void rank<bool>::take_as_init_(const argument& t)
00112       {
00113         nfalse_ = t ? 0 : 1;
00114       }
00115 
00116       inline
00117       void rank<bool>::take(const argument& t)
00118       {
00119         if (t == false)
00120           ++nfalse_;
00121       }
00122 
00123       inline
00124       void rank<bool>::untake(const argument& t)
00125       {
00126         if (t == false)
00127           {
00128             mln_assertion(nfalse_ > 0);
00129             --nfalse_;
00130           }
00131       }
00132 
00133       inline
00134       void
00135       rank<bool>::take(const rank<bool>& other)
00136       {
00137         nfalse_ += other.nfalse_;
00138       }
00139 
00140       inline
00141       void
00142       rank<bool>::untake(const rank<bool>& other)
00143       {
00144         mln_precondition(other.nfalse_ <= nfalse_);
00145         nfalse_ -= other.nfalse_;
00146       }
00147 
00148       inline
00149       bool
00150       rank<bool>::to_result() const
00151       {
00152         return k_ >= nfalse_;
00153       }
00154 
00155       inline
00156       bool
00157       rank<bool>::is_valid() const
00158       {
00159         return true;
00160       }
00161 
00162 # endif // ! MLN_INCLUDE_ONLY
00163 
00164     } // end of namespace mln::accu::stat
00165 
00166   } // end of namespace mln::accu
00167 
00168 } // end of namespace mln
00169 
00170 
00171 #endif // ! MLN_ACCU_STAT_RANK_BOOL_HH

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