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_LOGIC_LAND_HH
00027 # define MLN_ACCU_LOGIC_LAND_HH
00028
00034
00035 # include <mln/core/concept/meta_accumulator.hh>
00036 # include <mln/accu/internal/base.hh>
00037
00038
00039 namespace mln
00040 {
00041
00042
00043 namespace accu {
00044 namespace logic {
00045 struct land;
00046 }
00047 }
00048
00049
00050
00051
00052 namespace trait
00053 {
00054
00055 template <>
00056 struct accumulator_< accu::logic::land >
00057 {
00058 typedef accumulator::has_untake::yes has_untake;
00059 typedef accumulator::has_set_value::no has_set_value;
00060 typedef accumulator::has_stop::no has_stop;
00061 typedef accumulator::when_pix::use_v when_pix;
00062 };
00063
00064 }
00065
00066
00067 namespace accu
00068 {
00069
00070 namespace meta
00071 {
00072 namespace logic
00073 {
00074
00076 struct land : public Meta_Accumulator< land >
00077 {
00078 template <typename T>
00079 struct with
00080 {
00081 typedef accu::logic::land ret;
00082 };
00083 };
00084
00085 }
00086 }
00087
00088
00089 namespace logic
00090 {
00091
00095
00096 struct land : public mln::accu::internal::base< bool, land >
00097 {
00098 typedef bool argument;
00099
00100 land();
00101
00104 void init();
00105 void take_as_init_(const argument& t);
00106
00107 void take(const argument& t);
00108 void take(const land& other);
00109
00110 void untake(const argument& t);
00111 void untake(const land& other);
00113
00115 bool to_result() const;
00116
00119 bool is_valid() const;
00120
00121 protected:
00122 unsigned nfalse_;
00123 };
00124
00125
00126 # ifndef MLN_INCLUDE_ONLY
00127
00128 inline
00129 land::land()
00130 {
00131 init();
00132 }
00133
00134 inline
00135 void
00136 land::init()
00137 {
00138 nfalse_ = 0;
00139 }
00140
00141 inline
00142 void land::take_as_init_(const argument& t)
00143 {
00144 nfalse_ = t ? 0 : 1;
00145 }
00146
00147 inline
00148 void land::take(const argument& t)
00149 {
00150 if (t == false)
00151 ++nfalse_;
00152 }
00153
00154 inline
00155 void
00156 land::take(const land& other)
00157 {
00158 nfalse_ += other.nfalse_;
00159 }
00160
00161 inline
00162 void land::untake(const argument& t)
00163 {
00164 if (t == false)
00165 --nfalse_;
00166 }
00167
00168 inline
00169 void
00170 land::untake(const land& other)
00171 {
00172 mln_precondition(other.nfalse_ <= nfalse_);
00173 nfalse_ -= other.nfalse_;
00174 }
00175
00176 inline
00177 bool
00178 land::to_result() const
00179 {
00180 return nfalse_ == 0;
00181 }
00182
00183 inline
00184 bool
00185 land::is_valid() const
00186 {
00187 return true;
00188 }
00189
00190 # endif // ! MLN_INCLUDE_ONLY
00191
00192 }
00193 }
00194 }
00195
00196 #endif // ! MLN_ACCU_LOGIC_LAND_HH