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 #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
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_;
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 }
00165
00166 }
00167
00168 }
00169
00170
00171 #endif // ! MLN_ACCU_STAT_RANK_BOOL_HH