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

lor.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_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   namespace accu
00043   {
00044 
00045     namespace logic
00046     {
00047       // Forward declaration.
00048       struct lor;
00049     }
00050 
00051     namespace meta
00052     {
00053 
00054       namespace logic
00055       {
00057         struct lor : public Meta_Accumulator< lor >
00058         {
00059           template <typename T>
00060           struct with
00061           {
00062             typedef accu::logic::lor ret;
00063           };
00064         };
00065 
00066       } // end of namespace mln::accu::meta::logic
00067     } // end of namespace mln::accu::meta
00068 
00069     namespace logic
00070     {
00071 
00075     //
00076     struct lor : public mln::accu::internal::base< bool, lor >
00077     {
00078       typedef bool argument;
00079 
00080       lor();
00081 
00084       void init();
00085       void take_as_init_(const argument& t);
00086 
00087       void take(const argument& t);
00088       void take(const lor& other);
00089 
00090       void untake(const argument& t);
00091       void untake(const lor& other);
00093 
00095       bool to_result() const;
00096 
00099       bool is_valid() const;
00100 
00101     protected:
00102       unsigned ntrue_;
00103     };
00104 
00105 # ifndef MLN_INCLUDE_ONLY
00106 
00107     inline
00108     lor::lor()
00109     {
00110       init();
00111     }
00112 
00113     inline
00114     void
00115     lor::init()
00116     {
00117       ntrue_ = 0;
00118     }
00119 
00120     inline
00121     void lor::take_as_init_(const argument& t)
00122     {
00123       ntrue_ = t ? 1 : 0;
00124     }
00125 
00126     inline
00127     void lor::take(const argument& t)
00128     {
00129       if (t == true)
00130         ++ntrue_;
00131     }
00132 
00133     inline
00134     void
00135     lor::take(const lor& other)
00136     {
00137       ntrue_ += other.ntrue_;
00138     }
00139 
00140     inline
00141     void lor::untake(const argument& t)
00142     {
00143       if (t == true)
00144         --ntrue_;
00145     }
00146 
00147     inline
00148     void
00149     lor::untake(const lor& other)
00150     {
00151       mln_precondition(other.ntrue_ <= ntrue_);
00152       ntrue_ -= other.ntrue_;
00153     }
00154 
00155     inline
00156     bool
00157     lor::to_result() const
00158     {
00159       return ntrue_ != 0;
00160     }
00161 
00162     inline
00163     bool
00164     lor::is_valid() const
00165     {
00166       return true;
00167     }
00168 
00169 # endif // ! MLN_INCLUDE_ONLY
00170 
00171     } // end of namespace mln::accu::logic
00172   } // end of namespace mln::accu
00173 } // end of namespace mln
00174 
00175 
00176 #endif // ! MLN_ACCU_LOGIC_LOR_HH

Generated on Thu Sep 8 2011 18:32:04 for Milena (Olena) by  doxygen 1.7.1