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 // Forward declaration. 00043 namespace accu { 00044 namespace logic { 00045 struct lor; 00046 } 00047 } 00048 00049 00050 // Traits. 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 } // end of namespace mln::trait 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 } // end of namespace mln::accu::meta::logic 00086 } // end of namespace mln::accu::meta 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 } // end of namespace mln::accu::logic 00191 } // end of namespace mln::accu 00192 } // end of namespace mln 00193 00194 00195 #endif // ! MLN_ACCU_LOGIC_LOR_HH