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

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

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