00001 // Copyright (C) 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_LABEL_USED_HH 00027 # define MLN_ACCU_LABEL_USED_HH 00028 00032 00033 # include <mln/accu/internal/base.hh> 00034 # include <mln/core/concept/meta_accumulator.hh> 00035 # include <mln/math/max.hh> 00036 # include <mln/fun/i2v/array.hh> 00037 00038 00039 namespace mln 00040 { 00041 00042 namespace accu 00043 { 00044 00049 // 00050 template <typename L> 00051 struct label_used : public mln::accu::internal::base< const fun::i2v::array<bool>& , label_used<L> > 00052 { 00053 typedef L argument; 00054 00055 label_used(); 00056 00058 void init(); 00059 00062 void take(const argument&); 00063 void take(const label_used<L>& other); 00065 00067 const fun::i2v::array<bool>& to_result() const; 00068 00071 bool is_valid() const; 00072 00073 protected: 00075 fun::i2v::array<bool> label_used_; 00076 }; 00077 00078 00079 namespace meta 00080 { 00081 00083 struct label_used : public Meta_Accumulator< label_used > 00084 { 00085 template <typename L> 00086 struct with 00087 { 00088 typedef accu::label_used<L> ret; 00089 }; 00090 }; 00091 00092 } // end of namespace mln::accu::meta 00093 00094 00095 00096 # ifndef MLN_INCLUDE_ONLY 00097 00098 template <typename L> 00099 inline 00100 label_used<L>::label_used() 00101 { 00102 init(); 00103 } 00104 00105 template <typename L> 00106 inline 00107 void 00108 label_used<L>::init() 00109 { 00110 label_used_.resize(1, true); 00111 } 00112 00113 template <typename L> 00114 inline 00115 void 00116 label_used<L>::take(const argument& l) 00117 { 00118 if (label_used_.size() <= l) 00119 label_used_.resize(l.next(), false); 00120 00121 label_used_(l) = true; 00122 } 00123 00124 template <typename L> 00125 inline 00126 void 00127 label_used<L>::take(const label_used<L>& other) 00128 { 00129 unsigned 00130 max_size = mln::math::max(other.to_result().size(), label_used_.size()); 00131 00132 label_used_.resize(max_size, false); 00133 for (unsigned i = 1; i < label_used_.size(); ++i) 00134 label_used_(i) = label_used_(i) || other.to_result()(i); 00135 } 00136 00137 template <typename L> 00138 inline 00139 const fun::i2v::array<bool>& 00140 label_used<L>::to_result() const 00141 { 00142 return label_used_; 00143 } 00144 00145 template <typename L> 00146 inline 00147 bool 00148 label_used<L>::is_valid() const 00149 { 00150 return true; 00151 } 00152 00153 # endif // ! MLN_INCLUDE_ONLY 00154 00155 } // end of namespace mln::accu 00156 00157 } // end of namespace mln 00158 00159 00160 #endif // ! MLN_ACCU_LABEL_USED_HH