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_LOR_HH
00027 # define MLN_ACCU_LOGIC_LOR_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 lor;
00046     }
00047   }
00048 
00049 
00050   
00051 
00052   namespace trait
00053   {
00054 
00055     template <>
00056     struct accumulator_< accu::logic::lor >
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 
00073       namespace logic
00074       {
00076         struct lor : public Meta_Accumulator< lor >
00077         {
00078           template <typename T>
00079           struct with
00080           {
00081             typedef accu::logic::lor ret;
00082           };
00083         };
00084 
00085       } 
00086     } 
00087 
00088     namespace logic
00089     {
00090 
00094     
00095     struct lor : public mln::accu::internal::base< bool, lor >
00096     {
00097       typedef bool argument;
00098 
00099       lor();
00100 
00103       void init();
00104       void take_as_init_(const argument& t);
00105 
00106       void take(const argument& t);
00107       void take(const lor& other);
00108 
00109       void untake(const argument& t);
00110       void untake(const lor& other);
00112 
00114       bool to_result() const;
00115 
00118       bool is_valid() const;
00119 
00120     protected:
00121       unsigned ntrue_;
00122     };
00123 
00124 # ifndef MLN_INCLUDE_ONLY
00125 
00126     inline
00127     lor::lor()
00128     {
00129       init();
00130     }
00131 
00132     inline
00133     void
00134     lor::init()
00135     {
00136       ntrue_ = 0;
00137     }
00138 
00139     inline
00140     void lor::take_as_init_(const argument& t)
00141     {
00142       ntrue_ = t ? 1 : 0;
00143     }
00144 
00145     inline
00146     void lor::take(const argument& t)
00147     {
00148       if (t == true)
00149         ++ntrue_;
00150     }
00151 
00152     inline
00153     void
00154     lor::take(const lor& other)
00155     {
00156       ntrue_ += other.ntrue_;
00157     }
00158 
00159     inline
00160     void lor::untake(const argument& t)
00161     {
00162       if (t == true)
00163         --ntrue_;
00164     }
00165 
00166     inline
00167     void
00168     lor::untake(const lor& other)
00169     {
00170       mln_precondition(other.ntrue_ <= ntrue_);
00171       ntrue_ -= other.ntrue_;
00172     }
00173 
00174     inline
00175     bool
00176     lor::to_result() const
00177     {
00178       return ntrue_ != 0;
00179     }
00180 
00181     inline
00182     bool
00183     lor::is_valid() const
00184     {
00185       return true;
00186     }
00187 
00188 # endif // ! MLN_INCLUDE_ONLY
00189 
00190     } 
00191   } 
00192 } 
00193 
00194 
00195 #endif // ! MLN_ACCU_LOGIC_LOR_HH